use of org.cloudfoundry.client.v2.applications.ApplicationResource in project promregator by promregator.
the class CFAccessorMock method retrieveApplicationId.
@Override
public Mono<ListApplicationsResponse> retrieveApplicationId(String orgId, String spaceId, String applicationName) {
if (orgId.equals(UNITTEST_ORG_UUID) && spaceId.equals(UNITTEST_SPACE_UUID)) {
ApplicationResource ar = null;
if (applicationName.equals("testapp")) {
ar = ApplicationResource.builder().entity(ApplicationEntity.builder().name(applicationName).build()).metadata(Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_APP1_UUID).build()).build();
} else if (applicationName.equals("testapp2")) {
ar = ApplicationResource.builder().entity(ApplicationEntity.builder().name(applicationName).build()).metadata(Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_APP2_UUID).build()).build();
} else {
Assert.fail("Invalid ApplicationId request, application name is invalid");
}
List<ApplicationResource> list = new LinkedList<>();
list.add(ar);
ListApplicationsResponse resp = ListApplicationsResponse.builder().addAllResources(list).build();
return Mono.just(resp);
}
Assert.fail("Invalid ApplicationId request");
return null;
}
use of org.cloudfoundry.client.v2.applications.ApplicationResource in project promregator by promregator.
the class ReactiveAppInstanceScanner method getApplicationId.
private Mono<String> getApplicationId(Mono<String> orgIdMono, Mono<String> spaceIdMono, String applicationNameString) {
String key = String.format("%d|%d|%s", orgIdMono.hashCode(), spaceIdMono.hashCode(), applicationNameString);
synchronized (key.intern()) {
Mono<String> cached = this.applicationMap.get(key);
if (cached != null) {
this.internalMetrics.countHit("appinstancescanner.app");
return cached;
}
this.internalMetrics.countMiss("appinstancescanner.app");
ReactiveTimer reactiveTimer = new ReactiveTimer(this.internalMetrics, "app");
cached = Mono.zip(orgIdMono, spaceIdMono, Mono.just(applicationNameString)).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().start();
return tuple.getT1();
}).flatMap(triple -> {
return this.cfAccessor.retrieveApplicationId(triple.getT1(), triple.getT2(), triple.getT3());
}).flatMap(response -> {
List<ApplicationResource> resources = response.getResources();
if (resources == null) {
return Mono.empty();
}
if (resources.isEmpty()) {
log.warn(String.format("Received empty result on requesting application %s", applicationNameString));
return Mono.empty();
}
ApplicationResource applicationResource = resources.get(0);
return Mono.just(applicationResource.getMetadata().getId());
}).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().stop();
return tuple.getT1();
}).cache();
this.applicationMap.put(key, cached);
return cached;
}
}
Aggregations