use of org.cloudfoundry.client.v2.domains.Domain 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.domains.Domain in project cf-java-client by cloudfoundry.
the class DefaultApplicationsTest method pushNoDomainPrivate.
@Test
public void pushNoDomainPrivate() 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).name("test-name").build(), TEST_SPACE_ID, null, "test-application-id");
requestSpace(this.cloudFoundryClient, TEST_SPACE_ID, TEST_ORGANIZATION_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-private-domain-id");
requestSharedDomainsEmpty(this.cloudFoundryClient);
requestListMatchingResources(this.cloudFoundryClient, Arrays.asList(new ResourceMatchingUtils.ArtifactMetadata("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Staticfile", "100644", 0), new ResourceMatchingUtils.ArtifactMetadata("45044a6ddbfe11415a8f8a6219de68a2c66b496b", "index.html", "100644", 178)));
requestApplicationRoutesEmpty(this.cloudFoundryClient, "test-application-id");
this.applications.push(PushApplicationRequest.builder().path(testApplication).name("test-name").build()).as(StepVerifier::create).consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("No default domain found")).verify(Duration.ofSeconds(5));
}
use of org.cloudfoundry.client.v2.domains.Domain 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.domains.Domain 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;
}
}
use of org.cloudfoundry.client.v2.domains.Domain in project promregator by promregator.
the class ReactiveAppInstanceScanner method getDomain.
private Mono<String> getDomain(String domainIdString) {
String key = domainIdString;
synchronized (key.intern()) {
Mono<String> cached = this.domainMap.get(key);
if (cached != null) {
this.internalMetrics.countHit("appinstancescanner.domain");
return cached;
}
this.internalMetrics.countMiss("appinstancescanner.domain");
ReactiveTimer reactiveTimer = new ReactiveTimer(this.internalMetrics, "domain");
cached = Mono.just(domainIdString).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().start();
return tuple.getT1();
}).flatMap(domainId -> {
return this.cfAccessor.retrieveSharedDomain(domainId);
}).map(response -> {
SharedDomainEntity sharedDomain = response.getEntity();
return sharedDomain.getName();
}).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().stop();
return tuple.getT1();
}).cache();
this.domainMap.put(key, cached);
return cached;
}
}
Aggregations