org.cloudfoundry.client.v2.spaces.SpaceResource Java Examples
The following examples show how to use
org.cloudfoundry.client.v2.spaces.SpaceResource.
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 |
@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: ReactiveCFAccessorImpl.java From promregator with Apache License 2.0 | 6 votes |
@Override public Mono<ListSpacesResponse> retrieveSpaceIdsInOrg(String orgId) { PaginatedRequestGeneratorFunction<ListSpacesRequest> requestGenerator = (orderDirection, resultsPerPage, pageNumber) -> ListSpacesRequest.builder() .organizationId(orgId) .orderDirection(orderDirection) .resultsPerPage(resultsPerPage) .page(pageNumber) .build(); PaginatedResponseGeneratorFunction<SpaceResource, ListSpacesResponse> responseGenerator = (list, numberOfPages) -> ListSpacesResponse.builder() .addAllResources(list) .totalPages(numberOfPages) .totalResults(list.size()) .build(); return this.paginatedRequestFetcher.performGenericPagedRetrieval(RequestType.SPACE_IN_ORG, orgId, requestGenerator, r -> this.cloudFoundryClient.spaces().list(r), this.requestTimeoutSpace, responseGenerator); }
Example #3
Source File: ReactiveAppInstanceScanner.java From promregator with Apache License 2.0 | 6 votes |
private Mono<String> getSpaceId(String orgIdString, String spaceNameString) { Mono<ListSpacesResponse> listSpacesResponse = this.cfAccessor.retrieveSpaceId(orgIdString, spaceNameString); return listSpacesResponse.flatMap(response -> { List<SpaceResource> resources = response.getResources(); if (resources == null) { return Mono.just(INVALID_SPACE_ID); } if (resources.isEmpty()) { log.warn(String.format("Received empty result on requesting space %s", spaceNameString)); return Mono.just(INVALID_SPACE_ID); } SpaceResource spaceResource = resources.get(0); return Mono.just(spaceResource.getMetadata().getId()); }).onErrorResume(e -> { log.error(String.format("retrieving space id for org id '%s' and space name '%s' resulted in an exception", orgIdString, spaceNameString), e); return Mono.just(INVALID_SPACE_ID); }).cache(); }
Example #4
Source File: CFAccessorMassMock.java From promregator with Apache License 2.0 | 6 votes |
@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 #5
Source File: CloudFoundryTaskLauncherCachingTests.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 5 votes |
private Mono<ListSpacesResponse> listSpacesResponse(AtomicBoolean error) { // defer so that we can conditionally throw within mono return Mono.defer(() -> { if (error.get()) { throw new RuntimeException(); } ListSpacesResponse response = ListSpacesResponse.builder() .addAllResources(Collections.<SpaceResource>singletonList( SpaceResource.builder() .metadata(Metadata.builder().id("123").build()).build()) ) .build(); return Mono.just(response); }); }
Example #6
Source File: CloudFoundryTaskLauncherTests.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 5 votes |
private Mono<ListSpacesResponse> listSpacesResponse() { ListSpacesResponse response = ListSpacesResponse.builder() .addAllResources(Collections.<SpaceResource>singletonList( SpaceResource.builder() .metadata(Metadata.builder().id("123").build()).build()) ).build(); return Mono.just(response); }
Example #7
Source File: MultiplePlatformTypeTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
private Mono<ListSpacesResponse> listSpacesResponse() { ListSpacesResponse response = ListSpacesResponse.builder() .addAllResources(Collections.<SpaceResource>singletonList( SpaceResource.builder() .metadata(Metadata.builder().id("123").build()).build()) ).build(); return Mono.just(response); }
Example #8
Source File: CloudFoundrySchedulerTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
private Mono<ListSpacesResponse> listSpacesResponse() { ListSpacesResponse response = ListSpacesResponse.builder() .addAllResources(Collections.<SpaceResource>singletonList( SpaceResource.builder() .metadata(Metadata.builder().id("123").build()).build()) ).build(); return Mono.just(response); }
Example #9
Source File: CloudFoundryTaskPlatformFactoryTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
private Mono<ListSpacesResponse> listSpacesResponse() { ListSpacesResponse response = ListSpacesResponse.builder() .addAllResources(Collections.<SpaceResource>singletonList( SpaceResource.builder() .metadata(Metadata.builder().id("123").build()).build()) ).build(); return Mono.just(response); }
Example #10
Source File: CloudFoundryAppDeployerTest.java From spring-cloud-app-broker with Apache License 2.0 | 4 votes |
@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: ReactiveTargetResolver.java From promregator with Apache License 2.0 | 4 votes |
private Flux<IntermediateTarget> resolveSpace(IntermediateTarget it) { /* NB: Now we have to consider three cases: * Case 1: both spaceName and spaceRegex is empty => select all spaces (within the org) * Case 2: spaceName is null, but spaceRegex is filled => filter all spaces with the regex * Case 3: spaceName is filled, but spaceRegex is null => select a single space * In cases 1 and 2, we need the list of all spaces in the org. */ if (it.getConfigTarget().getSpaceRegex() == null && it.getConfigTarget().getSpaceName() != null) { // Case 3: we have the spaceName, but we also need its id Mono<IntermediateTarget> itMono = this.cfAccessor.retrieveSpaceId(it.getResolvedOrgId(), it.getConfigTarget().getSpaceName()) .map(ListSpacesResponse::getResources) .flatMap(resList -> { if (resList == null || resList.isEmpty()) { return Mono.empty(); } return Mono.just(resList.get(0)); }) .map(res -> { it.setResolvedSpaceName(res.getEntity().getName()); it.setResolvedSpaceId(res.getMetadata().getId()); return it; }).doOnError(e -> log.warn(String.format("Error on retrieving space id for org '%s' and space '%s'", it.getResolvedOrgName(), it.getConfigTarget().getSpaceName()), e)) .onErrorResume(__ -> Mono.empty()); return itMono.flux(); } // Case 1 & 2: Get all spaces in the current org Mono<ListSpacesResponse> responseMono = this.cfAccessor.retrieveSpaceIdsInOrg(it.getResolvedOrgId()); Flux<SpaceResource> spaceResFlux = responseMono.map(ListSpacesResponse::getResources) .flatMapMany(Flux::fromIterable); if (it.getConfigTarget().getSpaceRegex() != null) { // Case 2 final Pattern filterPattern = Pattern.compile(it.getConfigTarget().getSpaceRegex(), Pattern.CASE_INSENSITIVE); spaceResFlux = spaceResFlux.filter(spaceRes -> { Matcher m = filterPattern.matcher(spaceRes.getEntity().getName()); return m.matches(); }); } return spaceResFlux.map(spaceRes -> { IntermediateTarget itnew = new IntermediateTarget(it); itnew.setResolvedSpaceId(spaceRes.getMetadata().getId()); itnew.setResolvedSpaceName(spaceRes.getEntity().getName()); return itnew; }); }
Example #12
Source File: RawCloudSpaceTest.java From cf-java-client-sap with Apache License 2.0 | 4 votes |
private static Resource<SpaceEntity> buildTestResource() { return SpaceResource.builder() .metadata(RawCloudEntityTest.METADATA) .entity(buildTestEntity()) .build(); }