From 13b11977fbcf2320760f92e3db4463587a9b96e0 Mon Sep 17 00:00:00 2001 From: Abhishek Bhaskar Kulkarni Date: Wed, 4 Jan 2023 11:26:58 +0530 Subject: [PATCH 1/4] defaultApplication-api --- .../applications/DefaultApplications.java | 206 ++++++++---------- 1 file changed, 85 insertions(+), 121 deletions(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java index af2a190df6..f20336b204 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java @@ -44,8 +44,6 @@ import org.cloudfoundry.client.v2.OrderDirection; import org.cloudfoundry.client.v2.applications.AbstractApplicationResource; import org.cloudfoundry.client.v2.applications.ApplicationEntity; -import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentRequest; -import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentResponse; import org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo; import org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest; import org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse; @@ -112,33 +110,13 @@ import org.cloudfoundry.client.v3.Resource; import org.cloudfoundry.client.v3.ToOneRelationship; import org.cloudfoundry.client.v3.applications.ApplicationResource; +import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest; +import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse; import org.cloudfoundry.client.v3.applications.GetApplicationResponse; -import org.cloudfoundry.client.v3.applications.ListApplicationProcessesRequest; +import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest; +import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse; import org.cloudfoundry.client.v3.applications.ListApplicationsRequest; -import org.cloudfoundry.client.v3.applications.SetApplicationCurrentDropletRequest; -import org.cloudfoundry.client.v3.builds.BuildState; -import org.cloudfoundry.client.v3.builds.CreateBuildRequest; -import org.cloudfoundry.client.v3.builds.CreateBuildResponse; -import org.cloudfoundry.client.v3.builds.GetBuildRequest; -import org.cloudfoundry.client.v3.builds.GetBuildResponse; -import org.cloudfoundry.client.v3.domains.DomainResource; -import org.cloudfoundry.client.v3.domains.ListDomainsRequest; -import org.cloudfoundry.client.v3.packages.BitsData; -import org.cloudfoundry.client.v3.packages.CreatePackageRequest; -import org.cloudfoundry.client.v3.packages.CreatePackageResponse; -import org.cloudfoundry.client.v3.packages.DockerData; -import org.cloudfoundry.client.v3.packages.GetPackageRequest; -import org.cloudfoundry.client.v3.packages.GetPackageResponse; -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.processes.GetProcessStatisticsRequest; -import org.cloudfoundry.client.v3.processes.GetProcessStatisticsResponse; -import org.cloudfoundry.client.v3.processes.ProcessState; -import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource; -import org.cloudfoundry.client.v3.resourcematch.MatchedResource; -import org.cloudfoundry.client.v3.spaces.ApplyManifestRequest; +import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest; import org.cloudfoundry.client.v3.tasks.CancelTaskRequest; import org.cloudfoundry.client.v3.tasks.CancelTaskResponse; import org.cloudfoundry.client.v3.tasks.CreateTaskRequest; @@ -314,48 +292,42 @@ public Mono delete(DeleteApplicationRequest request) { @Override public Mono disableSsh(DisableApplicationSshRequest request) { - return Mono.zip(this.cloudFoundryClient, this.spaceId) - .flatMap( - function( - (cloudFoundryClient, spaceId) -> - Mono.zip( - Mono.just(cloudFoundryClient), - getApplicationIdWhere( - cloudFoundryClient, - request.getName(), - spaceId, - sshEnabled(true))))) - .flatMap( - function( - (cloudFoundryClient, applicationId) -> - requestUpdateApplicationSsh( - cloudFoundryClient, applicationId, false))) - .then() - .transform(OperationsLogging.log("Disable Application SSH")) - .checkpoint(); + return Mono + .zip(this.cloudFoundryClient, this.spaceId) + .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId) + ))) + .flatMap(function((cloudFoundryClient, applicationId) -> Mono.zip( + Mono.just(cloudFoundryClient), + Mono.just(applicationId), + getSshEnabled(cloudFoundryClient, applicationId) + ))) + .filter(predicate((cloudFoundryClient,applicationId,sshEnabled) -> sshEnabled.equals(true))) + .flatMap(function((cloudFoundryClient, applicationId) -> requestUpdateApplicationSsh(cloudFoundryClient, applicationId, false))) + .then() + .transform(OperationsLogging.log("Disable Application SSH")) + .checkpoint(); } @Override public Mono enableSsh(EnableApplicationSshRequest request) { - return Mono.zip(this.cloudFoundryClient, this.spaceId) - .flatMap( - function( - (cloudFoundryClient, spaceId) -> - Mono.zip( - Mono.just(cloudFoundryClient), - getApplicationIdWhere( - cloudFoundryClient, - request.getName(), - spaceId, - sshEnabled(false))))) - .flatMap( - function( - (cloudFoundryClient, applicationId) -> - requestUpdateApplicationSsh( - cloudFoundryClient, applicationId, true))) - .then() - .transform(OperationsLogging.log("Enable Application SSH")) - .checkpoint(); + return Mono + .zip(this.cloudFoundryClient, this.spaceId) + .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId) + ))) + .flatMap(function((cloudFoundryClient, applicationId) -> Mono.zip( + Mono.just(cloudFoundryClient), + Mono.just(applicationId), + getSshEnabled(cloudFoundryClient, applicationId) + ))) + .filter(predicate((cloudFoundryClient,applicationId,sshEnabled) -> sshEnabled.equals(false))) + .flatMap(function((cloudFoundryClient, applicationId) -> requestUpdateApplicationSsh(cloudFoundryClient, applicationId, true))) + .then() + .transform(OperationsLogging.log("Enable Application SSH")) + .checkpoint(); } @Override @@ -412,22 +384,17 @@ public Mono getApplicationManifest(GetApplicationManifestRe } @Override - public Mono getEnvironments( - GetApplicationEnvironmentsRequest request) { - return Mono.zip(this.cloudFoundryClient, this.spaceId) - .flatMap( - function( - (cloudFoundryClient, spaceId) -> - Mono.zip( - Mono.just(cloudFoundryClient), - getApplicationId( - cloudFoundryClient, - request.getName(), - spaceId)))) - .flatMap(function(DefaultApplications::requestApplicationEnvironment)) - .map(DefaultApplications::toApplicationEnvironments) - .transform(OperationsLogging.log("Get Application Environments")) - .checkpoint(); + public Mono getEnvironments(GetApplicationEnvironmentsRequest request) { + return Mono + .zip(this.cloudFoundryClient, this.spaceId) + .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId) + ))) + .flatMap(function(DefaultApplications::requestApplicationEnvironment)) + .map(DefaultApplications::toApplicationEnvironments) + .transform(OperationsLogging.log("Get Application Environments")) + .checkpoint(); } @Override @@ -902,17 +869,21 @@ public Mono setHealthCheck(SetApplicationHealthCheckRequest request) { @Override public Mono sshEnabled(ApplicationSshEnabledRequest request) { - return Mono.zip(this.cloudFoundryClient, this.spaceId) - .flatMap( - function( - (cloudFoundryClient, spaceId) -> - getApplication( - cloudFoundryClient, request.getName(), spaceId))) - .map( - applicationResource -> - ResourceUtils.getEntity(applicationResource).getEnableSsh()) - .transform(OperationsLogging.log("Is Application SSH Enabled")) - .checkpoint(); + return Mono + .zip(this.cloudFoundryClient, this.spaceId) + .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId)))) + .flatMap(function(DefaultApplications::getSshEnabled)) + .transform(OperationsLogging.log("Is Application SSH Enabled")) + .checkpoint(); + } + + private static Mono getSshEnabled(CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient.applicationsV3() + .getSshEnabled(GetApplicationSshEnabledRequest.builder() + .applicationId(applicationId).build()) + .map(GetApplicationSshEnabledResponse::getEnabled); } @Override @@ -2086,14 +2057,11 @@ private static Mono removeServiceBindings( .then(); } - private static Mono requestApplicationEnvironment( - CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient - .applicationsV2() - .environment( - ApplicationEnvironmentRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestApplicationEnvironment(CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient.applicationsV3() + .getEnvironment(GetApplicationEnvironmentRequest.builder() + .applicationId(applicationId) + .build()); } private static Mono requestApplicationInstances( @@ -2656,10 +2624,16 @@ private static Mono requestUpdateApplicationHealthC builder -> builder.healthCheckType(type.getValue())); } - private static Mono requestUpdateApplicationName( - CloudFoundryClient cloudFoundryClient, String applicationId, String name) { - return requestUpdateApplication( - cloudFoundryClient, applicationId, builder -> builder.name(name)); + private static Mono requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) { + return requestUpdateApplicationFeature(cloudFoundryClient, applicationId,builder -> builder.featureName("ssh").enabled(enabled)); + } + + private static Mono requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator modifier) { + return cloudFoundryClient.applicationsV3() + .updateFeature(modifier.apply(org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest.builder() + .applicationId(applicationId)) + .build()) + .cast(ApplicationResource.class); } private static Mono requestUpdateApplicationScale( @@ -2773,16 +2747,7 @@ private static boolean shouldStartApplication(PushApplicationManifestRequest req return !Optional.ofNullable(request.getNoStart()).orElse(false); } - private static Predicate sshEnabled(Boolean enabled) { - return resource -> enabled.equals(ResourceUtils.getEntity(resource).getEnableSsh()); - } - - private static Mono startApplicationAndWait( - CloudFoundryClient cloudFoundryClient, - String application, - String applicationId, - Duration stagingTimeout, - Duration startupTimeout) { + private static Mono startApplicationAndWait(CloudFoundryClient cloudFoundryClient, String application, String applicationId, Duration stagingTimeout, Duration startupTimeout) { return requestUpdateApplicationState(cloudFoundryClient, applicationId, STARTED_STATE) .flatMap( response -> @@ -2852,14 +2817,13 @@ private static ApplicationDetail toApplicationDetail( .build(); } - private static ApplicationEnvironments toApplicationEnvironments( - ApplicationEnvironmentResponse response) { + private static ApplicationEnvironments toApplicationEnvironments(GetApplicationEnvironmentResponse response) { return ApplicationEnvironments.builder() - .running(response.getRunningEnvironmentJsons()) - .staging(response.getStagingEnvironmentJsons()) - .systemProvided(response.getSystemEnvironmentJsons()) - .userProvided(response.getEnvironmentJsons()) - .build(); + .running(response.getRunningEnvironmentVariables()) + .staging(response.getStagingEnvironmentVariables()) + .systemProvided(response.getSystemEnvironmentVariables()) + .userProvided(response.getEnvironmentVariables()) + .build(); } private static Mono toApplicationManifest( From 4f37f2158a26d7364e4543751e43b30cd00601e3 Mon Sep 17 00:00:00 2001 From: Abhishek Bhaskar Kulkarni Date: Wed, 4 Jan 2023 11:54:58 +0530 Subject: [PATCH 2/4] minor changes --- .../operations/applications/DefaultApplications.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java index f20336b204..05dfe07d96 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java @@ -180,6 +180,8 @@ public final class DefaultApplications implements Applications { private static final String STOPPED_STATE = "STOPPED"; + private static final String APP_FEATURE_SSH = "ssh"; + private final Mono cloudFoundryClient; private final Mono dopplerClient; @@ -2625,7 +2627,7 @@ private static Mono requestUpdateApplicationHealthC } private static Mono requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) { - return requestUpdateApplicationFeature(cloudFoundryClient, applicationId,builder -> builder.featureName("ssh").enabled(enabled)); + return requestUpdateApplicationFeature(cloudFoundryClient, applicationId,builder -> builder.featureName(APP_FEATURE_SSH).enabled(enabled)); } private static Mono requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator modifier) { From 257ca3a6c3dc7c6e4b25d9a28df17219eac3c18e Mon Sep 17 00:00:00 2001 From: Abhishek Bhaskar Kulkarni Date: Fri, 13 Jan 2023 17:03:08 +0530 Subject: [PATCH 3/4] Modified Junit tests to adopt V3 changes. --- .../applications/DefaultApplications.java | 7 +- .../operations/AbstractOperationsTest.java | 2 + .../applications/DefaultApplicationsTest.java | 178 ++++++++++-------- 3 files changed, 109 insertions(+), 78 deletions(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java index 05dfe07d96..c14e82b2af 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java @@ -109,6 +109,7 @@ import org.cloudfoundry.client.v3.Relationship; import org.cloudfoundry.client.v3.Resource; import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.ApplicationFeature; import org.cloudfoundry.client.v3.applications.ApplicationResource; import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest; import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse; @@ -2626,16 +2627,16 @@ private static Mono requestUpdateApplicationHealthC builder -> builder.healthCheckType(type.getValue())); } - private static Mono requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) { + private static Mono requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) { return requestUpdateApplicationFeature(cloudFoundryClient, applicationId,builder -> builder.featureName(APP_FEATURE_SSH).enabled(enabled)); } - private static Mono requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator modifier) { + private static Mono requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator modifier) { return cloudFoundryClient.applicationsV3() .updateFeature(modifier.apply(org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest.builder() .applicationId(applicationId)) .build()) - .cast(ApplicationResource.class); + .cast(ApplicationFeature.class); } private static Mono requestUpdateApplicationScale( diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java index c5afec5a21..2bd120e0f2 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java @@ -80,6 +80,8 @@ public abstract class AbstractOperationsTest { protected static final String TEST_USERNAME = "test-username"; + protected static final String APP_FEATURE_SSH = "ssh"; + protected final ApplicationsV2 applications = mock(ApplicationsV2.class, RETURNS_SMART_NULLS); protected final ApplicationsV3 applicationsV3 = mock(ApplicationsV3.class, RETURNS_SMART_NULLS); diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java index d8494294c1..bb7f72b6aa 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java @@ -127,8 +127,14 @@ import org.cloudfoundry.client.v3.DockerData; import org.cloudfoundry.client.v3.Lifecycle; import org.cloudfoundry.client.v3.applications.ApplicationState; +import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest; +import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse; +import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest; +import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse; import org.cloudfoundry.client.v3.applications.ListApplicationsRequest; import org.cloudfoundry.client.v3.applications.ListApplicationsResponse; +import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest; +import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureResponse; import org.cloudfoundry.client.v3.tasks.CancelTaskRequest; import org.cloudfoundry.client.v3.tasks.CancelTaskResponse; import org.cloudfoundry.client.v3.tasks.CreateTaskRequest; @@ -405,10 +411,11 @@ void deleteWithBoundRoutes() { } @Test - void disableSsh() { - requestApplications( - this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-metadata-id"); - requestUpdateApplicationSsh(this.cloudFoundryClient, "test-metadata-id", false); + public void disableSsh() { + requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true); + requestUpdateApplicationSshV3(this.cloudFoundryClient, "test-application-id", false); + this.applications .disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build()) @@ -418,8 +425,9 @@ void disableSsh() { } @Test - void disableSshAlreadyDisabled() { - requestApplicationsWithSsh(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, false); + public void disableSshAlreadyDisabled() { + requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",false); this.applications .disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build()) @@ -429,8 +437,8 @@ void disableSshAlreadyDisabled() { } @Test - void disableSshNoApp() { - requestApplicationsEmpty(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); + public void disableSshNoApp() { + requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); this.applications .disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build()) @@ -444,10 +452,10 @@ void disableSshNoApp() { } @Test - void enableSsh() { - requestApplications( - this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-metadata-id"); - requestUpdateApplicationSsh(this.cloudFoundryClient, "test-application-id", true); + public void enableSsh() { + requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",false); + requestUpdateApplicationSshV3(this.cloudFoundryClient, "test-application-id", true); this.applications .enableSsh(EnableApplicationSshRequest.builder().name("test-app-name").build()) @@ -457,8 +465,9 @@ void enableSsh() { } @Test - void enableSshAlreadyEnabled() { - requestApplicationsWithSsh(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, true); + public void enableSshAlreadyEnabled() { + requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true); this.applications .enableSsh(EnableApplicationSshRequest.builder().name("test-app-name").build()) @@ -468,8 +477,8 @@ void enableSshAlreadyEnabled() { } @Test - void enableSshNoApp() { - requestApplicationsEmpty(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); + public void enableSshNoApp() { + requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); this.applications .enableSsh(EnableApplicationSshRequest.builder().name("test-app-name").build()) @@ -721,8 +730,8 @@ void getDetectedBuildpack() { } @Test - void getEnvironments() { - requestApplications(this.cloudFoundryClient, "test-app", TEST_SPACE_ID, "test-metadata-id"); + public void getEnvironments() { + requestApplicationsV3(this.cloudFoundryClient, "test-app", TEST_SPACE_ID, "test-metadata-id"); requestApplicationEnvironment(this.cloudFoundryClient, "test-metadata-id"); this.applications @@ -753,8 +762,8 @@ void getEnvironments() { } @Test - void getEnvironmentsNoApp() { - requestApplicationsEmpty(this.cloudFoundryClient, "test-app", TEST_SPACE_ID); + public void getEnvironmentsNoApp() { + requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app", TEST_SPACE_ID); this.applications .getEnvironments( @@ -3733,9 +3742,9 @@ void setHealthCheck() { } @Test - void sshEnabled() { - requestApplications( - this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-metadata-id"); + public void sshEnabled() { + requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true); this.applications .sshEnabled(ApplicationSshEnabledRequest.builder().name("test-app-name").build()) @@ -3746,8 +3755,8 @@ void sshEnabled() { } @Test - void sshEnabledNoApp() { - requestApplicationsEmpty(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); + public void sshEnabledNoApp() { + requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); this.applications .sshEnabled(ApplicationSshEnabledRequest.builder().name("test-app-name").build()) @@ -3760,6 +3769,7 @@ void sshEnabledNoApp() { .verify(Duration.ofSeconds(5)); } + @Test void startApplicationFailurePartial() { requestApplicationsSpecificState( @@ -4046,27 +4056,19 @@ private static void requestApplicationEmptyStats( .thenReturn(Mono.just(ApplicationStatisticsResponse.builder().build())); } - private static void requestApplicationEnvironment( - CloudFoundryClient cloudFoundryClient, String applicationId) { - when(cloudFoundryClient - .applicationsV2() - .environment( - ApplicationEnvironmentRequest.builder() - .applicationId(applicationId) - .build())) - .thenReturn( - Mono.just( - ApplicationEnvironmentResponse.builder() - .runningEnvironmentJson( - "running-env-name", "running-env-value") - .applicationEnvironmentJson( - "application-env-name", "application-env-value") - .stagingEnvironmentJson( - "staging-env-name", "staging-env-value") - .environmentJson("env-name", "env-value") - .systemEnvironmentJson( - "system-env-name", "system-env-value") - .build())); + private static void requestApplicationEnvironment(CloudFoundryClient cloudFoundryClient, String applicationId) { + when(cloudFoundryClient.applicationsV3() + .getEnvironment(GetApplicationEnvironmentRequest.builder() + .applicationId(applicationId) + .build())) + .thenReturn(Mono + .just(GetApplicationEnvironmentResponse.builder() + .runningEnvironmentVariable("running-env-name", "running-env-value") + .applicationEnvironmentVariable("application-env-name", "application-env-value") + .stagingEnvironmentVariable("staging-env-name", "staging-env-value") + .environmentVariable("env-name", "env-value") + .systemEnvironmentVariable("system-env-name", "system-env-value") + .build())); } private static void requestApplicationInstances( @@ -4661,33 +4663,33 @@ private static void requestApplicationsEmpty( .thenReturn(Mono.just(fill(ListSpaceApplicationsResponse.builder()).build())); } - private static void requestApplicationsSpecificState( - CloudFoundryClient cloudFoundryClient, - String application, - String spaceId, - String stateReturned) { - when(cloudFoundryClient - .spaces() - .listApplications( - ListSpaceApplicationsRequest.builder() - .name(application) - .page(1) - .spaceId(spaceId) - .build())) - .thenReturn( - Mono.just( - fill(ListSpaceApplicationsResponse.builder()) - .resource( - fill(ApplicationResource.builder(), "application-") - .entity( - fill( - ApplicationEntity - .builder(), - "application-entity-") - .state(stateReturned) - .build()) - .build()) - .build())); + private static void requestApplicationsEmptyV3(CloudFoundryClient cloudFoundryClient, String application, String spaceId) { + when(cloudFoundryClient.applicationsV3() + .list(ListApplicationsRequest.builder() + .name(application) + .spaceId(spaceId) + .page(1) + .build())) + .thenReturn(Mono + .just(fill(ListApplicationsResponse.builder()) + .build())); + } + + private static void requestApplicationsSpecificState(CloudFoundryClient cloudFoundryClient, String application, String spaceId, String stateReturned) { + when(cloudFoundryClient.spaces() + .listApplications(ListSpaceApplicationsRequest.builder() + .name(application) + .page(1) + .spaceId(spaceId) + .build())) + .thenReturn(Mono + .just(fill(ListSpaceApplicationsResponse.builder()) + .resource(fill(ApplicationResource.builder(), "application-") + .entity(fill(ApplicationEntity.builder(), "application-entity-") + .state(stateReturned) + .build()) + .build()) + .build())); } private static void requestApplicationsV3( @@ -5850,8 +5852,34 @@ private static void requestUpdateApplicationSsh( .build())); } - private static void requestUpdateApplicationState( - CloudFoundryClient cloudFoundryClient, String applicationId, String state) { + private static void requestUpdateApplicationSshV3(CloudFoundryClient cloudFoundryClient, String applicationId, Boolean enabled) { + + when(cloudFoundryClient.applicationsV3() + .updateFeature(UpdateApplicationFeatureRequest.builder() + .applicationId(applicationId) + .featureName(APP_FEATURE_SSH) + .enabled(enabled) + .build())) + .thenReturn(Mono + .just(fill(UpdateApplicationFeatureResponse.builder()) + .description("test-description") + .name("test-application-name") + .enabled(enabled) + .build())); + } + + private static void requestGetSshEnabled(CloudFoundryClient cloudFoundryClient, String applicationId,boolean status) { + when(cloudFoundryClient.applicationsV3() + .getSshEnabled(GetApplicationSshEnabledRequest.builder() + .applicationId(applicationId).build())) + .thenReturn(Mono + .just(fill(GetApplicationSshEnabledResponse.builder()) + .reason("test-reason") + .enabled(status) + .build())); + } + + private static void requestUpdateApplicationState(CloudFoundryClient cloudFoundryClient, String applicationId, String state) { requestUpdateApplicationState(cloudFoundryClient, applicationId, state, 1); } From 628c05f5d2c7c1f4b3c9f0262e50343aca70b02b Mon Sep 17 00:00:00 2001 From: David O'Sullivan Date: Tue, 13 Feb 2024 12:09:40 +0000 Subject: [PATCH 4/4] rebasing 1173 --- .../applications/DefaultApplications.java | 243 ++++++++++++------ .../applications/DefaultApplicationsTest.java | 209 ++++++++------- 2 files changed, 288 insertions(+), 164 deletions(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java index c14e82b2af..03ddf9527c 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java @@ -116,8 +116,33 @@ import org.cloudfoundry.client.v3.applications.GetApplicationResponse; import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest; import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse; +import org.cloudfoundry.client.v3.applications.ListApplicationProcessesRequest; import org.cloudfoundry.client.v3.applications.ListApplicationsRequest; +import org.cloudfoundry.client.v3.applications.SetApplicationCurrentDropletRequest; import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest; +import org.cloudfoundry.client.v3.builds.BuildState; +import org.cloudfoundry.client.v3.builds.CreateBuildRequest; +import org.cloudfoundry.client.v3.builds.CreateBuildResponse; +import org.cloudfoundry.client.v3.builds.GetBuildRequest; +import org.cloudfoundry.client.v3.builds.GetBuildResponse; +import org.cloudfoundry.client.v3.domains.DomainResource; +import org.cloudfoundry.client.v3.domains.ListDomainsRequest; +import org.cloudfoundry.client.v3.packages.BitsData; +import org.cloudfoundry.client.v3.packages.CreatePackageRequest; +import org.cloudfoundry.client.v3.packages.CreatePackageResponse; +import org.cloudfoundry.client.v3.packages.DockerData; +import org.cloudfoundry.client.v3.packages.GetPackageRequest; +import org.cloudfoundry.client.v3.packages.GetPackageResponse; +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.processes.GetProcessStatisticsRequest; +import org.cloudfoundry.client.v3.processes.GetProcessStatisticsResponse; +import org.cloudfoundry.client.v3.processes.ProcessState; +import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource; +import org.cloudfoundry.client.v3.resourcematch.MatchedResource; +import org.cloudfoundry.client.v3.spaces.ApplyManifestRequest; import org.cloudfoundry.client.v3.tasks.CancelTaskRequest; import org.cloudfoundry.client.v3.tasks.CancelTaskResponse; import org.cloudfoundry.client.v3.tasks.CreateTaskRequest; @@ -295,42 +320,68 @@ public Mono delete(DeleteApplicationRequest request) { @Override public Mono disableSsh(DisableApplicationSshRequest request) { - return Mono - .zip(this.cloudFoundryClient, this.spaceId) - .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( - Mono.just(cloudFoundryClient), - getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId) - ))) - .flatMap(function((cloudFoundryClient, applicationId) -> Mono.zip( - Mono.just(cloudFoundryClient), - Mono.just(applicationId), - getSshEnabled(cloudFoundryClient, applicationId) - ))) - .filter(predicate((cloudFoundryClient,applicationId,sshEnabled) -> sshEnabled.equals(true))) - .flatMap(function((cloudFoundryClient, applicationId) -> requestUpdateApplicationSsh(cloudFoundryClient, applicationId, false))) - .then() - .transform(OperationsLogging.log("Disable Application SSH")) - .checkpoint(); + return Mono.zip(this.cloudFoundryClient, this.spaceId) + .flatMap( + function( + (cloudFoundryClient, spaceId) -> + Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3( + cloudFoundryClient, + request.getName(), + spaceId)))) + .flatMap( + function( + (cloudFoundryClient, applicationId) -> + Mono.zip( + Mono.just(cloudFoundryClient), + Mono.just(applicationId), + getSshEnabled(cloudFoundryClient, applicationId)))) + .filter( + predicate( + (cloudFoundryClient, applicationId, sshEnabled) -> + sshEnabled.equals(true))) + .flatMap( + function( + (cloudFoundryClient, applicationId) -> + requestUpdateApplicationSsh( + cloudFoundryClient, applicationId, false))) + .then() + .transform(OperationsLogging.log("Disable Application SSH")) + .checkpoint(); } @Override public Mono enableSsh(EnableApplicationSshRequest request) { - return Mono - .zip(this.cloudFoundryClient, this.spaceId) - .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( - Mono.just(cloudFoundryClient), - getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId) - ))) - .flatMap(function((cloudFoundryClient, applicationId) -> Mono.zip( - Mono.just(cloudFoundryClient), - Mono.just(applicationId), - getSshEnabled(cloudFoundryClient, applicationId) - ))) - .filter(predicate((cloudFoundryClient,applicationId,sshEnabled) -> sshEnabled.equals(false))) - .flatMap(function((cloudFoundryClient, applicationId) -> requestUpdateApplicationSsh(cloudFoundryClient, applicationId, true))) - .then() - .transform(OperationsLogging.log("Enable Application SSH")) - .checkpoint(); + return Mono.zip(this.cloudFoundryClient, this.spaceId) + .flatMap( + function( + (cloudFoundryClient, spaceId) -> + Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3( + cloudFoundryClient, + request.getName(), + spaceId)))) + .flatMap( + function( + (cloudFoundryClient, applicationId) -> + Mono.zip( + Mono.just(cloudFoundryClient), + Mono.just(applicationId), + getSshEnabled(cloudFoundryClient, applicationId)))) + .filter( + predicate( + (cloudFoundryClient, applicationId, sshEnabled) -> + sshEnabled.equals(false))) + .flatMap( + function( + (cloudFoundryClient, applicationId) -> + requestUpdateApplicationSsh( + cloudFoundryClient, applicationId, true))) + .then() + .transform(OperationsLogging.log("Enable Application SSH")) + .checkpoint(); } @Override @@ -387,17 +438,22 @@ public Mono getApplicationManifest(GetApplicationManifestRe } @Override - public Mono getEnvironments(GetApplicationEnvironmentsRequest request) { - return Mono - .zip(this.cloudFoundryClient, this.spaceId) - .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( - Mono.just(cloudFoundryClient), - getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId) - ))) - .flatMap(function(DefaultApplications::requestApplicationEnvironment)) - .map(DefaultApplications::toApplicationEnvironments) - .transform(OperationsLogging.log("Get Application Environments")) - .checkpoint(); + public Mono getEnvironments( + GetApplicationEnvironmentsRequest request) { + return Mono.zip(this.cloudFoundryClient, this.spaceId) + .flatMap( + function( + (cloudFoundryClient, spaceId) -> + Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3( + cloudFoundryClient, + request.getName(), + spaceId)))) + .flatMap(function(DefaultApplications::requestApplicationEnvironment)) + .map(DefaultApplications::toApplicationEnvironments) + .transform(OperationsLogging.log("Get Application Environments")) + .checkpoint(); } @Override @@ -872,21 +928,30 @@ public Mono setHealthCheck(SetApplicationHealthCheckRequest request) { @Override public Mono sshEnabled(ApplicationSshEnabledRequest request) { - return Mono - .zip(this.cloudFoundryClient, this.spaceId) - .flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip( - Mono.just(cloudFoundryClient), - getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId)))) - .flatMap(function(DefaultApplications::getSshEnabled)) - .transform(OperationsLogging.log("Is Application SSH Enabled")) - .checkpoint(); + return Mono.zip(this.cloudFoundryClient, this.spaceId) + .flatMap( + function( + (cloudFoundryClient, spaceId) -> + Mono.zip( + Mono.just(cloudFoundryClient), + getApplicationIdV3( + cloudFoundryClient, + request.getName(), + spaceId)))) + .flatMap(function(DefaultApplications::getSshEnabled)) + .transform(OperationsLogging.log("Is Application SSH Enabled")) + .checkpoint(); } - private static Mono getSshEnabled(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .getSshEnabled(GetApplicationSshEnabledRequest.builder() - .applicationId(applicationId).build()) - .map(GetApplicationSshEnabledResponse::getEnabled); + private static Mono getSshEnabled( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .getSshEnabled( + GetApplicationSshEnabledRequest.builder() + .applicationId(applicationId) + .build()) + .map(GetApplicationSshEnabledResponse::getEnabled); } @Override @@ -2060,11 +2125,14 @@ private static Mono removeServiceBindings( .then(); } - private static Mono requestApplicationEnvironment(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .getEnvironment(GetApplicationEnvironmentRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestApplicationEnvironment( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .getEnvironment( + GetApplicationEnvironmentRequest.builder() + .applicationId(applicationId) + .build()); } private static Mono requestApplicationInstances( @@ -2627,16 +2695,33 @@ private static Mono requestUpdateApplicationHealthC builder -> builder.healthCheckType(type.getValue())); } - private static Mono requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) { - return requestUpdateApplicationFeature(cloudFoundryClient, applicationId,builder -> builder.featureName(APP_FEATURE_SSH).enabled(enabled)); + private static Mono requestUpdateApplicationName( + CloudFoundryClient cloudFoundryClient, String applicationId, String name) { + return requestUpdateApplication( + cloudFoundryClient, applicationId, builder -> builder.name(name)); + } + + private static Mono requestUpdateApplicationSsh( + CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) { + return requestUpdateApplicationFeature( + cloudFoundryClient, + applicationId, + builder -> builder.featureName(APP_FEATURE_SSH).enabled(enabled)); } - private static Mono requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator modifier) { - return cloudFoundryClient.applicationsV3() - .updateFeature(modifier.apply(org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest.builder() - .applicationId(applicationId)) - .build()) - .cast(ApplicationFeature.class); + private static Mono requestUpdateApplicationFeature( + CloudFoundryClient cloudFoundryClient, + String applicationId, + UnaryOperator modifier) { + return cloudFoundryClient + .applicationsV3() + .updateFeature( + modifier.apply( + org.cloudfoundry.client.v3.applications + .UpdateApplicationFeatureRequest.builder() + .applicationId(applicationId)) + .build()) + .cast(ApplicationFeature.class); } private static Mono requestUpdateApplicationScale( @@ -2750,7 +2835,12 @@ private static boolean shouldStartApplication(PushApplicationManifestRequest req return !Optional.ofNullable(request.getNoStart()).orElse(false); } - private static Mono startApplicationAndWait(CloudFoundryClient cloudFoundryClient, String application, String applicationId, Duration stagingTimeout, Duration startupTimeout) { + private static Mono startApplicationAndWait( + CloudFoundryClient cloudFoundryClient, + String application, + String applicationId, + Duration stagingTimeout, + Duration startupTimeout) { return requestUpdateApplicationState(cloudFoundryClient, applicationId, STARTED_STATE) .flatMap( response -> @@ -2820,13 +2910,14 @@ private static ApplicationDetail toApplicationDetail( .build(); } - private static ApplicationEnvironments toApplicationEnvironments(GetApplicationEnvironmentResponse response) { + private static ApplicationEnvironments toApplicationEnvironments( + GetApplicationEnvironmentResponse response) { return ApplicationEnvironments.builder() - .running(response.getRunningEnvironmentVariables()) - .staging(response.getStagingEnvironmentVariables()) - .systemProvided(response.getSystemEnvironmentVariables()) - .userProvided(response.getEnvironmentVariables()) - .build(); + .running(response.getRunningEnvironmentVariables()) + .staging(response.getStagingEnvironmentVariables()) + .systemProvided(response.getSystemEnvironmentVariables()) + .userProvided(response.getEnvironmentVariables()) + .build(); } private static Mono toApplicationManifest( diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java index bb7f72b6aa..e8730cead5 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java @@ -41,8 +41,6 @@ import org.cloudfoundry.client.v2.Metadata; import org.cloudfoundry.client.v2.OrderDirection; import org.cloudfoundry.client.v2.applications.ApplicationEntity; -import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentRequest; -import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentResponse; import org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo; import org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest; import org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse; @@ -411,12 +409,12 @@ void deleteWithBoundRoutes() { } @Test - public void disableSsh() { - requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); - requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true); + void disableSsh() { + requestApplicationsV3( + this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient, "test-application-id", true); requestUpdateApplicationSshV3(this.cloudFoundryClient, "test-application-id", false); - this.applications .disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build()) .as(StepVerifier::create) @@ -425,9 +423,10 @@ public void disableSsh() { } @Test - public void disableSshAlreadyDisabled() { - requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); - requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",false); + void disableSshAlreadyDisabled() { + requestApplicationsV3( + this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient, "test-application-id", false); this.applications .disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build()) @@ -437,7 +436,7 @@ public void disableSshAlreadyDisabled() { } @Test - public void disableSshNoApp() { + void disableSshNoApp() { requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); this.applications @@ -452,9 +451,10 @@ public void disableSshNoApp() { } @Test - public void enableSsh() { - requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); - requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",false); + void enableSsh() { + requestApplicationsV3( + this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient, "test-application-id", false); requestUpdateApplicationSshV3(this.cloudFoundryClient, "test-application-id", true); this.applications @@ -465,9 +465,10 @@ public void enableSsh() { } @Test - public void enableSshAlreadyEnabled() { - requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); - requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true); + void enableSshAlreadyEnabled() { + requestApplicationsV3( + this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient, "test-application-id", true); this.applications .enableSsh(EnableApplicationSshRequest.builder().name("test-app-name").build()) @@ -477,7 +478,7 @@ public void enableSshAlreadyEnabled() { } @Test - public void enableSshNoApp() { + void enableSshNoApp() { requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); this.applications @@ -730,8 +731,9 @@ void getDetectedBuildpack() { } @Test - public void getEnvironments() { - requestApplicationsV3(this.cloudFoundryClient, "test-app", TEST_SPACE_ID, "test-metadata-id"); + void getEnvironments() { + requestApplicationsV3( + this.cloudFoundryClient, "test-app", TEST_SPACE_ID, "test-metadata-id"); requestApplicationEnvironment(this.cloudFoundryClient, "test-metadata-id"); this.applications @@ -762,7 +764,7 @@ public void getEnvironments() { } @Test - public void getEnvironmentsNoApp() { + void getEnvironmentsNoApp() { requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app", TEST_SPACE_ID); this.applications @@ -3742,9 +3744,10 @@ void setHealthCheck() { } @Test - public void sshEnabled() { - requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); - requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true); + void sshEnabled() { + requestApplicationsV3( + this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id"); + requestGetSshEnabled(this.cloudFoundryClient, "test-application-id", true); this.applications .sshEnabled(ApplicationSshEnabledRequest.builder().name("test-app-name").build()) @@ -3755,7 +3758,7 @@ public void sshEnabled() { } @Test - public void sshEnabledNoApp() { + void sshEnabledNoApp() { requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID); this.applications @@ -3769,7 +3772,6 @@ public void sshEnabledNoApp() { .verify(Duration.ofSeconds(5)); } - @Test void startApplicationFailurePartial() { requestApplicationsSpecificState( @@ -4056,19 +4058,27 @@ private static void requestApplicationEmptyStats( .thenReturn(Mono.just(ApplicationStatisticsResponse.builder().build())); } - private static void requestApplicationEnvironment(CloudFoundryClient cloudFoundryClient, String applicationId) { - when(cloudFoundryClient.applicationsV3() - .getEnvironment(GetApplicationEnvironmentRequest.builder() - .applicationId(applicationId) - .build())) - .thenReturn(Mono - .just(GetApplicationEnvironmentResponse.builder() - .runningEnvironmentVariable("running-env-name", "running-env-value") - .applicationEnvironmentVariable("application-env-name", "application-env-value") - .stagingEnvironmentVariable("staging-env-name", "staging-env-value") - .environmentVariable("env-name", "env-value") - .systemEnvironmentVariable("system-env-name", "system-env-value") - .build())); + private static void requestApplicationEnvironment( + CloudFoundryClient cloudFoundryClient, String applicationId) { + when(cloudFoundryClient + .applicationsV3() + .getEnvironment( + GetApplicationEnvironmentRequest.builder() + .applicationId(applicationId) + .build())) + .thenReturn( + Mono.just( + GetApplicationEnvironmentResponse.builder() + .runningEnvironmentVariable( + "running-env-name", "running-env-value") + .applicationEnvironmentVariable( + "application-env-name", "application-env-value") + .stagingEnvironmentVariable( + "staging-env-name", "staging-env-value") + .environmentVariable("env-name", "env-value") + .systemEnvironmentVariable( + "system-env-name", "system-env-value") + .build())); } private static void requestApplicationInstances( @@ -4663,33 +4673,46 @@ private static void requestApplicationsEmpty( .thenReturn(Mono.just(fill(ListSpaceApplicationsResponse.builder()).build())); } - private static void requestApplicationsEmptyV3(CloudFoundryClient cloudFoundryClient, String application, String spaceId) { - when(cloudFoundryClient.applicationsV3() - .list(ListApplicationsRequest.builder() - .name(application) - .spaceId(spaceId) - .page(1) - .build())) - .thenReturn(Mono - .just(fill(ListApplicationsResponse.builder()) - .build())); - } - - private static void requestApplicationsSpecificState(CloudFoundryClient cloudFoundryClient, String application, String spaceId, String stateReturned) { - when(cloudFoundryClient.spaces() - .listApplications(ListSpaceApplicationsRequest.builder() - .name(application) - .page(1) - .spaceId(spaceId) - .build())) - .thenReturn(Mono - .just(fill(ListSpaceApplicationsResponse.builder()) - .resource(fill(ApplicationResource.builder(), "application-") - .entity(fill(ApplicationEntity.builder(), "application-entity-") - .state(stateReturned) - .build()) - .build()) - .build())); + private static void requestApplicationsEmptyV3( + CloudFoundryClient cloudFoundryClient, String application, String spaceId) { + when(cloudFoundryClient + .applicationsV3() + .list( + ListApplicationsRequest.builder() + .name(application) + .spaceId(spaceId) + .page(1) + .build())) + .thenReturn(Mono.just(fill(ListApplicationsResponse.builder()).build())); + } + + private static void requestApplicationsSpecificState( + CloudFoundryClient cloudFoundryClient, + String application, + String spaceId, + String stateReturned) { + when(cloudFoundryClient + .spaces() + .listApplications( + ListSpaceApplicationsRequest.builder() + .name(application) + .page(1) + .spaceId(spaceId) + .build())) + .thenReturn( + Mono.just( + fill(ListSpaceApplicationsResponse.builder()) + .resource( + fill(ApplicationResource.builder(), "application-") + .entity( + fill( + ApplicationEntity + .builder(), + "application-entity-") + .state(stateReturned) + .build()) + .build()) + .build())); } private static void requestApplicationsV3( @@ -5852,34 +5875,44 @@ private static void requestUpdateApplicationSsh( .build())); } - private static void requestUpdateApplicationSshV3(CloudFoundryClient cloudFoundryClient, String applicationId, Boolean enabled) { + private static void requestUpdateApplicationSshV3( + CloudFoundryClient cloudFoundryClient, String applicationId, Boolean enabled) { - when(cloudFoundryClient.applicationsV3() - .updateFeature(UpdateApplicationFeatureRequest.builder() - .applicationId(applicationId) - .featureName(APP_FEATURE_SSH) - .enabled(enabled) - .build())) - .thenReturn(Mono - .just(fill(UpdateApplicationFeatureResponse.builder()) - .description("test-description") - .name("test-application-name") - .enabled(enabled) - .build())); + when(cloudFoundryClient + .applicationsV3() + .updateFeature( + UpdateApplicationFeatureRequest.builder() + .applicationId(applicationId) + .featureName(APP_FEATURE_SSH) + .enabled(enabled) + .build())) + .thenReturn( + Mono.just( + fill(UpdateApplicationFeatureResponse.builder()) + .description("test-description") + .name("test-application-name") + .enabled(enabled) + .build())); } - private static void requestGetSshEnabled(CloudFoundryClient cloudFoundryClient, String applicationId,boolean status) { - when(cloudFoundryClient.applicationsV3() - .getSshEnabled(GetApplicationSshEnabledRequest.builder() - .applicationId(applicationId).build())) - .thenReturn(Mono - .just(fill(GetApplicationSshEnabledResponse.builder()) - .reason("test-reason") - .enabled(status) - .build())); + private static void requestGetSshEnabled( + CloudFoundryClient cloudFoundryClient, String applicationId, boolean status) { + when(cloudFoundryClient + .applicationsV3() + .getSshEnabled( + GetApplicationSshEnabledRequest.builder() + .applicationId(applicationId) + .build())) + .thenReturn( + Mono.just( + fill(GetApplicationSshEnabledResponse.builder()) + .reason("test-reason") + .enabled(status) + .build())); } - private static void requestUpdateApplicationState(CloudFoundryClient cloudFoundryClient, String applicationId, String state) { + private static void requestUpdateApplicationState( + CloudFoundryClient cloudFoundryClient, String applicationId, String state) { requestUpdateApplicationState(cloudFoundryClient, applicationId, state, 1); }