Search in sources :

Example 1 with ListSpacesResponse

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

the class CFAccessorSimulator method retrieveSpaceId.

@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;
}
Also used : SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) LinkedList(java.util.LinkedList) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse)

Example 2 with ListSpacesResponse

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

the class ReactiveTargetResolver method resolveSpace.

private Flux<IntermediateTarget> resolveSpace(IntermediateTarget it) {
    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;
    });
}
Also used : Target(org.cloudfoundry.promregator.config.Target) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Mono(reactor.core.publisher.Mono) ListOrganizationsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse) CFAccessor(org.cloudfoundry.promregator.cfaccessor.CFAccessor) INVALID_APPLICATIONS_RESPONSE(org.cloudfoundry.promregator.cfaccessor.ReactiveCFAccessorImpl.INVALID_APPLICATIONS_RESPONSE) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse) Flux(reactor.core.publisher.Flux) List(java.util.List) Matcher(java.util.regex.Matcher) ApplicationResource(org.cloudfoundry.client.v2.applications.ApplicationResource) Locale(java.util.Locale) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource) Schedulers(reactor.core.scheduler.Schedulers) Pattern(java.util.regex.Pattern) NoSuchElementException(java.util.NoSuchElementException) ListApplicationsResponse(org.cloudfoundry.client.v2.applications.ListApplicationsResponse) Pattern(java.util.regex.Pattern) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) Matcher(java.util.regex.Matcher) Flux(reactor.core.publisher.Flux) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse)

Example 3 with ListSpacesResponse

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

the class CFAccessorSimulatorTest method testRetrieveSpaceId.

@Test
void testRetrieveSpaceId() {
    CFAccessorSimulator subject = new CFAccessorSimulator(2);
    Mono<ListSpacesResponse> mono = subject.retrieveSpaceId(CFAccessorSimulator.ORG_UUID, "simspace");
    ListSpacesResponse result = mono.block();
    Assertions.assertEquals(CFAccessorSimulator.SPACE_UUID, result.getResources().get(0).getMetadata().getId());
}
Also used : ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse) Test(org.junit.jupiter.api.Test)

Example 4 with ListSpacesResponse

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

the class CFAccessorMock method retrieveSpaceId.

@Override
public Mono<ListSpacesResponse> retrieveSpaceId(String orgId, String spaceName) {
    if (orgId.equals(UNITTEST_ORG_UUID)) {
        if ("unittestspace".equalsIgnoreCase(spaceName)) {
            SpaceResource sr = SpaceResource.builder().entity(SpaceEntity.builder().name("unittestspace").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);
        } else if ("unittestspace-summarydoesnotexist".equals(spaceName)) {
            SpaceResource sr = SpaceResource.builder().entity(SpaceEntity.builder().name(spaceName).build()).metadata(Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_SPACE_UUID_DOESNOTEXIST).build()).build();
            List<SpaceResource> list = new LinkedList<>();
            list.add(sr);
            ListSpacesResponse resp = ListSpacesResponse.builder().addAllResources(list).build();
            return Mono.just(resp);
        } else if ("unittestspace-summaryexception".equals(spaceName)) {
            SpaceResource sr = SpaceResource.builder().entity(SpaceEntity.builder().name(spaceName).build()).metadata(Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_SPACE_UUID_EXCEPTION).build()).build();
            List<SpaceResource> list = new LinkedList<>();
            list.add(sr);
            ListSpacesResponse resp = ListSpacesResponse.builder().addAllResources(list).build();
            return Mono.just(resp);
        } else if ("doesnotexist".equals(spaceName)) {
            return Mono.just(ListSpacesResponse.builder().resources(new ArrayList<>()).build());
        } else if ("exception".equals(spaceName)) {
            return Mono.just(ListSpacesResponse.builder().build()).map(x -> {
                throw new Error("exception space name provided");
            });
        }
    }
    Assertions.fail("Invalid SpaceId request");
    return null;
}
Also used : SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse)

Example 5 with ListSpacesResponse

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

the class CFAccessorMassMock method retrieveSpaceId.

@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());
    }
    Assertions.fail("Invalid SpaceId request");
    return null;
}
Also used : SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) LinkedList(java.util.LinkedList) ListSpacesResponse(org.cloudfoundry.client.v2.spaces.ListSpacesResponse)

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