Search in sources :

Example 1 with RouteEntity

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);
    })));
}
Also used : Version(com.github.zafarkhaja.semver.Version) UserProvidedServiceInstanceResource(org.cloudfoundry.client.v2.userprovidedserviceinstances.UserProvidedServiceInstanceResource) ListServiceInstanceRoutesRequest(org.cloudfoundry.client.v2.serviceinstances.ListServiceInstanceRoutesRequest) ListIdentityZonesRequest(org.cloudfoundry.uaa.identityzones.ListIdentityZonesRequest) ListSpacesRequest(org.cloudfoundry.client.v2.spaces.ListSpacesRequest) LoggerFactory(org.slf4j.LoggerFactory) Tuples(reactor.util.function.Tuples) UnbindServiceInstanceRouteRequest(org.cloudfoundry.client.v2.serviceinstances.UnbindServiceInstanceRouteRequest) ListServiceInstancesRequest(org.cloudfoundry.client.v2.serviceinstances.ListServiceInstancesRequest) DeleteServiceKeyRequest(org.cloudfoundry.client.v2.servicekeys.DeleteServiceKeyRequest) ListUsersRequest(org.cloudfoundry.uaa.users.ListUsersRequest) ListServiceInstanceServiceKeysRequest(org.cloudfoundry.client.v2.serviceinstances.ListServiceInstanceServiceKeysRequest) DeleteUserRequest(org.cloudfoundry.uaa.users.DeleteUserRequest) RemoveUserProvidedServiceInstanceRouteRequest(org.cloudfoundry.client.v2.userprovidedserviceinstances.RemoveUserProvidedServiceInstanceRouteRequest) Destination(org.cloudfoundry.networking.v1.policies.Destination) ListPrivateDomainsRequest(org.cloudfoundry.client.v2.privatedomains.ListPrivateDomainsRequest) DeleteServiceBrokerRequest(org.cloudfoundry.client.v2.servicebrokers.DeleteServiceBrokerRequest) ListPoliciesResponse(org.cloudfoundry.networking.v1.policies.ListPoliciesResponse) ServiceInstanceResource(org.cloudfoundry.client.v2.serviceinstances.ServiceInstanceResource) ListBuildpacksRequest(org.cloudfoundry.client.v2.buildpacks.ListBuildpacksRequest) ListUserProvidedServiceInstanceRoutesRequest(org.cloudfoundry.client.v2.userprovidedserviceinstances.ListUserProvidedServiceInstanceRoutesRequest) DeleteStackRequest(org.cloudfoundry.client.v2.stacks.DeleteStackRequest) Duration(java.time.Duration) Map(java.util.Map) ListSecurityGroupsRequest(org.cloudfoundry.client.v2.securitygroups.ListSecurityGroupsRequest) ListApplicationsRequest(org.cloudfoundry.client.v2.applications.ListApplicationsRequest) DeleteGroupRequest(org.cloudfoundry.uaa.groups.DeleteGroupRequest) ListSpaceQuotaDefinitionsRequest(org.cloudfoundry.client.v2.spacequotadefinitions.ListSpaceQuotaDefinitionsRequest) Policy(org.cloudfoundry.networking.v1.policies.Policy) ListClientsRequest(org.cloudfoundry.uaa.clients.ListClientsRequest) LastOperationUtils(org.cloudfoundry.util.LastOperationUtils) UaaClient(org.cloudfoundry.uaa.UaaClient) ListServiceBrokersRequest(org.cloudfoundry.client.v2.servicebrokers.ListServiceBrokersRequest) PCF_1_12(org.cloudfoundry.CloudFoundryVersion.PCF_1_12) DeleteSharedDomainRequest(org.cloudfoundry.client.v2.shareddomains.DeleteSharedDomainRequest) DeleteBuildpackRequest(org.cloudfoundry.client.v2.buildpacks.DeleteBuildpackRequest) SSLException(javax.net.ssl.SSLException) JobEntity(org.cloudfoundry.client.v2.jobs.JobEntity) CloudFoundryClient(org.cloudfoundry.client.CloudFoundryClient) DeleteRouteRequest(org.cloudfoundry.client.v2.routes.DeleteRouteRequest) ListUserProvidedServiceInstanceServiceBindingsRequest(org.cloudfoundry.client.v2.userprovidedserviceinstances.ListUserProvidedServiceInstanceServiceBindingsRequest) Source(org.cloudfoundry.networking.v1.policies.Source) ListGroupsRequest(org.cloudfoundry.uaa.groups.ListGroupsRequest) ListStacksRequest(org.cloudfoundry.client.v2.stacks.ListStacksRequest) TupleUtils.function(org.cloudfoundry.util.tuple.TupleUtils.function) RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity) ListIdentityProvidersResponse(org.cloudfoundry.uaa.identityproviders.ListIdentityProvidersResponse) DeleteUserProvidedServiceInstanceRequest(org.cloudfoundry.client.v2.userprovidedserviceinstances.DeleteUserProvidedServiceInstanceRequest) DeleteIdentityZoneRequest(org.cloudfoundry.uaa.identityzones.DeleteIdentityZoneRequest) ListOrganizationQuotaDefinitionsRequest(org.cloudfoundry.client.v2.organizationquotadefinitions.ListOrganizationQuotaDefinitionsRequest) DeleteClientRequest(org.cloudfoundry.uaa.clients.DeleteClientRequest) DeleteOrganizationRequest(org.cloudfoundry.client.v2.organizations.DeleteOrganizationRequest) ResourceUtils(org.cloudfoundry.util.ResourceUtils) DeleteApplicationRequest(org.cloudfoundry.client.v2.applications.DeleteApplicationRequest) Supplier(java.util.function.Supplier) ListFeatureFlagsResponse(org.cloudfoundry.client.v2.featureflags.ListFeatureFlagsResponse) DeleteServiceInstanceRequest(org.cloudfoundry.client.v2.serviceinstances.DeleteServiceInstanceRequest) ListOrganizationsRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest) ListIdentityZonesResponse(org.cloudfoundry.uaa.identityzones.ListIdentityZonesResponse) ApplicationResource(org.cloudfoundry.client.v2.applications.ApplicationResource) DeleteSecurityGroupRequest(org.cloudfoundry.client.v2.securitygroups.DeleteSecurityGroupRequest) TupleUtils.predicate(org.cloudfoundry.util.tuple.TupleUtils.predicate) DeletePoliciesRequest(org.cloudfoundry.networking.v1.policies.DeletePoliciesRequest) ListRoutesRequest(org.cloudfoundry.client.v2.routes.ListRoutesRequest) UserResource(org.cloudfoundry.client.v2.users.UserResource) DeleteSpaceRequest(org.cloudfoundry.client.v2.spaces.DeleteSpaceRequest) DeleteIdentityProviderRequest(org.cloudfoundry.uaa.identityproviders.DeleteIdentityProviderRequest) PaginationUtils(org.cloudfoundry.util.PaginationUtils) NetworkingClient(org.cloudfoundry.networking.NetworkingClient) Logger(org.slf4j.Logger) Group(org.cloudfoundry.uaa.groups.Group) ListPoliciesRequest(org.cloudfoundry.networking.v1.policies.ListPoliciesRequest) ListApplicationServiceBindingsRequest(org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest) Mono(reactor.core.publisher.Mono) ListIdentityProvidersRequest(org.cloudfoundry.uaa.identityproviders.ListIdentityProvidersRequest) ListSharedDomainsRequest(org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsRequest) SetFeatureFlagRequest(org.cloudfoundry.client.v2.featureflags.SetFeatureFlagRequest) DeleteOrganizationQuotaDefinitionRequest(org.cloudfoundry.client.v2.organizationquotadefinitions.DeleteOrganizationQuotaDefinitionRequest) ListFeatureFlagsRequest(org.cloudfoundry.client.v2.featureflags.ListFeatureFlagsRequest) GetServiceInstanceRequest(org.cloudfoundry.client.v2.serviceinstances.GetServiceInstanceRequest) Flux(reactor.core.publisher.Flux) ListUserProvidedServiceInstancesRequest(org.cloudfoundry.client.v2.userprovidedserviceinstances.ListUserProvidedServiceInstancesRequest) MemberSummary(org.cloudfoundry.uaa.groups.MemberSummary) Ports(org.cloudfoundry.networking.v1.policies.Ports) FluentMap(org.cloudfoundry.util.FluentMap) RemoveApplicationServiceBindingRequest(org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest) DeletePrivateDomainRequest(org.cloudfoundry.client.v2.privatedomains.DeletePrivateDomainRequest) JobUtils(org.cloudfoundry.util.JobUtils) ListServiceInstanceServiceBindingsRequest(org.cloudfoundry.client.v2.serviceinstances.ListServiceInstanceServiceBindingsRequest) DeleteSpaceQuotaDefinitionRequest(org.cloudfoundry.client.v2.spacequotadefinitions.DeleteSpaceQuotaDefinitionRequest) RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity)

Example 2 with RouteEntity

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

Example 3 with RouteEntity

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

Example 4 with RouteEntity

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

Aggregations

RouteEntity (org.cloudfoundry.client.v2.routes.RouteEntity)4 ApplicationResource (org.cloudfoundry.client.v2.applications.ApplicationResource)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2 Version (com.github.zafarkhaja.semver.Version)1 Timer (io.prometheus.client.Histogram.Timer)1 Duration (java.time.Duration)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Supplier (java.util.function.Supplier)1 PostConstruct (javax.annotation.PostConstruct)1 SSLException (javax.net.ssl.SSLException)1 PassiveExpiringMap (org.apache.commons.collections4.map.PassiveExpiringMap)1 Logger (org.apache.log4j.Logger)1 PCF_1_12 (org.cloudfoundry.CloudFoundryVersion.PCF_1_12)1 CloudFoundryClient (org.cloudfoundry.client.CloudFoundryClient)1 DeleteApplicationRequest (org.cloudfoundry.client.v2.applications.DeleteApplicationRequest)1 ListApplicationServiceBindingsRequest (org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest)1