-
Notifications
You must be signed in to change notification settings - Fork 41
Bg stop reorder #1761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Bg stop reorder #1761
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...org/cloudfoundry/multiapps/controller/process/steps/PrepareToStopDependentModuleStep.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package org.cloudfoundry.multiapps.controller.process.steps; | ||
|
|
||
| import java.text.MessageFormat; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import jakarta.inject.Inject; | ||
| import jakarta.inject.Named; | ||
| import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudRoute; | ||
| 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.v2.ApplicationCloudModelBuilder; | ||
| import org.cloudfoundry.multiapps.controller.core.helpers.ModuleToDeployHelper; | ||
| import org.cloudfoundry.multiapps.controller.process.Messages; | ||
| import org.cloudfoundry.multiapps.controller.process.util.ApplicationEnvironmentCalculator; | ||
| import org.cloudfoundry.multiapps.controller.process.variables.Variables; | ||
| import org.cloudfoundry.multiapps.mta.handlers.HandlerFactory; | ||
| import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; | ||
| import org.cloudfoundry.multiapps.mta.model.Module; | ||
| import org.springframework.beans.factory.config.BeanDefinition; | ||
| import org.springframework.context.annotation.Scope; | ||
|
|
||
| @Named("prepareToStopDependentModuleStep") | ||
| @Scope(BeanDefinition.SCOPE_PROTOTYPE) | ||
| public class PrepareToStopDependentModuleStep extends SyncFlowableStep { | ||
|
|
||
| private ModuleToDeployHelper moduleToDeployHelper; | ||
|
|
||
| private ApplicationEnvironmentCalculator applicationEnvironmentCalculator; | ||
|
|
||
| @Inject | ||
| public PrepareToStopDependentModuleStep(ModuleToDeployHelper moduleToDeployHelper, | ||
| ApplicationEnvironmentCalculator applicationEnvironmentCalculator) { | ||
| this.moduleToDeployHelper = moduleToDeployHelper; | ||
| this.applicationEnvironmentCalculator = applicationEnvironmentCalculator; | ||
| } | ||
|
|
||
| @Override | ||
| protected StepPhase executeStep(ProcessContext context) { | ||
| Module applicationModule = findModuleInDeploymentDescriptor(context, getCurrentModuleToStop(context).getName()); | ||
| context.setVariable(Variables.MODULE_TO_DEPLOY, applicationModule); | ||
| CloudApplicationExtended modifiedApp = getApplicationCloudModelBuilder(context).build(applicationModule, moduleToDeployHelper); | ||
| Map<String, String> calculatedAppEnv = applicationEnvironmentCalculator.calculateNewApplicationEnv(context, modifiedApp); | ||
| modifiedApp = getCloudApplicationExtended(context, modifiedApp, calculatedAppEnv); | ||
| context.setVariable(Variables.APP_TO_PROCESS, modifiedApp); | ||
| return StepPhase.DONE; | ||
| } | ||
|
|
||
| private CloudApplicationExtended getCloudApplicationExtended(ProcessContext context, CloudApplicationExtended modifiedApp, | ||
| Map<String, String> calculatedAppEnv) { | ||
| return ImmutableCloudApplicationExtended.builder() | ||
| .from(modifiedApp) | ||
| .staging(modifiedApp.getStaging()) | ||
| .routes(getApplicationRoutes(context, modifiedApp)) | ||
| .env(calculatedAppEnv) | ||
| .build(); | ||
| } | ||
|
|
||
| protected ApplicationCloudModelBuilder getApplicationCloudModelBuilder(ProcessContext context) { | ||
| return StepsUtil.getApplicationCloudModelBuilder(context); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getStepErrorMessage(ProcessContext context) { | ||
| return MessageFormat.format(Messages.ERROR_WHILE_STOPPING_DEPENDENT_MODULE, context.getVariable(Variables.APP_TO_PROCESS) | ||
| .getName()); | ||
| } | ||
|
|
||
| private Module getCurrentModuleToStop(ProcessContext context) { | ||
| List<Module> modules = context.getVariable(Variables.DEPENDENT_MODULES_TO_STOP); | ||
| int index = context.getVariable(Variables.APPS_TO_STOP_INDEX); | ||
| return modules.get(index); | ||
| } | ||
|
|
||
| private Module findModuleInDeploymentDescriptor(ProcessContext context, String module) { | ||
| HandlerFactory handlerFactory = StepsUtil.getHandlerFactory(context.getExecution()); | ||
| DeploymentDescriptor deploymentDescriptor = context.getVariable(Variables.COMPLETE_DEPLOYMENT_DESCRIPTOR); | ||
| return handlerFactory.getDescriptorHandler() | ||
| .findModule(deploymentDescriptor, module); | ||
| } | ||
|
|
||
| private Set<CloudRoute> getApplicationRoutes(ProcessContext context, CloudApplicationExtended modifiedApp) { | ||
| if (Boolean.TRUE.equals(context.getVariable(Variables.USE_IDLE_URIS))) { | ||
| return modifiedApp.getIdleRoutes(); | ||
| } | ||
| return modifiedApp.getRoutes(); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you creating here new APP_TO_PROCESS here and what is the difference from the old one?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APP_TO_PROCESS is set to the dependent app inside the subprocess. This is done due to the fact that ExecuteTaskStep relies on that variable to be set. Otherwise the logic would fail whenever a there's a need for hook executions.