Skip to content

Commit 891f35d

Browse files
Merge pull request #1218 from cloudfoundry/1173
PR 1173
2 parents 996a815 + 628c05f commit 891f35d

File tree

3 files changed

+174
-53
lines changed

3 files changed

+174
-53
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java

Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import org.cloudfoundry.client.v2.OrderDirection;
4545
import org.cloudfoundry.client.v2.applications.AbstractApplicationResource;
4646
import org.cloudfoundry.client.v2.applications.ApplicationEntity;
47-
import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentRequest;
48-
import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentResponse;
4947
import org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo;
5048
import org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest;
5149
import org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse;
@@ -111,11 +109,17 @@
111109
import org.cloudfoundry.client.v3.Relationship;
112110
import org.cloudfoundry.client.v3.Resource;
113111
import org.cloudfoundry.client.v3.ToOneRelationship;
112+
import org.cloudfoundry.client.v3.applications.ApplicationFeature;
114113
import org.cloudfoundry.client.v3.applications.ApplicationResource;
114+
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest;
115+
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse;
115116
import org.cloudfoundry.client.v3.applications.GetApplicationResponse;
117+
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest;
118+
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse;
116119
import org.cloudfoundry.client.v3.applications.ListApplicationProcessesRequest;
117120
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
118121
import org.cloudfoundry.client.v3.applications.SetApplicationCurrentDropletRequest;
122+
import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest;
119123
import org.cloudfoundry.client.v3.builds.BuildState;
120124
import org.cloudfoundry.client.v3.builds.CreateBuildRequest;
121125
import org.cloudfoundry.client.v3.builds.CreateBuildResponse;
@@ -202,6 +206,8 @@ public final class DefaultApplications implements Applications {
202206

203207
private static final String STOPPED_STATE = "STOPPED";
204208

209+
private static final String APP_FEATURE_SSH = "ssh";
210+
205211
private final Mono<CloudFoundryClient> cloudFoundryClient;
206212

207213
private final Mono<DopplerClient> dopplerClient;
@@ -320,11 +326,21 @@ public Mono<Void> disableSsh(DisableApplicationSshRequest request) {
320326
(cloudFoundryClient, spaceId) ->
321327
Mono.zip(
322328
Mono.just(cloudFoundryClient),
323-
getApplicationIdWhere(
329+
getApplicationIdV3(
324330
cloudFoundryClient,
325331
request.getName(),
326-
spaceId,
327-
sshEnabled(true)))))
332+
spaceId))))
333+
.flatMap(
334+
function(
335+
(cloudFoundryClient, applicationId) ->
336+
Mono.zip(
337+
Mono.just(cloudFoundryClient),
338+
Mono.just(applicationId),
339+
getSshEnabled(cloudFoundryClient, applicationId))))
340+
.filter(
341+
predicate(
342+
(cloudFoundryClient, applicationId, sshEnabled) ->
343+
sshEnabled.equals(true)))
328344
.flatMap(
329345
function(
330346
(cloudFoundryClient, applicationId) ->
@@ -343,11 +359,21 @@ public Mono<Void> enableSsh(EnableApplicationSshRequest request) {
343359
(cloudFoundryClient, spaceId) ->
344360
Mono.zip(
345361
Mono.just(cloudFoundryClient),
346-
getApplicationIdWhere(
362+
getApplicationIdV3(
347363
cloudFoundryClient,
348364
request.getName(),
349-
spaceId,
350-
sshEnabled(false)))))
365+
spaceId))))
366+
.flatMap(
367+
function(
368+
(cloudFoundryClient, applicationId) ->
369+
Mono.zip(
370+
Mono.just(cloudFoundryClient),
371+
Mono.just(applicationId),
372+
getSshEnabled(cloudFoundryClient, applicationId))))
373+
.filter(
374+
predicate(
375+
(cloudFoundryClient, applicationId, sshEnabled) ->
376+
sshEnabled.equals(false)))
351377
.flatMap(
352378
function(
353379
(cloudFoundryClient, applicationId) ->
@@ -420,7 +446,7 @@ public Mono<ApplicationEnvironments> getEnvironments(
420446
(cloudFoundryClient, spaceId) ->
421447
Mono.zip(
422448
Mono.just(cloudFoundryClient),
423-
getApplicationId(
449+
getApplicationIdV3(
424450
cloudFoundryClient,
425451
request.getName(),
426452
spaceId))))
@@ -906,15 +932,28 @@ public Mono<Boolean> sshEnabled(ApplicationSshEnabledRequest request) {
906932
.flatMap(
907933
function(
908934
(cloudFoundryClient, spaceId) ->
909-
getApplication(
910-
cloudFoundryClient, request.getName(), spaceId)))
911-
.map(
912-
applicationResource ->
913-
ResourceUtils.getEntity(applicationResource).getEnableSsh())
935+
Mono.zip(
936+
Mono.just(cloudFoundryClient),
937+
getApplicationIdV3(
938+
cloudFoundryClient,
939+
request.getName(),
940+
spaceId))))
941+
.flatMap(function(DefaultApplications::getSshEnabled))
914942
.transform(OperationsLogging.log("Is Application SSH Enabled"))
915943
.checkpoint();
916944
}
917945

