Search in sources :

Example 6 with ListSpacesResponse

use of org.cloudfoundry.client.v2.spaces.ListSpacesResponse in project promregator by promregator.

the class ReactiveAppInstanceScanner method getSpaceId.

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();
}
Also used : Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) SpaceApplicationSummary(org.cloudfoundry.client.v2.spaces.SpaceApplicationSummary) DomainResource(org.cloudfoundry.client.v2.domains.DomainResource) CFAccessor(org.cloudfoundry.promregator.cfaccessor.CFAccessor) ArrayList(java.util.ArrayList) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse) Value(org.springframework.beans.factory.annotation.Value) Flux(reactor.core.publisher.Flux) List(java.util.List) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) CollectionUtils(org.springframework.util.CollectionUtils) Map(java.util.Map) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource) Pattern(java.util.regex.Pattern) Route(org.cloudfoundry.client.v2.routes.Route) Nullable(javax.annotation.Nullable) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse)

Example 7 with ListSpacesResponse

use of org.cloudfoundry.client.v2.spaces.ListSpacesResponse in project promregator by promregator.

the class ReactiveCFAccessorImpl method retrieveSpaceId.

/* (non-Javadoc)
	 * @see org.cloudfoundry.promregator.cfaccessor.CFAccessor#retrieveSpaceId(java.lang.String, java.lang.String)
	 */
@Override
public Mono<ListSpacesResponse> retrieveSpaceId(String orgId, String spaceName) {
    // Note: even though we use the List request here, the number of values returned is either zero or one
    // ==> No need for a paged request.
    String key = String.format("%s|%s", orgId, spaceName);
    ListSpacesRequest spacesRequest = ListSpacesRequest.builder().organizationId(orgId).name(spaceName).build();
    return this.paginatedRequestFetcher.performGenericRetrieval(RequestType.SPACE, key, spacesRequest, sr -> this.cloudFoundryClient.spaces().list(sr), this.requestTimeoutSpace);
}
Also used : ListSpacesRequest(org.cloudfoundry.client.v2.spaces.ListSpacesRequest)

Aggregations

ListSpacesResponse (org.cloudfoundry.client.v2.spaces.ListSpacesResponse)6 SpaceResource (org.cloudfoundry.client.v2.spaces.SpaceResource)5 LinkedList (java.util.LinkedList)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 OrganizationResource (org.cloudfoundry.client.v2.organizations.OrganizationResource)2 CFAccessor (org.cloudfoundry.promregator.cfaccessor.CFAccessor)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Predicate (java.util.function.Predicate)1 Nullable (javax.annotation.Nullable)1