use of org.cloudfoundry.client.v2.routes.RouteEntity in project cf-java-client by cloudfoundry.
the class CloudFoundryCleaner method cleanRoutes.
private static Flux<Void> cleanRoutes(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
return getAllDomains(cloudFoundryClient).flatMapMany(domains -> PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.routes().list(ListRoutesRequest.builder().page(page).build())).map(resource -> Tuples.of(domains, resource))).filter(predicate((domains, route) -> nameFactory.isDomainName(domains.get(ResourceUtils.getEntity(route).getDomainId())) || nameFactory.isApplicationName(ResourceUtils.getEntity(route).getHost()) || nameFactory.isHostName(ResourceUtils.getEntity(route).getHost()))).flatMap(function((domains, route) -> cloudFoundryClient.routes().delete(DeleteRouteRequest.builder().async(true).routeId(ResourceUtils.getId(route)).build()).flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)).doOnError(t -> {
RouteEntity entity = ResourceUtils.getEntity(route);
LOGGER.error("Unable to delete route {}.{}:{}{}", entity.getHost(), domains.get(entity.getDomainId()), entity.getPort(), entity.getPath(), t);
})));
}
use of org.cloudfoundry.client.v2.routes.RouteEntity in project cf-java-client by cloudfoundry.
the class DefaultRoutes method toRoute.
private static Route toRoute(List<String> applications, String domain, RouteResource resource, Optional<String> service, String space) {
RouteEntity entity = ResourceUtils.getEntity(resource);
Route.Builder builder = Route.builder().applications(applications).domain(domain).host(entity.getHost()).id(ResourceUtils.getId(resource)).path(entity.getPath()).space(space);
service.ifPresent(builder::service);
return builder.build();
}
use of org.cloudfoundry.client.v2.routes.RouteEntity 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);
}
use of org.cloudfoundry.client.v2.routes.RouteEntity 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;
}
}
Aggregations