org.cloudfoundry.operations.services.GetServiceInstanceRequest Java Examples

The following examples show how to use org.cloudfoundry.operations.services.GetServiceInstanceRequest. 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: ServiceInstanceDetailTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<ServiceInstanceDetail> getServiceInstanceDetail(ServiceInstanceDetail fragment) {
    log.trace("Fetching service instance detail for org={}, space={}, id={}, name={}", fragment.getOrganization(), fragment.getSpace(), fragment.getServiceInstanceId(), fragment.getName());
    return buildClient(buildSpace(fragment.getOrganization(), fragment.getSpace()))
            .services()
                .getInstance(GetServiceInstanceRequest.builder().name(fragment.getName()).build())
                .map(sid ->
                            ServiceInstanceDetail
                                .from(fragment)
                                    .description(sid.getDescription())
                                    .type(sid.getType() != null ? sid.getType().getValue(): null)
                                    .lastOperation(sid.getLastOperation())
                                    .lastUpdated(StringUtils.isNotBlank(sid.getUpdatedAt()) ? Instant.parse(sid.getUpdatedAt())
                                                .atZone(ZoneId.systemDefault())
                                                .toLocalDateTime() : null)
                                    .dashboardUrl(sid.getDashboardUrl())
                                    .requestedState(StringUtils.isNotBlank(sid.getStatus()) ? sid.getStatus().toLowerCase(): null)
                                    .build()
                )
                .onErrorResume(e -> Mono.just(fragment));
}
 
Example #2
Source File: CfCreateServiceHelperTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateServiceWithNoExistingService() {
    CloudFoundryOperations cfOps = mock(CloudFoundryOperations.class);
    Services mockServices = mock(Services.class);

    when(mockServices
        .getInstance(any(GetServiceInstanceRequest.class)))
        .thenReturn(Mono.empty());

    when(cfOps.services()).thenReturn(mockServices);

    CfServiceDetail cfServiceDetail = ImmutableCfServiceDetail
        .builder().name("testName")
        .plan("testPlan")
        .instanceName("inst")
        .build();


    Mono<ServiceInstance> createServiceResult = this.cfCreateServiceHelper.createService(cfOps, cfServiceDetail);

    StepVerifier.create(createServiceResult)
        .verifyComplete();
}
 
Example #3
Source File: CfPushDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCfPushWithoutEnvOrServices() throws Exception {
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    Applications mockApplications = mock(Applications.class);
    when(cfOperations.applications()).thenReturn(mockApplications);
    when(mockApplications.push(any(PushApplicationRequest.class))).thenReturn(Mono.empty());
    when(mockApplications.restart(any(RestartApplicationRequest.class))).thenReturn(Mono.empty());

    Services mockServices = mock(Services.class);
    when(cfOperations.services()).thenReturn(mockServices);
    ServiceInstance mockInstance = ServiceInstance.builder().name("testservice").id("id").type(ServiceInstanceType.MANAGED).build();
    when(mockServices.getInstance(any(GetServiceInstanceRequest.class))).thenReturn(Mono.just(mockInstance));

    CfProperties cfAppProperties = sampleApp();
    cfPushDelegate.push(cfOperations, cfAppProperties);
}
 
Example #4
Source File: CfServicesDetailHelperTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetServiceDetails() {
    CloudFoundryOperations cfOps = mock(CloudFoundryOperations.class);
    Services mockServices = mock(Services.class);

    when(mockServices
        .getInstance(any(GetServiceInstanceRequest.class)))
        .thenReturn(Mono.just(ServiceInstance.builder()
            .id("id")
            .type(ServiceInstanceType.MANAGED)
            .name("test")
            .build()));

    when(cfOps.services()).thenReturn(mockServices);

    Mono<Optional<ServiceInstance>> serviceDetailMono =
        this.cfServicesDetailHelper.getServiceInstanceDetail(cfOps, "srvc");

    StepVerifier.create(serviceDetailMono).expectNextMatches(serviceInstance ->
        serviceInstance.isPresent());
}
 
