Skip to content

Commit

Permalink
feat(provider/gce): Support nested health checks in autoHealingPolicy. (
Browse files Browse the repository at this point in the history
  • Loading branch information
jtk54 authored Apr 3, 2018
1 parent c119e9d commit c39e49c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
instanceTypes: gceInstanceTypeService.getAllTypesByRegion(),
persistentDiskTypes: $q.when(angular.copy(persistentDiskTypes)),
authScopes: $q.when(angular.copy(authScopes)),
httpHealthChecks: gceHealthCheckReader.listHealthChecks('HTTP'),
healthChecks: gceHealthCheckReader.listHealthChecks(),
}).then(function(backingData) {
var loadBalancerReloader = $q.when(null);
var securityGroupReloader = $q.when(null);
var networkReloader = $q.when(null);
var httpHealthCheckReloader = $q.when(null);
var healthCheckReloader = $q.when(null);
backingData.accounts = _.keys(backingData.credentialsKeyedByAccount);
backingData.filtered = {};
command.backingData = backingData;
Expand Down Expand Up @@ -124,14 +124,14 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
command.enableAutoHealing = true;
}
if (_.has(command, 'autoHealingPolicy.healthCheck')) {
// Verify http health check is accounted for; otherwise, try refreshing http health checks cache.
var httpHealthChecks = getHttpHealthChecks(command);
if (!_.chain(httpHealthChecks).includes(command.autoHealingPolicy.healthCheck).value()) {
httpHealthCheckReloader = refreshHttpHealthChecks(command, true);
// Verify health check is accounted for; otherwise, try refreshing health checks cache.
var healthChecks = getHealthChecks(command);
if (!_.chain(healthChecks).includes(command.autoHealingPolicy.healthCheck).value()) {
healthCheckReloader = refreshHealthChecks(command, true);
}
}

return $q.all([loadBalancerReloader, securityGroupReloader, networkReloader, httpHealthCheckReloader]).then(function() {
return $q.all([loadBalancerReloader, securityGroupReloader, networkReloader, healthCheckReloader]).then(function() {
gceTagManager.register(command);
attachEventHandlers(command);
});
Expand Down Expand Up @@ -328,24 +328,24 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
return result;
}

function getHttpHealthChecks(command) {
return _.chain(command.backingData.httpHealthChecks)
function getHealthChecks(command) {
return _.chain(command.backingData.healthChecks)
.filter({account: command.credentials})
.map('name')
.value();
}

function configureHttpHealthChecks(command) {
function configureHealthChecks(command) {
var result = { dirty: {} };
var filteredData = command.backingData.filtered;

if (command.credentials === null) {
return result;
}

filteredData.httpHealthChecks = getHttpHealthChecks(command);
filteredData.healthChecks = getHealthChecks(command);

if (_.has(command, 'autoHealingPolicy.healthCheck') && !_.chain(filteredData.httpHealthChecks).includes(command.autoHealingPolicy.healthCheck).value()) {
if (_.has(command, 'autoHealingPolicy.healthCheck') && !_.chain(filteredData.healthChecks).includes(command.autoHealingPolicy.healthCheck).value()) {
delete command.autoHealingPolicy.healthCheck;
result.dirty.autoHealingPolicy = true;
} else {
Expand Down Expand Up @@ -436,15 +436,15 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
});
}

function refreshHttpHealthChecks(command, skipCommandReconfiguration) {
function refreshHealthChecks(command, skipCommandReconfiguration) {
return cacheInitializer.refreshCache('healthChecks')
.then(function() {
return gceHealthCheckReader.listHealthChecks('HTTP');
return gceHealthCheckReader.listHealthChecks();
})
.then(function(httpHealthChecks) {
command.backingData.httpHealthChecks = httpHealthChecks;
.then(function(healthChecks) {
command.backingData.healthChecks = healthChecks;
if (!skipCommandReconfiguration) {
configureHttpHealthChecks(command);
configureHealthChecks(command);
}
});
}
Expand Down Expand Up @@ -626,7 +626,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
angular.extend(result.dirty, command.networkChanged().dirty);
}

angular.extend(result.dirty, configureHttpHealthChecks(command).dirty);
angular.extend(result.dirty, configureHealthChecks(command).dirty);
angular.extend(result.dirty, configureInstanceTypes(command).dirty);
} else {
command.region = null;
Expand Down Expand Up @@ -696,7 +696,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
refreshLoadBalancers: refreshLoadBalancers,
refreshSecurityGroups: refreshSecurityGroups,
refreshInstanceTypes: refreshInstanceTypes,
refreshHttpHealthChecks: refreshHttpHealthChecks,
refreshHealthChecks: refreshHealthChecks,
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<gce-auto-healing-policy-selector ng-if="command.enableAutoHealing"
on-health-check-refresh="ctrl.onHealthCheckRefresh()"
set-auto-healing-policy="ctrl.setAutoHealingPolicy(autoHealingPolicy)"
http-health-checks="command.backingData.filtered.httpHealthChecks"
health-checks="command.backingData.filtered.healthChecks"
enabled="command.enableAutoHealing"
auto-healing-policy="command.autoHealingPolicy"></gce-auto-healing-policy-selector>
</ng-form>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="form-group">
<div class="col-md-{{::$ctrl.labelColumns || 3}} sm-label-right">
<b>HTTP Health Check</b>
<b>Health Check</b>
</div>
<div class="col-md-6">
<ui-select ng-model="$ctrl.autoHealingPolicy.healthCheck" class="form-control input-sm" required>
<ui-select-match placeholder="Select...">{{$select.selected}}</ui-select-match>
<ui-select-choices repeat="httpHealthCheck in $ctrl.httpHealthChecks | filter: $select.search">
<span ng-bind-html="httpHealthCheck | highlight: $select.search"></span>
<ui-select-choices repeat="healthCheck in $ctrl.healthChecks | filter: $select.search">
<span ng-bind-html="healthCheck | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
</div>
Expand Down Expand Up @@ -63,7 +63,7 @@
<div class="form-group small" style="margin-top: 20px">
<div class="col-md-7 col-md-offset-{{::$ctrl.labelColumns || 3}}">
<gce-cache-refresh cache-key="healthChecks"
cache-key-alias="HTTP health checks"
cache-key-alias="Health checks"
on-refresh="$ctrl.onHealthCheckRefresh()">
</gce-cache-refresh>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { set } from 'lodash';
import { IGceAutoHealingPolicy } from 'google/domain/autoHealingPolicy';

class GceAutoHealingPolicySelector implements IController {
public httpHealthChecks: string[];
public healthChecks: string[];
public autoHealingPolicy: IGceAutoHealingPolicy;
public enabled: boolean;
public viewState: {maxUnavailableMetric: 'percent' | 'fixed'};
Expand Down Expand Up @@ -42,7 +42,7 @@ class GceAutoHealingPolicySelectorComponent implements IComponentOptions {
public bindings: any = {
onHealthCheckRefresh: '&',
setAutoHealingPolicy: '&',
httpHealthChecks: '<',
healthChecks: '<',
autoHealingPolicy: '<',
enabled: '<',
labelColumns: '@?',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.cloneServer
};

this.onHealthCheckRefresh = function() {
gceServerGroupConfigurationService.refreshHttpHealthChecks($scope.command);
gceServerGroupConfigurationService.refreshHealthChecks($scope.command);
};

this.setAutoHealingPolicy = function(autoHealingPolicy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import './upsertAutoHealingPolicy.modal.less';
class GceUpsertAutoHealingPolicyModalCtrl implements IController {
public autoHealingPolicy: IGceAutoHealingPolicy;
public taskMonitor: TaskMonitor;
public httpHealthChecks: string[];
public healthChecks: string[];
public action: 'Edit' | 'New';
public isNew: boolean;
public submitButtonLabel: string;
Expand Down Expand Up @@ -43,9 +43,9 @@ class GceUpsertAutoHealingPolicyModalCtrl implements IController {
}

public onHealthCheckRefresh(): void {
this.gceHealthCheckReader.listHealthChecks('HTTP')
this.gceHealthCheckReader.listHealthChecks()
.then((healthChecks) => {
this.httpHealthChecks = chain(healthChecks)
this.healthChecks = chain(healthChecks)
.filter({ account: this.serverGroup.account })
.map('name')
.value() as string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h3>{{ctrl.action}} autohealing policy</h3>
<div class="modal-body clearfix">
<gce-auto-healing-policy-selector on-health-check-refresh="ctrl.onHealthCheckRefresh()"
set-auto-healing-policy="ctrl.setAutoHealingPolicy(autoHealingPolicy)"
http-health-checks="ctrl.httpHealthChecks"
health-checks="ctrl.healthChecks"
enabled="true"
label-columns="4"
auto-healing-policy="ctrl.autoHealingPolicy"></gce-auto-healing-policy-selector>
Expand Down

0 comments on commit c39e49c

Please sign in to comment.