org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition Java Examples

The following examples show how to use org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExampleCatalogConfiguration.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Bean
public Catalog catalog() {
	Plan plan = Plan.builder()
			.id("simple-plan")
			.name("standard")
			.description("A simple plan")
			.free(true)
			.build();

	ServiceDefinition serviceDefinition = ServiceDefinition.builder()
			.id("example-service")
			.name("example")
			.description("A simple example")
			.bindable(true)
			.tags("example", "tags")
			.plans(plan)
			.build();

	return Catalog.builder()
	  .serviceDefinitions(serviceDefinition)
	  .build();
}
 
Example #2
Source File: CatalogConfigTest.java    From ecs-cf-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
public void testEcsBucketPlans() {
    // Service Definition Plans
    ServiceDefinition service = catalog.getServiceDefinitions().get(1);
    List<Plan> ecsBucketPlans = service.getPlans();
    Plan plan0 = ecsBucketPlans.get(0);

    testPlan(plan0, "8e777d49-0a78-4cf4-810a-b5f5173b019d", "5gb",
            "Free Trial", 0.0, "MONTHLY",
            Arrays.asList("Shared object storage", "5 GB Storage",
                    "S3 protocol access"));

    Plan plan1 = ecsBucketPlans.get(1);
    testPlan(plan1, "89d20694-9ab0-4a98-bc6a-868d6d4ecf31", "unlimited",
            "Pay per GB for Month", 0.03, "PER GB PER MONTH",
            Arrays.asList("Shared object storage", "Unlimited Storage",
                    "S3 protocol access"));
}
 
Example #3
Source File: ServiceDefinitionProxy.java    From ecs-cf-service-broker with Apache License 2.0 6 votes vote down vote up
public ServiceDefinition unproxy() {
    List<Plan> realPlans = null;
    if (plans != null)
        realPlans = plans.stream().map(PlanProxy::unproxy)
                .collect(Collectors.toList());

    DashboardClient realDashboardClient = null;
    if (dashboardClient != null)
        realDashboardClient = dashboardClient.unproxy();

    if ((boolean) this.getServiceSettings().getOrDefault("file-accessible", false))
        requires.add("volume_mount");

   return  new ServiceDefinition(id, name, description, bindable, planUpdatable,
            instancesRetrievable, bindingsRetrievable, allowContextUpdates, realPlans, tags, metadata, requires,
            realDashboardClient);
}
 
Example #4
Source File: ServiceCatalogConfiguration.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@Bean
public Catalog catalog() {
	Plan plan = Plan.builder()
			.id("b973fb78-82f3-49ef-9b8b-c1876974a6cd")
			.name("standard")
			.description("A simple book store plan")
			.free(true)
			.build();

	ServiceDefinition serviceDefinition = ServiceDefinition.builder()
			.id("bdb1be2e-360b-495c-8115-d7697f9c6a9e")
			.name("bookstore")
			.description("A simple book store service")
			.bindable(true)
			.tags("book-store", "books", "sample")
			.plans(plan)
			.metadata("displayName", "bookstore")
			.metadata("longDescription", "A simple book store service")
			.metadata("providerDisplayName", "Acme Books")
			.build();

	return Catalog.builder()
			.serviceDefinitions(serviceDefinition)
			.build();
}
 
