Skip to content

Commit

Permalink
Merge pull request #35 from orange-cloudfoundry/29_add_support_for_da…
Browse files Browse the repository at this point in the history
…shboard_url

Add support for dashboard_url
  • Loading branch information
s-bortolussi authored Jan 27, 2017
2 parents eefaa0d + 11f61d1 commit ff48e25
Show file tree
Hide file tree
Showing 26 changed files with 355 additions and 89 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ among the cloudfoundry installation to register with (among orgs and spaces).
as ```tag1,tag2,tag3```, default is ```[]```)
* SERVICES[{SERVICE_ID}]_REQUIRES (String holding an array-of-strings, multiple requires are separated by comma,
as ```syslog_drain, route_forwarding```, default is ```[]```). A list of permissions that the user would have to give the service, if they provision it. The only permission currently supported is syslog_drain.
* SERVICES[{SERVICE_ID}]_DASHBOARD_URL (String, no default). The URL of a web-based management user interface for the service instance.
* SERVICES[{SERVICE_ID}]_METADATA_DISPLAY_NAME (String, default is SERVICES_ID_NAME). The user-facing name of the service.
* SERVICES[{SERVICE_ID}]_METADATA_IMAGE_URL (String, default is "")
* SERVICES[{SERVICE_ID}]_METADATA_SUPPORT_URL (String, default is "")
Expand All @@ -130,6 +131,7 @@ Multiple plans are supported. Use the following environment variables to configu
* SERVICES[{SERVICE_ID}]\_PLANS\[{PLAN_ID}]_DESCRIPTION (String, default is "Default plan")
* SERVICES[{SERVICE_ID}]\_PLANS\[{PLAN_ID}]_METADATA (String holding a JSON object, default is "{}")
* SERVICES[{SERVICE_ID}]\_PLANS\[{PLAN_ID}]_FREE (String, default is "true")
* SERVICES[{SERVICE_ID}]\_PLANS\[{PLAN_ID}]_DASHBOARD_URL (String, no default). The URL of a web-based management user interface for the service instance.

