Search in sources :

Example 1 with GetRouteResponse

use of org.cloudfoundry.client.v2.routes.GetRouteResponse in project promregator by promregator.

the class CFAccessorMock method retrieveRoute.

@Override
public Mono<GetRouteResponse> retrieveRoute(String routeId) {
    RouteEntity entity = null;
    if (routeId.equals(UNITTEST_APP1_ROUTE_UUID)) {
        entity = RouteEntity.builder().domainId(UNITTEST_SHARED_DOMAIN_UUID).host(UNITTEST_APP1_HOST).build();
    } else if (routeId.equals(UNITTEST_APP2_ROUTE_UUID)) {
        entity = RouteEntity.builder().domainId(UNITTEST_SHARED_DOMAIN_UUID).host(UNITTEST_APP2_HOST).path("additionalPath").build();
    }
    if (entity == null) {
        Assert.fail("Invalid route request");
        return null;
    }
    GetRouteResponse resp = GetRouteResponse.builder().entity(entity).build();
    return Mono.just(resp);
}
Also used : GetRouteResponse(org.cloudfoundry.client.v2.routes.GetRouteResponse) RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity)

Example 2 with GetRouteResponse

use of org.cloudfoundry.client.v2.routes.GetRouteResponse in project promregator by promregator.

the class ReactiveAppInstanceScanner method getApplicationUrl.

private Mono<String> getApplicationUrl(Mono<String> applicationIdMono, String protocol) {
    String key = String.format("%d", applicationIdMono.hashCode());
    synchronized (key.intern()) {
        Mono<String> cached = this.hostnameMap.get(key);
        if (cached != null) {
            this.internalMetrics.countHit("appinstancescanner.route");
            return cached;
        }
        this.internalMetrics.countMiss("appinstancescanner.route");
        ReactiveTimer reactiveTimer = new ReactiveTimer(this.internalMetrics, "route");
        Mono<RouteEntity> routeMono = applicationIdMono.zipWith(Mono.just(reactiveTimer)).map(tuple -> {
            tuple.getT2().start();
            return tuple.getT1();
        }).flatMap(appId -> {
            return this.cfAccessor.retrieveRouteMapping(appId);
        }).flatMap(mappingResponse -> {
            List<RouteMappingResource> resourceList = mappingResponse.getResources();
            if (resourceList.isEmpty())
                return Mono.empty();
            String routeId = resourceList.get(0).getEntity().getRouteId();
            if (routeId == null)
                return Mono.empty();
            return this.cfAccessor.retrieveRoute(routeId);
        }).flatMap(GetRouteResponse -> {
            RouteEntity route = GetRouteResponse.getEntity();
            if (route == null)
                return Mono.empty();
            // and not the URL which points to the endpoint of the cell!
            return Mono.just(route);
        });
        Mono<String> domainMono = routeMono.map(route -> route.getDomainId()).flatMap(domainId -> {
            return this.getDomain(domainId);
        });
        Mono<String> applicationUrlMono = Mono.zip(domainMono, routeMono).map(tuple -> {
            String domain = tuple.getT1();
            RouteEntity route = tuple.getT2();
            String url = String.format("%s://%s.%s", protocol, route.getHost(), domain);
            if (route.getPath() != null) {
                url += "/" + route.getPath();
            }
            return url;
        }).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
            tuple.getT2().stop();
            return tuple.getT1();
        }).cache();
        this.hostnameMap.put(key, applicationUrlMono);
        return applicationUrlMono;
    }
}
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) List(java.util.List) LinkedList(java.util.LinkedList) RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity)

Aggregations

RouteEntity (org.cloudfoundry.client.v2.routes.RouteEntity)2 Timer (io.prometheus.client.Histogram.Timer)1 LinkedList (java.util.LinkedList)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 GetRouteResponse (org.cloudfoundry.client.v2.routes.GetRouteResponse)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