Skip to content

Commit 13b1197

Browse files
abhishek7-sapDavid O'Sullivan
authored andcommitted
defaultApplication-api
1 parent 40fd854 commit 13b1197

1 file changed

Lines changed: 85 additions & 121 deletions

File tree

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

Lines changed: 85 additions & 121 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;
@@ -112,33 +110,13 @@
112110
import org.cloudfoundry.client.v3.Resource;
113111
import org.cloudfoundry.client.v3.ToOneRelationship;
114112
import org.cloudfoundry.client.v3.applications.ApplicationResource;
113+
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest;
114+
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse;
115115
import org.cloudfoundry.client.v3.applications.GetApplicationResponse;
116-
import org.cloudfoundry.client.v3.applications.ListApplicationProcessesRequest;
116+
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest;
117+
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse;
117118
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
118-
import org.cloudfoundry.client.v3.applications.SetApplicationCurrentDropletRequest;
119-
import org.cloudfoundry.client.v3.builds.BuildState;
120-
import org.cloudfoundry.client.v3.builds.CreateBuildRequest;
121-
import org.cloudfoundry.client.v3.builds.CreateBuildResponse;
122-
import org.cloudfoundry.client.v3.builds.GetBuildRequest;
123-
import org.cloudfoundry.client.v3.builds.GetBuildResponse;
124-
import org.cloudfoundry.client.v3.domains.DomainResource;
125-
import org.cloudfoundry.client.v3.domains.ListDomainsRequest;
126-
import org.cloudfoundry.client.v3.packages.BitsData;
127-
import org.cloudfoundry.client.v3.packages.CreatePackageRequest;
128-
import org.cloudfoundry.client.v3.packages.CreatePackageResponse;
129-
import org.cloudfoundry.client.v3.packages.DockerData;
130-
import org.cloudfoundry.client.v3.packages.GetPackageRequest;
131-
import org.cloudfoundry.client.v3.packages.GetPackageResponse;
132-
import org.cloudfoundry.client.v3.packages.PackageRelationships;
133-
import org.cloudfoundry.client.v3.packages.PackageState;
134-
import org.cloudfoundry.client.v3.packages.PackageType;
135-
import org.cloudfoundry.client.v3.packages.UploadPackageRequest;
136-
import org.cloudfoundry.client.v3.processes.GetProcessStatisticsRequest;
137-
import org.cloudfoundry.client.v3.processes.GetProcessStatisticsResponse;
138-
import org.cloudfoundry.client.v3.processes.ProcessState;
139-
import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource;
140-
import org.cloudfoundry.client.v3.resourcematch.MatchedResource;
141-
import org.cloudfoundry.client.v3.spaces.ApplyManifestRequest;
119+
import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest;
142120
import org.cloudfoundry.client.v3.tasks.CancelTaskRequest;
143121
import org.cloudfoundry.client.v3.tasks.CancelTaskResponse;
144122
import org.cloudfoundry.client.v3.tasks.CreateTaskRequest;
@@ -314,48 +292,42 @@ public Mono<Void> delete(DeleteApplicationRequest request) {
314292

315293
@Override
316294
public Mono<Void> disableSsh(DisableApplicationSshRequest request) {
317-
return Mono.zip(this.cloudFoundryClient, this.spaceId)
318-
.flatMap(
319-
function(
320-
(cloudFoundryClient, spaceId) ->
321-
Mono.zip(
322-
Mono.just(cloudFoundryClient),
323-
getApplicationIdWhere(
324-
cloudFoundryClient,
325-
request.getName(),
326-
spaceId,
327-
sshEnabled(true)))))
328-
.flatMap(
329-
function(
330-
(cloudFoundryClient, applicationId) ->
331-
requestUpdateApplicationSsh(
332-
cloudFoundryClient, applicationId, false)))
333-
.then()
334-
.transform(OperationsLogging.log("Disable Application SSH"))
335-
.checkpoint();
295+
return Mono
296+
.zip(this.cloudFoundryClient, this.spaceId)
297+
.flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip(
298+
Mono.just(cloudFoundryClient),
299+
getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId)
300+
)))
301+
.flatMap(function((cloudFoundryClient, applicationId) -> Mono.zip(
302+
Mono.just(cloudFoundryClient),
303+
Mono.just(applicationId),
304+
getSshEnabled(cloudFoundryClient, applicationId)
305+
)))
306+
.filter(predicate((cloudFoundryClient,applicationId,sshEnabled) -> sshEnabled.equals(true)))
307+
.flatMap(function((cloudFoundryClient, applicationId) -> requestUpdateApplicationSsh(cloudFoundryClient, applicationId, false)))
308+
.then()
309+
.transform(OperationsLogging.log("Disable Application SSH"))
310+
.checkpoint();
336311
}
337312

