Search in sources :

Example 1 with ProcessResource

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;
}
Also used : ListProcessesResponse(org.cloudfoundry.client.v3.processes.ListProcessesResponse) Builder(org.cloudfoundry.client.v3.processes.ProcessResource.Builder) HealthCheck(org.cloudfoundry.client.v3.processes.HealthCheck) ProcessResource(org.cloudfoundry.client.v3.processes.ProcessResource) Data(org.cloudfoundry.client.v3.processes.Data) LinkedList(java.util.LinkedList)

Example 2 with ProcessResource

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;
}
Also used : RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity) Target(org.cloudfoundry.promregator.config.Target) Autowired(org.springframework.beans.factory.annotation.Autowired) SharedDomainEntity(org.cloudfoundry.client.v2.shareddomains.SharedDomainEntity) ListProcessesResponse(org.cloudfoundry.client.v3.processes.ListProcessesResponse) Mono(reactor.core.publisher.Mono) CFAccessor(org.cloudfoundry.promregator.cfaccessor.CFAccessor) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) TimeUnit(java.util.concurrent.TimeUnit) Value(org.springframework.beans.factory.annotation.Value) PassiveExpiringMap(org.apache.commons.collections4.map.PassiveExpiringMap) Logger(org.apache.log4j.Logger) Flux(reactor.core.publisher.Flux) List(java.util.List) Component(org.springframework.stereotype.Component) ApplicationResource(org.cloudfoundry.client.v2.applications.ApplicationResource) Timer(io.prometheus.client.Histogram.Timer) ProcessResource(org.cloudfoundry.client.v3.processes.ProcessResource) PostConstruct(javax.annotation.PostConstruct) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource) LinkedList(java.util.LinkedList) InternalMetrics(org.cloudfoundry.promregator.internalmetrics.InternalMetrics) RouteMappingResource(org.cloudfoundry.client.v2.routemappings.RouteMappingResource) ListProcessesResponse(org.cloudfoundry.client.v3.processes.ListProcessesResponse) ProcessResource(org.cloudfoundry.client.v3.processes.ProcessResource) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)2 ListProcessesResponse (org.cloudfoundry.client.v3.processes.ListProcessesResponse)2 ProcessResource (org.cloudfoundry.client.v3.processes.ProcessResource)2 Timer (io.prometheus.client.Histogram.Timer)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 PostConstruct (javax.annotation.PostConstruct)1 PassiveExpiringMap (org.apache.commons.collections4.map.PassiveExpiringMap)1 Logger (org.apache.log4j.Logger)1 ApplicationResource (org.cloudfoundry.client.v2.applications.ApplicationResource)1 OrganizationResource (org.cloudfoundry.client.v2.organizations.OrganizationResource)1 RouteMappingResource (org.cloudfoundry.client.v2.routemappings.RouteMappingResource)1 RouteEntity (org.cloudfoundry.client.v2.routes.RouteEntity)1 SharedDomainEntity (org.cloudfoundry.client.v2.shareddomains.SharedDomainEntity)1 SpaceResource (org.cloudfoundry.client.v2.spaces.SpaceResource)1 Data (org.cloudfoundry.client.v3.processes.Data)1 HealthCheck (org.cloudfoundry.client.v3.processes.HealthCheck)1 Builder (org.cloudfoundry.client.v3.processes.ProcessResource.Builder)1 CFAccessor (org.cloudfoundry.promregator.cfaccessor.CFAccessor)1 Target (org.cloudfoundry.promregator.config.Target)1