diff --git a/app/scripts/modules/core/src/deploymentStrategy/deploymentStrategy.module.ts b/app/scripts/modules/core/src/deploymentStrategy/deploymentStrategy.module.ts index 8a126d0a531..9add7c8ef0d 100644 --- a/app/scripts/modules/core/src/deploymentStrategy/deploymentStrategy.module.ts +++ b/app/scripts/modules/core/src/deploymentStrategy/deploymentStrategy.module.ts @@ -7,10 +7,12 @@ import './strategies/redblack/redblack.strategy'; import './strategies/rollingredblack/rollingredblack.strategy'; import { CUSTOM_STRATEGY_SELECTOR_COMPONENT } from './strategies/custom/customStrategySelector.component'; +import { PIPELINE_SELECTOR_COMPONENT } from './strategies/rollingredblack/pipelineSelector.component'; import { DEPLOYMENT_STRATEGY_SELECTOR_COMPONENT } from './deploymentStrategySelector.component'; export const DEPLOYMENT_STRATEGY_MODULE = 'spinnaker.core.deploymentStrategy'; module(DEPLOYMENT_STRATEGY_MODULE, [ CUSTOM_STRATEGY_SELECTOR_COMPONENT, + PIPELINE_SELECTOR_COMPONENT, DEPLOYMENT_STRATEGY_SELECTOR_COMPONENT, ]); diff --git a/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/additionalFields.html b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/additionalFields.html index a19dcb29ac9..dcb04c126e2 100644 --- a/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/additionalFields.html +++ b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/additionalFields.html @@ -1,13 +1,18 @@
-
-
diff --git a/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/pipelineSelector.component.html b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/pipelineSelector.component.html new file mode 100644 index 00000000000..a0c063abbe4 --- /dev/null +++ b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/pipelineSelector.component.html @@ -0,0 +1,70 @@ +
+
+
+ +
+ + {{$select.selected}} + +
+
+
+
+
+ +
+ +
+
+ + {{$select.selected.name}} + + +
+
+
+ +
+ Parameters +
+
+ {{parameter.name}} + +
+
+ + + + + {{$select.selected.value}} + + +
{{option.value}}
+
+
+
+
+ +
+
+ +
+
+
diff --git a/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/pipelineSelector.component.ts b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/pipelineSelector.component.ts new file mode 100644 index 00000000000..2159ed86449 --- /dev/null +++ b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/pipelineSelector.component.ts @@ -0,0 +1,125 @@ +import { IController, IComponentOptions, module } from 'angular'; + +import { APPLICATION_READ_SERVICE, ApplicationReader } from 'core/application/service/application.read.service'; +import { PIPELINE_CONFIG_SERVICE, PipelineConfigService } from 'core/pipeline/config/services/pipelineConfig.service'; +import { IParameter, IPipeline } from 'core/domain'; + +interface IPipelineSelectorState { + pipelinesLoaded: boolean; + applications: string[]; + pipelines: IPipeline[]; + pipelineParameters?: IParameter[]; + useDefaultParameters: { [key: string]: boolean }; + userSuppliedParameters: { [key: string]: any }; + currentApplicationCount: number; +} + +interface IPipelineSelectorCommand { + application?: string; + pipelineId?: string; + pipelineParameters?: { [key: string]: any }; +} + +class PipelineSelectorController implements IController { + + public command: IPipelineSelectorCommand; + public state: IPipelineSelectorState = { + pipelinesLoaded: false, + applications: [], + pipelines: [], + pipelineParameters: [], + useDefaultParameters: {}, + userSuppliedParameters: {}, + currentApplicationCount: 20, + }; + + constructor(private applicationReader: ApplicationReader, private pipelineConfigService: PipelineConfigService) { + 'ngInject'; + } + + public $onInit() { + this.applicationReader.listApplications().then((applications) => { + this.state.applications = applications.map(a => a.name).sort(); + this.initializePipelines(); + }); + } + + public addMoreApplications(): void { + this.state.currentApplicationCount += 20; + } + + public initializePipelines(): void { + if (this.command.application) { + this.pipelineConfigService.getPipelinesForApplication(this.command.application).then((pipelines) => { + this.state.pipelines = pipelines; + console.log(pipelines); + if (pipelines.every(p => p.id !== this.command.pipelineId)) { + this.command.pipelineId = null; + } + this.state.pipelinesLoaded = true; + this.updatePipelineConfig(); + }); + } + } + + public updatePipelineConfig(): void { + if (this.command && this.command.application && this.command.pipelineId) { + const config = this.state.pipelines.find(p => p.id === this.command.pipelineId); + if (config && config.parameterConfig) { + if (!this.command.pipelineParameters) { + this.command.pipelineParameters = {}; + } + this.state.pipelineParameters = config.parameterConfig; + this.state.userSuppliedParameters = this.command.pipelineParameters; + this.state.useDefaultParameters = {}; + this.configureParamDefaults(); + } else { + this.clearParams(); + } + } else { + this.clearParams(); + } + } + + public updateParam(parameter: string): void { + if (this.state.useDefaultParameters[parameter] === true) { + delete this.state.userSuppliedParameters[parameter]; + delete this.command.pipelineParameters[parameter]; + } else if (this.state.userSuppliedParameters[parameter]) { + this.command.pipelineParameters[parameter] = this.state.userSuppliedParameters[parameter]; + } + } + + private configureParamDefaults(): void { + this.state.pipelineParameters.forEach((param: any) => { + const defaultValue = param.default; + if (defaultValue !== null && defaultValue !== undefined) { + const configuredParamValue = this.command.pipelineParameters[param.name]; + if (configuredParamValue === undefined || configuredParamValue === defaultValue) { + this.state.useDefaultParameters[param.name] = true; + this.command.pipelineParameters[param.name] = defaultValue; + } + } + }); + } + + private clearParams(): void { + this.state.pipelineParameters = []; + this.state.useDefaultParameters = {}; + this.state.userSuppliedParameters = {}; + } +} + +const pipelineSelectorComponent: IComponentOptions = { + bindings: { + command: '=', + }, + templateUrl: require('./pipelineSelector.component.html'), + controller: PipelineSelectorController, +}; + +export const PIPELINE_SELECTOR_COMPONENT = 'spinnaker.core.deploymentStrategy.rollingredblack.pipelineSelector'; +module(PIPELINE_SELECTOR_COMPONENT, [ + APPLICATION_READ_SERVICE, + PIPELINE_CONFIG_SERVICE, +]).component('pipelineSelector', pipelineSelectorComponent); diff --git a/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/rollingredblack.strategy.ts b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/rollingredblack.strategy.ts index ebad3607f45..d3b094a5d3b 100644 --- a/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/rollingredblack.strategy.ts +++ b/app/scripts/modules/core/src/deploymentStrategy/strategies/rollingredblack/rollingredblack.strategy.ts @@ -11,5 +11,11 @@ DeploymentStrategyRegistry.registerStrategy({ if (!command.targetPercentages) { command.targetPercentages = [50, 100]; } + + if (!command.pipelineBeforeCleanup) { + command.beforeCleanupPipeline = { + application: command.application + } + } } });