Search in sources :

Example 1 with Domain

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));
}
Also used : Path(java.nio.file.Path) LogMessage(org.cloudfoundry.doppler.LogMessage) Arrays(java.util.Arrays) GetApplicationResponse(org.cloudfoundry.client.v2.applications.GetApplicationResponse) StepVerifier(reactor.test.StepVerifier) GetJobRequest(org.cloudfoundry.client.v2.jobs.GetJobRequest) SharedDomainEntity(org.cloudfoundry.client.v2.shareddomains.SharedDomainEntity) CancelTaskResponse(org.cloudfoundry.client.v3.tasks.CancelTaskResponse) OrderDirection(org.cloudfoundry.client.v2.OrderDirection) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) LifecycleType(org.cloudfoundry.client.v3.LifecycleType) ApplicationEntity(org.cloudfoundry.client.v2.applications.ApplicationEntity) ListRoutesResponse(org.cloudfoundry.client.v2.routes.ListRoutesResponse) TestObjects.fill(org.cloudfoundry.operations.TestObjects.fill) Duration(java.time.Duration) Map(java.util.Map) ListApplicationsResponse(org.cloudfoundry.client.v3.applications.ListApplicationsResponse) GetSpaceSummaryResponse(org.cloudfoundry.client.v2.spaces.GetSpaceSummaryResponse) Path(java.nio.file.Path) GetStackRequest(org.cloudfoundry.client.v2.stacks.GetStackRequest) PrivateDomainEntity(org.cloudfoundry.client.v2.privatedomains.PrivateDomainEntity) SharedDomainResource(org.cloudfoundry.client.v2.shareddomains.SharedDomainResource) SpaceApplicationSummary(org.cloudfoundry.client.v2.spaces.SpaceApplicationSummary) Envelope(org.cloudfoundry.doppler.Envelope) UpdateApplicationRequest(org.cloudfoundry.client.v2.applications.UpdateApplicationRequest) PrivateDomainResource(org.cloudfoundry.client.v2.privatedomains.PrivateDomainResource) ListEventsResponse(org.cloudfoundry.client.v2.events.ListEventsResponse) CloudFoundryClient(org.cloudfoundry.client.CloudFoundryClient) RETURNS_SMART_NULLS(org.mockito.Mockito.RETURNS_SMART_NULLS) CancelTaskRequest(org.cloudfoundry.client.v3.tasks.CancelTaskRequest) DopplerClient(org.cloudfoundry.doppler.DopplerClient) Mockito.mock(org.mockito.Mockito.mock) RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity) RecentLogsRequest(org.cloudfoundry.doppler.RecentLogsRequest) CreateRouteResponse(org.cloudfoundry.client.v2.routes.CreateRouteResponse) ListApplicationsRequest(org.cloudfoundry.client.v3.applications.ListApplicationsRequest) TaskResource(org.cloudfoundry.client.v3.tasks.TaskResource) GetSpaceRequest(org.cloudfoundry.client.v2.spaces.GetSpaceRequest) Supplier(java.util.function.Supplier) AssociateApplicationRouteRequest(org.cloudfoundry.client.v2.applications.AssociateApplicationRouteRequest) ListOrganizationSpacesRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationSpacesRequest) Lifecycle(org.cloudfoundry.client.v3.Lifecycle) Resource(org.cloudfoundry.client.v2.resourcematch.Resource) ListOrganizationPrivateDomainsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationPrivateDomainsResponse) Statistics(org.cloudfoundry.client.v2.applications.Statistics) ApplicationInstanceInfo(org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo) RemoveApplicationRouteRequest(org.cloudfoundry.client.v2.applications.RemoveApplicationRouteRequest) ErrorDetails(org.cloudfoundry.client.v2.jobs.ErrorDetails) VirtualTimeScheduler(reactor.test.scheduler.VirtualTimeScheduler) ApplicationStatisticsResponse(org.cloudfoundry.client.v2.applications.ApplicationStatisticsResponse) ListApplicationServiceBindingsRequest(org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) ApplicationStatisticsRequest(org.cloudfoundry.client.v2.applications.ApplicationStatisticsRequest) ListApplicationRoutesResponse(org.cloudfoundry.client.v2.applications.ListApplicationRoutesResponse) UpdateApplicationResponse(org.cloudfoundry.client.v2.applications.UpdateApplicationResponse) Flux(reactor.core.publisher.Flux) InstanceStatistics(org.cloudfoundry.client.v2.applications.InstanceStatistics) EventEntity(org.cloudfoundry.client.v2.events.EventEntity) FluentMap(org.cloudfoundry.util.FluentMap) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource) ListEventsRequest(org.cloudfoundry.client.v2.events.ListEventsRequest) OrganizationEntity(org.cloudfoundry.client.v2.organizations.OrganizationEntity) GetSharedDomainRequest(org.cloudfoundry.client.v2.shareddomains.GetSharedDomainRequest) BuildpackData(org.cloudfoundry.client.v3.BuildpackData) StreamRequest(org.cloudfoundry.doppler.StreamRequest) ListSharedDomainsResponse(org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsResponse) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ListSpaceApplicationsResponse(org.cloudfoundry.client.v2.spaces.ListSpaceApplicationsResponse) SpaceEntity(org.cloudfoundry.client.v2.spaces.SpaceEntity) EventResource(org.cloudfoundry.client.v2.events.EventResource) AbstractOperationsTest(org.cloudfoundry.operations.AbstractOperationsTest) ApplicationEnvironmentResponse(org.cloudfoundry.client.v2.applications.ApplicationEnvironmentResponse) UploadApplicationRequest(org.cloudfoundry.client.v2.applications.UploadApplicationRequest) GetSpaceSummaryRequest(org.cloudfoundry.client.v2.spaces.GetSpaceSummaryRequest) GetSharedDomainResponse(org.cloudfoundry.client.v2.shareddomains.GetSharedDomainResponse) TerminateApplicationInstanceRequest(org.cloudfoundry.client.v2.applications.TerminateApplicationInstanceRequest) ListApplicationRoutesRequest(org.cloudfoundry.client.v2.applications.ListApplicationRoutesRequest) ListSpaceApplicationsRequest(org.cloudfoundry.client.v2.spaces.ListSpaceApplicationsRequest) Collection(java.util.Collection) UploadApplicationResponse(org.cloudfoundry.client.v2.applications.UploadApplicationResponse) ListOrganizationsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse) ResourceMatchingUtils(org.cloudfoundry.util.ResourceMatchingUtils) JobEntity(org.cloudfoundry.client.v2.jobs.JobEntity) CreateApplicationResponse(org.cloudfoundry.client.v2.applications.CreateApplicationResponse) SummaryApplicationRequest(org.cloudfoundry.client.v2.applications.SummaryApplicationRequest) ServiceBindingResource(org.cloudfoundry.client.v2.servicebindings.ServiceBindingResource) CreateRouteRequest(org.cloudfoundry.client.v2.routes.CreateRouteRequest) Optional(java.util.Optional) ListOrganizationPrivateDomainsRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationPrivateDomainsRequest) RouteResource(org.cloudfoundry.client.v2.routes.RouteResource) Queue(java.util.Queue) EventType(org.cloudfoundry.doppler.EventType) ListStacksRequest(org.cloudfoundry.client.v2.stacks.ListStacksRequest) GetJobResponse(org.cloudfoundry.client.v2.jobs.GetJobResponse) Usage(org.cloudfoundry.client.v2.applications.Usage) ClassPathResource(org.springframework.core.io.ClassPathResource) RestageApplicationResponse(org.cloudfoundry.client.v2.applications.RestageApplicationResponse) DeleteRouteResponse(org.cloudfoundry.client.v2.routes.DeleteRouteResponse) CreateTaskResponse(org.cloudfoundry.client.v3.tasks.CreateTaskResponse) CopyApplicationResponse(org.cloudfoundry.client.v2.applications.CopyApplicationResponse) ListStacksResponse(org.cloudfoundry.client.v2.stacks.ListStacksResponse) ListOrganizationsRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest) ApplicationResource(org.cloudfoundry.client.v2.applications.ApplicationResource) CopyApplicationRequest(org.cloudfoundry.client.v2.applications.CopyApplicationRequest) ListRoutesRequest(org.cloudfoundry.client.v2.routes.ListRoutesRequest) ListOrganizationSpacesResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationSpacesResponse) LinkedList(java.util.LinkedList) ListMatchingResourcesResponse(org.cloudfoundry.client.v2.resourcematch.ListMatchingResourcesResponse) GetStackResponse(org.cloudfoundry.client.v2.stacks.GetStackResponse) ApplicationEnvironmentRequest(org.cloudfoundry.client.v2.applications.ApplicationEnvironmentRequest) ListMatchingResourcesRequest(org.cloudfoundry.client.v2.resourcematch.ListMatchingResourcesRequest) CreateTaskRequest(org.cloudfoundry.client.v3.tasks.CreateTaskRequest) Mockito.when(org.mockito.Mockito.when) ListApplicationServiceBindingsResponse(org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsResponse) ServiceInstance(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance) GetSpaceResponse(org.cloudfoundry.client.v2.spaces.GetSpaceResponse) ListSharedDomainsRequest(org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsRequest) DateUtils(org.cloudfoundry.util.DateUtils) ApplicationInstancesResponse(org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse) ApplicationState(org.cloudfoundry.client.v3.applications.ApplicationState) ClientV2Exception(org.cloudfoundry.client.v2.ClientV2Exception) StackEntity(org.cloudfoundry.client.v2.stacks.StackEntity) CreateApplicationRequest(org.cloudfoundry.client.v2.applications.CreateApplicationRequest) Metadata(org.cloudfoundry.client.v2.Metadata) RemoveApplicationServiceBindingRequest(org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest) Collections(java.util.Collections) ApplicationInstancesRequest(org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest) SummaryApplicationResponse(org.cloudfoundry.client.v2.applications.SummaryApplicationResponse) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) AbstractOperationsTest(org.cloudfoundry.operations.AbstractOperationsTest)