Example #5
Source File: AppDeploymentUpdateServiceInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private UpdateServiceInstanceRequest buildRequest(String serviceName, String planName,
	Map<String, Object> parameters) {
	return UpdateServiceInstanceRequest
		.builder()
		.serviceInstanceId("service-instance-id")
		.serviceDefinitionId(serviceName + "-id")
		.planId(planName + "-id")
		.serviceDefinition(ServiceDefinition.builder()
			.id(serviceName + "-id")
			.name(serviceName)
			.plans(Plan.builder()
				.id(planName + "-id")
				.name(planName)
				.build())
			.build())
		.plan(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.parameters(parameters == null ? new HashMap<>() : parameters)
		.build();
}
 
Example #6
Source File: AppDeploymentCreateServiceInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private CreateServiceInstanceRequest buildRequest(String serviceName, String planName,
	Map<String, Object> parameters) {
	return CreateServiceInstanceRequest
		.builder()
		.serviceInstanceId("service-instance-id")
		.serviceDefinitionId(serviceName + "-id")
		.planId(planName + "-id")
		.serviceDefinition(ServiceDefinition
			.builder()
			.id(serviceName + "-id")
			.name(serviceName)
			.plans(Plan.builder()
				.id(planName + "-id")
				.name(planName)
				.build())
			.build())
		.plan(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.parameters(parameters == null ? new HashMap<>() : parameters)
		.build();
}
 
Example #7
Source File: AppDeploymentDeleteServiceInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private DeleteServiceInstanceRequest buildRequest(String serviceName, String planName) {
	return DeleteServiceInstanceRequest
		.builder()
		.serviceDefinitionId(serviceName + "-id")
		.serviceInstanceId("service-instance-id")
		.planId(planName + "-id")
		.serviceDefinition(ServiceDefinition.builder()
			.id(serviceName + "-id")
			.name(serviceName)
			.plans(Plan.builder()
				.id(planName + "-id")
				.name(planName)
				.build())
			.build())
		.plan(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.build();
}
 
Example #8
Source File: AbstractBasePathIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Bean
protected CatalogService catalogService() {
	return new CatalogService() {

		@Override
		public Mono<ServiceDefinition> getServiceDefinition(String serviceId) {
			return this.getCatalog()
					.flatMapIterable(Catalog::getServiceDefinitions)
					.filter(service -> serviceId.equals(service.getId()))
					.next();
		}

		@Override
		public Mono<Catalog> getCatalog() {
			return Mono.just(Catalog.builder()
					.serviceDefinitions(ServiceDefinition.builder()
							.id("default-service")
							.plans(Plan.builder()
									.id("default-plan")
									.build())
							.build())
					.build()
			);
		}
	};
}
 
Example #9
Source File: CreateServiceInstanceBindingRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void requestSerializesToJsonExcludingTransients() {
	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("api-info-location")
			.originatingIdentity(PlatformContext.builder()
					.platform("sample-platform").build())
			.asyncAccepted(true)
			.serviceDefinitionId("definition-id")
			.serviceDefinition(ServiceDefinition.builder().build())
			.plan(Plan.builder().build())
			.build();

	DocumentContext json = JsonUtils.toJsonPath(request);

	// Fields present in OSB Json body should be present, but no unspecified optional ones.
	JsonPathAssert.assertThat(json).hasPath("$.service_id").isEqualTo("definition-id");

	// other fields mapped outside of json body (typically http headers or request paths)
	// should be excluded
	JsonPathAssert.assertThat(json).hasMapAtPath("$").hasSize(1);
}
 
Example #10
Source File: CatalogConfiguration.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public Catalog catalog() {
    Plan mailFreePlan = Plan.builder()
        .id("fd81196c-a414-43e5-bd81-1dbb082a3c55")
        .name("mail-free-plan")
        .description("Mail Service Free Plan")
        .free(true)
        .build();

    ServiceDefinition serviceDefinition = ServiceDefinition.builder()
        .id("b92c0ca7-c162-4029-b567-0d92978c0a97")
        .name("mail-service")
        .description("Mail Service")
        .bindable(true)
        .tags("mail", "service")
        .plans(mailFreePlan)
        .build();

    return Catalog.builder()
        .serviceDefinitions(serviceDefinition)
        .build();
}
 
Example #11
Source File: AppDeploymentInstanceWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Mono<Boolean> accept(ServiceDefinition serviceDefinition, Plan plan) {
	return getBackingApplicationsForService(serviceDefinition, plan)
		.map(backingApplications -> !backingApplications.isEmpty())
		.filter(Boolean::booleanValue) // filter out Boolean.False to proceed with flux, see https://stackoverflow.com/questions/49860558/project-reactor-conditional-execution
		.switchIfEmpty(
			getBackingServicesForService(serviceDefinition, plan)
			.map(backingServices -> !backingServices.isEmpty())
			.defaultIfEmpty(false)
		);
}
 
Example #12
Source File: ExampleCatalogService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ServiceDefinition> getServiceDefinition(String serviceId) {
	return Mono.just(ServiceDefinition.builder()
		.id(serviceId)
		.name("example")
		.description("A simple example")
		.bindable(true)
		.tags("example", "tags")
		.plans(getPlan())
		.build());
}
 
Example #13
Source File: CatalogConfigTest.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
public void testEcsBucket() {
    ServiceDefinition ecsBucketService = catalog.getServiceDefinitions()
            .get(1);
    testServiceDefinition(ecsBucketService,
            "f3cbab6a-5172-4ff1-a5c7-72990f0ce2aa", "ecs-bucket",
            "Elastic Cloud S3 Object Storage Bucket", true, true, Collections.emptyList(), null);
}
 
Example #14
Source File: BaseController.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Find the Plan for the Service Definition and Plan ID, or empty if not found.
 *
 * @param serviceDefinition the Service Definition
 * @param planId the plan ID
 * @return the Plan
 */
protected Mono<Plan> getServiceDefinitionPlan(ServiceDefinition serviceDefinition, String planId) {
	return Mono.justOrEmpty(serviceDefinition)
			.flatMap(serviceDef -> Mono.justOrEmpty(serviceDef.getPlans())
					.flatMap(plans -> Flux.fromIterable(plans)
							.filter(plan -> plan.getId().equals(planId))
							.singleOrEmpty()));
}
 
Example #15
Source File: ServiceFixture.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
public static ServiceDefinition getSimpleService() {
	return ServiceDefinition.builder()
			.id("service-one-id")
			.name("Service One")
			.description("Description for Service One")
			.bindable(true)
			.plans(getPlanOne(), getPlanTwo(), getPlanThree())
			.requires(ServiceDefinitionRequires.SERVICE_REQUIRES_SYSLOG_DRAIN.toString(),
					ServiceDefinitionRequires.SERVICE_REQUIRES_ROUTE_FORWARDING.toString())
			.metadata(getMetadata())
			.build();
}
 
Example #16
Source File: DeleteServiceInstanceRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void serializesAccordingToOsbSpecs() {
	Context originatingIdentity = PlatformContext.builder()
			.platform("test-platform")
			.build();

	DeleteServiceInstanceRequest request = DeleteServiceInstanceRequest.builder()
			.serviceInstanceId("service-instance-id")
			.serviceDefinitionId("service-definition-id")
			.planId("plan-id")
			.asyncAccepted(true)
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("https://api.app.local")
			.originatingIdentity(originatingIdentity)
			.requestIdentity("request-id")
			.plan(Plan.builder().build())
			.serviceDefinition(ServiceDefinition.builder().build())
			.build();

	DocumentContext json = JsonUtils.toJsonPath(request);

	//OSB fields
	JsonPathAssert.assertThat(json).hasPath("$.service_id").isEqualTo("service-definition-id");
	JsonPathAssert.assertThat(json).hasPath("$.plan_id").isEqualTo("plan-id");
	JsonPathAssert.assertThat(json).hasPath("$.accepts_incomplete").isEqualTo(true);
	//Other internals should not be polluting the JSON representation
	JsonPathAssert.assertThat(json).hasMapAtPath("$").hasSize(3);
	JsonPathAssert.assertThat(json).hasNoPath("$.request_identity");
}
 
Example #17
Source File: ControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUpControllerRequestTest() {
	initMocks(this);

	plan = Plan.builder()
			.id("plan-id")
			.build();

	serviceDefinition = ServiceDefinition.builder()
			.id("service-definition-id")
			.plans(plan)
			.build();

	lenient().when(catalogService.getServiceDefinition(anyString()))
			.thenReturn(Mono.empty());

	lenient().when(catalogService.getServiceDefinition("service-definition-id"))
			.thenReturn(Mono.just(serviceDefinition));

	identityContext = PlatformContext.builder()
			.platform("test-platform")
			.property("user", "user-id")
			.build();

	requestContext = PlatformContext.builder()
			.platform("test-platform")
			.property("request-property", "value")
			.build();
}
 
Example #18
Source File: CreateServiceInstanceRequest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
private CreateServiceInstanceRequest(String serviceDefinitionId, String serviceInstanceId, String planId,
		ServiceDefinition serviceDefinition, Plan plan, Map<String, Object> parameters, Context context,
		boolean asyncAccepted, String platformInstanceId, String apiInfoLocation, Context originatingIdentity,
		String requestIdentity, String organizationGuid, String spaceGuid, MaintenanceInfo maintenanceInfo) {
	super(parameters, context, asyncAccepted, platformInstanceId, apiInfoLocation, originatingIdentity,
			requestIdentity);
	this.serviceDefinitionId = serviceDefinitionId;
	this.serviceInstanceId = serviceInstanceId;
	this.planId = planId;
	this.serviceDefinition = serviceDefinition;
	this.plan = plan;
	this.organizationGuid = organizationGuid;
	this.spaceGuid = spaceGuid;
	this.maintenanceInfo = maintenanceInfo;
}
 
Example #19
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	controller = new ServiceInstanceBindingController(catalogService, bindingService);
	ServiceDefinition serviceDefinition = mock(ServiceDefinition.class);
	List<Plan> plans = new ArrayList<>();
	plans.add(Plan.builder().id("service-definition-plan-id").build());
	given(serviceDefinition.getPlans()).willReturn(plans);
	given(serviceDefinition.getId()).willReturn("service-definition-id");
	given(catalogService.getServiceDefinition(any())).willReturn(Mono.just(serviceDefinition));
}
 
Example #20
Source File: ServiceInstanceControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	controller = new ServiceInstanceController(catalogService, serviceInstanceService);
	ServiceDefinition serviceDefinition = mock(ServiceDefinition.class);
	List<Plan> plans = new ArrayList<>();
	plans.add(Plan.builder().id("service-definition-plan-id").build());
	given(serviceDefinition.getPlans()).willReturn(plans);
	given(serviceDefinition.getId()).willReturn("service-definition-id");
	given(catalogService.getServiceDefinition(any())).willReturn(Mono.just(serviceDefinition));
}
 
Example #21
Source File: ControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
protected void setupCatalogService(ServiceDefinition serviceDefinition) {
	Mono<ServiceDefinition> serviceDefinitionMono;
	if (serviceDefinition == null) {
		serviceDefinitionMono = Mono.empty();
	}
	else {
		serviceDefinitionMono = Mono.just(serviceDefinition);
	}
	given(catalogService.getServiceDefinition(isNull()))
			.willReturn(Mono.empty());
	given(catalogService.getServiceDefinition(eq(this.serviceDefinition.getId())))
			.willReturn(serviceDefinitionMono);
}
 
Example #22
Source File: DeleteServiceInstanceBindingRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void serializesAccordingToOsbSpecs() {
	Context originatingIdentity = PlatformContext.builder()
			.platform("test-platform")
			.build();

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
			.serviceInstanceId("service-instance-id")
			.serviceDefinitionId("service-definition-id")
			.planId("plan-id")
			.bindingId("binding-id")
			.asyncAccepted(true)
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("https://api.app.local")
			.originatingIdentity(originatingIdentity)
			.requestIdentity("request-id")
			.plan(Plan.builder().build())
			.serviceDefinition(ServiceDefinition.builder().build())
			.build();

	DocumentContext json = JsonUtils.toJsonPath(request);

	// 3 OSB Fields should be present
	JsonPathAssert.assertThat(json).hasPath("$.plan_id").isEqualTo("plan-id");
	JsonPathAssert.assertThat(json).hasPath("$.service_id").isEqualTo("service-definition-id");
	JsonPathAssert.assertThat(json).hasPath("$.accepts_incomplete").isEqualTo(true);


	// fields mapped outside of json body (typically http headers or request paths)
	// should be excluded
	JsonPathAssert.assertThat(json).hasMapAtPath("$").hasSize(3);
}
 
Example #23
Source File: CatalogConfigTest.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
private void testServiceDefinition(ServiceDefinition service, String id,
                                   String name, String description, boolean bindable,
                                   boolean updatable, List<String> requires, String dashboardUrl) {
    assertEquals(id, service.getId());
    assertEquals(name, service.getName());
    assertEquals(description, service.getDescription());
    assertEquals(bindable, service.isBindable());
    assertEquals(updatable, service.isPlanUpdateable());
    assertEquals(requires, service.getRequires());
}
 
Example #24
Source File: ServiceDefinitionProxyTest.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnproxy() {
    ServiceDefinitionProxy service = catalog
            .findServiceDefinition("f3cbab6a-5172-4ff1-a5c7-72990f0ce2aa");
    assertEquals(PlanProxy.class, service.getPlans().get(0).getClass());
    ServiceDefinition service2 = service.unproxy();
    assertEquals(Plan.class, service2.getPlans().get(0).getClass());
}
 
Example #25
Source File: AppDeploymentInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private ServiceDefinition buildServiceDefinition(String serviceName, String planName) {
	return ServiceDefinition.builder()
		.id(serviceName + "-id")
		.name(serviceName)
		.plans(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.build();
}
 
Example #26
Source File: AppDeploymentInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getBackingAppForServiceWithUnknownPlanIdDoesNothing() {
	ServiceDefinition serviceDefinition = buildServiceDefinition("service1", "unknown-plan");
	StepVerifier
		.create(workflow
			.getBackingApplicationsForService(serviceDefinition, serviceDefinition.getPlans().get(0)))
		.verifyComplete();
}
 
Example #27
Source File: AppDeploymentInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getBackingAppForServiceWithUnknownServiceIdDoesNothing() {
	ServiceDefinition serviceDefinition = buildServiceDefinition("unknown-service", "plan1");
	StepVerifier
		.create(workflow
			.getBackingApplicationsForService(serviceDefinition, serviceDefinition.getPlans().get(0)))
		.verifyComplete();
}
 
Example #28
Source File: AppDeploymentInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getBackingAppForServiceSucceeds() {
	ServiceDefinition serviceDefinition = buildServiceDefinition("service1", "plan1");
	StepVerifier
		.create(workflow
			.getBackingApplicationsForService(serviceDefinition, serviceDefinition.getPlans().get(0)))
		.assertNext(actual -> assertThat(actual)
			.isEqualTo(backingApps)
			.isNotSameAs(backingApps))
		.verifyComplete();
}
 
Example #29
Source File: AppDeploymentInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void doNotAcceptWithUnsupportedPlan() {
	ServiceDefinition serviceDefinition = buildServiceDefinition("service1", "unknown-plan");
	StepVerifier
		.create(workflow.accept(serviceDefinition, serviceDefinition.getPlans().get(0)))
		.expectNextMatches(value -> !value)
		.verifyComplete();
}
 
Example #30
Source File: AppDeploymentInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void doNotAcceptWithUnsupportedService() {
	ServiceDefinition serviceDefinition = buildServiceDefinition("unknown-service", "plan1");
	StepVerifier
		.create(workflow.accept(serviceDefinition, serviceDefinition.getPlans().get(0)))
		.expectNextMatches(value -> !value)
		.verifyComplete();
}