use of org.cloudfoundry.client.v2.organizations.OrganizationResource in project promregator by promregator.
the class CFAccessorMock method retrieveOrgId.
@Override
public Mono<ListOrganizationsResponse> retrieveOrgId(String orgName) {
if ("unittestorg".equals(orgName)) {
OrganizationResource or = OrganizationResource.builder().entity(OrganizationEntity.builder().name(orgName).build()).metadata(Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_ORG_UUID).build()).build();
List<org.cloudfoundry.client.v2.organizations.OrganizationResource> list = new LinkedList<>();
list.add(or);
ListOrganizationsResponse resp = org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse.builder().addAllResources(list).build();
return Mono.just(resp);
}
Assert.fail("Invalid OrgId request");
return null;
}
use of org.cloudfoundry.client.v2.organizations.OrganizationResource in project promregator by promregator.
the class ReactiveAppInstanceScanner method getOrgId.
private Mono<String> getOrgId(String orgNameString) {
Mono<String> cached = this.orgMap.get(orgNameString);
if (cached != null) {
this.internalMetrics.countHit("appinstancescanner.org");
return cached;
}
this.internalMetrics.countMiss("appinstancescanner.org");
ReactiveTimer reactiveTimer = new ReactiveTimer(this.internalMetrics, "org");
cached = Mono.just(orgNameString).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().start();
return tuple.getT1();
}).flatMap(orgName -> {
return this.cfAccessor.retrieveOrgId(orgName);
}).flatMap(response -> {
List<OrganizationResource> resources = response.getResources();
if (resources == null) {
return Mono.empty();
}
if (resources.isEmpty()) {
log.warn(String.format("Received empty result on requesting org %s", orgNameString));
return Mono.empty();
}
OrganizationResource organizationResource = resources.get(0);
return Mono.just(organizationResource.getMetadata().getId());
}).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().stop();
return tuple.getT1();
}).cache();
this.orgMap.put(orgNameString, cached);
return cached;
}
Aggregations