Search in sources :

Example 1 with OrganizationResource

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;
}
Also used : ListOrganizationsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource) LinkedList(java.util.LinkedList)

Example 2 with OrganizationResource

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;
}
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) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource)

Aggregations

LinkedList (java.util.LinkedList)2 OrganizationResource (org.cloudfoundry.client.v2.organizations.OrganizationResource)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 ListOrganizationsResponse (org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse)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 ListProcessesResponse (org.cloudfoundry.client.v3.processes.ListProcessesResponse)1 ProcessResource (org.cloudfoundry.client.v3.processes.ProcessResource)1 CFAccessor (org.cloudfoundry.promregator.cfaccessor.CFAccessor)1 Target (org.cloudfoundry.promregator.config.Target)1 InternalMetrics (org.cloudfoundry.promregator.internalmetrics.InternalMetrics)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1