Example 2 with Domain

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));
}
Also used : Path(java.nio.file.Path) LogMessage(org.cloudfoundry.doppler.LogMessage) Arrays(java.util.Arrays) GetApplicationResponse(org.cloudfoundry.client.v2.applications.GetApplicationResponse) StepVerifier(reactor.test.StepVerifier) GetJobRequest(org.cloudfoundry.client.v2.jobs.GetJobRequest) SharedDomainEntity(org.cloudfoundry.client.v2.shareddomains.SharedDomainEntity) CancelTaskResponse(org.cloudfoundry.client.v3.tasks.CancelTaskResponse) OrderDirection(org.cloudfoundry.client.v2.OrderDirection) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) LifecycleType(org.cloudfoundry.client.v3.LifecycleType) ApplicationEntity(org.cloudfoundry.client.v2.applications.ApplicationEntity) ListRoutesResponse(org.cloudfoundry.client.v2.routes.ListRoutesResponse) TestObjects.fill(org.cloudfoundry.operations.TestObjects.fill) Duration(java.time.Duration) Map(java.util.Map) ListApplicationsResponse(org.cloudfoundry.client.v3.applications.ListApplicationsResponse) GetSpaceSummaryResponse(org.cloudfoundry.client.v2.spaces.GetSpaceSummaryResponse) Path(java.nio.file.Path) GetStackRequest(org.cloudfoundry.client.v2.stacks.GetStackRequest) PrivateDomainEntity(org.cloudfoundry.client.v2.privatedomains.PrivateDomainEntity) SharedDomainResource(org.cloudfoundry.client.v2.shareddomains.SharedDomainResource) SpaceApplicationSummary(org.cloudfoundry.client.v2.spaces.SpaceApplicationSummary) Envelope(org.cloudfoundry.doppler.Envelope) UpdateApplicationRequest(org.cloudfoundry.client.v2.applications.UpdateApplicationRequest) PrivateDomainResource(org.cloudfoundry.client.v2.privatedomains.PrivateDomainResource) ListEventsResponse(org.cloudfoundry.client.v2.events.ListEventsResponse) CloudFoundryClient(org.cloudfoundry.client.CloudFoundryClient) RETURNS_SMART_NULLS(org.mockito.Mockito.RETURNS_SMART_NULLS) CancelTaskRequest(org.cloudfoundry.client.v3.tasks.CancelTaskRequest) DopplerClient(org.cloudfoundry.doppler.DopplerClient) Mockito.mock(org.mockito.Mockito.mock) RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity) RecentLogsRequest(org.cloudfoundry.doppler.RecentLogsRequest) CreateRouteResponse(org.cloudfoundry.client.v2.routes.CreateRouteResponse) ListApplicationsRequest(org.cloudfoundry.client.v3.applications.ListApplicationsRequest) TaskResource(org.cloudfoundry.client.v3.tasks.TaskResource) GetSpaceRequest(org.cloudfoundry.client.v2.spaces.GetSpaceRequest) Supplier(java.util.function.Supplier) AssociateApplicationRouteRequest(org.cloudfoundry.client.v2.applications.AssociateApplicationRouteRequest) ListOrganizationSpacesRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationSpacesRequest) Lifecycle(org.cloudfoundry.client.v3.Lifecycle) Resource(org.cloudfoundry.client.v2.resourcematch.Resource) ListOrganizationPrivateDomainsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationPrivateDomainsResponse) Statistics(org.cloudfoundry.client.v2.applications.Statistics) ApplicationInstanceInfo(org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo) RemoveApplicationRouteRequest(org.cloudfoundry.client.v2.applications.RemoveApplicationRouteRequest) ErrorDetails(org.cloudfoundry.client.v2.jobs.ErrorDetails) VirtualTimeScheduler(reactor.test.scheduler.VirtualTimeScheduler) ApplicationStatisticsResponse(org.cloudfoundry.client.v2.applications.ApplicationStatisticsResponse) ListApplicationServiceBindingsRequest(org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) ApplicationStatisticsRequest(org.cloudfoundry.client.v2.applications.ApplicationStatisticsRequest) ListApplicationRoutesResponse(org.cloudfoundry.client.v2.applications.ListApplicationRoutesResponse) UpdateApplicationResponse(org.cloudfoundry.client.v2.applications.UpdateApplicationResponse) Flux(reactor.core.publisher.Flux) InstanceStatistics(org.cloudfoundry.client.v2.applications.InstanceStatistics) EventEntity(org.cloudfoundry.client.v2.events.EventEntity) FluentMap(org.cloudfoundry.util.FluentMap) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource) ListEventsRequest(org.cloudfoundry.client.v2.events.ListEventsRequest) OrganizationEntity(org.cloudfoundry.client.v2.organizations.OrganizationEntity) GetSharedDomainRequest(org.cloudfoundry.client.v2.shareddomains.GetSharedDomainRequest) BuildpackData(org.cloudfoundry.client.v3.BuildpackData) StreamRequest(org.cloudfoundry.doppler.StreamRequest) ListSharedDomainsResponse(org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsResponse) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ListSpaceApplicationsResponse(org.cloudfoundry.client.v2.spaces.ListSpaceApplicationsResponse) SpaceEntity(org.cloudfoundry.client.v2.spaces.SpaceEntity) EventResource(org.cloudfoundry.client.v2.events.EventResource) AbstractOperationsTest(org.cloudfoundry.operations.AbstractOperationsTest) ApplicationEnvironmentResponse(org.cloudfoundry.client.v2.applications.ApplicationEnvironmentResponse) UploadApplicationRequest(org.cloudfoundry.client.v2.applications.UploadApplicationRequest) GetSpaceSummaryRequest(org.cloudfoundry.client.v2.spaces.GetSpaceSummaryRequest) GetSharedDomainResponse(org.cloudfoundry.client.v2.shareddomains.GetSharedDomainResponse) TerminateApplicationInstanceRequest(org.cloudfoundry.client.v2.applications.TerminateApplicationInstanceRequest) ListApplicationRoutesRequest(org.cloudfoundry.client.v2.applications.ListApplicationRoutesRequest) ListSpaceApplicationsRequest(org.cloudfoundry.client.v2.spaces.ListSpaceApplicationsRequest) Collection(java.util.Collection) UploadApplicationResponse(org.cloudfoundry.client.v2.applications.UploadApplicationResponse) ListOrganizationsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse) ResourceMatchingUtils(org.cloudfoundry.util.ResourceMatchingUtils) JobEntity(org.cloudfoundry.client.v2.jobs.JobEntity) CreateApplicationResponse(org.cloudfoundry.client.v2.applications.CreateApplicationResponse) SummaryApplicationRequest(org.cloudfoundry.client.v2.applications.SummaryApplicationRequest) ServiceBindingResource(org.cloudfoundry.client.v2.servicebindings.ServiceBindingResource) CreateRouteRequest(org.cloudfoundry.client.v2.routes.CreateRouteRequest) Optional(java.util.Optional) ListOrganizationPrivateDomainsRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationPrivateDomainsRequest) RouteResource(org.cloudfoundry.client.v2.routes.RouteResource) Queue(java.util.Queue) EventType(org.cloudfoundry.doppler.EventType) ListStacksRequest(org.cloudfoundry.client.v2.stacks.ListStacksRequest) GetJobResponse(org.cloudfoundry.client.v2.jobs.GetJobResponse) Usage(org.cloudfoundry.client.v2.applications.Usage) ClassPathResource(org.springframework.core.io.ClassPathResource) RestageApplicationResponse(org.cloudfoundry.client.v2.applications.RestageApplicationResponse) DeleteRouteResponse(org.cloudfoundry.client.v2.routes.DeleteRouteResponse) CreateTaskResponse(org.cloudfoundry.client.v3.tasks.CreateTaskResponse) CopyApplicationResponse(org.cloudfoundry.client.v2.applications.CopyApplicationResponse) ListStacksResponse(org.cloudfoundry.client.v2.stacks.ListStacksResponse) ListOrganizationsRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest) ApplicationResource(org.cloudfoundry.client.v2.applications.ApplicationResource) CopyApplicationRequest(org.cloudfoundry.client.v2.applications.CopyApplicationRequest) ListRoutesRequest(org.cloudfoundry.client.v2.routes.ListRoutesRequest) ListOrganizationSpacesResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationSpacesResponse) LinkedList(java.util.LinkedList) ListMatchingResourcesResponse(org.cloudfoundry.client.v2.resourcematch.ListMatchingResourcesResponse) GetStackResponse(org.cloudfoundry.client.v2.stacks.GetStackResponse) ApplicationEnvironmentRequest(org.cloudfoundry.client.v2.applications.ApplicationEnvironmentRequest) ListMatchingResourcesRequest(org.cloudfoundry.client.v2.resourcematch.ListMatchingResourcesRequest) CreateTaskRequest(org.cloudfoundry.client.v3.tasks.CreateTaskRequest) Mockito.when(org.mockito.Mockito.when) ListApplicationServiceBindingsResponse(org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsResponse) ServiceInstance(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance) GetSpaceResponse(org.cloudfoundry.client.v2.spaces.GetSpaceResponse) ListSharedDomainsRequest(org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsRequest) DateUtils(org.cloudfoundry.util.DateUtils) ApplicationInstancesResponse(org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse) ApplicationState(org.cloudfoundry.client.v3.applications.ApplicationState) ClientV2Exception(org.cloudfoundry.client.v2.ClientV2Exception) StackEntity(org.cloudfoundry.client.v2.stacks.StackEntity) CreateApplicationRequest(org.cloudfoundry.client.v2.applications.CreateApplicationRequest) Metadata(org.cloudfoundry.client.v2.Metadata) RemoveApplicationServiceBindingRequest(org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest) Collections(java.util.Collections) ApplicationInstancesRequest(org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest) SummaryApplicationResponse(org.cloudfoundry.client.v2.applications.SummaryApplicationResponse) StepVerifier(reactor.test.StepVerifier) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) AbstractOperationsTest(org.cloudfoundry.operations.AbstractOperationsTest)