Example #5
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceInstanceByName() {
	given(operationsServices.getInstance(any(GetServiceInstanceRequest.class)))
		.willReturn(Mono.just(ServiceInstance.builder()
			.id("foo-service-instance-id")
			.name("my-foo-service")
			.service("foo-service")
			.plan("foo-plan")
			.type(ServiceInstanceType.MANAGED)
			.build()));

	org.springframework.cloud.appbroker.deployer.GetServiceInstanceRequest request = org.springframework.cloud.appbroker.deployer.GetServiceInstanceRequest
		.builder()
		.name("my-foo-service")
		.build();

	StepVerifier.create(appDeployer.getServiceInstance(request))
		.assertNext(response -> {
			assertThat(response.getName()).isEqualTo("my-foo-service");
			assertThat(response.getService()).isEqualTo("foo-service");
			assertThat(response.getPlan()).isEqualTo("foo-plan");
		})
		.verifyComplete();

	then(operationsUtils).should().getOperations(argThat(CollectionUtils::isEmpty));
	then(cloudFoundryOperations).should().services();
	then(operationsServices).should().getInstance(argThat(req -> "my-foo-service".equals(req.getName())));
	then(cloudFoundryClient).shouldHaveNoInteractions();
	then(cloudFoundryOperations).shouldHaveNoMoreInteractions();
	then(operationsUtils).shouldHaveNoMoreInteractions();
}
 
Example #6
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceInstanceByNameAndSpace() {
	given(operationsServices.getInstance(any(GetServiceInstanceRequest.class)))
		.willReturn(Mono.just(ServiceInstance.builder()
			.id("foo-service-instance-id")
			.name("my-foo-service")
			.service("foo-service")
			.plan("foo-plan")
			.type(ServiceInstanceType.MANAGED)
			.build()));

	org.springframework.cloud.appbroker.deployer.GetServiceInstanceRequest request = org.springframework.cloud.appbroker.deployer.GetServiceInstanceRequest
		.builder()
		.name("my-foo-service")
		.properties(singletonMap(TARGET_PROPERTY_KEY, "foo-space"))
		.build();

	StepVerifier.create(appDeployer.getServiceInstance(request))
		.assertNext(response -> {
			assertThat(response.getName()).isEqualTo("my-foo-service");
			assertThat(response.getService()).isEqualTo("foo-service");
			assertThat(response.getPlan()).isEqualTo("foo-plan");
		})
		.verifyComplete();

	then(operationsUtils).should().getOperations(
		argThat(argument -> "foo-space".equals(argument.get(TARGET_PROPERTY_KEY))));
	then(cloudFoundryOperations).should().services();
	then(operationsServices).should().getInstance(argThat(req -> "my-foo-service".equals(req.getName())));
	then(cloudFoundryClient).shouldHaveNoInteractions();
	then(cloudFoundryOperations).shouldHaveNoMoreInteractions();
	then(operationsUtils).shouldHaveNoMoreInteractions();
}
 
Example #7
Source File: CloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private Mono<ServiceInstance> getServiceInstance(CloudFoundryOperations operations,
	String serviceInstanceName) {
	return operations.services().getInstance(GetServiceInstanceRequest.builder()
		.name(serviceInstanceName)
		.build())
		.doOnSuccess(item -> LOG.info("Success getting service instance. serviceInstanceName={}",
			serviceInstanceName))
		.doOnError(e -> LOG.error(String.format("Error getting service instance. serviceInstanceName=%s, " +
			"error=%s", serviceInstanceName, e.getMessage()), e));
}
 
Example #8
Source File: UserCloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
public Mono<ServiceInstance> getServiceInstance(String serviceInstanceName) {
	return cloudFoundryOperations.services()
		.getInstance(GetServiceInstanceRequest.builder()
			.name(serviceInstanceName)
			.build())
		.doOnSuccess(item -> LOG.info("Got service instance " + serviceInstanceName))
		.doOnError(error -> LOG.error("Error getting service instance " + serviceInstanceName + ": " + error));
}
 
Example #9
Source File: CfServicesDetailHelper.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
public Mono<Optional<ServiceInstance>> getServiceInstanceDetail(CloudFoundryOperations cfOperations,
                                                                String serviceName) {

    LOGGER.lifecycle("Checking details of service '{}'", serviceName);
    Mono<ServiceInstance> serviceInstanceMono = cfOperations.services()
        .getInstance(
            GetServiceInstanceRequest.builder()
                .name(serviceName)
                .build());

    return serviceInstanceMono
        .map(serviceInstance -> Optional.ofNullable(serviceInstance))
        .onErrorResume(Exception.class, e -> Mono.just(Optional.empty()));
}
 
Example #10
Source File: CfCreateServiceHelperTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateServiceWithAnExistingService() {
    CloudFoundryOperations cfOps = mock(CloudFoundryOperations.class);
    Services mockServices = mock(Services.class);

    when(mockServices
        .getInstance(any(GetServiceInstanceRequest.class)))
        .thenReturn(Mono.just(ServiceInstance.builder()
            .id("inst")
            .type(ServiceInstanceType.MANAGED)
            .name("inst")
            .build()));

    when(cfOps.services()).thenReturn(mockServices);

    CfServiceDetail cfServiceDetail = ImmutableCfServiceDetail
        .builder().name("testName")
        .plan("testPlan")
        .instanceName("inst")
        .build();
    
    
    Mono<ServiceInstance> createServiceResult = this.cfCreateServiceHelper.createService(cfOps, cfServiceDetail);

    StepVerifier.create(createServiceResult)
        .expectNextMatches(instance -> instance != null)
        .verifyComplete();
}
 
