org.cloudfoundry.client.v2.spaces.SpaceEntity Java Examples

The following examples show how to use org.cloudfoundry.client.v2.spaces.SpaceEntity. 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: CFAccessorSimulator.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListSpacesResponse> retrieveSpaceId(String orgId, String spaceName) {
	if ("simspace".equals(spaceName) && orgId.equals(ORG_UUID)) {
		
		SpaceResource sr = SpaceResource.builder().entity(
				SpaceEntity.builder().name(spaceName).build()
			).metadata(
				Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(SPACE_UUID).build()
			).build();
		List<SpaceResource> list = new LinkedList<>();
		list.add(sr);
		ListSpacesResponse resp = ListSpacesResponse.builder().addAllResources(list).build();
		
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	
	log.error("Invalid SpaceId request");
	return null;
}
 
Example #2
Source File: CFAccessorMassMock.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListSpacesResponse> retrieveSpaceId(String orgId, String spaceName) {
	if ("unittestspace".equals(spaceName) && orgId.equals(UNITTEST_ORG_UUID)) {
		
		SpaceResource sr = SpaceResource.builder().entity(
				SpaceEntity.builder().name(spaceName).build()
			).metadata(
				Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_SPACE_UUID).build()
			).build();
		List<SpaceResource> list = new LinkedList<>();
		list.add(sr);
		ListSpacesResponse resp = ListSpacesResponse.builder().addAllResources(list).build();
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	
	Assert.fail("Invalid SpaceId request");
	return null;
}
 
Example #3
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private Mono<ServiceInstance> getServiceInstance(String name, SpaceEntity spaceEntity) {
	return getOrganization(spaceEntity.getOrganizationId())
		.flatMap(organizationEntity ->
			operationsUtils.getOperationsForOrgAndSpace(organizationEntity.getName(), spaceEntity.getName())
				.flatMap(cfOperations -> cfOperations.services()
					.getInstance(org.cloudfoundry.operations.services.GetServiceInstanceRequest.builder()
						.name(name)
						.build())));
}
 
Example #4
Source File: RawCloudSpace.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
@Override
public CloudSpace derive() {
    Resource<SpaceEntity> resource = getResource();
    SpaceEntity entity = resource.getEntity();
    return ImmutableCloudSpace.builder()
                              .metadata(parseResourceMetadata(resource))
                              .name(entity.getName())
                              .organization(deriveFromNullable(getOrganization()))
                              .build();
}
 
Example #5
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private Mono<? extends Resource<SpaceEntity>> getSpaceResource(UUID guid) {
    GetSpaceRequest request = GetSpaceRequest.builder()
                                             .spaceId(guid.toString())
                                             .build();
    return delegate.spaces()
                   .get(request);
}
 
Example #6
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private Flux<? extends Resource<SpaceEntity>> getSpaceResourcesByOrganizationGuid(UUID organizationGuid) {
    IntFunction<ListSpacesRequest> pageRequestSupplier = page -> ListSpacesRequest.builder()
                                                                                  .organizationId(organizationGuid.toString())
                                                                                  .page(page)
                                                                                  .build();
    return getSpaceResources(pageRequestSupplier);
}
 
Example #7
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private Mono<? extends Resource<SpaceEntity>> getSpaceResourceByOrganizationGuidAndName(UUID organizationGuid, String name) {
    IntFunction<ListOrganizationSpacesRequest> pageRequestSupplier = page -> ListOrganizationSpacesRequest.builder()
                                                                                                          .organizationId(organizationGuid.toString())
                                                                                                          .name(name)
                                                                                                          .page(page)
                                                                                                          .build();
    return PaginationUtils.requestClientV2Resources(page -> delegate.organizations()
                                                                    .listSpaces(pageRequestSupplier.apply(page)))
                          .singleOrEmpty();
}
 
Example #8
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private Mono<Derivable<CloudSpace>> zipWithAuxiliarySpaceContent(Resource<SpaceEntity> resource) {
    UUID organizationGuid = UUID.fromString(resource.getEntity()
                                                    .getOrganizationId());
    return getOrganizationMono(organizationGuid).map(organization -> ImmutableRawCloudSpace.builder()
                                                                                           .resource(resource)
                                                                                           .organization(organization)
                                                                                           .build());
}
 
Example #9
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
private Mono<SpaceEntity> getSpace(String spaceId) {
	return client.spaces().get(org.cloudfoundry.client.v2.spaces.GetSpaceRequest.builder()
		.spaceId(spaceId)
		.build())
		.map(ResourceUtils::getEntity);
}
 
Example #10
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 #11
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();
}
 
Example #12
Source File: RawCloudSpace.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
@Value.Parameter
public abstract Resource<SpaceEntity> getResource();
 
Example #13
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
private Flux<? extends Resource<SpaceEntity>> getSpaceResources() {
    IntFunction<ListSpacesRequest> pageRequestSupplier = page -> ListSpacesRequest.builder()
                                                                                  .page(page)
                                                                                  .build();
    return getSpaceResources(pageRequestSupplier);
}
 
Example #14
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
private Flux<? extends Resource<SpaceEntity>> getSpaceResources(IntFunction<ListSpacesRequest> requestForPage) {
    return PaginationUtils.requestClientV2Resources(page -> delegate.spaces()
                                                                    .list(requestForPage.apply(page)));
}
 
Example #15
Source File: RawCloudSpaceTest.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
private static Resource<SpaceEntity> buildTestResource() {
    return SpaceResource.builder()
                        .metadata(RawCloudEntityTest.METADATA)
                        .entity(buildTestEntity())
                        .build();
}
 
Example #16
Source File: RawCloudSpaceTest.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
private static SpaceEntity buildTestEntity() {
    return SpaceEntity.builder()
                      .name(NAME)
                      .build();
}