diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/uaa/ratelimit/_Current.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/uaa/ratelimit/_Current.java index 57811e9e59..79dd374286 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/uaa/ratelimit/_Current.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/uaa/ratelimit/_Current.java @@ -22,6 +22,7 @@ import java.util.Date; +import org.cloudfoundry.Nullable; import org.immutables.value.Value; /** @@ -35,6 +36,7 @@ abstract class _Current { * The number of configured limiter mappings */ @JsonProperty("limiterMappings") + @Nullable abstract Integer getLimiterMappings(); /** @@ -53,11 +55,13 @@ abstract class _Current { * The credentialIdExtractor */ @JsonProperty("credentialIdExtractor") + @Nullable abstract String getCredentialIdExtractor(); /** * The loggingLevel. Valid values include: "OnlyLimited", "AllCalls" and "AllCallsWithDetails" */ @JsonProperty("loggingLevel") + @Nullable abstract String getLoggingLevel(); } diff --git a/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java b/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java index 0efd69a03f..41bb195e76 100644 --- a/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java +++ b/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java @@ -23,30 +23,40 @@ import java.time.Duration; import java.util.Collection; import java.util.Map; -import java.util.Optional; import java.util.stream.Collectors; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo; -import org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest; -import org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse; -import org.cloudfoundry.client.v2.applications.AssociateApplicationRouteRequest; -import org.cloudfoundry.client.v2.applications.AssociateApplicationRouteResponse; -import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; -import org.cloudfoundry.client.v2.applications.CreateApplicationResponse; -import org.cloudfoundry.client.v2.applications.GetApplicationRequest; -import org.cloudfoundry.client.v2.applications.GetApplicationResponse; -import org.cloudfoundry.client.v2.applications.UpdateApplicationRequest; -import org.cloudfoundry.client.v2.applications.UpdateApplicationResponse; -import org.cloudfoundry.client.v2.applications.UploadApplicationRequest; -import org.cloudfoundry.client.v2.applications.UploadApplicationResponse; -import org.cloudfoundry.client.v2.routes.CreateRouteRequest; -import org.cloudfoundry.client.v2.routes.CreateRouteResponse; -import org.cloudfoundry.client.v2.servicebindings.CreateServiceBindingRequest; -import org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsRequest; -import org.cloudfoundry.client.v2.shareddomains.SharedDomainResource; -import org.cloudfoundry.util.JobUtils; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.ApplicationRelationships; +import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; +import org.cloudfoundry.client.v3.applications.CreateApplicationResponse; +import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsRequest; +import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsResponse; +import org.cloudfoundry.client.v3.applications.SetApplicationCurrentDropletRequest; +import org.cloudfoundry.client.v3.applications.StartApplicationRequest; +import org.cloudfoundry.client.v3.applications.UpdateApplicationEnvironmentVariablesRequest; +import org.cloudfoundry.client.v3.builds.BuildState; +import org.cloudfoundry.client.v3.builds.CreateBuildRequest; +import org.cloudfoundry.client.v3.builds.GetBuildRequest; +import org.cloudfoundry.client.v3.domains.DomainResource; +import org.cloudfoundry.client.v3.domains.ListDomainsRequest; +import org.cloudfoundry.client.v3.packages.CreatePackageRequest; +import org.cloudfoundry.client.v3.packages.GetPackageRequest; +import org.cloudfoundry.client.v3.packages.PackageRelationships; +import org.cloudfoundry.client.v3.packages.PackageState; +import org.cloudfoundry.client.v3.packages.PackageType; +import org.cloudfoundry.client.v3.packages.UploadPackageRequest; +import org.cloudfoundry.client.v3.packages.UploadPackageResponse; +import org.cloudfoundry.client.v3.routes.Application; +import org.cloudfoundry.client.v3.routes.CreateRouteRequest; +import org.cloudfoundry.client.v3.routes.CreateRouteResponse; +import org.cloudfoundry.client.v3.routes.Destination; +import org.cloudfoundry.client.v3.routes.InsertRouteDestinationsRequest; +import org.cloudfoundry.client.v3.routes.RouteRelationships; +import org.cloudfoundry.client.v3.servicebindings.CreateServiceBindingRequest; +import org.cloudfoundry.client.v3.servicebindings.ServiceBindingRelationships; +import org.cloudfoundry.client.v3.servicebindings.ServiceBindingType; import org.cloudfoundry.util.PaginationUtils; -import org.cloudfoundry.util.ResourceUtils; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -57,7 +67,7 @@ static Mono pushApplication( Path applicationBits, String applicationName, Collection boundServices, - Map env, + Map env, String hostName, String spaceId) { return getSharedDomain(cloudFoundryClient) @@ -70,7 +80,7 @@ static Mono pushApplication( applicationName), createRouteId( cloudFoundryClient, - ResourceUtils.getId(domain), + domain.getId(), spaceId, hostName)) .flatMap( @@ -103,9 +113,7 @@ static Mono pushApplication( .format( "https://%s.%s", hostName, - ResourceUtils - .getEntity( - domain) + domain .getName()))))); } @@ -118,14 +126,37 @@ private static Mono bindServices( .map( serviceInstanceId -> cloudFoundryClient - .serviceBindingsV2() + .serviceBindingsV3() .create( CreateServiceBindingRequest .builder() - .applicationId( - applicationId) - .serviceInstanceId( - serviceInstanceId) + .type( + ServiceBindingType + .APPLICATION) + .relationships( + ServiceBindingRelationships + .builder() + .application( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + applicationId) + .build()) + .build()) + .serviceInstance( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + serviceInstanceId) + .build()) + .build()) + .build()) .build())) .collect(Collectors.toList()), a -> Mono.just(applicationId)) @@ -135,7 +166,7 @@ private static Mono bindServices( private static Mono createApplicationId( CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(response -> response.getId()); } private static Mono createRouteId( @@ -144,29 +175,73 @@ private static Mono createRouteId( String spaceId, String hostName) { return requestCreateRoute(cloudFoundryClient, domainId, spaceId, hostName) - .map(ResourceUtils::getId); + .map(response -> response.getId()); } private static Mono createRunningApplication( CloudFoundryClient cloudFoundryClient, Path applicationBits, String applicationId, - Map env) { - return ApplicationUtils.requestUploadApplication( - cloudFoundryClient, applicationId, applicationBits) + Map env) { + return requestUploadApplication(cloudFoundryClient, applicationId, applicationBits) .flatMap( - job -> - JobUtils.waitForCompletion( - cloudFoundryClient, Duration.ofMinutes(5), job)) - .then(requestUpdateApplication(cloudFoundryClient, applicationId, env, "STARTED")) - .then( - getApplicationPackageState(cloudFoundryClient, applicationId) - .filter(state -> "STAGED".equals(state) || "FAILED".equals(state)) - .repeatWhenEmpty( - exponentialBackOff( - Duration.ofSeconds(1), - Duration.ofSeconds(15), - Duration.ofMinutes(5)))) + pkg -> + getApplicationPackageState(cloudFoundryClient, pkg.getId()) + .filter( + state -> + PackageState.READY.equals(state) + || PackageState.FAILED.equals( + state)) + .repeatWhenEmpty( + exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))) + .thenReturn(pkg.getId())) + .flatMap( + packageId -> + cloudFoundryClient + .builds() + .create( + CreateBuildRequest.builder() + .getPackage( + Relationship.builder() + .id(packageId) + .build()) + .build())) + .flatMap( + build -> + getBuildState(cloudFoundryClient, build.getId()) + .filter( + state -> + BuildState.STAGED.equals(state) + || BuildState.FAILED.equals(state)) + .repeatWhenEmpty( + exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))) + .then( + cloudFoundryClient + .builds() + .get( + GetBuildRequest.builder() + .buildId(build.getId()) + .build())) + .map(b -> b.getDroplet().getId())) + .flatMap( + dropletId -> + cloudFoundryClient + .applicationsV3() + .setCurrentDroplet( + SetApplicationCurrentDropletRequest.builder() + .applicationId(applicationId) + .data( + Relationship.builder() + .id(dropletId) + .build()) + .build())) + .then(requestUpdateApplication(cloudFoundryClient, applicationId, env)) .then( getApplicationInstanceState(cloudFoundryClient, applicationId) .filter("RUNNING"::equals) @@ -177,60 +252,80 @@ private static Mono createRunningApplication( Duration.ofMinutes(5)))); } - private static Mono getApplicationPackageState( - CloudFoundryClient cloudFoundryClient, String applicationId) { - return requestGetApplication(cloudFoundryClient, applicationId) - .map(response -> ResourceUtils.getEntity(response).getPackageState()); + private static Mono getApplicationPackageState( + CloudFoundryClient cloudFoundryClient, String packageId) { + return cloudFoundryClient + .packages() + .get(GetPackageRequest.builder().packageId(packageId).build()) + .map(pkg -> pkg.getState()); + } + + private static Mono getBuildState( + CloudFoundryClient cloudFoundryClient, String buildId) { + return cloudFoundryClient + .builds() + .get(GetBuildRequest.builder().buildId(buildId).build()) + .map(build -> build.getState()); } private static Mono getApplicationInstanceState( CloudFoundryClient cloudFoundryClient, String applicationId) { return requestApplicationInstances(cloudFoundryClient, applicationId) - .flatMapMany(response -> Flux.fromIterable(response.getInstances().values())) + .flatMapIterable(response -> response.getResources()) .single() - .map(ApplicationInstanceInfo::getState); + .map(resource -> resource.getState().getValue()); } - private static Mono getSharedDomain( - CloudFoundryClient cloudFoundryClient) { - return requestListSharedDomains(cloudFoundryClient) - .filter( - resource -> - !Optional.ofNullable( - ResourceUtils.getEntity(resource).getInternal()) - .orElse(false)) - .next(); + private static Mono getSharedDomain(CloudFoundryClient cloudFoundryClient) { + return requestListDomains(cloudFoundryClient).filter(domain -> !domain.isInternal()).next(); } - private static Mono requestApplicationInstances( + private static Mono requestApplicationInstances( CloudFoundryClient cloudFoundryClient, String applicationId) { return cloudFoundryClient - .applicationsV2() - .instances( - ApplicationInstancesRequest.builder().applicationId(applicationId).build()); + .applicationsV3() + .getProcessStatistics( + GetApplicationProcessStatisticsRequest.builder() + .applicationId(applicationId) + .type("web") // hardcoded "web" is save for our tests. + .build()); } - private static Mono requestAssociateApplicationRoute( + private static Mono requestAssociateApplicationRoute( CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { return cloudFoundryClient - .applicationsV2() - .associateRoute( - AssociateApplicationRouteRequest.builder() - .applicationId(applicationId) + .routesV3() + .insertDestinations( + InsertRouteDestinationsRequest.builder() .routeId(routeId) - .build()); + .destination( + Destination.builder() + .application( + Application.builder() + .applicationId(applicationId) + .build()) + .build()) + .build()) + .then(); } private static Mono requestCreateApplication( CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return cloudFoundryClient - .applicationsV2() + .applicationsV3() .create( CreateApplicationRequest.builder() - .buildpack("https://github.com/cloudfoundry/java-buildpack.git") - .memory(768) .name(applicationName) - .spaceId(spaceId) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) .build()); } @@ -240,56 +335,85 @@ private static Mono requestCreateRoute( String spaceId, String hostName) { return cloudFoundryClient - .routes() + .routesV3() .create( CreateRouteRequest.builder() - .domainId(domainId) .host(hostName) - .spaceId(spaceId) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(domainId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) .build()); } - private static Mono requestGetApplication( - CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient - .applicationsV2() - .get(GetApplicationRequest.builder().applicationId(applicationId).build()); - } - - private static Flux requestListSharedDomains( - CloudFoundryClient cloudFoundryClient) { - return PaginationUtils.requestClientV2Resources( + private static Flux requestListDomains(CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .sharedDomains() - .list(ListSharedDomainsRequest.builder().page(page).build())); + .domainsV3() + .list(ListDomainsRequest.builder().page(page).build())); } - private static Mono requestUpdateApplication( - CloudFoundryClient cloudFoundryClient, - String applicationId, - Map env, - String state) { + private static Mono requestUpdateApplication( + CloudFoundryClient cloudFoundryClient, String applicationId, Map env) { return cloudFoundryClient - .applicationsV2() - .update( - UpdateApplicationRequest.builder() + .applicationsV3() + .updateEnvironmentVariables( + UpdateApplicationEnvironmentVariablesRequest.builder() .applicationId(applicationId) - .environmentJsons(env) - .state(state) - .build()); + .vars(env) + .build()) + .then( + cloudFoundryClient + .applicationsV3() + .start( + StartApplicationRequest.builder() + .applicationId(applicationId) + .build())) + .then(); } - private static Mono requestUploadApplication( + private static Mono requestUploadApplication( CloudFoundryClient cloudFoundryClient, String applicationId, Path application) { + // here only uploading the application bits, the record is created earlier. return cloudFoundryClient - .applicationsV2() - .upload( - UploadApplicationRequest.builder() - .application(application) - .applicationId(applicationId) - .async(true) - .build()); + .packages() + .create( + CreatePackageRequest.builder() + .type(PackageType.BITS) + .relationships( + PackageRelationships.builder() + .application( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(applicationId) + .build()) + .build()) + .build()) + .build()) + .flatMap( + pkg -> + cloudFoundryClient + .packages() + .upload( + UploadPackageRequest.builder() + .packageId(pkg.getId()) + .bits(application) + .build())); } public static final class ApplicationMetadata { diff --git a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java index 54455f7f4d..198fa34f69 100644 --- a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java +++ b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java @@ -35,19 +35,11 @@ import org.cloudfoundry.client.v2.featureflags.ListFeatureFlagsResponse; import org.cloudfoundry.client.v2.featureflags.SetFeatureFlagRequest; import org.cloudfoundry.client.v2.jobs.JobEntity; -import org.cloudfoundry.client.v2.organizationquotadefinitions.DeleteOrganizationQuotaDefinitionRequest; -import org.cloudfoundry.client.v2.organizationquotadefinitions.ListOrganizationQuotaDefinitionsRequest; -import org.cloudfoundry.client.v2.organizations.DeleteOrganizationRequest; -import org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest; import org.cloudfoundry.client.v2.privatedomains.DeletePrivateDomainRequest; import org.cloudfoundry.client.v2.privatedomains.ListPrivateDomainsRequest; import org.cloudfoundry.client.v2.routes.DeleteRouteRequest; import org.cloudfoundry.client.v2.routes.ListRoutesRequest; import org.cloudfoundry.client.v2.routes.RouteEntity; -import org.cloudfoundry.client.v2.securitygroups.DeleteSecurityGroupRequest; -import org.cloudfoundry.client.v2.securitygroups.ListSecurityGroupsRequest; -import org.cloudfoundry.client.v2.servicebrokers.DeleteServiceBrokerRequest; -import org.cloudfoundry.client.v2.servicebrokers.ListServiceBrokersRequest; import org.cloudfoundry.client.v2.serviceinstances.DeleteServiceInstanceRequest; import org.cloudfoundry.client.v2.serviceinstances.GetServiceInstanceRequest; import org.cloudfoundry.client.v2.serviceinstances.ListServiceInstanceRoutesRequest; @@ -59,13 +51,6 @@ import org.cloudfoundry.client.v2.servicekeys.DeleteServiceKeyRequest; import org.cloudfoundry.client.v2.shareddomains.DeleteSharedDomainRequest; import org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsRequest; -import org.cloudfoundry.client.v2.spacequotadefinitions.DeleteSpaceQuotaDefinitionRequest; -import org.cloudfoundry.client.v2.spacequotadefinitions.ListSpaceQuotaDefinitionsRequest; -import org.cloudfoundry.client.v2.spaces.DeleteSpaceRequest; -import org.cloudfoundry.client.v2.spaces.ListSpacesRequest; -import org.cloudfoundry.client.v2.spaces.SpaceResource; -import org.cloudfoundry.client.v2.stacks.DeleteStackRequest; -import org.cloudfoundry.client.v2.stacks.ListStacksRequest; import org.cloudfoundry.client.v2.userprovidedserviceinstances.DeleteUserProvidedServiceInstanceRequest; import org.cloudfoundry.client.v2.userprovidedserviceinstances.ListUserProvidedServiceInstanceRoutesRequest; import org.cloudfoundry.client.v2.userprovidedserviceinstances.ListUserProvidedServiceInstanceServiceBindingsRequest; @@ -77,15 +62,30 @@ import org.cloudfoundry.client.v3.applications.Application; import org.cloudfoundry.client.v3.applications.DeleteApplicationRequest; import org.cloudfoundry.client.v3.applications.ListApplicationsRequest; +import org.cloudfoundry.client.v3.organizations.DeleteOrganizationRequest; +import org.cloudfoundry.client.v3.organizations.ListOrganizationsRequest; +import org.cloudfoundry.client.v3.quotas.organizations.DeleteOrganizationQuotaRequest; +import org.cloudfoundry.client.v3.quotas.organizations.ListOrganizationQuotasRequest; +import org.cloudfoundry.client.v3.quotas.spaces.DeleteSpaceQuotaRequest; +import org.cloudfoundry.client.v3.quotas.spaces.ListSpaceQuotasRequest; +import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest; import org.cloudfoundry.client.v3.servicebindings.DeleteServiceBindingRequest; import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsRequest; +import org.cloudfoundry.client.v3.servicebrokers.DeleteServiceBrokerRequest; +import org.cloudfoundry.client.v3.servicebrokers.ListServiceBrokersRequest; import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipRequest; import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipResponse; import org.cloudfoundry.client.v3.serviceinstances.UnshareServiceInstanceRequest; +import org.cloudfoundry.client.v3.spaces.DeleteSpaceRequest; import org.cloudfoundry.client.v3.spaces.GetSpaceRequest; import org.cloudfoundry.client.v3.spaces.GetSpaceResponse; +import org.cloudfoundry.client.v3.spaces.ListSpacesRequest; +import org.cloudfoundry.client.v3.spaces.Space; import org.cloudfoundry.client.v3.spaces.UpdateSpaceRequest; import org.cloudfoundry.client.v3.spaces.UpdateSpaceResponse; +import org.cloudfoundry.client.v3.stacks.DeleteStackRequest; +import org.cloudfoundry.client.v3.stacks.ListStacksRequest; import org.cloudfoundry.client.v3.users.UserResource; import org.cloudfoundry.networking.NetworkingClient; import org.cloudfoundry.networking.v1.policies.DeletePoliciesRequest; @@ -548,83 +548,68 @@ private static Flux cleanNetworkingPolicies( private static Flux cleanOrganizationQuotaDefinitions( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .organizationQuotaDefinitions() + .organizationQuotasV3() .list( - ListOrganizationQuotaDefinitionsRequest.builder() + ListOrganizationQuotasRequest.builder() .page(page) .build())) - .filter( - domain -> - nameFactory.isQuotaDefinitionName( - ResourceUtils.getEntity(domain).getName())) + .filter(domain -> nameFactory.isQuotaDefinitionName(domain.getName())) .flatMap( - organizationQuotaDefinition -> + quota -> cloudFoundryClient - .organizationQuotaDefinitions() + .organizationQuotasV3() .delete( - DeleteOrganizationQuotaDefinitionRequest.builder() - .async(true) - .organizationQuotaDefinitionId( - ResourceUtils.getId( - organizationQuotaDefinition)) + DeleteOrganizationQuotaRequest.builder() + .organizationQuotaId(quota.getId()) .build()) - .flatMapMany( - job -> + .flatMap( + jobId -> JobUtils.waitForCompletion( cloudFoundryClient, Duration.ofMinutes(5), - job)) + jobId)) .doOnError( t -> LOGGER.error( "Unable to delete organization" + " quota definition {}", - ResourceUtils.getEntity( - organizationQuotaDefinition) - .getName(), + quota.getName(), t))); } private static Flux cleanOrganizations( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .organizations() + .organizationsV3() .list( ListOrganizationsRequest.builder() .page(page) .build())) - .filter( - organization -> - nameFactory.isOrganizationName( - ResourceUtils.getEntity(organization).getName())) + .filter(organization -> nameFactory.isOrganizationName(organization.getName())) .flatMap( organization -> cloudFoundryClient - .organizations() + .organizationsV3() .delete( DeleteOrganizationRequest.builder() - .async(true) - .organizationId( - ResourceUtils.getId(organization)) + .organizationId(organization.getId()) .build()) - .flatMapMany( - job -> + .flatMap( + jobId -> JobUtils.waitForCompletion( cloudFoundryClient, Duration.ofMinutes(5), - job)) + jobId)) .doOnError( t -> LOGGER.error( "Unable to delete organization {}", - ResourceUtils.getEntity( - organization) - .getName(), + organization.getName(), t))); } @@ -727,70 +712,69 @@ private static Flux cleanRoutes( private static Flux cleanSecurityGroups( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .securityGroups() + .securityGroupsV3() .list( ListSecurityGroupsRequest.builder() .page(page) .build())) - .filter( - securityGroup -> - nameFactory.isSecurityGroupName( - ResourceUtils.getEntity(securityGroup).getName())) + .filter(securityGroup -> nameFactory.isSecurityGroupName(securityGroup.getName())) .flatMap( securityGroup -> cloudFoundryClient - .securityGroups() + .securityGroupsV3() .delete( DeleteSecurityGroupRequest.builder() - .securityGroupId( - ResourceUtils.getId(securityGroup)) + .securityGroupId(securityGroup.getId()) .build()) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + jobId)) .doOnError( t -> LOGGER.error( "Unable to delete security group" + " {}", - ResourceUtils.getEntity( - securityGroup) - .getName(), - t)) - .then()); + securityGroup.getName(), + t))); } private static Flux cleanServiceBrokers( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .serviceBrokers() + .serviceBrokersV3() .list( ListServiceBrokersRequest.builder() .page(page) .build())) - .filter( - serviceBroker -> - nameFactory.isServiceBrokerName( - ResourceUtils.getEntity(serviceBroker).getName())) + .filter(serviceBroker -> nameFactory.isServiceBrokerName(serviceBroker.getName())) .flatMap( serviceBroker -> cloudFoundryClient - .serviceBrokers() + .serviceBrokersV3() .delete( DeleteServiceBrokerRequest.builder() - .serviceBrokerId( - ResourceUtils.getId(serviceBroker)) + .serviceBrokerId(serviceBroker.getId()) .build()) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + jobId)) .doOnError( t -> LOGGER.error( "Unable to delete service broker" + " {}", - ResourceUtils.getEntity( - serviceBroker) - .getName(), + serviceBroker.getName(), t))); } @@ -912,52 +896,43 @@ private static Flux cleanSharedDomains( private static Flux cleanSpaceQuotaDefinitions( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .spaceQuotaDefinitions() - .list( - ListSpaceQuotaDefinitionsRequest.builder() - .page(page) - .build())) - .filter( - quota -> - nameFactory.isQuotaDefinitionName( - ResourceUtils.getEntity(quota).getName())) + .spaceQuotasV3() + .list(ListSpaceQuotasRequest.builder().page(page).build())) + .filter(quota -> nameFactory.isQuotaDefinitionName(quota.getName())) .flatMap( quota -> cloudFoundryClient - .spaceQuotaDefinitions() + .spaceQuotasV3() .delete( - (DeleteSpaceQuotaDefinitionRequest.builder() - .async(true) - .spaceQuotaDefinitionId( - ResourceUtils.getId(quota)) - .build())) - .flatMapMany( - job -> + DeleteSpaceQuotaRequest.builder() + .spaceQuotaId(quota.getId()) + .build()) + .flatMap( + jobId -> JobUtils.waitForCompletion( cloudFoundryClient, Duration.ofMinutes(5), - job)) + jobId)) .doOnError( t -> LOGGER.error( "Unable to delete space quota" + " definition {}", - ResourceUtils.getEntity(quota) - .getName(), + quota.getName(), t))); } private static Flux cleanSpaces( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .spaces() + .spacesV3() .list(ListSpacesRequest.builder().page(page).build())) - .filter(space -> nameFactory.isSpaceName(ResourceUtils.getEntity(space).getName())) + .filter(space -> nameFactory.isSpaceName(space.getName())) .delayUntil( space -> removeSpaceMetadata( @@ -967,57 +942,46 @@ private static Flux cleanSpaces( .flatMap( space -> cloudFoundryClient - .spaces() + .spacesV3() .delete( DeleteSpaceRequest.builder() - .async(true) - .recursive(true) - .spaceId(ResourceUtils.getId(space)) + .spaceId(space.getId()) .build()) - .flatMapMany( - job -> + .flatMap( + jobId -> JobUtils.waitForCompletion( cloudFoundryClient, Duration.ofMinutes(5), - job)) + jobId)) .doOnError( t -> LOGGER.error( "Unable to delete space {}", - ResourceUtils.getEntity(space) - .getName(), + space.getName(), t))); } private static Flux cleanStacks( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .stacks() + .stacksV3() .list(ListStacksRequest.builder().page(page).build())) - .filter(stack -> nameFactory.isStackName(ResourceUtils.getEntity(stack).getName())) + .filter(stack -> nameFactory.isStackName(stack.getName())) .flatMap( stack -> cloudFoundryClient - .stacks() + .stacksV3() .delete( - (DeleteStackRequest.builder() - .async(true) - .stackId(ResourceUtils.getId(stack)) - .build())) - .flatMapMany( - job -> - JobUtils.waitForCompletion( - cloudFoundryClient, - Duration.ofMinutes(5), - job)) + DeleteStackRequest.builder() + .stackId(stack.getId()) + .build()) .doOnError( t -> LOGGER.error( "Unable to delete stack {}", - ResourceUtils.getEntity(stack) - .getName(), + stack.getName(), t))); } @@ -1379,10 +1343,10 @@ private static Flux removeServiceShares( } private static Mono removeSpaceMetadata( - CloudFoundryClient cloudFoundryClient, SpaceResource space) { + CloudFoundryClient cloudFoundryClient, Space space) { return cloudFoundryClient .spacesV3() - .get(GetSpaceRequest.builder().spaceId(ResourceUtils.getId(space)).build()) + .get(GetSpaceRequest.builder().spaceId(space.getId()).build()) .map(GetSpaceResponse::getMetadata) .flatMap( metadata -> { @@ -1399,16 +1363,12 @@ private static Mono removeSpaceMetadata( labels.replaceAll((k, v) -> null); return requestUpdateSpace( - cloudFoundryClient, - annotations, - labels, - ResourceUtils.getId(space)) + cloudFoundryClient, annotations, labels, space.getId()) .doOnError( t -> LOGGER.error( "Unable to remove metadata from {}", - ResourceUtils.getEntity(space) - .getName())); + space.getName())); }); } diff --git a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java index 553b6999ce..205be98782 100644 --- a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java +++ b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java @@ -39,8 +39,6 @@ import java.util.List; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.GetRootRequest; -import org.cloudfoundry.client.v2.info.GetInfoRequest; -import org.cloudfoundry.client.v2.userprovidedserviceinstances.CreateUserProvidedServiceInstanceRequest; import org.cloudfoundry.client.v3.Relationship; import org.cloudfoundry.client.v3.ToOneRelationship; import org.cloudfoundry.client.v3.organizations.CreateOrganizationRequest; @@ -53,6 +51,9 @@ import org.cloudfoundry.client.v3.roles.CreateRoleRequest; import org.cloudfoundry.client.v3.roles.RoleRelationships; import org.cloudfoundry.client.v3.roles.RoleType; +import org.cloudfoundry.client.v3.serviceinstances.CreateServiceInstanceRequest; +import org.cloudfoundry.client.v3.serviceinstances.ServiceInstanceRelationships; +import org.cloudfoundry.client.v3.serviceinstances.ServiceInstanceType; import org.cloudfoundry.client.v3.spaces.CreateSpaceRequest; import org.cloudfoundry.client.v3.spaces.CreateSpaceResponse; import org.cloudfoundry.client.v3.spaces.SpaceRelationships; @@ -92,7 +93,6 @@ import org.cloudfoundry.uaa.users.Email; import org.cloudfoundry.uaa.users.Name; import org.cloudfoundry.util.PaginationUtils; -import org.cloudfoundry.util.ResourceUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.SmartInitializingSingleton; @@ -370,23 +370,33 @@ RandomNameFactory nameFactory() { @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - @ConditionalOnProperty( - name = RequiresV2Api.SKIP_V2_TESTS_ENV, - havingValue = "false", - matchIfMissing = true) Mono metricRegistrarServiceInstance( CloudFoundryClient cloudFoundryClient, Mono spaceId, NameFactory nameFactory) { return spaceId.flatMap( spaceIdValue -> cloudFoundryClient - .userProvidedServiceInstances() + .serviceInstancesV3() .create( - CreateUserProvidedServiceInstanceRequest.builder() + CreateServiceInstanceRequest.builder() + .type(ServiceInstanceType.USER_PROVIDED) .name(nameFactory.getServiceInstanceName()) - .spaceId(spaceIdValue) + .relationships( + ServiceInstanceRelationships + .builder() + .space( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + spaceIdValue) + .build()) + .build()) + .build()) .syslogDrainUrl("structured-format://json") .build())) - .map(ResourceUtils::getId) + .map(r -> r.getServiceInstance().get().getId()) .cache(); } @@ -511,27 +521,12 @@ RoutingClient routingClient(ConnectionContext connectionContext, TokenProvider t @Bean Version serverVersion(@Qualifier("admin") CloudFoundryClient cloudFoundryClient) { - return serverVersionV2(cloudFoundryClient) - .switchIfEmpty(serverVersionV3(cloudFoundryClient)) + return serverVersionV3(cloudFoundryClient) .doOnSubscribe(s -> this.logger.debug(">> CLOUD FOUNDRY VERSION <<")) .doOnSuccess(r -> this.logger.debug("<< CLOUD FOUNDRY VERSION >>")) .block(); } - private static Mono serverVersionV2(CloudFoundryClient cloudFoundryClient) { - return cloudFoundryClient - .info() - .get(GetInfoRequest.builder().build()) - .flatMap( - response -> { - String version = response.getApiVersion(); - if (version == null || version.isEmpty()) { - return Mono.empty(); - } - return Mono.just(Version.valueOf(version)); - }); - } - private static Mono serverVersionV3(CloudFoundryClient cloudFoundryClient) { return cloudFoundryClient .rootEndpoint() @@ -542,10 +537,6 @@ private static Mono serverVersionV3(CloudFoundryClient cloudFoundryClie @Lazy @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - @ConditionalOnProperty( - name = RequiresV2Api.SKIP_V2_TESTS_ENV, - havingValue = "false", - matchIfMissing = true) Mono serviceBrokerId( CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, diff --git a/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java b/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java index f4766314f3..cb0d02436f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java +++ b/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java @@ -18,21 +18,28 @@ import java.io.IOException; import java.nio.file.Path; +import java.time.Duration; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.DeleteApplicationRequest; -import org.cloudfoundry.client.v2.servicebrokers.CreateServiceBrokerRequest; -import org.cloudfoundry.client.v2.servicebrokers.CreateServiceBrokerResponse; -import org.cloudfoundry.client.v2.serviceplans.ListServicePlansRequest; -import org.cloudfoundry.client.v2.serviceplans.ServicePlanResource; -import org.cloudfoundry.client.v2.serviceplans.UpdateServicePlanRequest; -import org.cloudfoundry.client.v2.serviceplans.UpdateServicePlanResponse; -import org.cloudfoundry.client.v2.services.ListServicesRequest; -import org.cloudfoundry.client.v2.services.ServiceResource; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.DeleteApplicationRequest; +import org.cloudfoundry.client.v3.servicebrokers.BasicAuthentication; +import org.cloudfoundry.client.v3.servicebrokers.CreateServiceBrokerRequest; +import org.cloudfoundry.client.v3.servicebrokers.ListServiceBrokersRequest; +import org.cloudfoundry.client.v3.servicebrokers.ServiceBrokerRelationships; +import org.cloudfoundry.client.v3.servicebrokers.ServiceBrokerResource; +import org.cloudfoundry.client.v3.serviceofferings.ListServiceOfferingsRequest; +import org.cloudfoundry.client.v3.serviceofferings.ServiceOfferingResource; +import org.cloudfoundry.client.v3.serviceplans.ListServicePlansRequest; +import org.cloudfoundry.client.v3.serviceplans.ServicePlanResource; +import org.cloudfoundry.client.v3.serviceplans.UpdateServicePlanVisibilityRequest; +import org.cloudfoundry.client.v3.serviceplans.UpdateServicePlanVisibilityResponse; +import org.cloudfoundry.client.v3.serviceplans.Visibility; +import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; -import org.cloudfoundry.util.ResourceUtils; import org.springframework.core.io.ClassPathResource; import reactor.core.Exceptions; import reactor.core.publisher.Flux; @@ -70,8 +77,18 @@ public static Mono createServiceBroker applicationMetadata, serviceBrokerName, spaceScoped) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + jobId) + .then( + requestGetServiceBrokerId( + cloudFoundryClient, + serviceBrokerName))) .delayUntil( - response -> + brokerId -> Mono.zip( makeServicePlanPubliclyVisible( cloudFoundryClient, @@ -82,10 +99,9 @@ public static Mono createServiceBroker serviceName + "-shareable", spaceScoped))) .map( - response -> + brokerId -> new ServiceBrokerMetadata( - applicationMetadata, - ResourceUtils.getId(response)))); + applicationMetadata, brokerId))); } @SuppressWarnings("BlockingMethodInNonBlockingContext") @@ -118,18 +134,28 @@ public static Mono createServiceBroker applicationMetadata, serviceBrokerName, spaceScoped) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + jobId) + .then( + requestGetServiceBrokerId( + cloudFoundryClient, + serviceBrokerName))) .map( - response -> + brokerId -> new ServiceBrokerMetadata( - applicationMetadata, - ResourceUtils.getId(response)))); + applicationMetadata, brokerId))); } public static Mono deleteServiceBroker( CloudFoundryClient cloudFoundryClient, String applicationId) { return cloudFoundryClient - .applicationsV2() - .delete(DeleteApplicationRequest.builder().applicationId(applicationId).build()); + .applicationsV3() + .delete(DeleteApplicationRequest.builder().applicationId(applicationId).build()) + .then(); } public static Mono pushServiceBrokerApplication( @@ -142,7 +168,7 @@ public static Mono pushServiceBrokerApplic String applicationName = nameFactory.getApplicationName(); String hostName = nameFactory.getHostName(); - Map env = new HashMap<>(); + Map env = new HashMap<>(); env.put("SERVICE_NAME", serviceName); env.put("PLAN_NAME", planName); env.put( @@ -164,17 +190,17 @@ private static Mono getServiceId( CloudFoundryClient cloudFoundryClient, String serviceName) { return requestListServices(cloudFoundryClient, serviceName) .single() - .map(ResourceUtils::getId); + .map(ServiceOfferingResource::getId); } private static Mono getServicePlanId( CloudFoundryClient cloudFoundryClient, String serviceId) { return requestListServicePlans(cloudFoundryClient, serviceId) .single() - .map(ResourceUtils::getId); + .map(ServicePlanResource::getId); } - private static Mono makeServicePlanPubliclyVisible( + private static Mono makeServicePlanPubliclyVisible( CloudFoundryClient cloudFoundryClient, String serviceName, Boolean spaceScoped) { if (spaceScoped) { return Mono.empty(); @@ -185,53 +211,88 @@ private static Mono makeServicePlanPubliclyVisible( .flatMap(planId -> requestUpdateServicePlan(cloudFoundryClient, planId, true)); } - private static Mono requestCreateServiceBroker( + private static Mono requestCreateServiceBroker( CloudFoundryClient cloudFoundryClient, ApplicationUtils.ApplicationMetadata applicationMetadata, String serviceBrokerName, Boolean spaceScoped) { return cloudFoundryClient - .serviceBrokers() + .serviceBrokersV3() .create( CreateServiceBrokerRequest.builder() - .authenticationPassword("test-authentication-password") - .authenticationUsername("test-authentication-username") - .brokerUrl(applicationMetadata.uri) + .authentication( + BasicAuthentication.builder() + .username("test-authentication-username") + .password("test-authentication-password") + .build()) .name(serviceBrokerName) - .spaceId(spaceScoped ? applicationMetadata.spaceId : null) + .relationships( + spaceScoped + ? ServiceBrokerRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id( + applicationMetadata + .spaceId) + .build()) + .build()) + .build() + : null) + .url(applicationMetadata.uri) .build()); } + private static Mono requestGetServiceBrokerId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .serviceBrokersV3() + .list( + ListServiceBrokersRequest.builder() + .name(serviceBrokerName) + .page(page) + .build())) + .single() + .map(ServiceBrokerResource::getId); + } + private static Flux requestListServicePlans( - CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils.requestClientV2Resources( + CloudFoundryClient cloudFoundryClient, String serviceOfferingId) { + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .servicePlans() + .servicePlansV3() .list( ListServicePlansRequest.builder() - .serviceId(serviceId) + .serviceOfferingId(serviceOfferingId) .page(page) .build())); } - private static Flux requestListServices( + private static Flux requestListServices( CloudFoundryClient cloudFoundryClient, String serviceName) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .services() - .list(ListServicesRequest.builder().label(serviceName).build())); + .serviceOfferingsV3() + .list( + ListServiceOfferingsRequest.builder() + .name(serviceName) + .page(page) + .build())); } - private static Mono requestUpdateServicePlan( + private static Mono requestUpdateServicePlan( CloudFoundryClient cloudFoundryClient, String planId, Boolean visibility) { return cloudFoundryClient - .servicePlans() - .update( - UpdateServicePlanRequest.builder() + .servicePlansV3() + .updateVisibility( + UpdateServicePlanVisibilityRequest.builder() .servicePlanId(planId) - .publiclyVisible(visibility) + .type(Visibility.PUBLIC) .build()); } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java index 580fb30214..5bd7bc9d7c 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java @@ -22,12 +22,8 @@ import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; -import org.cloudfoundry.RequiresV2Api; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.organizations.CreateOrganizationRequest; -import org.cloudfoundry.client.v2.organizations.CreateOrganizationResponse; -import org.cloudfoundry.client.v2.spaces.CreateSpaceRequest; -import org.cloudfoundry.client.v2.spaces.CreateSpaceResponse; +import org.cloudfoundry.client.v3.ToOneRelationship; import org.cloudfoundry.client.v3.isolationsegments.AddIsolationSegmentOrganizationEntitlementRequest; import org.cloudfoundry.client.v3.isolationsegments.AddIsolationSegmentOrganizationEntitlementResponse; import org.cloudfoundry.client.v3.isolationsegments.CreateIsolationSegmentRequest; @@ -42,11 +38,15 @@ import org.cloudfoundry.client.v3.isolationsegments.ListIsolationSegmentsRequest; import org.cloudfoundry.client.v3.isolationsegments.RemoveIsolationSegmentOrganizationEntitlementRequest; import org.cloudfoundry.client.v3.isolationsegments.UpdateIsolationSegmentRequest; +import org.cloudfoundry.client.v3.organizations.CreateOrganizationRequest; +import org.cloudfoundry.client.v3.organizations.CreateOrganizationResponse; import org.cloudfoundry.client.v3.organizations.OrganizationResource; import org.cloudfoundry.client.v3.spaces.AssignSpaceIsolationSegmentRequest; import org.cloudfoundry.client.v3.spaces.AssignSpaceIsolationSegmentResponse; +import org.cloudfoundry.client.v3.spaces.CreateSpaceRequest; +import org.cloudfoundry.client.v3.spaces.CreateSpaceResponse; +import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.util.PaginationUtils; -import org.cloudfoundry.util.ResourceUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; @@ -54,7 +54,6 @@ import reactor.test.StepVerifier; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_11) -@RequiresV2Api public final class IsolationSegmentsTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; @@ -537,13 +536,13 @@ private static Mono createIsolationSegmentId( private static Mono createOrganizationId( CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(ResourceUtils::getId); + .map(CreateOrganizationResponse::getId); } private static Mono createSpaceId( CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(CreateSpaceResponse::getId); } private static Mono @@ -595,18 +594,27 @@ private static Mono requestCreateIsolationSegmen private static Mono requestCreateOrganization( CloudFoundryClient cloudFoundryClient, String organizationName) { return cloudFoundryClient - .organizations() + .organizationsV3() .create(CreateOrganizationRequest.builder().name(organizationName).build()); } private static Mono requestCreateSpace( CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return cloudFoundryClient - .spaces() + .spacesV3() .create( CreateSpaceRequest.builder() .name(spaceName) - .organizationId(organizationId) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) .build()); } diff --git a/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java b/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java index eaa9916908..362133cecd 100644 --- a/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java @@ -23,8 +23,11 @@ import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; -import org.cloudfoundry.client.v2.applications.CreateApplicationResponse; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.ApplicationRelationships; +import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; +import org.cloudfoundry.client.v3.applications.CreateApplicationResponse; import org.cloudfoundry.networking.NetworkingClient; import org.cloudfoundry.networking.v1.policies.CreatePoliciesRequest; import org.cloudfoundry.networking.v1.policies.DeletePoliciesRequest; @@ -34,7 +37,7 @@ import org.cloudfoundry.networking.v1.policies.Policy; import org.cloudfoundry.networking.v1.policies.Ports; import org.cloudfoundry.networking.v1.policies.Source; -import org.cloudfoundry.util.ResourceUtils; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; @@ -290,21 +293,26 @@ public void listFiltered() { private static Mono createApplicationId( CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(CreateApplicationResponse::getId); } private static Mono requestCreateApplication( CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return cloudFoundryClient - .applicationsV2() + .applicationsV3() .create( CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) .name(applicationName) - .spaceId(spaceId) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) .build()); } diff --git a/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java b/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java index 6393f0c2d0..cf1669c98d 100644 --- a/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java @@ -23,8 +23,11 @@ import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; -import org.cloudfoundry.client.v2.applications.CreateApplicationResponse; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.ApplicationRelationships; +import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; +import org.cloudfoundry.client.v3.applications.CreateApplicationResponse; import org.cloudfoundry.networking.NetworkingClient; import org.cloudfoundry.networking.v1.policies.CreatePoliciesRequest; import org.cloudfoundry.networking.v1.policies.Destination; @@ -33,7 +36,7 @@ import org.cloudfoundry.networking.v1.policies.Source; import org.cloudfoundry.networking.v1.tags.ListTagsRequest; import org.cloudfoundry.networking.v1.tags.ListTagsResponse; -import org.cloudfoundry.util.ResourceUtils; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; @@ -94,21 +97,26 @@ public void create() { private static Mono createApplicationId( CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(CreateApplicationResponse::getId); } private static Mono requestCreateApplication( CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return cloudFoundryClient - .applicationsV2() + .applicationsV3() .create( CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) .name(applicationName) - .spaceId(spaceId) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) .build()); } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java index 1d32a910a2..5512b9a00a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java @@ -20,22 +20,23 @@ import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; -import org.cloudfoundry.RequiresV2Api; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; -import org.cloudfoundry.client.v2.applications.CreateApplicationResponse; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.ApplicationRelationships; +import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; +import org.cloudfoundry.client.v3.applications.CreateApplicationResponse; import org.cloudfoundry.operations.networkpolicies.AddNetworkPolicyRequest; import org.cloudfoundry.operations.networkpolicies.ListNetworkPoliciesRequest; import org.cloudfoundry.operations.networkpolicies.Policy; import org.cloudfoundry.operations.networkpolicies.RemoveNetworkPolicyRequest; -import org.cloudfoundry.util.ResourceUtils; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -@RequiresV2Api public final class NetworkPoliciesTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; @@ -168,7 +169,7 @@ public void remove() { private static Mono createApplicationId( CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(CreateApplicationResponse::getId); } private static Flux requestAddNetworkPolicy( @@ -189,15 +190,20 @@ private static Flux requestAddNetworkPolicy( private static Mono requestCreateApplication( CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return cloudFoundryClient - .applicationsV2() + .applicationsV3() .create( CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) .name(applicationName) - .spaceId(spaceId) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) .build()); } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java index ebd89c92e3..d0ae4b3b82 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java @@ -22,17 +22,18 @@ import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CleanupCloudFoundryAfterClass; -import org.cloudfoundry.RequiresV2Api; import org.cloudfoundry.ServiceBrokerUtils; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.spaces.CreateSpaceRequest; -import org.cloudfoundry.client.v2.spaces.CreateSpaceResponse; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.spaces.CreateSpaceRequest; +import org.cloudfoundry.client.v3.spaces.CreateSpaceResponse; +import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.operations.serviceadmin.Access; import org.cloudfoundry.operations.serviceadmin.DisableServiceAccessRequest; import org.cloudfoundry.operations.serviceadmin.EnableServiceAccessRequest; import org.cloudfoundry.operations.serviceadmin.ListServiceAccessSettingsRequest; import org.cloudfoundry.operations.serviceadmin.ServiceAccess; -import org.cloudfoundry.util.ResourceUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -41,7 +42,6 @@ import reactor.test.StepVerifier; @CleanupCloudFoundryAfterClass -@RequiresV2Api public final class ServiceAdminTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; @@ -602,17 +602,26 @@ public void listServiceAccessSettingsSpecifyService() { private static Mono createSpaceId( CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(CreateSpaceResponse::getId); } private static Mono requestCreateSpace( CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return cloudFoundryClient - .spaces() + .spacesV3() .create( CreateSpaceRequest.builder() .name(spaceName) - .organizationId(organizationId) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) .build()); } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java index f81ddb1a67..5d3072b78c 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java @@ -24,12 +24,11 @@ import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CleanupCloudFoundryAfterClass; -import org.cloudfoundry.RequiresV2Api; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.servicebindings.ListServiceBindingsRequest; -import org.cloudfoundry.client.v2.servicebindings.ServiceBindingResource; -import org.cloudfoundry.client.v2.userprovidedserviceinstances.ListUserProvidedServiceInstancesRequest; -import org.cloudfoundry.client.v2.userprovidedserviceinstances.UserProvidedServiceInstanceResource; +import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsRequest; +import org.cloudfoundry.client.v3.servicebindings.ServiceBindingResource; +import org.cloudfoundry.client.v3.serviceinstances.ListServiceInstancesRequest; +import org.cloudfoundry.client.v3.serviceinstances.ServiceInstanceResource; import org.cloudfoundry.operations.applications.ApplicationDetail; import org.cloudfoundry.operations.applications.ApplicationHealthCheck; import org.cloudfoundry.operations.applications.GetApplicationRequest; @@ -67,7 +66,6 @@ import reactor.test.StepVerifier; @CleanupCloudFoundryAfterClass -@RequiresV2Api public final class ServicesTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; @@ -555,7 +553,7 @@ public void updateUserProvidedInstance() { .thenMany( requestListUserProvidedServiceInstances( this.cloudFoundryClient, serviceInstanceName) - .map(r -> r.getEntity().getSyslogDrainUrl())) + .map(ServiceInstanceResource::getSyslogDrainUrl)) .as(StepVerifier::create) .expectNext("test.url") .expectComplete() @@ -721,10 +719,10 @@ private static Flux requestListRoutes(CloudFoundryOperations cloudFoundry private static Flux requestListServiceBindings( CloudFoundryClient cloudFoundryClient, String applicationId) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .serviceBindingsV2() + .serviceBindingsV3() .list( ListServiceBindingsRequest.builder() .applicationId(applicationId) @@ -737,16 +735,16 @@ private static Flux requestListServiceInstances( return cloudFoundryOperations.services().listInstances(); } - private static Flux + private static Flux requestListUserProvidedServiceInstances( CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .userProvidedServiceInstances() + .serviceInstancesV3() .list( - ListUserProvidedServiceInstancesRequest.builder() - .name(serviceInstanceName) + ListServiceInstancesRequest.builder() + .serviceInstanceName(serviceInstanceName) .page(page) .build())); } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java index af534acda3..11ed31292c 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java @@ -20,12 +20,15 @@ import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; -import org.cloudfoundry.RequiresV2Api; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.organizations.ListOrganizationAuditorsRequest; -import org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest; -import org.cloudfoundry.client.v2.users.ListUsersRequest; -import org.cloudfoundry.client.v2.users.UserResource; +import org.cloudfoundry.client.v3.organizations.ListOrganizationsRequest; +import org.cloudfoundry.client.v3.organizations.OrganizationResource; +import org.cloudfoundry.client.v3.roles.ListRolesRequest; +import org.cloudfoundry.client.v3.roles.RoleType; +import org.cloudfoundry.client.v3.users.GetUserRequest; +import org.cloudfoundry.client.v3.users.GetUserResponse; +import org.cloudfoundry.client.v3.users.ListUsersRequest; +import org.cloudfoundry.client.v3.users.UserResource; import org.cloudfoundry.operations.organizations.CreateOrganizationRequest; import org.cloudfoundry.operations.spaces.CreateSpaceRequest; import org.cloudfoundry.operations.useradmin.CreateUserRequest; @@ -41,14 +44,12 @@ import org.cloudfoundry.operations.useradmin.UnsetOrganizationRoleRequest; import org.cloudfoundry.operations.useradmin.UnsetSpaceRoleRequest; import org.cloudfoundry.util.PaginationUtils; -import org.cloudfoundry.util.ResourceUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -@RequiresV2Api public final class UserAdminTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; @@ -67,9 +68,7 @@ public void create() { .username(username) .build()) .thenMany(requestListUsers(this.cloudFoundryClient)) - .filter( - response -> - username.equals(ResourceUtils.getEntity(response).getUsername())) + .filter(response -> username.equals(response.getUsername())) .as(StepVerifier::create) .expectNextCount(1) .expectComplete() @@ -101,9 +100,7 @@ public void delete() { .userAdmin() .delete(DeleteUserRequest.builder().username(username).build())) .thenMany(requestListUsers(this.cloudFoundryClient)) - .filter( - response -> - username.equals(ResourceUtils.getEntity(response).getUsername())) + .filter(response -> username.equals(response.getUsername())) .as(StepVerifier::create) .expectComplete() .verify(Duration.ofMinutes(5)); @@ -205,7 +202,7 @@ public void setOrganizationUser() { organizationId -> requestListOrganizationAuditors( this.cloudFoundryClient, organizationId)) - .map(resource -> ResourceUtils.getEntity(resource).getUsername()) + .map(GetUserResponse::getUsername) .as(StepVerifier::create) .expectNext(username) .expectComplete() @@ -342,16 +339,16 @@ private static Mono createUser( private static Mono getOrganizationId( CloudFoundryClient cloudFoundryClient, String organizationName) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .organizations() + .organizationsV3() .list( ListOrganizationsRequest.builder() + .name(organizationName) .page(page) .build())) - .filter(r -> organizationName.equals(ResourceUtils.getEntity(r).getName())) - .map(ResourceUtils::getId) + .map(OrganizationResource::getId) .singleOrEmpty(); } @@ -378,24 +375,37 @@ private static Mono listSpaceUsers( .build()); } - private static Flux requestListOrganizationAuditors( + private static Flux requestListOrganizationAuditors( CloudFoundryClient cloudFoundryClient, String organizationId) { - return PaginationUtils.requestClientV2Resources( - page -> - cloudFoundryClient - .organizations() - .listAuditors( - ListOrganizationAuditorsRequest.builder() - .organizationId(organizationId) - .page(page) - .build())); + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .rolesV3() + .list( + ListRolesRequest.builder() + .organizationId(organizationId) + .type(RoleType.ORGANIZATION_AUDITOR) + .page(page) + .build())) + .flatMap( + role -> + cloudFoundryClient + .usersV3() + .get( + GetUserRequest.builder() + .userId( + role.getRelationships() + .getUser() + .getData() + .getId()) + .build())); } private static Flux requestListUsers(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils.requestClientV2Resources( + return PaginationUtils.requestClientV3Resources( page -> cloudFoundryClient - .users() + .usersV3() .list(ListUsersRequest.builder().page(page).build())); }