diff --git a/multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/clients/CustomControllerClient.java b/multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/clients/CustomControllerClient.java index adb1602558..321bd0ffd4 100644 --- a/multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/clients/CustomControllerClient.java +++ b/multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/clients/CustomControllerClient.java @@ -22,6 +22,11 @@ public abstract class CustomControllerClient { private String correlationId = StringUtils.EMPTY; private final CloudControllerHeaderConfiguration headerConfiguration; + protected CustomControllerClient(WebClient webClient, String version) { + this.webClient = webClient; + headerConfiguration = new CloudControllerHeaderConfiguration(version); + } + protected CustomControllerClient(ApplicationConfiguration configuration, WebClientFactory webClientFactory, CloudCredentials credentials, String correlationID) { this.webClient = webClientFactory.getWebClient(credentials); diff --git a/multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/clients/CustomInstancesInfoClient.java b/multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/clients/CustomInstancesInfoClient.java new file mode 100644 index 0000000000..ffa1774cd2 --- /dev/null +++ b/multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/clients/CustomInstancesInfoClient.java @@ -0,0 +1,67 @@ +package org.cloudfoundry.multiapps.controller.core.cf.clients; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import com.sap.cloudfoundry.client.facade.CloudCredentials; +import com.sap.cloudfoundry.client.facade.domain.ImmutableInstanceInfo; +import com.sap.cloudfoundry.client.facade.domain.ImmutableInstancesInfo; +import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; +import com.sap.cloudfoundry.client.facade.domain.InstanceState; +import com.sap.cloudfoundry.client.facade.domain.InstancesInfo; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration; +import org.springframework.web.reactive.function.client.WebClient; + +public class CustomInstancesInfoClient extends CustomControllerClient { + + private static final String GET_APPLICATION_PROCESS_URL = "/v3/apps/%s/processes/web/stats"; + + public CustomInstancesInfoClient(WebClient webClient, String version) { + super(webClient, version); + } + + public CustomInstancesInfoClient(ApplicationConfiguration configuration, + WebClientFactory webClientFactory, CloudCredentials credentials, + String correlationID) { + super(configuration, webClientFactory, credentials, correlationID); + } + + public CustomInstancesInfoClient(ApplicationConfiguration configuration, + WebClientFactory webClientFactory, CloudCredentials credentials) { + super(configuration, webClientFactory, credentials); + } + + public InstancesInfo getInstancesInfo(String appGuid) { + return new CustomControllerClientErrorHandler().handleErrorsOrReturnResult(() -> doGetInstancesInfo(appGuid)); + } + + private InstancesInfo doGetInstancesInfo(String appGuid) { + String url = String.format(GET_APPLICATION_PROCESS_URL, appGuid); + var list = getListOfResources(new InstancesInfoResourceMapper(), url); + return ImmutableInstancesInfo.builder() + .instances(list) + .build(); + } + + protected static class InstancesInfoResourceMapper extends ResourcesResponseMapper { + + @Override + public List getMappedResources() { + return getQueriedResources().stream() + .map(this::buildInstancesInfo) + .collect(Collectors.toList()); + } + + private InstanceInfo buildInstancesInfo(Map resource) { + return ImmutableInstanceInfo.builder() + .index(Integer.parseInt(resource.get("index") + .toString())) + .state(InstanceState.valueOf(resource.get("state") + .toString() + .toUpperCase())) + .build(); + + } + } + +} diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/DetermineDesiredStateAchievingActionsStep.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/DetermineDesiredStateAchievingActionsStep.java index f8a99a3341..b9e732229c 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/DetermineDesiredStateAchievingActionsStep.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/DetermineDesiredStateAchievingActionsStep.java @@ -4,10 +4,13 @@ import java.util.ArrayList; import java.util.Map; import java.util.Set; - +import com.sap.cloudfoundry.client.facade.CloudControllerClient; +import com.sap.cloudfoundry.client.facade.CloudCredentials; +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; +import com.sap.cloudfoundry.client.facade.domain.CloudPackage; +import com.sap.cloudfoundry.client.facade.oauth2.OAuth2AccessTokenWithAdditionalInfo; import jakarta.inject.Inject; import jakarta.inject.Named; - import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; import org.cloudfoundry.multiapps.controller.client.lib.domain.RestartParameters; import org.cloudfoundry.multiapps.controller.core.cf.apps.ActionCalculator; @@ -16,22 +19,25 @@ import org.cloudfoundry.multiapps.controller.core.cf.apps.ApplicationStateAction; import org.cloudfoundry.multiapps.controller.core.cf.apps.ChangedApplicationActionCalculator; import org.cloudfoundry.multiapps.controller.core.cf.apps.UnchangedApplicationActionCalculator; +import org.cloudfoundry.multiapps.controller.core.cf.clients.CustomInstancesInfoClient; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.model.Phase; +import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; import org.cloudfoundry.multiapps.controller.process.Messages; import org.cloudfoundry.multiapps.controller.process.variables.Variables; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; -import com.sap.cloudfoundry.client.facade.CloudControllerClient; -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; -import com.sap.cloudfoundry.client.facade.domain.CloudPackage; - @Named("determineDesiredStateAchievingActionsStep") @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class DetermineDesiredStateAchievingActionsStep extends SyncFlowableStep { @Inject private ApplicationStartupStateCalculator startupStateCalculator; + @Inject + private TokenService tokenService; + @Inject + private WebClientFactory webClientFactory; @Override protected StepPhase executeStep(ProcessContext context) { @@ -39,7 +45,17 @@ protected StepPhase executeStep(ProcessContext context) { .getName(); CloudControllerClient client = context.getControllerClient(); CloudApplication app = client.getApplication(appName); - var appInstances = client.getApplicationInstances(app); + + OAuth2AccessTokenWithAdditionalInfo token = tokenService.getToken(context.getVariable(Variables.USER), + context.getVariable(Variables.USER_GUID)); + CloudCredentials credentials = new CloudCredentials(token); + CustomInstancesInfoClient customInstancesInfoClient = new CustomInstancesInfoClient(configuration, webClientFactory, + credentials, context.getVariable( + Variables.CORRELATION_ID)); + + var appInstances = customInstancesInfoClient.getInstancesInfo(app.getMetadata() + .getGuid() + .toString()); var appEnv = client.getApplicationEnvironment(app.getGuid()); ApplicationStartupState currentState = startupStateCalculator.computeCurrentState(app, appInstances, appEnv); diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstancesUpdateStep.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstancesUpdateStep.java index 194ace9711..4d4f1c7bf4 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstancesUpdateStep.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstancesUpdateStep.java @@ -1,16 +1,22 @@ package org.cloudfoundry.multiapps.controller.process.steps; -import static org.cloudfoundry.multiapps.controller.process.steps.StepsUtil.disableAutoscaling; -import static org.cloudfoundry.multiapps.controller.process.steps.StepsUtil.enableAutoscaling; - import java.text.MessageFormat; import java.time.Duration; import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; - +import com.sap.cloudfoundry.client.facade.CloudControllerClient; +import com.sap.cloudfoundry.client.facade.CloudCredentials; +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; +import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; +import com.sap.cloudfoundry.client.facade.domain.InstanceState; +import com.sap.cloudfoundry.client.facade.oauth2.OAuth2AccessTokenWithAdditionalInfo; +import jakarta.inject.Inject; +import jakarta.inject.Named; import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.CustomInstancesInfoClient; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.model.DeployedMta; import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; import org.cloudfoundry.multiapps.controller.core.model.ImmutableIncrementalAppInstanceUpdateConfiguration; @@ -22,14 +28,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; - -import com.sap.cloudfoundry.client.facade.CloudControllerClient; -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; -import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; -import com.sap.cloudfoundry.client.facade.domain.InstanceState; - -import jakarta.inject.Inject; -import jakarta.inject.Named; +import static org.cloudfoundry.multiapps.controller.process.steps.StepsUtil.disableAutoscaling; +import static org.cloudfoundry.multiapps.controller.process.steps.StepsUtil.enableAutoscaling; @Named("incrementalAppInstancesUpdateStep") @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -40,11 +40,14 @@ public class IncrementalAppInstancesUpdateStep extends TimeoutAsyncFlowableStep private final CloudControllerClientFactory clientFactory; private final TokenService tokenService; + private final WebClientFactory webClientFactory; @Inject - public IncrementalAppInstancesUpdateStep(CloudControllerClientFactory clientFactory, TokenService tokenService) { + public IncrementalAppInstancesUpdateStep(CloudControllerClientFactory clientFactory, TokenService tokenService, + WebClientFactory webClientFactory) { this.clientFactory = clientFactory; this.tokenService = tokenService; + this.webClientFactory = webClientFactory; } @Override @@ -60,18 +63,29 @@ protected StepPhase executeAsyncStep(ProcessContext context) throws Exception { disableAutoscaling(context, client, oldApplicationGuid); UUID applicationId = client.getApplicationGuid(application.getName()); - checkWhetherLiveAppNeedsPolling(context, client, oldApplication); + OAuth2AccessTokenWithAdditionalInfo token = tokenService.getToken(context.getVariable(Variables.USER), + context.getVariable(Variables.USER_GUID)); + CloudCredentials credentials = new CloudCredentials(token); + CustomInstancesInfoClient customInstancesInfoClient = new CustomInstancesInfoClient(configuration, webClientFactory, + credentials, context.getVariable( + Variables.CORRELATION_ID)); + + checkWhetherLiveAppNeedsPolling(context, customInstancesInfoClient, oldApplication); context.getStepLogger() .info(Messages.STARTING_INCREMENTAL_APPLICATION_INSTANCE_UPDATE_FOR_0, application.getName()); - List idleApplicationInstances = client.getApplicationInstances(applicationId) - .getInstances(); + List idleApplicationInstances = customInstancesInfoClient.getInstancesInfo(applicationId.toString()) + .getInstances(); var incrementalAppInstanceUpdateConfigurationBuilder = ImmutableIncrementalAppInstanceUpdateConfiguration.builder() - .newApplication(application) - .newApplicationInstanceCount(idleApplicationInstances.size()); - - int oldApplicationInstanceCount = client.getApplicationInstances(oldApplication) - .getInstances() - .size(); + .newApplication( + application) + .newApplicationInstanceCount( + idleApplicationInstances.size()); + + int oldApplicationInstanceCount = customInstancesInfoClient.getInstancesInfo(oldApplication.getMetadata() + .getGuid() + .toString()) + .getInstances() + .size(); incrementalAppInstanceUpdateConfigurationBuilder.oldApplication(oldApplication) .oldApplicationInitialInstanceCount(oldApplicationInstanceCount) .oldApplicationInstanceCount(oldApplicationInstanceCount); @@ -95,7 +109,8 @@ private StepPhase scaleUpNewAppToTheRequiredInstances(ProcessContext context, Cl client.updateApplicationInstances(application.getName(), application.getInstances()); incrementalAppInstanceUpdateConfigurationBuilder = ImmutableIncrementalAppInstanceUpdateConfiguration.builder() .newApplication(application) - .newApplicationInstanceCount(application.getInstances()); + .newApplicationInstanceCount( + application.getInstances()); context.setVariable(Variables.INCREMENTAL_APP_INSTANCE_UPDATE_CONFIGURATION, incrementalAppInstanceUpdateConfigurationBuilder.build()); setExecutionIndexForPollingNewAppInstances(context); @@ -115,7 +130,8 @@ private DeployedMtaApplication getOldApplication(ProcessContext context, CloudAp DeployedMtaApplication deployedMtaApplication = deployedMta.getApplications() .stream() .filter(deployedApplication -> deployedApplication.getModuleName() - .equals(currentApplication.getModuleName())) + .equals( + currentApplication.getModuleName())) .findFirst() .orElse(null); if (deployedMtaApplication == null) { @@ -131,9 +147,12 @@ private DeployedMtaApplication getOldApplication(ProcessContext context, CloudAp return deployedMtaApplication; } - private void checkWhetherLiveAppNeedsPolling(ProcessContext context, CloudControllerClient client, CloudApplication cloudApplication) { + private void checkWhetherLiveAppNeedsPolling(ProcessContext context, CustomInstancesInfoClient client, + CloudApplication cloudApplication) { setExecutionIndexToTriggerNewApplicationRollingUpdate(context); - List appInstances = client.getApplicationInstances(cloudApplication) + List appInstances = client.getInstancesInfo(cloudApplication.getMetadata() + .getGuid() + .toString()) .getInstances(); if (!appInstances.stream() .allMatch(instanceInfo -> instanceInfo.getState() == InstanceState.RUNNING)) { @@ -172,8 +191,8 @@ private void setExecutionIndexToTriggerNewApplicationRollingUpdate(ProcessContex protected List getAsyncStepExecutions(ProcessContext context) { // The sequence of executions is crucial, as the incremental blue-green deployment alternates between them during the polling // process - return List.of(new PollStartLiveAppExecution(clientFactory, tokenService), - new PollStartAppExecutionWithRollbackExecution(clientFactory, tokenService), + return List.of(new PollStartLiveAppExecution(clientFactory, tokenService, configuration, webClientFactory), + new PollStartAppExecutionWithRollbackExecution(clientFactory, tokenService, configuration, webClientFactory), new PollIncrementalAppInstanceUpdateExecution()); } diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecution.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecution.java index 6dc6879582..d9ea865612 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecution.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecution.java @@ -1,21 +1,23 @@ package org.cloudfoundry.multiapps.controller.process.steps; +import com.sap.cloudfoundry.client.facade.CloudControllerClient; +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.model.IncrementalAppInstanceUpdateConfiguration; import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration; import org.cloudfoundry.multiapps.controller.process.Messages; import org.cloudfoundry.multiapps.controller.process.variables.Variables; - -import com.sap.cloudfoundry.client.facade.CloudControllerClient; -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; - import static org.cloudfoundry.multiapps.controller.process.steps.StepsUtil.enableAutoscaling; public class PollStartAppExecutionWithRollbackExecution extends PollStartAppStatusExecution { - public PollStartAppExecutionWithRollbackExecution(CloudControllerClientFactory clientFactory, TokenService tokenService) { - super(clientFactory, tokenService); + public PollStartAppExecutionWithRollbackExecution(CloudControllerClientFactory clientFactory, TokenService tokenService, + ApplicationConfiguration applicationConfiguration, + WebClientFactory webClientFactory) { + super(clientFactory, tokenService, applicationConfiguration, webClientFactory); } @Override @@ -28,7 +30,8 @@ public AsyncExecutionState execute(ProcessContext context) { } private void rollbackOldAppInstances(ProcessContext context) { - IncrementalAppInstanceUpdateConfiguration incrementalAppInstanceUpdateConfiguration = context.getVariable(Variables.INCREMENTAL_APP_INSTANCE_UPDATE_CONFIGURATION); + IncrementalAppInstanceUpdateConfiguration incrementalAppInstanceUpdateConfiguration = context.getVariable( + Variables.INCREMENTAL_APP_INSTANCE_UPDATE_CONFIGURATION); CloudApplication oldApplication = incrementalAppInstanceUpdateConfiguration.getOldApplication(); CloudControllerClient client = context.getControllerClient(); context.getStepLogger() @@ -50,7 +53,8 @@ private void rollbackOldAppInstances(ProcessContext context) { @Override protected void onSuccess(ProcessContext context, String message, Object... arguments) { - IncrementalAppInstanceUpdateConfiguration incrementalAppInstanceUpdateConfiguration = context.getVariable(Variables.INCREMENTAL_APP_INSTANCE_UPDATE_CONFIGURATION); + IncrementalAppInstanceUpdateConfiguration incrementalAppInstanceUpdateConfiguration = context.getVariable( + Variables.INCREMENTAL_APP_INSTANCE_UPDATE_CONFIGURATION); CloudApplicationExtended appToProcess = context.getVariable(Variables.APP_TO_PROCESS); if (incrementalAppInstanceUpdateConfiguration.getNewApplicationInstanceCount() == appToProcess.getInstances()) { super.onSuccess(context, message, arguments); diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecution.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecution.java index 893f0cdcf6..87912a469c 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecution.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecution.java @@ -3,21 +3,24 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import com.sap.cloudfoundry.client.facade.CloudControllerClient; +import com.sap.cloudfoundry.client.facade.CloudCredentials; import com.sap.cloudfoundry.client.facade.domain.CloudApplication; import com.sap.cloudfoundry.client.facade.domain.CloudRoute; import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; import com.sap.cloudfoundry.client.facade.domain.InstanceState; +import com.sap.cloudfoundry.client.facade.oauth2.OAuth2AccessTokenWithAdditionalInfo; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.CustomInstancesInfoClient; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration; import org.cloudfoundry.multiapps.controller.core.util.UriUtil; import org.cloudfoundry.multiapps.controller.persistence.services.ProcessLoggerProvider; import org.cloudfoundry.multiapps.controller.process.Messages; import org.cloudfoundry.multiapps.controller.process.variables.Variables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import static java.text.MessageFormat.format; public class PollStartAppStatusExecution implements AsyncExecution { @@ -25,10 +28,15 @@ public class PollStartAppStatusExecution implements AsyncExecution { private static final Logger LOGGER = LoggerFactory.getLogger(PollStartAppStatusExecution.class); private final CloudControllerClientFactory clientFactory; private final TokenService tokenService; + private final ApplicationConfiguration applicationConfiguration; + private final WebClientFactory webClientFactory; - public PollStartAppStatusExecution(CloudControllerClientFactory clientFactory, TokenService tokenService) { + public PollStartAppStatusExecution(CloudControllerClientFactory clientFactory, TokenService tokenService, + ApplicationConfiguration applicationConfiguration, WebClientFactory webClientFactory) { this.clientFactory = clientFactory; this.tokenService = tokenService; + this.applicationConfiguration = applicationConfiguration; + this.webClientFactory = webClientFactory; } @Override @@ -40,8 +48,18 @@ public AsyncExecutionState execute(ProcessContext context) { .debug(Messages.CHECKING_APP_STATUS, appToPoll); CloudApplication app = getApplication(context, appToPoll, client); - List appInstances = client.getApplicationInstances(app) - .getInstances(); + + OAuth2AccessTokenWithAdditionalInfo token = tokenService.getToken(context.getVariable(Variables.USER), + context.getVariable(Variables.USER_GUID)); + CloudCredentials credentials = new CloudCredentials(token); + CustomInstancesInfoClient customInstancesInfoClient = new CustomInstancesInfoClient(applicationConfiguration, webClientFactory, + credentials, context.getVariable( + Variables.CORRELATION_ID)); + + List appInstances = customInstancesInfoClient.getInstancesInfo(app.getMetadata() + .getGuid() + .toString()) + .getInstances(); StartupStatus status = getStartupStatus(context, app.getName(), appInstances); ProcessLoggerProvider processLoggerProvider = context.getStepLogger() .getProcessLoggerProvider(); diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecution.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecution.java index 03497d8cbe..7b4384c139 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecution.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecution.java @@ -1,20 +1,22 @@ package org.cloudfoundry.multiapps.controller.process.steps; +import com.sap.cloudfoundry.client.facade.CloudControllerClient; +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; import org.cloudfoundry.multiapps.common.SLException; import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration; import org.cloudfoundry.multiapps.controller.process.Messages; import org.cloudfoundry.multiapps.controller.process.variables.Variables; -import com.sap.cloudfoundry.client.facade.CloudControllerClient; -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; - public class PollStartLiveAppExecution extends PollStartAppStatusExecution { - public PollStartLiveAppExecution(CloudControllerClientFactory clientFactory, TokenService tokenService) { - super(clientFactory, tokenService); + public PollStartLiveAppExecution(CloudControllerClientFactory clientFactory, TokenService tokenService, + ApplicationConfiguration configuration, WebClientFactory webClientFactory) { + super(clientFactory, tokenService, configuration, webClientFactory); } @Override diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartServiceBrokerSubscriberStatusExecution.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartServiceBrokerSubscriberStatusExecution.java index 0d67c0e7cc..7b22e54eb2 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartServiceBrokerSubscriberStatusExecution.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartServiceBrokerSubscriberStatusExecution.java @@ -1,15 +1,17 @@ package org.cloudfoundry.multiapps.controller.process.steps; +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; - -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration; public class PollStartServiceBrokerSubscriberStatusExecution extends PollStartAppStatusExecution { public PollStartServiceBrokerSubscriberStatusExecution(CloudControllerClientFactory clientFactory, - TokenService tokenService) { - super(clientFactory, tokenService); + TokenService tokenService, ApplicationConfiguration configuration, + WebClientFactory webClientFactory) { + super(clientFactory, tokenService, configuration, webClientFactory); } @Override diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartAppStep.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartAppStep.java index 30ed0eba7f..89f7c7282f 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartAppStep.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartAppStep.java @@ -3,8 +3,14 @@ import java.text.MessageFormat; import java.time.Duration; import java.util.List; - +import com.sap.cloudfoundry.client.facade.CloudControllerClient; +import com.sap.cloudfoundry.client.facade.CloudOperationException; +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; +import com.sap.cloudfoundry.client.facade.domain.CloudApplication.State; +import jakarta.inject.Inject; +import jakarta.inject.Named; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.model.HookPhase; import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; import org.cloudfoundry.multiapps.controller.process.Messages; @@ -14,14 +20,6 @@ import org.springframework.context.annotation.Scope; import org.springframework.http.HttpStatus; -import com.sap.cloudfoundry.client.facade.CloudControllerClient; -import com.sap.cloudfoundry.client.facade.CloudOperationException; -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; -import com.sap.cloudfoundry.client.facade.domain.CloudApplication.State; - -import jakarta.inject.Inject; -import jakarta.inject.Named; - @Named("restartAppStep") @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class RestartAppStep extends TimeoutAsyncFlowableStepWithHooks implements BeforeStepHookPhaseProvider { @@ -30,6 +28,8 @@ public class RestartAppStep extends TimeoutAsyncFlowableStepWithHooks implements protected CloudControllerClientFactory clientFactory; @Inject protected TokenService tokenService; + @Inject + private WebClientFactory webClientFactory; @Override public StepPhase executePollingStep(ProcessContext context) { @@ -90,7 +90,7 @@ public List getHookPhasesBeforeStep(ProcessContext context) { @Override protected List getAsyncStepExecutions(ProcessContext context) { - return List.of(new PollStartAppStatusExecution(clientFactory, tokenService), + return List.of(new PollStartAppStatusExecution(clientFactory, tokenService, configuration, webClientFactory), new PollExecuteAppStatusExecution(clientFactory, tokenService)); } diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartServiceBrokerSubscriberStep.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartServiceBrokerSubscriberStep.java index d4b76dc88c..53d73f1675 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartServiceBrokerSubscriberStep.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RestartServiceBrokerSubscriberStep.java @@ -2,19 +2,21 @@ import java.text.MessageFormat; import java.util.List; - +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; +import jakarta.inject.Inject; import jakarta.inject.Named; - +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.process.Messages; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; - @Named("restartServiceBrokerSubscriberStep") @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class RestartServiceBrokerSubscriberStep extends RestartAppStep { + @Inject + private WebClientFactory webClientFactory; + @Override protected String getStepErrorMessage(ProcessContext context) { return MessageFormat.format(Messages.ERROR_STARTING_APP_0, getAppToRestart(context).getName()); @@ -27,7 +29,7 @@ protected CloudApplication getAppToRestart(ProcessContext context) { @Override protected List getAsyncStepExecutions(ProcessContext context) { - return List.of(new PollStartServiceBrokerSubscriberStatusExecution(clientFactory, tokenService)); + return List.of(new PollStartServiceBrokerSubscriberStatusExecution(clientFactory, tokenService, configuration, webClientFactory)); } } diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstanceUpdateStepTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstanceUpdateStepTest.java index 4df0cca8c7..f700b9a0e1 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstanceUpdateStepTest.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/IncrementalAppInstanceUpdateStepTest.java @@ -1,20 +1,19 @@ package org.cloudfoundry.multiapps.controller.process.steps; -import static org.cloudfoundry.multiapps.controller.process.steps.StepsTestUtil.prepareDisablingAutoscaler; -import static org.cloudfoundry.multiapps.controller.process.steps.StepsTestUtil.testIfEnabledOrDisabledAutoscaler; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.text.MessageFormat; import java.time.Duration; import java.util.List; import java.util.UUID; - +import com.sap.cloudfoundry.client.facade.domain.ImmutableCloudMetadata; +import com.sap.cloudfoundry.client.facade.domain.ImmutableInstanceInfo; +import com.sap.cloudfoundry.client.facade.domain.ImmutableInstancesInfo; +import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; +import com.sap.cloudfoundry.client.facade.domain.InstanceState; +import com.sap.cloudfoundry.client.facade.domain.InstancesInfo; import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; import org.cloudfoundry.multiapps.controller.client.lib.domain.ImmutableCloudApplicationExtended; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.cf.metadata.ImmutableMtaMetadata; import org.cloudfoundry.multiapps.controller.core.model.DeployedMta; import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; @@ -29,14 +28,17 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; - -import com.sap.cloudfoundry.client.facade.domain.ImmutableCloudMetadata; -import com.sap.cloudfoundry.client.facade.domain.ImmutableInstanceInfo; -import com.sap.cloudfoundry.client.facade.domain.ImmutableInstancesInfo; -import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; -import com.sap.cloudfoundry.client.facade.domain.InstanceState; -import com.sap.cloudfoundry.client.facade.domain.InstancesInfo; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; +import static org.cloudfoundry.multiapps.controller.process.steps.StepsTestUtil.prepareDisablingAutoscaler; +import static org.cloudfoundry.multiapps.controller.process.steps.StepsTestUtil.testIfEnabledOrDisabledAutoscaler; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class IncrementalAppInstanceUpdateStepTest extends SyncFlowableStepTest { @@ -49,6 +51,8 @@ class IncrementalAppInstanceUpdateStepTest extends SyncFlowableStepTest { @@ -32,6 +30,7 @@ class PollIncrementalAppInstanceUpdateExecutionTest extends AsyncStepOperationTe private CloudControllerClientFactory clientFactory; private TokenService tokenService; + private WebClientFactory webClientFactory; private AsyncExecutionState expectedAsyncExecutionState; @@ -129,6 +128,7 @@ protected void validateOperationExecutionResult(AsyncExecutionState result) { protected IncrementalAppInstancesUpdateStep createStep() { clientFactory = Mockito.mock(CloudControllerClientFactory.class); tokenService = Mockito.mock(TokenService.class); - return new IncrementalAppInstancesUpdateStep(clientFactory, tokenService); + webClientFactory = Mockito.mock(WebClientFactory.class); + return new IncrementalAppInstancesUpdateStep(clientFactory, tokenService, webClientFactory); } } diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecutionTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecutionTest.java index a3bff40c6e..8bddba7844 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecutionTest.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppExecutionWithRollbackExecutionTest.java @@ -1,18 +1,18 @@ package org.cloudfoundry.multiapps.controller.process.steps; -import static org.cloudfoundry.multiapps.controller.process.steps.StepsTestUtil.testIfEnabledOrDisabledAutoscaler; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.util.List; import java.util.UUID; - +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; +import com.sap.cloudfoundry.client.facade.domain.ImmutableCloudMetadata; +import com.sap.cloudfoundry.client.facade.domain.ImmutableInstanceInfo; +import com.sap.cloudfoundry.client.facade.domain.ImmutableInstancesInfo; +import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; +import com.sap.cloudfoundry.client.facade.domain.InstanceState; +import com.sap.cloudfoundry.client.facade.domain.InstancesInfo; import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; import org.cloudfoundry.multiapps.controller.client.lib.domain.ImmutableCloudApplicationExtended; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaApplication; import org.cloudfoundry.multiapps.controller.core.model.ImmutableIncrementalAppInstanceUpdateConfiguration; @@ -21,14 +21,12 @@ import org.cloudfoundry.multiapps.controller.process.variables.Variables; import org.junit.jupiter.api.Test; import org.mockito.Mockito; - -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; -import com.sap.cloudfoundry.client.facade.domain.ImmutableCloudMetadata; -import com.sap.cloudfoundry.client.facade.domain.ImmutableInstanceInfo; -import com.sap.cloudfoundry.client.facade.domain.ImmutableInstancesInfo; -import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; -import com.sap.cloudfoundry.client.facade.domain.InstanceState; -import com.sap.cloudfoundry.client.facade.domain.InstancesInfo; +import static org.cloudfoundry.multiapps.controller.process.steps.StepsTestUtil.testIfEnabledOrDisabledAutoscaler; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class PollStartAppExecutionWithRollbackExecutionTest extends AsyncStepOperationTest { @@ -41,6 +39,8 @@ class PollStartAppExecutionWithRollbackExecutionTest extends AsyncStepOperationT private CloudControllerClientFactory clientFactory; private TokenService tokenService; + private WebClientFactory webClientFactory; + private AsyncExecutionState expectedAsyncExecutionState; @Test @@ -136,7 +136,8 @@ private void executeOnSuccess(CloudApplicationExtended cloudApplicationExtended) context.setVariable(Variables.INCREMENTAL_APP_INSTANCE_UPDATE_CONFIGURATION, updateConfig); step.initializeStepLogger(execution); ProcessContext wrapper = step.createProcessContext(execution); - PollStartAppExecutionWithRollbackExecution asyncExecution = (PollStartAppExecutionWithRollbackExecution) getAsyncOperations(wrapper).get(0); + PollStartAppExecutionWithRollbackExecution asyncExecution = (PollStartAppExecutionWithRollbackExecution) getAsyncOperations( + wrapper).get(0); asyncExecution.onSuccess(wrapper, "App started"); } @@ -150,7 +151,8 @@ void testOnSuccessWhenNewAppStillIsStarted() { @Override protected List getAsyncOperations(ProcessContext wrapper) { - return List.of(new PollStartAppExecutionWithRollbackExecution(clientFactory, tokenService)); + webClientFactory = Mockito.mock(WebClientFactory.class); + return List.of(new PollStartAppExecutionWithRollbackExecution(clientFactory, tokenService, configuration, webClientFactory)); } @Override @@ -162,7 +164,8 @@ protected void validateOperationExecutionResult(AsyncExecutionState result) { protected IncrementalAppInstancesUpdateStep createStep() { clientFactory = Mockito.mock(CloudControllerClientFactory.class); tokenService = Mockito.mock(TokenService.class); - return new IncrementalAppInstancesUpdateStep(clientFactory, tokenService); + webClientFactory = Mockito.mock(WebClientFactory.class); + return new IncrementalAppInstancesUpdateStep(clientFactory, tokenService, webClientFactory); } } diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecutionTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecutionTest.java index 457048ee5c..c2e723b1e3 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecutionTest.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartAppStatusExecutionTest.java @@ -7,7 +7,6 @@ import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; - import com.sap.cloudfoundry.client.facade.CloudControllerClient; import com.sap.cloudfoundry.client.facade.domain.ImmutableCloudMetadata; import com.sap.cloudfoundry.client.facade.domain.ImmutableInstanceInfo; @@ -19,7 +18,9 @@ import org.cloudfoundry.multiapps.controller.client.lib.domain.ImmutableCloudApplicationExtended; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientProvider; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration; import org.cloudfoundry.multiapps.controller.process.util.MockDelegateExecution; import org.cloudfoundry.multiapps.controller.process.util.StepLogger; import org.cloudfoundry.multiapps.controller.process.variables.Variables; @@ -30,7 +31,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -55,6 +55,10 @@ class PollStartAppStatusExecutionTest { private CloudControllerClientFactory clientFactory; @Mock private TokenService tokenService; + @Mock + private ApplicationConfiguration configuration; + @Mock + private WebClientFactory webClientFactory; private ProcessContext context; private PollStartAppStatusExecution step; @@ -65,7 +69,7 @@ void setUp() throws Exception { .close(); DelegateExecution execution = MockDelegateExecution.createSpyInstance(); context = new ProcessContext(execution, stepLogger, clientProvider); - step = new PollStartAppStatusExecution(clientFactory, tokenService); + step = new PollStartAppStatusExecution(clientFactory, tokenService, configuration, webClientFactory); } static Stream testStep() { diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecutionTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecutionTest.java index 91d641de23..3483506c13 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecutionTest.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/PollStartLiveAppExecutionTest.java @@ -1,29 +1,28 @@ package org.cloudfoundry.multiapps.controller.process.steps; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.when; - import java.util.List; import java.util.UUID; - +import com.sap.cloudfoundry.client.facade.domain.CloudApplication; import org.cloudfoundry.multiapps.common.SLException; import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; import org.cloudfoundry.multiapps.controller.client.lib.domain.ImmutableCloudApplicationExtended; import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; +import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory; import org.cloudfoundry.multiapps.controller.core.cf.metadata.ImmutableMtaMetadata; import org.cloudfoundry.multiapps.controller.core.model.DeployedMta; import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMta; import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaApplication; import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration; import org.cloudfoundry.multiapps.controller.process.variables.Variables; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - -import com.sap.cloudfoundry.client.facade.domain.CloudApplication; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.when; class PollStartLiveAppExecutionTest { @@ -36,6 +35,10 @@ class PollStartLiveAppExecutionTest { private TokenService tokenService; @Mock private ProcessContext context; + @Mock + private ApplicationConfiguration configuration; + @Mock + private WebClientFactory webClientFactory; private PollStartLiveAppExecution pollStartLiveAppExecution; @@ -43,7 +46,7 @@ class PollStartLiveAppExecutionTest { void setUp() throws Exception { MockitoAnnotations.openMocks(this) .close(); - pollStartLiveAppExecution = new PollStartLiveAppExecution(clientFactory, tokenService); + pollStartLiveAppExecution = new PollStartLiveAppExecution(clientFactory, tokenService, configuration, webClientFactory); } @Test diff --git a/multiapps-controller-shutdown-client/src/main/java/org/cloudfoundry/multiapps/controller/shutdown/client/ApplicationShutdownExecutor.java b/multiapps-controller-shutdown-client/src/main/java/org/cloudfoundry/multiapps/controller/shutdown/client/ApplicationShutdownExecutor.java index 2a69ed818a..96d3b22f88 100644 --- a/multiapps-controller-shutdown-client/src/main/java/org/cloudfoundry/multiapps/controller/shutdown/client/ApplicationShutdownExecutor.java +++ b/multiapps-controller-shutdown-client/src/main/java/org/cloudfoundry/multiapps/controller/shutdown/client/ApplicationShutdownExecutor.java @@ -3,15 +3,15 @@ import java.net.MalformedURLException; import java.net.URL; import java.text.MessageFormat; +import java.util.List; import java.util.UUID; - +import com.sap.cloudfoundry.client.facade.CloudCredentials; +import com.sap.cloudfoundry.client.facade.domain.InstanceInfo; +import com.sap.cloudfoundry.client.facade.util.RestUtil; +import org.cloudfoundry.multiapps.controller.core.cf.clients.CustomInstancesInfoClient; import org.cloudfoundry.multiapps.controller.shutdown.client.configuration.EnvironmentBasedShutdownConfiguration; import org.cloudfoundry.multiapps.controller.shutdown.client.configuration.ShutdownConfiguration; - -import com.sap.cloudfoundry.client.facade.CloudControllerClient; -import com.sap.cloudfoundry.client.facade.CloudControllerClientImpl; -import com.sap.cloudfoundry.client.facade.CloudCredentials; -import com.sap.cloudfoundry.client.facade.domain.InstancesInfo; +import org.springframework.web.reactive.function.client.WebClient; public class ApplicationShutdownExecutor { @@ -21,8 +21,9 @@ public static void main(String[] args) { private final ShutdownConfiguration shutdownConfiguration = new EnvironmentBasedShutdownConfiguration(); private final ShutdownClientFactory shutdownClientFactory = new ShutdownClientFactory(); - private final ApplicationInstanceShutdownExecutor instanceShutdownExecutor = new ApplicationInstanceShutdownExecutor(shutdownConfiguration, - shutdownClientFactory); + private final ApplicationInstanceShutdownExecutor instanceShutdownExecutor = new ApplicationInstanceShutdownExecutor( + shutdownConfiguration, + shutdownClientFactory); public void execute() { int applicationInstancesCount = getApplicationInstancesCount(shutdownConfiguration); @@ -37,15 +38,19 @@ private void shutdownInstances(int applicationInstancesCount) { } private static int getApplicationInstancesCount(ShutdownConfiguration shutdownConfiguration) { - CloudControllerClient client = createCloudControllerClient(shutdownConfiguration); - InstancesInfo instances = client.getApplicationInstances(shutdownConfiguration.getApplicationGuid()); - return instances.getInstances() - .size(); - } - - private static CloudControllerClient createCloudControllerClient(ShutdownConfiguration shutdownConfiguration) { URL cloudControllerUrl = toURL(shutdownConfiguration.getCloudControllerUrl()); - return new CloudControllerClientImpl(cloudControllerUrl, createCloudCredentials(shutdownConfiguration)); + WebClient.Builder webClientBuilder = new RestUtil().createWebClient(false) + .mutate() + .baseUrl(cloudControllerUrl.toString()); + webClientBuilder.defaultHeaders(httpHeaders -> httpHeaders.setBasicAuth(shutdownConfiguration.getUsername(), + shutdownConfiguration.getPassword())); + WebClient webClient = webClientBuilder.build(); + CustomInstancesInfoClient customInstancesInfoClient = new CustomInstancesInfoClient(webClient, ""); + List instanceInfoList = customInstancesInfoClient.getInstancesInfo(shutdownConfiguration.getApplicationGuid() + .toString()) + .getInstances(); + return instanceInfoList + .size(); } private static URL toURL(String string) {