2020import org .cloudfoundry .client .v2 .OrderDirection ;
2121import org .cloudfoundry .client .v2 .applications .AbstractApplicationResource ;
2222import org .cloudfoundry .client .v2 .applications .ApplicationEntity ;
23- import org .cloudfoundry .client .v2 .applications .ApplicationEnvironmentRequest ;
24- import org .cloudfoundry .client .v2 .applications .ApplicationEnvironmentResponse ;
2523import org .cloudfoundry .client .v2 .applications .ApplicationInstanceInfo ;
2624import org .cloudfoundry .client .v2 .applications .ApplicationInstancesRequest ;
2725import org .cloudfoundry .client .v2 .applications .ApplicationInstancesResponse ;
8684import org .cloudfoundry .client .v3 .Lifecycle ;
8785import org .cloudfoundry .client .v3 .Resource ;
8886import org .cloudfoundry .client .v3 .applications .ApplicationResource ;
87+ import org .cloudfoundry .client .v3 .applications .GetApplicationEnvironmentRequest ;
88+ import org .cloudfoundry .client .v3 .applications .GetApplicationEnvironmentResponse ;
8989import org .cloudfoundry .client .v3 .applications .GetApplicationResponse ;
90+ import org .cloudfoundry .client .v3 .applications .GetApplicationSshEnabledRequest ;
91+ import org .cloudfoundry .client .v3 .applications .GetApplicationSshEnabledResponse ;
9092import org .cloudfoundry .client .v3 .applications .ListApplicationsRequest ;
93+ import org .cloudfoundry .client .v3 .applications .UpdateApplicationFeatureRequest ;
9194import org .cloudfoundry .client .v3 .tasks .CancelTaskRequest ;
9295import org .cloudfoundry .client .v3 .tasks .CancelTaskResponse ;
9396import org .cloudfoundry .client .v3 .tasks .CreateTaskRequest ;
@@ -227,8 +230,14 @@ public Mono<Void> disableSsh(DisableApplicationSshRequest request) {
227230 .zip (this .cloudFoundryClient , this .spaceId )
228231 .flatMap (function ((cloudFoundryClient , spaceId ) -> Mono .zip (
229232 Mono .just (cloudFoundryClient ),
230- getApplicationIdWhere (cloudFoundryClient , request .getName (), spaceId , sshEnabled ( true ) )
233+ getApplicationIdV3 (cloudFoundryClient , request .getName (), spaceId )
231234 )))
235+ .flatMap (function ((cloudFoundryClient , applicationId ) -> Mono .zip (
236+ Mono .just (cloudFoundryClient ),
237+ Mono .just (applicationId ),
238+ getSshEnabled (cloudFoundryClient , applicationId )
239+ )))
240+ .filter (predicate ((cloudFoundryClient ,applicationId ,sshEnabled ) -> sshEnabled .equals (true )))
232241 .flatMap (function ((cloudFoundryClient , applicationId ) -> requestUpdateApplicationSsh (cloudFoundryClient , applicationId , false )))
233242 .then ()
234243 .transform (OperationsLogging .log ("Disable Application SSH" ))
@@ -241,8 +250,14 @@ public Mono<Void> enableSsh(EnableApplicationSshRequest request) {
241250 .zip (this .cloudFoundryClient , this .spaceId )
242251 .flatMap (function ((cloudFoundryClient , spaceId ) -> Mono .zip (
243252 Mono .just (cloudFoundryClient ),
244- getApplicationIdWhere (cloudFoundryClient , request .getName (), spaceId , sshEnabled ( false ) )
253+ getApplicationIdV3 (cloudFoundryClient , request .getName (), spaceId )
245254 )))
255+ .flatMap (function ((cloudFoundryClient , applicationId ) -> Mono .zip (
256+ Mono .just (cloudFoundryClient ),
257+ Mono .just (applicationId ),
258+ getSshEnabled (cloudFoundryClient , applicationId )
259+ )))
260+ .filter (predicate ((cloudFoundryClient ,applicationId ,sshEnabled ) -> sshEnabled .equals (false )))
246261 .flatMap (function ((cloudFoundryClient , applicationId ) -> requestUpdateApplicationSsh (cloudFoundryClient , applicationId , true )))
247262 .then ()
248263 .transform (OperationsLogging .log ("Enable Application SSH" ))
@@ -292,7 +307,7 @@ public Mono<ApplicationEnvironments> getEnvironments(GetApplicationEnvironmentsR
292307 .zip (this .cloudFoundryClient , this .spaceId )
293308 .flatMap (function ((cloudFoundryClient , spaceId ) -> Mono .zip (
294309 Mono .just (cloudFoundryClient ),
295- getApplicationId (cloudFoundryClient , request .getName (), spaceId )
310+ getApplicationIdV3 (cloudFoundryClient , request .getName (), spaceId )
296311 )))
297312 .flatMap (function (DefaultApplications ::requestApplicationEnvironment ))
298313 .map (DefaultApplications ::toApplicationEnvironments )
@@ -557,12 +572,21 @@ public Mono<Void> setHealthCheck(SetApplicationHealthCheckRequest request) {
557572 public Mono <Boolean > sshEnabled (ApplicationSshEnabledRequest request ) {
558573 return Mono
559574 .zip (this .cloudFoundryClient , this .spaceId )
560- .flatMap (function ((cloudFoundryClient , spaceId ) -> getApplication (cloudFoundryClient , request .getName (), spaceId )))
561- .map (applicationResource -> ResourceUtils .getEntity (applicationResource ).getEnableSsh ())
575+ .flatMap (function ((cloudFoundryClient , spaceId ) -> Mono .zip (
576+ Mono .just (cloudFoundryClient ),
577+ getApplicationIdV3 (cloudFoundryClient , request .getName (), spaceId ))))
578+ .flatMap (function (DefaultApplications ::getSshEnabled ))
562579 .transform (OperationsLogging .log ("Is Application SSH Enabled" ))
563580 .checkpoint ();
564581 }
565582
583+ private static Mono <Boolean > getSshEnabled (CloudFoundryClient cloudFoundryClient , String applicationId ) {
584+ return cloudFoundryClient .applicationsV3 ()
585+ .getSshEnabled (GetApplicationSshEnabledRequest .builder ()
586+ .applicationId (applicationId ).build ())
587+ .map (GetApplicationSshEnabledResponse ::getEnabled );
588+ }
589+
566590 @ Override
567591 public Mono <Void > start (StartApplicationRequest request ) {
568592 return Mono
@@ -1222,11 +1246,11 @@ private static Mono<Void> removeServiceBindings(CloudFoundryClient cloudFoundryC
12221246 .then ();
12231247 }
12241248
1225- private static Mono <ApplicationEnvironmentResponse > requestApplicationEnvironment (CloudFoundryClient cloudFoundryClient , String applicationId ) {
1226- return cloudFoundryClient .applicationsV2 ()
1227- .environment ( ApplicationEnvironmentRequest .builder ()
1228- .applicationId (applicationId )
1229- .build ());
1249+ private static Mono <GetApplicationEnvironmentResponse > requestApplicationEnvironment (CloudFoundryClient cloudFoundryClient , String applicationId ) {
1250+ return cloudFoundryClient .applicationsV3 ()
1251+ .getEnvironment ( GetApplicationEnvironmentRequest .builder ()
1252+ .applicationId (applicationId )
1253+ .build ());
12301254 }
12311255
12321256 private static Mono <ApplicationInstancesResponse > requestApplicationInstances (CloudFoundryClient cloudFoundryClient , String applicationId ) {
@@ -1662,8 +1686,16 @@ private static Mono<AbstractApplicationResource> requestUpdateApplicationScale(C
16621686 return requestUpdateApplication (cloudFoundryClient , applicationId , builder -> builder .diskQuota (disk ).instances (instances ).memory (memory ));
16631687 }
16641688
1665- private static Mono <AbstractApplicationResource > requestUpdateApplicationSsh (CloudFoundryClient cloudFoundryClient , String applicationId , Boolean enabled ) {
1666- return requestUpdateApplication (cloudFoundryClient , applicationId , builder -> builder .enableSsh (enabled ));
1689+ private static Mono <ApplicationResource > requestUpdateApplicationSsh (CloudFoundryClient cloudFoundryClient , String applicationId , boolean enabled ) {
1690+ return requestUpdateApplicationFeature (cloudFoundryClient , applicationId ,builder -> builder .featureName ("ssh" ).enabled (enabled ));
1691+ }
1692+
1693+ private static Mono <ApplicationResource > requestUpdateApplicationFeature (CloudFoundryClient cloudFoundryClient , String applicationId , UnaryOperator <UpdateApplicationFeatureRequest .Builder > modifier ) {
1694+ return cloudFoundryClient .applicationsV3 ()
1695+ .updateFeature (modifier .apply (org .cloudfoundry .client .v3 .applications .UpdateApplicationFeatureRequest .builder ()
1696+ .applicationId (applicationId ))
1697+ .build ())
1698+ .cast (ApplicationResource .class );
16671699 }
16681700
16691701 private static Mono <AbstractApplicationResource > requestUpdateApplicationState (CloudFoundryClient cloudFoundryClient , String applicationId , String state ) {
@@ -1709,10 +1741,6 @@ private static boolean shouldStartApplication(PushApplicationManifestRequest req
17091741 return !Optional .ofNullable (request .getNoStart ()).orElse (false );
17101742 }
17111743
1712- private static Predicate <AbstractApplicationResource > sshEnabled (Boolean enabled ) {
1713- return resource -> enabled .equals (ResourceUtils .getEntity (resource ).getEnableSsh ());
1714- }
1715-
17161744 private static Mono <Void > startApplicationAndWait (CloudFoundryClient cloudFoundryClient , String application , String applicationId , Duration stagingTimeout , Duration startupTimeout ) {
17171745 return requestUpdateApplicationState (cloudFoundryClient , applicationId , STARTED_STATE )
17181746 .flatMap (response -> waitForStaging (cloudFoundryClient , application , applicationId , stagingTimeout ))
@@ -1755,12 +1783,12 @@ private static ApplicationDetail toApplicationDetail(List<String> buildpacks, Su
17551783 .build ();
17561784 }
17571785
1758- private static ApplicationEnvironments toApplicationEnvironments (ApplicationEnvironmentResponse response ) {
1786+ private static ApplicationEnvironments toApplicationEnvironments (GetApplicationEnvironmentResponse response ) {
17591787 return ApplicationEnvironments .builder ()
1760- .running (response .getRunningEnvironmentJsons ())
1761- .staging (response .getStagingEnvironmentJsons ())
1762- .systemProvided (response .getSystemEnvironmentJsons ())
1763- .userProvided (response .getEnvironmentJsons ())
1788+ .running (response .getRunningEnvironmentVariables ())
1789+ .staging (response .getStagingEnvironmentVariables ())
1790+ .systemProvided (response .getSystemEnvironmentVariables ())
1791+ .userProvided (response .getEnvironmentVariables ())
17641792 .build ();
17651793 }
17661794
0 commit comments