Skip to content
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

Show toast notifications for scaling errors #1691

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions app/scripts/directives/deploymentDonut.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ angular.module('openshiftConsole')
QuotaService,
LabelFilter,
Navigate,
NotificationsService,
hashSizeFilter,
hasDeploymentConfigFilter) {
return {
Expand All @@ -28,14 +29,12 @@ angular.module('openshiftConsole')
project: '=',

// Pods
pods: '=',

// To display scaling errors
alerts: '='
pods: '='
},
templateUrl: 'views/directives/deployment-donut.html',
controller: function($scope) {
controller: function($scope, $filter, $q) {
var scaleRequestPending = false;
var humanizeKind = $filter('humanizeKind');

$scope.$watch("rc.spec.replicas", function() {
// Only reset desiredReplicas if we've already requested that value.
Expand Down Expand Up @@ -74,17 +73,6 @@ angular.module('openshiftConsole')

$scope.$watchGroup(['rc.spec.replicas', 'rc.status.replicas', 'quotas', 'clusterQuotas'], updateQuotaWarning);

var showScalingError = function(result) {
$scope.alerts = $scope.alerts || {};
$scope.desiredReplicas = null;
$scope.alerts["scale"] =
{
type: "error",
message: "An error occurred scaling the deployment.",
details: $filter('getErrorDetails')(result)
};
};

var getScaleTarget = function() {
return $scope.deploymentConfig || $scope.deployment || $scope.rc;
};
Expand All @@ -96,7 +84,17 @@ angular.module('openshiftConsole')
return;
}
var scaleTarget = getScaleTarget();
return DeploymentsService.scale(scaleTarget, $scope.desiredReplicas).then(_.noop, showScalingError);
return DeploymentsService.scale(scaleTarget, $scope.desiredReplicas).then(_.noop, function(result) {
var kind = humanizeKind(scaleTarget.kind);
NotificationsService.addNotification({
id: "deployment-scale-error",
type: "error",
message: "An error occurred scaling " + kind + " " + scaleTarget.metadata.name + ".",
details: $filter('getErrorDetails')(result)
});

return $q.reject(result);
});
};

// Debounce scaling so multiple consecutive clicks only result in one request
Expand Down Expand Up @@ -192,12 +190,10 @@ angular.module('openshiftConsole')

$scope.unIdle = function() {
$scope.desiredReplicas = $filter('unidleTargetReplicas')($scope.deploymentConfig || $scope.rc, $scope.hpa);
scale()
.then(function() {
$scope.isIdled = false;
},showScalingError);
scale().then(function() {
$scope.isIdled = false;
});
};

}
};
});
3 changes: 1 addition & 2 deletions app/views/browse/_replica-set-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
limit-ranges="limitRanges"
project="project"
quotas="quotas"
cluster-quotas="clusterQuotas"
alerts="alerts">
cluster-quotas="clusterQuotas">
</deployment-donut>
</div>
<div class="col-sm-8 col-sm-pull-4">
Expand Down
3 changes: 1 addition & 2 deletions app/views/browse/stateful-set.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ <h1>
pods="podsForStatefulSet"
scalable="isScalable()"
quotas="quotas"
cluster-quotas="clusterQuotas"
alerts="alerts">
cluster-quotas="clusterQuotas">
</deployment-donut>
</div>

