|
44 | 44 | import org.cloudfoundry.client.v2.OrderDirection; |
45 | 45 | import org.cloudfoundry.client.v2.applications.AbstractApplicationResource; |
46 | 46 | import org.cloudfoundry.client.v2.applications.ApplicationEntity; |
47 | | -import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentRequest; |
48 | | -import org.cloudfoundry.client.v2.applications.ApplicationEnvironmentResponse; |
49 | 47 | import org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo; |
50 | 48 | import org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest; |
51 | 49 | import org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse; |
|
112 | 110 | import org.cloudfoundry.client.v3.Resource; |
113 | 111 | import org.cloudfoundry.client.v3.ToOneRelationship; |
114 | 112 | import org.cloudfoundry.client.v3.applications.ApplicationResource; |
| 113 | +import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest; |
| 114 | +import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse; |
115 | 115 | 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; |
117 | 118 | 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; |
142 | 120 | import org.cloudfoundry.client.v3.tasks.CancelTaskRequest; |
143 | 121 | import org.cloudfoundry.client.v3.tasks.CancelTaskResponse; |
144 | 122 | import org.cloudfoundry.client.v3.tasks.CreateTaskRequest; |
@@ -314,48 +292,42 @@ public Mono<Void> delete(DeleteApplicationRequest request) { |
314 | 292 |
|
315 | 293 | @Override |
316 | 294 | 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(); |
336 | 311 | } |
337 | 312 |
|
338 | 313 | @Override |
339 | 314 | 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(); |
359 | 331 | } |
360 | 332 |
|
361 | 333 | @Override |
@@ -412,22 +384,17 @@ public Mono<ApplicationManifest> getApplicationManifest(GetApplicationManifestRe |
412 | 384 | } |
413 | 385 |
|
414 | 386 | @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(); |
431 | 398 | } |
432 | 399 |
|
433 | 400 | @Override |
@@ -902,17 +869,21 @@ public Mono<Void> setHealthCheck(SetApplicationHealthCheckRequest request) { |
902 | 869 |
|
903 | 870 | @Override |
904 | 871 | 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); |
916 | 887 | } |
917 | 888 |
|
918 | 889 | @Override |
@@ -2086,14 +2057,11 @@ private static Mono<Void> removeServiceBindings( |
2086 | 2057 | .then(); |
2087 | 2058 | } |
2088 | 2059 |
|
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()); |
2097 | 2065 | } |
2098 | 2066 |
|
2099 | 2067 | private static Mono<ApplicationInstancesResponse> requestApplicationInstances( |
@@ -2656,10 +2624,16 @@ private static Mono<AbstractApplicationResource> requestUpdateApplicationHealthC |
2656 | 2624 | builder -> builder.healthCheckType(type.getValue())); |
2657 | 2625 | } |
2658 | 2626 |
|
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); |
2663 | 2637 | } |
2664 | 2638 |
|
2665 | 2639 | private static Mono<AbstractApplicationResource> requestUpdateApplicationScale( |
@@ -2773,16 +2747,7 @@ private static boolean shouldStartApplication(PushApplicationManifestRequest req |
2773 | 2747 | return !Optional.ofNullable(request.getNoStart()).orElse(false); |
2774 | 2748 | } |
2775 | 2749 |
|
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) { |
2786 | 2751 | return requestUpdateApplicationState(cloudFoundryClient, applicationId, STARTED_STATE) |
2787 | 2752 | .flatMap( |
2788 | 2753 | response -> |
@@ -2852,14 +2817,13 @@ private static ApplicationDetail toApplicationDetail( |
2852 | 2817 | .build(); |
2853 | 2818 | } |
2854 | 2819 |
|
2855 | | - private static ApplicationEnvironments toApplicationEnvironments( |
2856 | | - ApplicationEnvironmentResponse response) { |
| 2820 | + private static ApplicationEnvironments toApplicationEnvironments(GetApplicationEnvironmentResponse response) { |
2857 | 2821 | 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(); |
2863 | 2827 | } |
2864 | 2828 |
|
2865 | 2829 | private static Mono<ApplicationManifest> toApplicationManifest( |
|
0 commit comments