Java源码示例:org.cloudfoundry.client.v2.spaces.SpaceEntity
示例1
@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;
}
示例2
@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;
}
示例3
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())));
}
示例4
@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();
}
示例5
private Mono<? extends Resource<SpaceEntity>> getSpaceResource(UUID guid) {
GetSpaceRequest request = GetSpaceRequest.builder()
.spaceId(guid.toString())
.build();
return delegate.spaces()
.get(request);
}
示例6
private Flux<? extends Resource<SpaceEntity>> getSpaceResourcesByOrganizationGuid(UUID organizationGuid) {
IntFunction<ListSpacesRequest> pageRequestSupplier = page -> ListSpacesRequest.builder()
.organizationId(organizationGuid.toString())
.page(page)
.build();
return getSpaceResources(pageRequestSupplier);
}
示例7
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();
}
示例8
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());
}
示例9
private Mono<SpaceEntity> getSpace(String spaceId) {
return client.spaces().get(org.cloudfoundry.client.v2.spaces.GetSpaceRequest.builder()
.spaceId(spaceId)
.build())
.map(ResourceUtils::getEntity);
}
示例10
@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();
}
示例11
@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();
}
示例12
@Value.Parameter
public abstract Resource<SpaceEntity> getResource();
示例13
private Flux<? extends Resource<SpaceEntity>> getSpaceResources() {
IntFunction<ListSpacesRequest> pageRequestSupplier = page -> ListSpacesRequest.builder()
.page(page)
.build();
return getSpaceResources(pageRequestSupplier);
}
示例14
private Flux<? extends Resource<SpaceEntity>> getSpaceResources(IntFunction<ListSpacesRequest> requestForPage) {
return PaginationUtils.requestClientV2Resources(page -> delegate.spaces()
.list(requestForPage.apply(page)));
}
示例15
private static Resource<SpaceEntity> buildTestResource() {
return SpaceResource.builder()
.metadata(RawCloudEntityTest.METADATA)
.entity(buildTestEntity())
.build();
}
示例16
private static SpaceEntity buildTestEntity() {
return SpaceEntity.builder()
.name(NAME)
.build();
}