Expand Down
6 changes: 2 additions & 4 deletions app/views/overview/_list-row-expanded.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ <h4 class="h5">Average Usage <small>Last 15 Minutes</small></h4>
project="row.state.project"
quotas="row.state.quotas"
cluster-quotas="row.state.clusterQuotas"
scalable="false"
alerts="row.state.alerts">
scalable="false">
</deployment-donut>
<div ng-if="row.previous" class="deployment-connector">
<div class="deployment-connector-arrow" aria-hidden="true">
Expand All @@ -85,8 +84,7 @@ <h4 class="h5">Average Usage <small>Last 15 Minutes</small></h4>
project="row.state.project"
quotas="row.state.quotas"
cluster-quotas="row.state.clusterQuotas"
scalable="row.isScalable()"
alerts="row.state.alerts">
scalable="row.isScalable()">
</deployment-donut>
</div>
</div>
Expand Down
109 changes: 55 additions & 54 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11617,7 +11617,7 @@ c && (c = c.destroy());
});
}
};
}), angular.module("openshiftConsole").directive("deploymentDonut", [ "$filter", "$location", "$timeout", "$uibModal", "DeploymentsService", "HPAService", "QuotaService", "LabelFilter", "Navigate", "hashSizeFilter", "hasDeploymentConfigFilter", function(a, b, c, d, e, f, g, h, i, j, k) {
}), angular.module("openshiftConsole").directive("deploymentDonut", [ "$filter", "$location", "$timeout", "$uibModal", "DeploymentsService", "HPAService", "QuotaService", "LabelFilter", "Navigate", "NotificationsService", "hashSizeFilter", "hasDeploymentConfigFilter", function(a, b, c, d, e, f, g, h, i, j, k, l) {
return {
restrict:"E",
scope:{
Expand All @@ -11630,82 +11630,83 @@ limitRanges:"=",
quotas:"=",
clusterQuotas:"=",
project:"=",
pods:"=",
alerts:"="
pods:"="
},
templateUrl:"views/directives/deployment-donut.html",
controller:[ "$scope", function(b) {
var c = !1;
b.$watch("rc.spec.replicas", function() {
c || (b.desiredReplicas = null);
controller:[ "$scope", "$filter", "$q", function(a, b, c) {
var h = !1, k = b("humanizeKind");
a.$watch("rc.spec.replicas", function() {
h || (a.desiredReplicas = null);
});
var h = function() {
f.getHPAWarnings(b.rc, b.hpa, b.limitRanges, b.project).then(function(a) {
b.hpaWarnings = _.map(a, function(a) {
var m = function() {
f.getHPAWarnings(a.rc, a.hpa, a.limitRanges, a.project).then(function(b) {
a.hpaWarnings = _.map(b, function(a) {
return _.escape(a.message);
}).join("<br>");
});
};
b.$watchGroup([ "limitRanges", "hpa", "project" ], h), b.$watch("rc.spec.template.spec.containers", h, !0);
var j = function() {
if (_.get(b.rc, "spec.replicas", 1) > _.get(b.rc, "status.replicas", 0)) {
var a = g.filterQuotasForResource(b.rc, b.quotas), c = g.filterQuotasForResource(b.rc, b.clusterQuotas), d = function(a) {
return !_.isEmpty(g.getResourceLimitAlerts(b.rc, a));
a.$watchGroup([ "limitRanges", "hpa", "project" ], m), a.$watch("rc.spec.template.spec.containers", m, !0);
var n = function() {
if (_.get(a.rc, "spec.replicas", 1) > _.get(a.rc, "status.replicas", 0)) {
var b = g.filterQuotasForResource(a.rc, a.quotas), c = g.filterQuotasForResource(a.rc, a.clusterQuotas), d = function(b) {
return !_.isEmpty(g.getResourceLimitAlerts(a.rc, b));
};
b.showQuotaWarning = _.some(a, d) || _.some(c, d);
} else b.showQuotaWarning = !1;
a.showQuotaWarning = _.some(b, d) || _.some(c, d);
} else a.showQuotaWarning = !1;
};
b.$watchGroup([ "rc.spec.replicas", "rc.status.replicas", "quotas", "clusterQuotas" ], j);
var l = function(c) {
b.alerts = b.alerts || {}, b.desiredReplicas = null, b.alerts.scale = {
a.$watchGroup([ "rc.spec.replicas", "rc.status.replicas", "quotas", "clusterQuotas" ], n);
var o = function() {
return a.deploymentConfig || a.deployment || a.rc;
}, p = function() {
if (h = !1, angular.isNumber(a.desiredReplicas)) {
var d = o();
return e.scale(d, a.desiredReplicas).then(_.noop, function(a) {
var e = k(d.kind);
return j.addNotification({
id:"deployment-scale-error",
type:"error",
message:"An error occurred scaling the deployment.",
details:a("getErrorDetails")(c)
};
}, m = function() {
return b.deploymentConfig || b.deployment || b.rc;
}, n = function() {
if (c = !1, angular.isNumber(b.desiredReplicas)) {
var a = m();
return e.scale(a, b.desiredReplicas).then(_.noop, l);
}
}, o = _.debounce(n, 650);
b.viewPodsForDeployment = function(a) {
_.isEmpty(b.pods) || i.toPodsForDeployment(a, b.pods);
}, b.scaleUp = function() {
b.scalable && (b.desiredReplicas = b.getDesiredReplicas(), b.desiredReplicas++, o(), c = !0);
}, b.scaleDown = function() {
if (b.scalable && (b.desiredReplicas = b.getDesiredReplicas(), 0 !== b.desiredReplicas)) {
if (1 === b.desiredReplicas) {
var a = d.open({
message:"An error occurred scaling " + e + " " + d.metadata.name + ".",
details:b("getErrorDetails")(a)
}), c.reject(a);
});
}
}, q = _.debounce(p, 650);
a.viewPodsForDeployment = function(b) {
_.isEmpty(a.pods) || i.toPodsForDeployment(b, a.pods);
}, a.scaleUp = function() {
a.scalable && (a.desiredReplicas = a.getDesiredReplicas(), a.desiredReplicas++, q(), h = !0);
}, a.scaleDown = function() {
if (a.scalable && (a.desiredReplicas = a.getDesiredReplicas(), 0 !== a.desiredReplicas)) {
if (1 === a.desiredReplicas) {
var b = d.open({
animation:!0,
templateUrl:"views/modals/confirmScale.html",
controller:"ConfirmScaleController",
resolve:{
resource:function() {
return b.rc;
return a.rc;
},
type:function() {
return k(b.rc) ? "deployment" :"replication controller";
return l(a.rc) ? "deployment" :"replication controller";
}
}
});
return void a.result.then(function() {
b.desiredReplicas = b.getDesiredReplicas() - 1, o(), c = !0;
return void b.result.then(function() {
a.desiredReplicas = a.getDesiredReplicas() - 1, q(), h = !0;
});
}
b.desiredReplicas--, o();
a.desiredReplicas--, q();
}
}, b.getDesiredReplicas = function() {
return angular.isDefined(b.desiredReplicas) && null !== b.desiredReplicas ? b.desiredReplicas :b.rc && b.rc.spec && angular.isDefined(b.rc.spec.replicas) ? b.rc.spec.replicas :1;
}, b.$watch(function() {
return !_.get(b.rc, "spec.replicas") && !!(b.deploymentConfig ? a("annotation")(b.deploymentConfig, "idledAt") :a("annotation")(b.rc, "idledAt"));
}, function(a) {
b.isIdled = !!a;
}), b.unIdle = function() {
b.desiredReplicas = a("unidleTargetReplicas")(b.deploymentConfig || b.rc, b.hpa), n().then(function() {
b.isIdled = !1;
}, l);
}, a.getDesiredReplicas = function() {
return angular.isDefined(a.desiredReplicas) && null !== a.desiredReplicas ? a.desiredReplicas :a.rc && a.rc.spec && angular.isDefined(a.rc.spec.replicas) ? a.rc.spec.replicas :1;
}, a.$watch(function() {
return !_.get(a.rc, "spec.replicas") && !!(a.deploymentConfig ? b("annotation")(a.deploymentConfig, "idledAt") :b("annotation")(a.rc, "idledAt"));
}, function(b) {
a.isIdled = !!b;
}), a.unIdle = function() {
a.desiredReplicas = b("unidleTargetReplicas")(a.deploymentConfig || a.rc, a.hpa), p().then(function() {
a.isIdled = !1;
});
};
} ]
};
Expand Down
8 changes: 4 additions & 4 deletions dist/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
$templateCache.put('views/browse/_replica-set-details.html',
"<div class=\"row\" style=\"max-width: 650px\">\n" +
"<div class=\"col-sm-4 col-sm-push-8 browse-deployment-donut\">\n" +
"<deployment-donut rc=\"replicaSet\" deployment=\"deployment\" deployment-config=\"deploymentConfig\" pods=\"podsForDeployment\" hpa=\"autoscalers\" scalable=\"isScalable()\" limit-ranges=\"limitRanges\" project=\"project\" quotas=\"quotas\" cluster-quotas=\"clusterQuotas\" alerts=\"alerts\">\n" +
"<deployment-donut rc=\"replicaSet\" deployment=\"deployment\" deployment-config=\"deploymentConfig\" pods=\"podsForDeployment\" hpa=\"autoscalers\" scalable=\"isScalable()\" limit-ranges=\"limitRanges\" project=\"project\" quotas=\"quotas\" cluster-quotas=\"clusterQuotas\">\n" +
"</deployment-donut>\n" +
"</div>\n" +
"<div class=\"col-sm-8 col-sm-pull-4\">\n" +
Expand Down Expand Up @@ -3909,7 +3909,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<div class=\"row\" style=\"max-width: 650px\">\n" +
"<div class=\"col-sm-4 col-sm-push-8 browse-deployment-donut\">\n" +
"\n" +
"<deployment-donut rc=\"statefulSet\" pods=\"podsForStatefulSet\" scalable=\"isScalable()\" quotas=\"quotas\" cluster-quotas=\"clusterQuotas\" alerts=\"alerts\">\n" +
"<deployment-donut rc=\"statefulSet\" pods=\"podsForStatefulSet\" scalable=\"isScalable()\" quotas=\"quotas\" cluster-quotas=\"clusterQuotas\">\n" +
"</deployment-donut>\n" +
"</div>\n" +
"<div class=\"col-sm-8 col-sm-pull-4\">\n" +
Expand Down Expand Up @@ -11669,7 +11669,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
" 'stacked-template': row.state.breakpoint !== 'lg'\n" +
" }\">\n" +
"<div ng-if=\"row.previous\" class=\"previous-donut\">\n" +
"<deployment-donut rc=\"row.previous\" deployment-config=\"row.apiObject\" pods=\"row.getPods(row.previous)\" hpa=\"row.hpa\" limit-ranges=\"row.state.limitRanges\" project=\"row.state.project\" quotas=\"row.state.quotas\" cluster-quotas=\"row.state.clusterQuotas\" scalable=\"false\" alerts=\"row.state.alerts\">\n" +
"<deployment-donut rc=\"row.previous\" deployment-config=\"row.apiObject\" pods=\"row.getPods(row.previous)\" hpa=\"row.hpa\" limit-ranges=\"row.state.limitRanges\" project=\"row.state.project\" quotas=\"row.state.quotas\" cluster-quotas=\"row.state.clusterQuotas\" scalable=\"false\">\n" +
"</deployment-donut>\n" +
"<div ng-if=\"row.previous\" class=\"deployment-connector\">\n" +
"<div class=\"deployment-connector-arrow\" aria-hidden=\"true\">\n" +
Expand All @@ -11683,7 +11683,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</a>\n" +
"</div>\n" +
"<div ng-if=\"row.apiObject.kind !== 'Pod'\">\n" +
"<deployment-donut rc=\"row.current\" deployment-config=\"row.apiObject\" pods=\"row.getPods(row.current)\" hpa=\"row.hpa\" limit-ranges=\"row.state.limitRanges\" project=\"row.state.project\" quotas=\"row.state.quotas\" cluster-quotas=\"row.state.clusterQuotas\" scalable=\"row.isScalable()\" alerts=\"row.state.alerts\">\n" +
"<deployment-donut rc=\"row.current\" deployment-config=\"row.apiObject\" pods=\"row.getPods(row.current)\" hpa=\"row.hpa\" limit-ranges=\"row.state.limitRanges\" project=\"row.state.project\" quotas=\"row.state.quotas\" cluster-quotas=\"row.state.clusterQuotas\" scalable=\"row.isScalable()\">\n" +
"</deployment-donut>\n" +
"</div>\n" +
"</div>\n" +
Expand Down