A number of catalog variables are not configureable, the broker always return the following default value:
* requires: ```[]``` (empty array)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public class Plan {
*/
private String syslogDrainUrl;

/**
* The URL of a web-based management user interface for the service instance. Can be <code>null</code> to indicate
* that a management dashboard is not provided.
*/
private String dashboardUrl;

public Plan() {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.orange.servicebroker.staticcreds.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.json.JsonParser;
import org.springframework.boot.json.JsonParserFactory;
import org.springframework.cloud.servicebroker.model.EmptyListSerializer;
import org.springframework.cloud.servicebroker.model.ServiceDefinitionRequires;

import javax.validation.Valid;
Expand Down Expand Up @@ -65,6 +65,12 @@ public class Service {
*/
private List<String> requires;

/**
* The URL of a web-based management user interface for the service instance. Can be <code>null</code> to indicate
* that a management dashboard is not provided.
*/
private String dashboardUrl;

public Service() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@ToString
@EqualsAndHashCode
@Builder
public class PlanSummary {
public class ServicePlanDetail {

/**
* The URL to which Cloud Foundry should drain logs for the bound application.
Expand All @@ -40,4 +40,9 @@ public class PlanSummary {
@Singular
private Map<String, Object> credentials;

/**
* The URL of a web-based management user interface for the service instance.
*/
private Optional<String> dashboardUrl;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/**
* Created by YSBU7453 on 04/04/2016.
*/
public interface PlanSummaryRepository {
public interface ServicePlanDetailRepository {

Optional<PlanSummary> find(String servicePlanId);
Optional<ServicePlanDetail> find(String servicePlanId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
* Created by YSBU7453 on 03/05/2016.
*/
@Component
public class SpringConfigPlanSummaryRepository implements PlanSummaryRepository {
public class SpringConfigServicePlanDetailRepository implements ServicePlanDetailRepository {

private final CatalogSettings catalog;

@Autowired
public SpringConfigPlanSummaryRepository(CatalogSettings catalogSettings) {
public SpringConfigServicePlanDetailRepository(CatalogSettings catalogSettings) {
this.catalog = catalogSettings;
}


@Override
public Optional<PlanSummary> find(String servicePlanId) {
public Optional<ServicePlanDetail> find(String servicePlanId) {
return catalog.getServices().values()
.stream()
.flatMap(service -> service.getPlans().values().stream()
.filter(plan -> servicePlanId.equals(plan.getId()))
.map(plan -> toPlanSummary(service, plan))
.map(plan -> toServicePlanDetail(service, plan))
)
.findFirst();
}

private PlanSummary toPlanSummary(Service service, Plan plan) {
final PlanSummary.PlanSummaryBuilder builder = PlanSummary.builder();

builder.syslogDrainUrl(plan.getSyslogDrainUrl() != null ? Optional.of(plan.getSyslogDrainUrl()) : Optional.ofNullable(service.getSyslogDrainUrl()));
private ServicePlanDetail toServicePlanDetail(Service service, Plan plan) {
final ServicePlanDetail.ServicePlanDetailBuilder builder = ServicePlanDetail.builder();
builder.syslogDrainUrl(Optional.ofNullable(plan.getSyslogDrainUrl()).map(Optional::of).orElse(Optional.ofNullable(service.getSyslogDrainUrl())));
builder.dashboardUrl(Optional.ofNullable(plan.getDashboardUrl()).map(Optional::of).orElse(Optional.ofNullable(service.getDashboardUrl())));
service.getFullCredentials().map(builder::credentials);
plan.getFullCredentials().forEach(builder::credential);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.orange.servicebroker.staticcreds.service;

import com.orange.servicebroker.staticcreds.domain.PlanSummary;
import com.orange.servicebroker.staticcreds.domain.PlanSummaryRepository;
import com.orange.servicebroker.staticcreds.domain.ServicePlanDetail;
import com.orange.servicebroker.staticcreds.domain.ServicePlanDetailRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,23 +19,23 @@ public class CredsServiceInstanceBindingService implements ServiceInstanceBindin

private static final Logger LOGGER = LoggerFactory.getLogger(CredsServiceInstanceService.class);

private PlanSummaryRepository planSummaryRepository;
private ServicePlanDetailRepository servicePlanDetailRepository;

@Autowired
public CredsServiceInstanceBindingService(PlanSummaryRepository planSummaryRepository) {
this.planSummaryRepository = planSummaryRepository;
public CredsServiceInstanceBindingService(ServicePlanDetailRepository servicePlanDetailRepository) {
this.servicePlanDetailRepository = servicePlanDetailRepository;
}

private static CreateServiceInstanceBindingResponse toResponse(PlanSummary planSummary) {
private static CreateServiceInstanceBindingResponse toResponse(ServicePlanDetail servicePlanDetail) {
return new CreateServiceInstanceAppBindingResponse()
.withCredentials(planSummary.getCredentials())
.withSyslogDrainUrl(planSummary.getSyslogDrainUrl().orElse(null));
.withCredentials(servicePlanDetail.getCredentials())
.withSyslogDrainUrl(servicePlanDetail.getSyslogDrainUrl().orElse(null));
}

@Override
public CreateServiceInstanceBindingResponse createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) {
LOGGER.debug("binding service instance");
final Optional<PlanSummary> planSummary = planSummaryRepository.find(request.getPlanId());
final Optional<ServicePlanDetail> planSummary = servicePlanDetailRepository.find(request.getPlanId());
return planSummary
.map(CredsServiceInstanceBindingService::toResponse)
.orElse(new CreateServiceInstanceAppBindingResponse());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.orange.servicebroker.staticcreds.service;

import com.orange.servicebroker.staticcreds.domain.ServicePlanDetail;
import com.orange.servicebroker.staticcreds.domain.ServicePlanDetailRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.servicebroker.model.*;
Expand All @@ -9,30 +11,42 @@
@Service
public class CredsServiceInstanceService implements ServiceInstanceService {

private static final Logger LOGGER = LoggerFactory.getLogger(CredsServiceInstanceService.class);
private static final Logger LOGGER = LoggerFactory.getLogger(CredsServiceInstanceService.class);

@Override
public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest arg0) {
LOGGER.debug("creating service instance");
return new CreateServiceInstanceResponse();
}
private final ServicePlanDetailRepository repository;

@Override
public DeleteServiceInstanceResponse deleteServiceInstance(DeleteServiceInstanceRequest arg0) {
LOGGER.debug("deleting service instance");
return new DeleteServiceInstanceResponse();
}
public CredsServiceInstanceService(ServicePlanDetailRepository repository) {
this.repository = repository;
}

private static CreateServiceInstanceResponse toResponse(ServicePlanDetail servicePlanDetail) {
return new CreateServiceInstanceResponse()
.withDashboardUrl(servicePlanDetail.getDashboardUrl().orElse(null));
}

@Override
public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request) {
LOGGER.debug("creating service instance");
return repository.find(request.getPlanId())
.map(CredsServiceInstanceService::toResponse)
.orElse(new CreateServiceInstanceResponse());
}

@Override
public DeleteServiceInstanceResponse deleteServiceInstance(DeleteServiceInstanceRequest request) {
LOGGER.debug("deleting service instance");
return new DeleteServiceInstanceResponse();
}

@Override
public GetLastServiceOperationResponse getLastOperation(GetLastServiceOperationRequest arg0) {
//TODO check id -> succeeded or failed
return new GetLastServiceOperationResponse().withOperationState(OperationState.SUCCEEDED);
}

@Override
public UpdateServiceInstanceResponse updateServiceInstance(UpdateServiceInstanceRequest arg0) {
LOGGER.debug("updating service instance");
return new UpdateServiceInstanceResponse();
}

@Override
public UpdateServiceInstanceResponse updateServiceInstance(UpdateServiceInstanceRequest arg0) {
LOGGER.debug("updating service instance");
return new UpdateServiceInstanceResponse();
}
}
12 changes: 4 additions & 8 deletions src/test/java/com/orange/RemoteConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.orange;

import com.orange.servicebroker.staticcreds.domain.PlanSummary;
import com.orange.servicebroker.staticcreds.domain.PlanSummaryRepository;
import com.orange.servicebroker.staticcreds.domain.ServicePlanDetail;
import com.orange.servicebroker.staticcreds.domain.ServicePlanDetailRepository;
import org.fest.assertions.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.servicebroker.model.Catalog;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Map;
import java.util.Optional;

import static org.fest.assertions.Assertions.assertThat;
Expand All @@ -34,7 +30,7 @@ public class RemoteConfigTest {
String serviceApiDirectoryName;

@Autowired
PlanSummaryRepository planSummaryRepository;
ServicePlanDetailRepository servicePlanDetailRepository;

@Autowired
Catalog catalog;
Expand All @@ -49,7 +45,7 @@ public void should_find_a_service_plan() {

//service plan id for plan dev of service API_DIRECTORY, see static-creds-broker.yml

final Optional<PlanSummary> credentials = planSummaryRepository.find(API_DIRECTORY_SERVICE_PLAN_DEV_ID);
final Optional<ServicePlanDetail> credentials = servicePlanDetailRepository.find(API_DIRECTORY_SERVICE_PLAN_DEV_ID);

assertThat(credentials.get().getCredentials()).hasSize(3).includes(entry("HOSTNAME", "http://company.com"),entry("URI", "http://mydev-api.org"), entry("ACCESS_KEY", "devAZERT23456664DFDSFSDFDSF"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package com.orange.servicebroker.staticcreds.domain;

import com.orange.servicebroker.staticcreds.YAML;
import com.orange.servicebroker.staticcreds.stories.formatter.CatalogYAML;
import com.tngtech.jgiven.Stage;
import org.assertj.core.api.Assertions;

Expand All @@ -26,7 +26,7 @@ public class ConfigureSyslogDrainUrlStage extends Stage<ConfigureSyslogDrainUrlS

private CatalogSettings.InvalidSyslogDrainUrlException invalidSyslogDrainUrlException;

public ConfigureSyslogDrainUrlStage paas_ops_configures_catalog(@YAML CatalogSettings catalogSettings) {
public ConfigureSyslogDrainUrlStage paas_ops_configures_catalog(@CatalogYAML CatalogSettings catalogSettings) {
try {
catalogSettings.init();
} catch (CatalogSettings.InvalidSyslogDrainUrlException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package com.orange.servicebroker.staticcreds.domain;

import com.orange.servicebroker.staticcreds.ConfigureCatalog;
import com.orange.servicebroker.staticcreds.stories.tags.ConfigureCatalog;
import com.tngtech.jgiven.junit.SimpleScenarioTest;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.orange.servicebroker.staticcreds.infrastructure;

import com.orange.servicebroker.staticcreds.domain.PlanSummary;
import com.orange.servicebroker.staticcreds.domain.ServicePlanDetail;
import org.junit.Test;

import java.util.Map;
import java.util.Optional;

import static com.orange.servicebroker.staticcreds.infrastructure.CatalogTestFactory.HOSTNAME_PLAN_PROD_VALUE;
Expand All @@ -21,9 +20,9 @@ public void plan_credentials_override_service_credentials() throws Exception {

//GIVEN credentials have been set at service and plan level
//some overlaps
SpringConfigPlanSummaryRepository repository = new SpringConfigPlanSummaryRepository(CatalogTestFactory.newInstance());
SpringConfigServicePlanDetailRepository repository = new SpringConfigServicePlanDetailRepository(CatalogTestFactory.newInstance());

final Optional<PlanSummary> planSummary = repository.find(CatalogTestFactory.SERVICE_PLAN_PROD);
final Optional<ServicePlanDetail> planSummary = repository.find(CatalogTestFactory.SERVICE_PLAN_PROD);

assertThat(planSummary.get().getCredentials()).hasSize(3).includes(entry("HOSTNAME", HOSTNAME_PLAN_PROD_VALUE),entry("URI", "http://myprod-api.org"), entry("ACCESS_KEY", "prod"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

package com.orange.servicebroker.staticcreds.service;

import com.orange.servicebroker.staticcreds.JSON;
import com.orange.servicebroker.staticcreds.YAML;
import com.orange.servicebroker.staticcreds.domain.CatalogSettings;
import com.orange.servicebroker.staticcreds.infrastructure.SpringConfigPlanSummaryRepository;
import com.orange.servicebroker.staticcreds.infrastructure.SpringConfigServicePlanDetailRepository;
import com.orange.servicebroker.staticcreds.stories.formatter.CatalogYAML;
import com.orange.servicebroker.staticcreds.stories.formatter.CreateServiceBindingResponseJSON;
import com.tngtech.jgiven.Stage;
import org.assertj.core.api.Assertions;
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceAppBindingResponse;
Expand All @@ -39,20 +39,13 @@ public CreateLogDrainServiceBindingStage cloud_controller_requests_to_create_a_s
return self();
}

public CreateLogDrainServiceBindingStage syslog_drain_url_set_in_catalog(@YAML CatalogSettings catalog) {
SpringConfigPlanSummaryRepository planSummaryRepository = new SpringConfigPlanSummaryRepository(catalog);
public CreateLogDrainServiceBindingStage syslog_drain_url_set_in_catalog(@CatalogYAML CatalogSettings catalog) {
SpringConfigServicePlanDetailRepository planSummaryRepository = new SpringConfigServicePlanDetailRepository(catalog);
instanceBindingService = new CredsServiceInstanceBindingService(planSummaryRepository);
return self();
}


public CreateLogDrainServiceBindingStage it_should_be_returned_with_syslog_drain_url(String syslogDrainUrl) {
Assertions.assertThat(response).isInstanceOf(CreateServiceInstanceAppBindingResponse.class);
Assertions.assertThat(((CreateServiceInstanceAppBindingResponse) response).getSyslogDrainUrl()).isEqualTo(syslogDrainUrl);
return self();
}

public CreateLogDrainServiceBindingStage it_should_be_returned_with_syslog_drain_url(@JSON CreateServiceInstanceAppBindingResponse expected) {
public CreateLogDrainServiceBindingStage it_should_be_returned_with_syslog_drain_url(@CreateServiceBindingResponseJSON CreateServiceInstanceAppBindingResponse expected) {
Assertions.assertThat(response).isInstanceOf(CreateServiceInstanceAppBindingResponse.class);
Assertions.assertThat(response).isEqualTo(expected);
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

package com.orange.servicebroker.staticcreds.service;

import com.orange.servicebroker.staticcreds.CreateServiceBinding;
import com.orange.servicebroker.staticcreds.domain.CatalogSettings;
import com.orange.servicebroker.staticcreds.domain.Plan;
import com.orange.servicebroker.staticcreds.domain.Service;
import com.orange.servicebroker.staticcreds.stories.tags.CreateServiceBinding;
import com.tngtech.jgiven.junit.SimpleScenarioTest;
import org.junit.Test;
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceAppBindingResponse;
Expand Down Expand Up @@ -83,8 +83,6 @@ private static CatalogSettings catalog_syslog_drain_url_at_service_plan_level_wi
public void create_service_binding_with_static_syslog_drain_url_set_at_service_level() throws Exception {
given().syslog_drain_url_set_in_catalog(catalog_syslog_drain_url_at_service_level_with_requires_field_set());
when().cloud_controller_requests_to_create_a_service_instance_binding_for_plan_id("dev-id");
Map<String, Object> credentials = new HashMap<>();
credentials.put("URI", "http://my-api.org");
then().it_should_be_returned_with_syslog_drain_url(new CreateServiceInstanceAppBindingResponse()
.withSyslogDrainUrl("syslog://log.example.com:5000")
.withCredentials(Collections.unmodifiableMap(Stream.of(
Expand All @@ -96,8 +94,6 @@ public void create_service_binding_with_static_syslog_drain_url_set_at_service_l
public void create_service_binding_with_static_syslog_drain_url_set_at_service_plan_level() throws Exception {
given().syslog_drain_url_set_in_catalog(catalog_syslog_drain_url_at_service_plan_level_with_requires_field_set());
when().cloud_controller_requests_to_create_a_service_instance_binding_for_plan_id("dev-id");
Map<String, Object> credentials = new HashMap<>();
credentials.put("URI", "http://my-api.org");
then().it_should_be_returned_with_syslog_drain_url(new CreateServiceInstanceAppBindingResponse()
.withSyslogDrainUrl("syslog://log.dev.com:5000")
.withCredentials(Collections.unmodifiableMap(Stream.of(
Expand Down
Loading

0 comments on commit ff48e25

Please sign in to comment.