Example 3 with Domain

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();
}
Also used : RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity)

Example 4 with Domain

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;
    }
}
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)

Example 5 with Domain

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;
    }
}
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) SharedDomainEntity(org.cloudfoundry.client.v2.shareddomains.SharedDomainEntity)

Aggregations

LinkedList (java.util.LinkedList)12 SpaceApplicationSummary (org.cloudfoundry.client.v2.spaces.SpaceApplicationSummary)11 Flux (reactor.core.publisher.Flux)11 Mono (reactor.core.publisher.Mono)11 OrganizationResource (org.cloudfoundry.client.v2.organizations.OrganizationResource)10 SharedDomainEntity (org.cloudfoundry.client.v2.shareddomains.SharedDomainEntity)10 GetSpaceSummaryResponse (org.cloudfoundry.client.v2.spaces.GetSpaceSummaryResponse)10 SpaceResource (org.cloudfoundry.client.v2.spaces.SpaceResource)10 ApplicationResource (org.cloudfoundry.client.v2.applications.ApplicationResource)9 IOException (java.io.IOException)8 Path (java.nio.file.Path)8 Duration (java.time.Duration)8 Map (java.util.Map)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 CloudFoundryClient (org.cloudfoundry.client.CloudFoundryClient)8 Arrays (java.util.Arrays)7 Collection (java.util.Collection)7 Collections (java.util.Collections)7 Date (java.util.Date)7 Optional (java.util.Optional)7