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;
}
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;
});
}
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());
}
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;
}
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;
}
Aggregations