946+
private static Mono<Boolean> getSshEnabled(
947+
CloudFoundryClient cloudFoundryClient, String applicationId) {
948+
return cloudFoundryClient
949+
.applicationsV3()
950+
.getSshEnabled(
951+
GetApplicationSshEnabledRequest.builder()
952+
.applicationId(applicationId)
953+
.build())
954+
.map(GetApplicationSshEnabledResponse::getEnabled);
955+
}
956+
918957
@Override
919958
public Mono<Void> start(StartApplicationRequest request) {
920959
return Mono.zip(this.cloudFoundryClient, this.spaceId)
@@ -2086,12 +2125,12 @@ private static Mono<Void> removeServiceBindings(
20862125
.then();
20872126
}
20882127

2089-
private static Mono<ApplicationEnvironmentResponse> requestApplicationEnvironment(
2128+
private static Mono<GetApplicationEnvironmentResponse> requestApplicationEnvironment(
20902129
CloudFoundryClient cloudFoundryClient, String applicationId) {
20912130
return cloudFoundryClient
2092-
.applicationsV2()
2093-
.environment(
2094-
ApplicationEnvironmentRequest.builder()
2131+
.applicationsV3()
2132+
.getEnvironment(
2133+
GetApplicationEnvironmentRequest.builder()
20952134
.applicationId(applicationId)
20962135
.build());
20972136
}
@@ -2662,6 +2701,29 @@ private static Mono<AbstractApplicationResource> requestUpdateApplicationName(
26622701
cloudFoundryClient, applicationId, builder -> builder.name(name));
26632702
}
26642703

2704+
private static Mono<ApplicationFeature> requestUpdateApplicationSsh(
2705+
CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) {
2706+
return requestUpdateApplicationFeature(
2707+
cloudFoundryClient,
2708+
applicationId,
2709+
builder -> builder.featureName(APP_FEATURE_SSH).enabled(enabled));
2710+
}
2711+
2712+
private static Mono<ApplicationFeature> requestUpdateApplicationFeature(
2713+
CloudFoundryClient cloudFoundryClient,
2714+
String applicationId,
2715+
UnaryOperator<UpdateApplicationFeatureRequest.Builder> modifier) {
2716+
return cloudFoundryClient
2717+
.applicationsV3()
2718+
.updateFeature(
2719+
modifier.apply(
2720+
org.cloudfoundry.client.v3.applications
2721+
.UpdateApplicationFeatureRequest.builder()
2722+
.applicationId(applicationId))
2723+
.build())
2724+
.cast(ApplicationFeature.class);
2725+
}
2726+
26652727
private static Mono<AbstractApplicationResource> requestUpdateApplicationScale(
26662728
CloudFoundryClient cloudFoundryClient,
26672729
String applicationId,
@@ -2773,10 +2835,6 @@ private static boolean shouldStartApplication(PushApplicationManifestRequest req
27732835
return !Optional.ofNullable(request.getNoStart()).orElse(false);
27742836
}
27752837

2776-
private static Predicate<AbstractApplicationResource> sshEnabled(Boolean enabled) {
2777-
return resource -> enabled.equals(ResourceUtils.getEntity(resource).getEnableSsh());
2778-
}
2779-
27802838
private static Mono<Void> startApplicationAndWait(
27812839
CloudFoundryClient cloudFoundryClient,
27822840
String application,
@@ -2853,12 +2911,12 @@ private static ApplicationDetail toApplicationDetail(
28532911
}
28542912

28552913
private static ApplicationEnvironments toApplicationEnvironments(
2856-
ApplicationEnvironmentResponse response) {
2914+
GetApplicationEnvironmentResponse response) {
28572915
return ApplicationEnvironments.builder()
2858-
.running(response.getRunningEnvironmentJsons())
2859-
.staging(response.getStagingEnvironmentJsons())
2860-
.systemProvided(response.getSystemEnvironmentJsons())
2861-
.userProvided(response.getEnvironmentJsons())
2916+
.running(response.getRunningEnvironmentVariables())
2917+
.staging(response.getStagingEnvironmentVariables())
2918+
.systemProvided(response.getSystemEnvironmentVariables())
2919+
.userProvided(response.getEnvironmentVariables())
28622920
.build();
28632921
}
28642922

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public abstract class AbstractOperationsTest {
8383

8484
protected static final String TEST_USERNAME = "test-username";
8585

86+
protected static final String APP_FEATURE_SSH = "ssh";
87+
8688
protected final ApplicationsV2 applications = mock(ApplicationsV2.class, RETURNS_SMART_NULLS);
8789

8890
protected final ApplicationsV3 applicationsV3 = mock(ApplicationsV3.class, RETURNS_SMART_NULLS);

0 commit comments

Comments
 (0)