use of org.cloudfoundry.client.v2.domains.Domain in project cf-java-client by cloudfoundry.
the class DefaultApplicationsTest method pushDomainNotFound.
@Test
public void pushDomainNotFound() throws IOException {
Path testApplication = new ClassPathResource("test-application.zip").getFile().toPath();
requestApplicationsEmpty(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestCreateApplication(this.cloudFoundryClient, ApplicationManifest.builder().path(testApplication).domain("test-shared-domain").name("test-application-name").build(), TEST_SPACE_ID, null, "test-application-id");
requestSpace(this.cloudFoundryClient, TEST_SPACE_ID, TEST_ORGANIZATION_ID);
requestPrivateDomainsEmpty(this.cloudFoundryClient, TEST_ORGANIZATION_ID);
requestSharedDomainsEmpty(this.cloudFoundryClient);
requestApplicationRoutes(this.cloudFoundryClient, "test-application-id", "test-route-id");
requestListMatchingResources(this.cloudFoundryClient, Arrays.asList(new ResourceMatchingUtils.ArtifactMetadata("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Staticfile", "100644", 0), new ResourceMatchingUtils.ArtifactMetadata("45044a6ddbfe11415a8f8a6219de68a2c66b496b", "index.html", "100644", 178)));
this.applications.push(PushApplicationRequest.builder().path(testApplication).domain("test-shared-domain").name("test-application-name").build()).as(StepVerifier::create).consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Domain test-shared-domain not found")).verify(Duration.ofSeconds(5));
}
use of org.cloudfoundry.client.v2.domains.Domain in project cf-java-client by cloudfoundry.
the class DefaultApplicationsTest method pushUploadFails.
@Test
public void pushUploadFails() 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);
requestPrivateDomainsEmpty(this.cloudFoundryClient, TEST_ORGANIZATION_ID);
requestApplicationRoutes(this.cloudFoundryClient, "test-application-id", "test-route-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");
requestJobFailure(this.cloudFoundryClient, "test-job-entity-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(ClientV2Exception.class).hasMessage("test-error-details-errorCode(1): test-error-details-description")).verify(Duration.ofSeconds(5));
}
use of org.cloudfoundry.client.v2.domains.Domain in project promregator by promregator.
the class ReactiveAppInstanceScanner method determineInstancesFromTargets.
@Override
public List<Instance> determineInstancesFromTargets(List<ResolvedTarget> targets, @Nullable Predicate<? super String> applicationIdFilter, @Nullable Predicate<? super Instance> instanceFilter) {
Flux<ResolvedTarget> targetsFlux = Flux.fromIterable(targets);
Flux<OSAVector> initialOSAVectorFlux = targetsFlux.map(target -> {
OSAVector v = new OSAVector();
v.setTarget(target);
v.setApplicationId(target.getApplicationId());
v.setInternalRoutePort(target.getOriginalTarget().getInternalRoutePort());
return v;
});
Flux<String> orgIdFlux = initialOSAVectorFlux.flatMapSequential(v -> this.getOrgId(v.getTarget().getOrgName()));
Flux<OSAVector> osaVectorOrgFlux = Flux.zip(initialOSAVectorFlux, orgIdFlux).flatMap(tuple -> {
OSAVector v = tuple.getT1();
if (INVALID_ORG_ID.equals(tuple.getT2())) {
// NB: This drops the current target!
return Mono.empty();
}
v.setOrgId(tuple.getT2());
return Mono.just(v);
});
Flux<String> spaceIdFlux = osaVectorOrgFlux.flatMapSequential(v -> this.getSpaceId(v.getOrgId(), v.getTarget().getSpaceName()));
Flux<OSAVector> osaVectorSpaceFlux = Flux.zip(osaVectorOrgFlux, spaceIdFlux).flatMap(tuple -> {
OSAVector v = tuple.getT1();
if (INVALID_SPACE_ID.equals(tuple.getT2())) {
// NB: This drops the current target!
return Mono.empty();
}
v.setSpaceId(tuple.getT2());
return Mono.just(v);
});
Flux<Map<String, SpaceApplicationSummary>> spaceSummaryFlux = osaVectorSpaceFlux.flatMapSequential(v -> this.getSpaceSummary(v.getSpaceId()));
Flux<OSAVector> osaVectorApplicationFlux = Flux.zip(osaVectorSpaceFlux, spaceSummaryFlux).flatMap(tuple -> {
OSAVector v = tuple.getT1();
if (INVALID_SUMMARY == tuple.getT2()) {
// NB: This drops the current target!
return Mono.empty();
}
Map<String, SpaceApplicationSummary> spaceSummaryMap = tuple.getT2();
SpaceApplicationSummary sas = spaceSummaryMap.get(v.getTarget().getApplicationName().toLowerCase(LOCALE_OF_LOWER_CASE_CONVERSION_FOR_IDENTIFIER_COMPARISON));
if (sas == null) {
// NB: This drops the current target!
return Mono.empty();
}
List<String> urls = sas.getUrls();
if (urls != null && !urls.isEmpty()) {
// Set the access url to the selected route (without any protocol or path yet)
v.setAccessURL(this.determineApplicationRoute(urls, v.getTarget().getOriginalTarget().getPreferredRouteRegexPatterns()));
} else {
// if there is no url, skip this one
return Mono.empty();
}
// There is little reason why this should not find the correct domain
try {
Route route = sas.getRoutes().stream().filter(rt -> v.getAccessURL().startsWith(rt.getHost() + "." + rt.getDomain().getName())).findFirst().get();
v.setDomainId(route.getDomain().getId());
} catch (Exception e) {
log.warn(String.format("unable to find matching domain for the url %s", v.getAccessURL()));
}
v.setNumberOfInstances(sas.getInstances());
return Mono.just(v);
});
Flux<List<DomainResource>> domainFlux = osaVectorApplicationFlux.flatMapSequential(v -> {
return this.cfAccessor.retrieveAllDomains(v.getOrgId()).map(mapper -> mapper.getResources());
});
Flux<OSAVector> osaVectorDomainApplicationFlux = Flux.zip(osaVectorApplicationFlux, domainFlux).flatMap(tuple -> {
OSAVector v = tuple.getT1();
List<DomainResource> domains = tuple.getT2();
if (domains.size() == 0 || v.getDomainId() == null) {
// NB: This drops the current target!
return Mono.empty();
}
// this is to make sure we have compatibility with existing behaviour
if (!v.getDomainId().isEmpty()) {
try {
DomainResource domain = domains.stream().filter(r -> r.getMetadata().getId().equals(v.getDomainId())).findFirst().get();
v.setInternal(domain.getEntity().getInternal());
} catch (Exception e) {
log.warn(String.format("unable to find matching domain for the domain with id %s", v.getDomainId()));
}
}
return Mono.just(v);
});
// perform pre-filtering, if available
if (applicationIdFilter != null) {
osaVectorDomainApplicationFlux = osaVectorDomainApplicationFlux.filter(v -> applicationIdFilter.test(v.getApplicationId()));
}
Flux<Instance> instancesFlux = osaVectorDomainApplicationFlux.flatMapSequential(v -> {
List<Instance> instances = new ArrayList<>(v.getNumberOfInstances());
for (int i = 0; i < v.numberOfInstances; i++) {
Instance inst = new Instance(v.getTarget(), String.format("%s:%d", v.getApplicationId(), i), v.getAccessURL(), v.isInternal());
if (v.isInternal()) {
inst.setAccessUrl(this.formatInternalAccessURL(v.getAccessURL(), v.getTarget().getPath(), v.getInternalRoutePort(), i));
} else {
inst.setAccessUrl(this.formatAccessURL(v.getTarget().getProtocol(), v.getAccessURL(), v.getTarget().getPath()));
}
instances.add(inst);
}
return Flux.fromIterable(instances);
});
// perform pre-filtering, if available
if (instanceFilter != null) {
instancesFlux = instancesFlux.filter(instanceFilter);
}
Mono<List<Instance>> listInstancesMono = instancesFlux.collectList();
List<Instance> result = null;
try {
result = listInstancesMono.block();
} catch (RuntimeException e) {
log.error("Error during retrieving the instances of a list of targets", e);
result = null;
}
return result;
}
use of org.cloudfoundry.client.v2.domains.Domain in project promregator by promregator.
the class CFAccessorMock method retrieveSpaceSummary.
@Override
public Mono<GetSpaceSummaryResponse> retrieveSpaceSummary(String spaceId) {
if (spaceId.equals(UNITTEST_SPACE_UUID)) {
List<SpaceApplicationSummary> list = new LinkedList<>();
Domain sharedDomain = Domain.builder().id(UNITTEST_SHARED_DOMAIN_UUID).name(UNITTEST_SHARED_DOMAIN).build();
Domain additionalSharedDomain = Domain.builder().id(UNITTEST_ADDITIONAL_SHARED_DOMAIN_UUID).name(UNITTEST_ADDITIONAL_SHARED_DOMAIN).build();
Domain internalDomain = Domain.builder().id(UNITTEST_INTERNAL_DOMAIN_UUID).name(UNITTEST_INTERNAL_DOMAIN).build();
final String[] urls1 = { UNITTEST_APP1_HOST + "." + UNITTEST_SHARED_DOMAIN };
final Route[] routes1 = { Route.builder().domain(sharedDomain).host(UNITTEST_APP1_HOST).build() };
SpaceApplicationSummary sas = SpaceApplicationSummary.builder().id(UNITTEST_APP1_UUID).name("testapp").addAllRoutes(Arrays.asList(routes1)).addAllUrls(Arrays.asList(urls1)).instances(2).build();
list.add(sas);
String additionalPath = "/additionalPath";
final String[] urls2 = { UNITTEST_APP2_HOST + "." + UNITTEST_SHARED_DOMAIN + additionalPath, UNITTEST_APP2_HOST + "." + UNITTEST_ADDITIONAL_SHARED_DOMAIN + additionalPath };
final Route[] routes2 = { Route.builder().domain(sharedDomain).host(UNITTEST_APP2_HOST).path(additionalPath).build(), Route.builder().domain(additionalSharedDomain).host(UNITTEST_APP2_HOST).path(additionalPath).build() };
sas = SpaceApplicationSummary.builder().id(UNITTEST_APP2_UUID).name("testapp2").addAllRoutes(Arrays.asList(routes2)).addAllUrls(Arrays.asList(urls2)).instances(1).build();
list.add(sas);
sas = SpaceApplicationSummary.builder().id(UNITTEST_APP3_UUID).name("testapp3").addAllRoutes(Lists.emptyList()).addAllUrls(Lists.emptyList()).instances(1).build();
list.add(sas);
final String[] urls3 = { UNITTEST_APP_INTERNAL_HOST + "." + UNITTEST_INTERNAL_DOMAIN };
final Route[] routes3 = { Route.builder().domain(internalDomain).host(UNITTEST_APP_INTERNAL_HOST).build() };
sas = SpaceApplicationSummary.builder().id(UNITTEST_APP_INTERNAL_UUID).name("internalapp").addAllRoutes(Arrays.asList(routes3)).addAllUrls(Arrays.asList(urls3)).instances(2).build();
list.add(sas);
GetSpaceSummaryResponse resp = GetSpaceSummaryResponse.builder().addAllApplications(list).build();
return Mono.just(resp);
} else if (spaceId.equals(UNITTEST_SPACE_UUID_DOESNOTEXIST)) {
return Mono.just(GetSpaceSummaryResponse.builder().build());
} else if (spaceId.equals(UNITTEST_SPACE_UUID_EXCEPTION)) {
return Mono.just(GetSpaceSummaryResponse.builder().build()).map(x -> {
throw new Error("exception on application summary");
});
}
Assertions.fail("Invalid retrieveSpaceSummary request");
return null;
}
use of org.cloudfoundry.client.v2.domains.Domain in project promregator by promregator.
the class CFAccessorMassMock method retrieveAllDomains.
@Override
public Mono<ListOrganizationDomainsResponse> retrieveAllDomains(String orgId) {
List<DomainResource> domains = new ArrayList<DomainResource>();
for (int i = 0; i < 100; i++) {
DomainResource domain = DomainResource.builder().entity(DomainEntity.builder().name(UNITTEST_SHARED_DOMAIN).internal(false).build()).metadata(Metadata.builder().id(UNITTEST_SHARED_DOMAIN_UUID + i).createdAt(CREATED_AT_TIMESTAMP).build()).build();
domains.add(domain);
}
ListOrganizationDomainsResponse response = ListOrganizationDomainsResponse.builder().addAllResources(domains).build();
return Mono.just(response);
}
Aggregations