use of org.cloudfoundry.client.v3.processes.ProcessResource in project promregator by promregator.
the class CFAccessorMock method retrieveProcesses.
@Override
public Mono<ListProcessesResponse> retrieveProcesses(String orgId, String spaceId, String appId) {
if (orgId.equals(UNITTEST_ORG_UUID) && spaceId.equals(UNITTEST_SPACE_UUID)) {
List<ProcessResource> list = new LinkedList<>();
Data data = Data.builder().timeout(100).build();
HealthCheck hc = HealthCheck.builder().type(HealthCheckType.HTTP).data(data).build();
Builder builder = ProcessResource.builder().type("dummy").command("dummycommand").memoryInMb(1024).diskInMb(1024).healthCheck(hc).createdAt(CREATED_AT_TIMESTAMP).updatedAt(UPDATED_AT_TIMESTAMP);
ProcessResource ar = null;
if (appId.equals(UNITTEST_APP1_UUID)) {
ar = builder.instances(2).id(UNITTEST_APP1_UUID).build();
} else if (appId.equals(UNITTEST_APP2_UUID)) {
ar = builder.instances(1).id(UNITTEST_APP2_UUID).build();
}
if (ar == null) {
Assert.fail("Invalid process request, invalid app id provided");
return null;
}
list.add(ar);
ListProcessesResponse resp = ListProcessesResponse.builder().addAllResources(list).build();
return Mono.just(resp);
}
Assert.fail("Invalid process request");
return null;
}
use of org.cloudfoundry.client.v3.processes.ProcessResource in project promregator by promregator.
the class ReactiveAppInstanceScanner method getInstances.
private Flux<InternalInstance> getInstances(Flux<InternalInstance> instancesFlux) {
Flux<InternalInstance> allInstances = instancesFlux.flatMap(instance -> {
ReactiveTimer reactiveTimer = new ReactiveTimer(this.internalMetrics, "instances");
Mono<ListProcessesResponse> processesResponse = Mono.zip(instance.orgId, instance.spaceId, instance.applicationId).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().start();
return tuple.getT1();
}).flatMap(tuple -> {
String orgId = tuple.getT1();
String spaceId = tuple.getT2();
String appId = tuple.getT3();
return this.cfAccessor.retrieveProcesses(orgId, spaceId, appId);
}).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().stop();
return tuple.getT1();
});
Flux<InternalInstance> fluxInstances = Mono.zip(Mono.just(instance), processesResponse, instance.applicationId).flatMapMany(tuple -> {
InternalInstance inst = tuple.getT1();
ListProcessesResponse response = tuple.getT2();
String appId = tuple.getT3();
List<ProcessResource> resourcesList = response.getResources();
if (resourcesList.isEmpty())
return Mono.empty();
int instances = resourcesList.get(0).getInstances();
List<InternalInstance> resultInstances = new LinkedList<>();
for (int i = 0; i < instances; i++) {
InternalInstance clone = null;
try {
clone = (InternalInstance) inst.clone();
} catch (Exception e) {
// may not happen
return Mono.empty();
}
clone.instanceId = String.format("%s:%d", appId, i);
resultInstances.add(clone);
}
return Flux.fromIterable(resultInstances);
});
return fluxInstances;
});
return allInstances;
}
Aggregations