use of org.cloudfoundry.client.v2.spaces.SpaceResource in project promregator by promregator.
the class CFAccessorMock 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);
}
Assert.fail("Invalid SpaceId request");
return null;
}
use of org.cloudfoundry.client.v2.spaces.SpaceResource in project promregator by promregator.
the class ReactiveAppInstanceScanner method getSpaceId.
private Mono<String> getSpaceId(Mono<String> orgIdMono, String spaceNameString) {
String key = String.format("%d|%s", orgIdMono.hashCode(), spaceNameString);
synchronized (key.intern()) {
Mono<String> cached = this.spaceMap.get(key);
if (cached != null) {
this.internalMetrics.countHit("appinstancescanner.space");
return cached;
}
this.internalMetrics.countMiss("appinstancescanner.space");
ReactiveTimer reactiveTimer = new ReactiveTimer(this.internalMetrics, "space");
cached = Mono.zip(orgIdMono, Mono.just(spaceNameString)).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().start();
return tuple.getT1();
}).flatMap(tuple -> {
return this.cfAccessor.retrieveSpaceId(tuple.getT1(), tuple.getT2());
}).flatMap(response -> {
List<SpaceResource> resources = response.getResources();
if (resources == null) {
return Mono.empty();
}
if (resources.isEmpty()) {
log.warn(String.format("Received empty result on requesting space %s", spaceNameString));
return Mono.empty();
}
SpaceResource spaceResource = resources.get(0);
return Mono.just(spaceResource.getMetadata().getId());
}).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().stop();
return tuple.getT1();
}).cache();
this.spaceMap.put(key, cached);
return cached;
}
}
Aggregations