Example #11
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deleteServiceInstanceShouldUnbindServices() {
	given(operationsServices.deleteInstance(
		org.cloudfoundry.operations.services.DeleteServiceInstanceRequest.builder()
			.name("service-instance-name")
			.completionTimeout(Duration.ofSeconds(DEFAULT_COMPLETION_DURATION))
			.build()))
		.willReturn(Mono.empty());

	given(operationsServices.getInstance(GetServiceInstanceRequest.builder().name("service-instance-name").build()))
		.willReturn(Mono.just(ServiceInstance.builder()
			.id("siid")
			.type(ServiceInstanceType.MANAGED)
			.name("service-instance-name")
			.applications("app1", "app2")
			.build()));

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.serviceInstanceName("service-instance-name")
		.applicationName("app1")
		.build()))
		.willReturn(Mono.empty());

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.serviceInstanceName("service-instance-name")
		.applicationName("app2")
		.build()))
		.willReturn(Mono.empty());

	DeleteServiceInstanceRequest request =
		DeleteServiceInstanceRequest.builder()
			.serviceInstanceName("service-instance-name")
			.properties(emptyMap())
			.build();

	StepVerifier.create(
		appDeployer.deleteServiceInstance(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo("service-instance-name"))
		.verifyComplete();

}
 
Example #12
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deleteServiceInstanceWithTarget() {
	given(operationsServices.deleteInstance(
		org.cloudfoundry.operations.services.DeleteServiceInstanceRequest.builder()
			.name("service-instance-name")
			.completionTimeout(Duration.ofSeconds(DEFAULT_COMPLETION_DURATION))
			.build()))
		.willReturn(Mono.empty());

	given(operationsServices.getInstance(GetServiceInstanceRequest.builder().name("service-instance-name").build()))
		.willReturn(Mono.just(ServiceInstance.builder()
			.id("siid")
			.type(ServiceInstanceType.MANAGED)
			.name("service-instance-name")
			.applications("app1", "app2")
			.build()));

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.serviceInstanceName("service-instance-name")
		.applicationName("app1")
		.build()))
		.willReturn(Mono.empty());

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.serviceInstanceName("service-instance-name")
		.applicationName("app2")
		.build()))
		.willReturn(Mono.empty());

	given(operationsOrganizations
		.get(
			OrganizationInfoRequest
				.builder()
				.name("default-org")
				.build()))
		.willReturn(Mono.just(
			OrganizationDetail
				.builder()
				.id("default-org-id")
				.name("default-org")
				.quota(OrganizationQuota
					.builder()
					.id("quota-id")
					.instanceMemoryLimit(0)
					.organizationId("default-org-id")
					.name("quota")
					.paidServicePlans(false)
					.totalMemoryLimit(0)
					.totalRoutes(0)
					.totalServiceInstances(0)
					.build())
				.build()));

	given(clientOrganizations
		.listSpaces(ListOrganizationSpacesRequest
			.builder()
			.name("service-instance-id")
			.organizationId("default-org-id")
			.page(1)
			.build()))
		.willReturn(Mono.just(ListOrganizationSpacesResponse
			.builder()
			.resource(SpaceResource
				.builder()
				.entity(SpaceEntity
					.builder()
					.name("service-instance-id")
					.build())
				.metadata(Metadata
					.builder()
					.id("service-instance-space-id")
					.build())
				.build())
			.build()));

	given(clientSpaces
		.delete(DeleteSpaceRequest
			.builder()
			.spaceId("service-instance-space-id")
			.build()))
		.willReturn(Mono.empty());

	DeleteServiceInstanceRequest request =
		DeleteServiceInstanceRequest.builder()
			.serviceInstanceName("service-instance-name")
			.properties(emptyMap())
			.properties(singletonMap(TARGET_PROPERTY_KEY, "service-instance-id"))
			.build();

	StepVerifier.create(
		appDeployer.deleteServiceInstance(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo("service-instance-name"))
		.verifyComplete();
}
 
