Search in sources :

Example 1 with CloudFoundryClient

use of org.cloudfoundry.client.CloudFoundryClient 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 CloudFoundryClient

use of org.cloudfoundry.client.CloudFoundryClient in project cf-java-client by cloudfoundry.

the class DefaultApplicationsTest method requestListMatchingResources.

private static void requestListMatchingResources(CloudFoundryClient cloudFoundryClient, Collection<ResourceMatchingUtils.ArtifactMetadata> artifactMetadatas) {
    ListMatchingResourcesRequest request = artifactMetadatas.stream().reduce(ListMatchingResourcesRequest.builder(), (builder, artifactMetadata) -> builder.resource(Resource.builder().hash(artifactMetadata.getHash()).mode(artifactMetadata.getPermissions()).size(artifactMetadata.getSize()).build()), (a, b) -> a.addAllResources(b.build().getResources())).build();
    when(cloudFoundryClient.resourceMatch().list(request)).thenReturn(Mono.just(ListMatchingResourcesResponse.builder().build()));
}
Also used : ListMatchingResourcesRequest(org.cloudfoundry.client.v2.resourcematch.ListMatchingResourcesRequest) 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)

Aggregations

Duration (java.time.Duration)2 Map (java.util.Map)2 Supplier (java.util.function.Supplier)2 CloudFoundryClient (org.cloudfoundry.client.CloudFoundryClient)2 ApplicationResource (org.cloudfoundry.client.v2.applications.ApplicationResource)2 ListApplicationServiceBindingsRequest (org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest)2 RemoveApplicationServiceBindingRequest (org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest)2 Version (com.github.zafarkhaja.semver.Version)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Optional (java.util.Optional)1 Queue (java.util.Queue)1 SSLException (javax.net.ssl.SSLException)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 PCF_1_12 (org.cloudfoundry.CloudFoundryVersion.PCF_1_12)1