use of org.cloudfoundry.client.v2.routes.Route in project cf-java-client by cloudfoundry.
the class DefaultApplicationsTest method pushStartFailsStaging.
@Test
public void pushStartFailsStaging() throws IOException {
Path testApplication = new ClassPathResource("test-application.zip").getFile().toPath();
requestApplicationsEmpty(this.cloudFoundryClient, "test-name", TEST_SPACE_ID);
requestCreateApplication(this.cloudFoundryClient, ApplicationManifest.builder().path(testApplication).domain("test-shared-domain").name("test-name").build(), TEST_SPACE_ID, null, "test-application-id");
requestSpace(this.cloudFoundryClient, TEST_SPACE_ID, TEST_ORGANIZATION_ID);
requestApplicationRoutes(this.cloudFoundryClient, "test-application-id", "test-route-id");
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-private-domain-id");
requestSharedDomains(this.cloudFoundryClient, "test-shared-domain", "test-shared-domain-id");
requestRoutesEmpty(this.cloudFoundryClient, "test-shared-domain-id", "test-name", null, null);
requestListMatchingResources(this.cloudFoundryClient, Arrays.asList(new ResourceMatchingUtils.ArtifactMetadata("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Staticfile", "100644", 0), new ResourceMatchingUtils.ArtifactMetadata("45044a6ddbfe11415a8f8a6219de68a2c66b496b", "index.html", "100644", 178)));
requestCreateRoute(this.cloudFoundryClient, "test-shared-domain-id", "test-name", null, null, TEST_SPACE_ID, "test-route-id");
requestAssociateRoute(this.cloudFoundryClient, "test-application-id", "test-route-id");
requestUpload(this.cloudFoundryClient, "test-application-id", testApplication, "test-job-id");
requestJobSuccess(this.cloudFoundryClient, "test-job-entity-id");
requestUpdateApplicationState(this.cloudFoundryClient, "test-application-id", "STOPPED");
requestUpdateApplicationState(this.cloudFoundryClient, "test-application-id", "STARTED");
requestGetApplicationFailing(this.cloudFoundryClient, "test-application-id");
StepVerifier.withVirtualTime(() -> this.applications.push(PushApplicationRequest.builder().path(testApplication).domain("test-shared-domain").name("test-name").build())).then(() -> VirtualTimeScheduler.get().advanceTimeBy(Duration.ofSeconds(3))).consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("Application test-name failed during staging")).verify(Duration.ofSeconds(5));
}
use of org.cloudfoundry.client.v2.routes.Route 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.Route 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.Route 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.Route 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