Example #13
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void updateServiceInstanceRebindsWhenRequired() {
	given(operationsServices.updateInstance(
		org.cloudfoundry.operations.services.UpdateServiceInstanceRequest.builder()
			.serviceInstanceName("service-instance-name")
			.parameters(emptyMap())
			.completionTimeout(Duration.ofSeconds(DEFAULT_COMPLETION_DURATION))
			.build()))
		.willReturn(Mono.empty());

	given(operationsServices.getInstance(GetServiceInstanceRequest.builder()
		.name("service-instance-name")
		.build()))
		.willReturn(Mono.just(ServiceInstance.builder()
			.name("service-instance-name")
			.id("service-instance-guid")
			.type(ServiceInstanceType.MANAGED)
			.applications("app1", "app2")
			.build()));

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.applicationName("app1")
		.serviceInstanceName("service-instance-name")
		.build()))
		.willReturn(Mono.empty());

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.applicationName("app2")
		.serviceInstanceName("service-instance-name")
		.build()))
		.willReturn(Mono.empty());

	given(operationsServices.bind(BindServiceInstanceRequest.builder()
		.applicationName("app1")
		.serviceInstanceName("service-instance-name")
		.build()))
		.willReturn(Mono.empty());

	given(operationsServices.bind(BindServiceInstanceRequest.builder()
		.applicationName("app2")
		.serviceInstanceName("service-instance-name")
		.build()))
		.willReturn(Mono.empty());

	UpdateServiceInstanceRequest request =
		UpdateServiceInstanceRequest.builder()
			.serviceInstanceName("service-instance-name")
			.parameters(emptyMap())
			.rebindOnUpdate(true)
			.build();

	StepVerifier.create(
		appDeployer.updateServiceInstance(request))
		.verifyComplete();
}
 
Example #14
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void getServiceInstanceById() {
	given(operationsServices.getInstance(any(GetServiceInstanceRequest.class)))
		.willReturn(Mono.just(ServiceInstance.builder()
			.id("foo-service-instance-id")
			.name("my-foo-service")
			.service("foo-service")
			.plan("foo-plan")
			.type(ServiceInstanceType.MANAGED)
			.build()));

	given(clientServiceInstances
		.get(any(org.cloudfoundry.client.v2.serviceinstances.GetServiceInstanceRequest.class)))
		.willReturn(Mono.just(GetServiceInstanceResponse.builder()
			.entity(ServiceInstanceEntity.builder()
				.name("my-foo-service")
				.spaceId("foo-space-id")
				.build())
			.build()));

	given(clientSpaces.get(GetSpaceRequest.builder()
		.spaceId("foo-space-id")
		.build()))
		.willReturn(Mono.just(GetSpaceResponse.builder()
			.entity(SpaceEntity.builder()
				.name("foo-space")
				.organizationId("foo-organization-id")
				.build())
			.build()));

	given(clientOrganizations.get(GetOrganizationRequest.builder()
		.organizationId("foo-organization-id")
		.build()))
		.willReturn(Mono.just(GetOrganizationResponse.builder()
			.entity(OrganizationEntity.builder()
				.name("foo-organization")
				.build())
			.build()));

	org.springframework.cloud.appbroker.deployer.GetServiceInstanceRequest request =
		org.springframework.cloud.appbroker.deployer.GetServiceInstanceRequest
			.builder()
			.serviceInstanceId("foo-service-instance-id")
			.properties(emptyMap())
			.build();

	StepVerifier.create(appDeployer.getServiceInstance(request))
		.assertNext(response -> {
			assertThat(response.getName()).isEqualTo("my-foo-service");
			assertThat(response.getService()).isEqualTo("foo-service");
			assertThat(response.getPlan()).isEqualTo("foo-plan");
		})
		.verifyComplete();

	then(operationsUtils).should()
		.getOperationsForOrgAndSpace(argThat("foo-organization"::equals), argThat("foo-space"::equals));
	then(cloudFoundryClient).should().serviceInstances();
	then(clientServiceInstances).should()
		.get(argThat(req -> "foo-service-instance-id".equals(req.getServiceInstanceId())));
	then(cloudFoundryClient).should().spaces();
	then(cloudFoundryClient).should().organizations();
	then(clientSpaces).should().get(argThat(req -> "foo-space-id".equals(req.getSpaceId())));
	then(clientOrganizations).should().get(argThat(req -> "foo-organization-id".equals(req.getOrganizationId())));
	then(cloudFoundryOperations).should().services();
	then(operationsServices).should().getInstance(argThat(req -> "my-foo-service".equals(req.getName())));
	then(cloudFoundryClient).shouldHaveNoMoreInteractions();
	then(cloudFoundryOperations).shouldHaveNoMoreInteractions();
	then(operationsUtils).shouldHaveNoMoreInteractions();
}