338313
@Override
339314
public Mono<Void> enableSsh(EnableApplicationSshRequest request) {
340-
return Mono.zip(this.cloudFoundryClient, this.spaceId)
341-
.flatMap(
342-
function(
343-
(cloudFoundryClient, spaceId) ->
344-
Mono.zip(
345-
Mono.just(cloudFoundryClient),
346-
getApplicationIdWhere(
347-
cloudFoundryClient,
348-
request.getName(),
349-
spaceId,
350-
sshEnabled(false)))))
351-
.flatMap(
352-
function(
353-
(cloudFoundryClient, applicationId) ->
354-
requestUpdateApplicationSsh(
355-
cloudFoundryClient, applicationId, true)))
356-
.then()
357-
.transform(OperationsLogging.log("Enable Application SSH"))
358-
.checkpoint();
315+
return Mono
316+
.zip(this.cloudFoundryClient, this.spaceId)
317+
.flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip(
318+
Mono.just(cloudFoundryClient),
319+
getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId)
320+
)))
321+
.flatMap(function((cloudFoundryClient, applicationId) -> Mono.zip(
322+
Mono.just(cloudFoundryClient),
323+
Mono.just(applicationId),
324+
getSshEnabled(cloudFoundryClient, applicationId)
325+
)))
326+
.filter(predicate((cloudFoundryClient,applicationId,sshEnabled) -> sshEnabled.equals(false)))
327+
.flatMap(function((cloudFoundryClient, applicationId) -> requestUpdateApplicationSsh(cloudFoundryClient, applicationId, true)))
328+
.then()
329+
.transform(OperationsLogging.log("Enable Application SSH"))
330+
.checkpoint();
359331
}
360332

361333
@Override
@@ -412,22 +384,17 @@ public Mono<ApplicationManifest> getApplicationManifest(GetApplicationManifestRe
412384
}
413385

414386
@Override
415-
public Mono<ApplicationEnvironments> getEnvironments(
416-
GetApplicationEnvironmentsRequest request) {
417-
return Mono.zip(this.cloudFoundryClient, this.spaceId)
418-
.flatMap(
419-
function(
420-
(cloudFoundryClient, spaceId) ->
421-
Mono.zip(
422-
Mono.just(cloudFoundryClient),
423-
getApplicationId(
424-
cloudFoundryClient,
425-
request.getName(),
426-
spaceId))))
427-
.flatMap(function(DefaultApplications::requestApplicationEnvironment))
428-
.map(DefaultApplications::toApplicationEnvironments)
429-
.transform(OperationsLogging.log("Get Application Environments"))
430-
.checkpoint();
387+
public Mono<ApplicationEnvironments> getEnvironments(GetApplicationEnvironmentsRequest request) {
388+
return Mono
389+
.zip(this.cloudFoundryClient, this.spaceId)
390+
.flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip(
391+
Mono.just(cloudFoundryClient),
392+
getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId)
393+
)))
394+
.flatMap(function(DefaultApplications::requestApplicationEnvironment))
395+
.map(DefaultApplications::toApplicationEnvironments)
396+
.transform(OperationsLogging.log("Get Application Environments"))
397+
.checkpoint();
431398
}
432399

