Skip to content

Commit

Permalink
feat(titus): Support rollback of disabled server groups (parity with …
Browse files Browse the repository at this point in the history
…aws) (#5100)

If only one possible server group exists as a rollback target, it will be
selected by default.

See #5077
  • Loading branch information
ajordens committed Mar 29, 2018
1 parent 5e64470 commit f742ffc
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,18 @@ export class AmazonServerGroupActions extends React.Component<IAmazonServerGroup
*/
serverGroup = orderBy(
allServerGroups.filter((g: IAmazonServerGroup) => g.name !== previousServerGroup.name && !g.isDisabled),
['instanceCounts.total'], ['desc']
['instanceCounts.total', 'createdTime'], ['desc', 'desc']
)[0] as IAmazonServerGroup;
}

// the set of all server groups should not include the server group selected for rollback
allServerGroups = allServerGroups.filter((g: IAmazonServerGroup) => g.name !== serverGroup.name);

if (allServerGroups.length === 1 && !previousServerGroup) {
// if there is only one other server group, default to it being the rollback target
previousServerGroup = allServerGroups[0];
}

ReactInjector.modalService.open({
templateUrl: ReactInjector.overrideRegistry.getTemplate('aws.rollback.modal', require('./rollback/rollbackServerGroup.html')),
controller: 'awsRollbackServerGroupCtrl as ctrl',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = angular.module('spinnaker.titus.serverGroup.details.rollback.co
])
.controller('titusRollbackServerGroupCtrl', function ($scope, $uibModalInstance, serverGroupWriter,
taskMonitorBuilder,
application, serverGroup, disabledServerGroups, allServerGroups) {
application,
serverGroup, previousServerGroup,
disabledServerGroups, allServerGroups) {
$scope.serverGroup = serverGroup;
$scope.disabledServerGroups = disabledServerGroups.sort((a, b) => b.name.localeCompare(a.name));
$scope.allServerGroups = allServerGroups.sort((a, b) => b.name.localeCompare(a.name));
Expand Down Expand Up @@ -49,6 +51,7 @@ module.exports = angular.module('spinnaker.titus.serverGroup.details.rollback.co
rollbackType: rollbackType,
rollbackContext: {
rollbackServerGroupName: serverGroup.name,
restoreServerGroupName: previousServerGroup ? previousServerGroup.name : undefined,
targetHealthyRollbackPercentage: healthyPercent
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h3>Rollback {{serverGroup.name}}</h3>
<div class="col-sm-3 sm-label-right">
Restore to
</div>
<div class="col-sm-8">
<div class="col-sm-7">
<ui-select ng-model="command.rollbackContext.restoreServerGroupName"
class="form-control input-sm"
ng-if="command.rollbackType === 'EXPLICIT'">
Expand Down Expand Up @@ -39,9 +39,7 @@ <h3>Rollback {{serverGroup.name}}</h3>
</div>
</div>

<div class="row">
<task-reason command="command"></task-reason>
</div>
<task-reason command="command"></task-reason>

<div class="row">
<div class="col-sm-11 col-sm-offset-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ <h3 select-on-dbl-click>
Titus Job Actions <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu">
<li><a href ng-if=" !serverGroup.isDisabled" ng-click="ctrl.rollbackServerGroup()">Rollback</a></li>
<li role="presentation" class="divider" ng-if="!serverGroup.isDisabled"></li>
<li><a href ng-if="ctrl.isRollbackEnabled()" ng-click="ctrl.rollbackServerGroup()">Rollback</a></li>
<li role="presentation" class="divider" ng-if="ctrl.isRollbackEnabled()"></li>
<li><a href ng-click="ctrl.resizeServerGroup()">Resize</a></li>
<li><a href ng-if="!serverGroup.isDisabled" ng-click="ctrl.disableServerGroup()">Disable</a></li>
<li><a href ng-if="serverGroup.isDisabled" ng-click="ctrl.enableServerGroup()">Enable</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,71 @@ module.exports = angular.module('spinnaker.serverGroup.details.titus.controller'
});
};

this.isRollbackEnabled = function rollbackServerGroup() {
let serverGroup = $scope.serverGroup;
if (!serverGroup.isDisabled) {
// enabled server groups are always a candidate for rollback
return true;
}

// if the server group selected for rollback is disabled, ensure that at least one enabled server group exists
return application.getDataSource('serverGroups').data.some(g =>
g.cluster === serverGroup.cluster &&
g.region === serverGroup.region &&
g.account === serverGroup.account &&
g.isDisabled === false
);
};

this.rollbackServerGroup = function rollbackServerGroup() {
var serverGroup = $scope.serverGroup;
let serverGroup = $scope.serverGroup;

let previousServerGroup;
let allServerGroups = app.getDataSource('serverGroups').data.filter(g =>
g.cluster === serverGroup.cluster &&
g.region === serverGroup.region &&
g.account === serverGroup.account
);

if (serverGroup.isDisabled) {
// if the selected server group is disabled, it represents the server group that should be _rolled back to_
previousServerGroup = serverGroup;

/*
* Find an existing server group to rollback, prefer the largest enabled server group.
*
* isRollbackEnabled() ensures that at least one enabled server group exists.
*/
serverGroup = _.orderBy(
allServerGroups.filter(g =>
g.name !== previousServerGroup.name && !g.isDisabled
),
['instanceCounts.total', 'createdTime'],
['desc', 'desc']
)[0];
}

// the set of all server groups should not include the server group selected for rollback
allServerGroups = allServerGroups.filter(g =>
g.name !== serverGroup.name
);

if (allServerGroups.length === 1 && !previousServerGroup) {
// if there is only one other server group, default to it being the rollback target
previousServerGroup = allServerGroups[0];
}

$uibModal.open({
templateUrl: require('./rollback/rollbackServerGroup.html'),
controller: 'titusRollbackServerGroupCtrl as ctrl',
resolve: {
serverGroup: () => serverGroup,
previousServerGroup: () => previousServerGroup,
disabledServerGroups: () => {
var cluster = _.find(application.clusters, { name: serverGroup.cluster, account: serverGroup.account });
return _.filter(cluster.serverGroups, { isDisabled: true, region: serverGroup.region });
},
allServerGroups: () => application.getDataSource('serverGroups').data.filter(g =>
g.cluster === serverGroup.cluster &&
g.region === serverGroup.region &&
g.account === serverGroup.account &&
g.name !== serverGroup.name
),
allServerGroups: () => allServerGroups,
application: () => application
}
});
Expand Down

0 comments on commit f742ffc

Please sign in to comment.