Skip to content

Commit

Permalink
Merge pull request #1753 from anotherchrisberry/rollback-fixup
Browse files Browse the repository at this point in the history
include rollback task in running tasks, sort rollback options
  • Loading branch information
ajordens committed Nov 24, 2015
2 parents 37edf43 + f084908 commit eeb998d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = angular.module('spinnaker.amazon.serverGroup.details.rollback.c
taskMonitorService,
application, serverGroup, disabledServerGroups) {
$scope.serverGroup = serverGroup;
$scope.disabledServerGroups = disabledServerGroups;
$scope.disabledServerGroups = disabledServerGroups.sort((a, b) => b.name.localeCompare(a.name));
$scope.verification = {
required: accountService.challengeDestructiveActions('aws', serverGroup.account)
};
Expand Down
14 changes: 13 additions & 1 deletion app/scripts/modules/core/cluster/cluster.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,23 @@ module.exports = angular.module('spinnaker.core.cluster.service', [
'enableservergroup': baseTaskMatcher,
'enablegoogleservergroup': baseTaskMatcher,
'disablegoogleservergroup': baseTaskMatcher,
'rollbackServerGroup': function(task, serverGroup) {
var account = task.getValueFor('credentials'),
region = task.getValueFor('regions') ? task.getValueFor('regions')[0] : null;

if (account && serverGroup.account === account && region && serverGroup.region === region) {
return serverGroup.name === task.getValueFor('targetop.asg.disableServerGroup.name') ||
serverGroup.name === task.getValueFor('targetop.asg.enableServerGroup.name');
}
return false;
},
};

function taskMatches(task, serverGroup) {
let notificationType = _.has(task, 'execution.stages') ?
task.execution.stages[0].context['notification.type'] :
task.execution.stages[0].context['notification.type'] ?
task.execution.stages[0].context['notification.type'] :
task.execution.stages[0].type : // TODO: good grief
task.getValueFor('notification.type');
var matcher = taskMatchers[notificationType];
return matcher ? matcher(task, serverGroup) : false;
Expand Down
22 changes: 22 additions & 0 deletions app/scripts/modules/core/cluster/cluster.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ describe('Service: InstanceType', function () {
});

describe('addTasksToServerGroups', function() {
describe('rollback tasks', function () {
it('attaches to source and target', function () {
var app = this.application;
app.tasks = [
this.buildTask({status: 'RUNNING', variables: [
{ key: 'credentials', value: 'test' },
{ key: 'regions', value: ['us-east-1'] },
{ key: 'targetop.asg.disableServerGroup.name', value: 'the-source' },
{ key: 'targetop.asg.enableServerGroup.name', value: 'the-target' }
]})
];

app.tasks[0].execution = {stages: [ { type: 'rollbackServerGroup', context: {} }] };
clusterService.addTasksToServerGroups(app);
expect(app.serverGroups[0].runningTasks.length).toBe(0);
expect(app.serverGroups[1].runningTasks.length).toBe(0);
expect(app.serverGroups[2].runningTasks.length).toBe(1);
expect(app.serverGroups[3].runningTasks.length).toBe(0);
expect(app.serverGroups[4].runningTasks.length).toBe(1);
});
});

describe('createcopylastasg tasks', function() {
it('attaches to source and target', function() {
var app = this.application;
Expand Down

0 comments on commit eeb998d

Please sign in to comment.