433400
@Override
@@ -902,17 +869,21 @@ public Mono<Void> setHealthCheck(SetApplicationHealthCheckRequest request) {
902869

903870
@Override
904871
public Mono<Boolean> sshEnabled(ApplicationSshEnabledRequest request) {
905-
return Mono.zip(this.cloudFoundryClient, this.spaceId)
906-
.flatMap(
907-
function(
908-
(cloudFoundryClient, spaceId) ->
909-
getApplication(
910-
cloudFoundryClient, request.getName(), spaceId)))
911-
.map(
912-
applicationResource ->
913-
ResourceUtils.getEntity(applicationResource).getEnableSsh())
914-
.transform(OperationsLogging.log("Is Application SSH Enabled"))
915-
.checkpoint();
872+
return Mono
873+
.zip(this.cloudFoundryClient, this.spaceId)
874+
.flatMap(function((cloudFoundryClient, spaceId) -> Mono.zip(
875+
Mono.just(cloudFoundryClient),
876+
getApplicationIdV3(cloudFoundryClient, request.getName(), spaceId))))
877+
.flatMap(function(DefaultApplications::getSshEnabled))
878+
.transform(OperationsLogging.log("Is Application SSH Enabled"))
879+
.checkpoint();
880+
}
881+
882+
private static Mono<Boolean> getSshEnabled(CloudFoundryClient cloudFoundryClient, String applicationId) {
883+
return cloudFoundryClient.applicationsV3()
884+
.getSshEnabled(GetApplicationSshEnabledRequest.builder()
885+
.applicationId(applicationId).build())
886+
.map(GetApplicationSshEnabledResponse::getEnabled);
916887
}
917888

918889
@Override
@@ -2086,14 +2057,11 @@ private static Mono<Void> removeServiceBindings(
20862057
.then();
20872058
}
20882059

2089-
private static Mono<ApplicationEnvironmentResponse> requestApplicationEnvironment(
2090-
CloudFoundryClient cloudFoundryClient, String applicationId) {
2091-
return cloudFoundryClient
2092-
.applicationsV2()
2093-
.environment(
2094-
ApplicationEnvironmentRequest.builder()
2095-
.applicationId(applicationId)
2096-
.build());
2060+
private static Mono<GetApplicationEnvironmentResponse> requestApplicationEnvironment(CloudFoundryClient cloudFoundryClient, String applicationId) {
2061+
return cloudFoundryClient.applicationsV3()
2062+
.getEnvironment(GetApplicationEnvironmentRequest.builder()
2063+
.applicationId(applicationId)
2064+
.build());
20972065
}
20982066

20992067
private static Mono<ApplicationInstancesResponse> requestApplicationInstances(
@@ -2656,10 +2624,16 @@ private static Mono<AbstractApplicationResource> requestUpdateApplicationHealthC
26562624
builder -> builder.healthCheckType(type.getValue()));
26572625
}
26582626

2659-
private static Mono<AbstractApplicationResource> requestUpdateApplicationName(
2660-
CloudFoundryClient cloudFoundryClient, String applicationId, String name) {
2661-
return requestUpdateApplication(
2662-
cloudFoundryClient, applicationId, builder -> builder.name(name));
2627+
private static Mono<ApplicationResource> requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) {
2628+
return requestUpdateApplicationFeature(cloudFoundryClient, applicationId,builder -> builder.featureName("ssh").enabled(enabled));
2629+
}
2630+
2631+
private static Mono<ApplicationResource> requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator<UpdateApplicationFeatureRequest.Builder> modifier) {
2632+
return cloudFoundryClient.applicationsV3()
2633+
.updateFeature(modifier.apply(org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest.builder()
2634+
.applicationId(applicationId))
2635+
.build())
2636+
.cast(ApplicationResource.class);
26632637
}
26642638

26652639
private static Mono<AbstractApplicationResource> requestUpdateApplicationScale(
@@ -2773,16 +2747,7 @@ private static boolean shouldStartApplication(PushApplicationManifestRequest req
27732747
return !Optional.ofNullable(request.getNoStart()).orElse(false);
27742748
}
27752749

2776-
private static Predicate<AbstractApplicationResource> sshEnabled(Boolean enabled) {
2777-
return resource -> enabled.equals(ResourceUtils.getEntity(resource).getEnableSsh());
2778-
}
2779-
2780-
private static Mono<Void> startApplicationAndWait(
2781-
CloudFoundryClient cloudFoundryClient,
2782-
String application,
2783-
String applicationId,
2784-
Duration stagingTimeout,
2785-
Duration startupTimeout) {
2750+
private static Mono<Void> startApplicationAndWait(CloudFoundryClient cloudFoundryClient, String application, String applicationId, Duration stagingTimeout, Duration startupTimeout) {
27862751
return requestUpdateApplicationState(cloudFoundryClient, applicationId, STARTED_STATE)
27872752
.flatMap(
27882753
response ->
@@ -2852,14 +2817,13 @@ private static ApplicationDetail toApplicationDetail(
28522817
.build();
28532818
}
28542819

2855-
private static ApplicationEnvironments toApplicationEnvironments(
2856-
ApplicationEnvironmentResponse response) {
2820+
private static ApplicationEnvironments toApplicationEnvironments(GetApplicationEnvironmentResponse response) {
28572821
return ApplicationEnvironments.builder()
2858-
.running(response.getRunningEnvironmentJsons())
2859-
.staging(response.getStagingEnvironmentJsons())
2860-
.systemProvided(response.getSystemEnvironmentJsons())
2861-
.userProvided(response.getEnvironmentJsons())
2862-
.build();
2822+
.running(response.getRunningEnvironmentVariables())
2823+
.staging(response.getStagingEnvironmentVariables())
2824+
.systemProvided(response.getSystemEnvironmentVariables())
2825+
.userProvided(response.getEnvironmentVariables())
2826+
.build();
28632827
}
28642828

28652829
private static Mono<ApplicationManifest> toApplicationManifest(

0 commit comments

Comments
 (0)