2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-02-27 07:19:21 +00:00
|
|
|
.controller('StackController', ['$q', '$scope', '$state', '$transition$', 'StackService', 'NodeService', 'ServiceService', 'TaskService', 'ServiceHelper', 'Notifications', 'FormHelper', 'EndpointProvider',
|
|
|
|
function ($q, $scope, $state, $transition$, StackService, NodeService, ServiceService, TaskService, ServiceHelper, Notifications, FormHelper, EndpointProvider) {
|
2017-10-15 17:24:40 +00:00
|
|
|
|
2017-11-12 19:27:28 +00:00
|
|
|
$scope.state = {
|
2017-12-06 11:04:02 +00:00
|
|
|
actionInProgress: false,
|
|
|
|
publicURL: EndpointProvider.endpointPublicURL()
|
2017-11-12 19:27:28 +00:00
|
|
|
};
|
2017-10-15 17:24:40 +00:00
|
|
|
|
2018-01-20 17:05:01 +00:00
|
|
|
$scope.formValues = {
|
|
|
|
Prune: false
|
|
|
|
};
|
|
|
|
|
2017-11-12 19:27:28 +00:00
|
|
|
$scope.deployStack = function () {
|
2018-02-27 07:19:21 +00:00
|
|
|
var stackFile = $scope.stackFileContent;
|
2017-11-01 09:30:02 +00:00
|
|
|
var env = FormHelper.removeInvalidEnvVars($scope.stack.Env);
|
2018-01-20 17:05:01 +00:00
|
|
|
var prune = $scope.formValues.Prune;
|
2017-10-15 17:24:40 +00:00
|
|
|
|
2017-11-12 21:39:12 +00:00
|
|
|
$scope.state.actionInProgress = true;
|
2018-01-20 17:05:01 +00:00
|
|
|
StackService.updateStack($scope.stack.Id, stackFile, env, prune)
|
2017-10-15 17:24:40 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
Notifications.success('Stack successfully deployed');
|
|
|
|
$state.reload();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to create stack');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
2017-11-12 21:39:12 +00:00
|
|
|
$scope.state.actionInProgress = false;
|
2017-10-15 17:24:40 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-11-01 09:30:02 +00:00
|
|
|
$scope.addEnvironmentVariable = function() {
|
|
|
|
$scope.stack.Env.push({ name: '', value: ''});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeEnvironmentVariable = function(index) {
|
|
|
|
$scope.stack.Env.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
2017-10-15 17:24:40 +00:00
|
|
|
function initView() {
|
2018-01-04 20:53:10 +00:00
|
|
|
var stackId = $transition$.params().id;
|
2018-01-20 17:05:01 +00:00
|
|
|
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
2017-10-15 17:24:40 +00:00
|
|
|
|
|
|
|
StackService.stack(stackId)
|
|
|
|
.then(function success(data) {
|
|
|
|
var stack = data;
|
|
|
|
$scope.stack = stack;
|
|
|
|
|
|
|
|
var serviceFilters = {
|
|
|
|
label: ['com.docker.stack.namespace=' + stack.Name]
|
|
|
|
};
|
|
|
|
|
|
|
|
return $q.all({
|
|
|
|
stackFile: StackService.getStackFile(stackId),
|
|
|
|
services: ServiceService.services(serviceFilters),
|
|
|
|
tasks: TaskService.tasks(serviceFilters),
|
|
|
|
nodes: NodeService.nodes()
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.stackFileContent = data.stackFile;
|
|
|
|
|
|
|
|
$scope.nodes = data.nodes;
|
|
|
|
|
|
|
|
var services = data.services;
|
|
|
|
|
|
|
|
var tasks = data.tasks;
|
|
|
|
$scope.tasks = tasks;
|
|
|
|
|
|
|
|
for (var i = 0; i < services.length; i++) {
|
|
|
|
var service = services[i];
|
|
|
|
ServiceHelper.associateTasksToService(service, tasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.services = services;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve tasks details');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-27 07:19:21 +00:00
|
|
|
$scope.editorUpdate = function(cm) {
|
|
|
|
$scope.stackFileContent = cm.getValue();
|
|
|
|
};
|
|
|
|
|
2018-04-04 09:45:35 +00:00
|
|
|
$scope.scaleAction = function scaleService(service) {
|
|
|
|
var config = ServiceHelper.serviceToConfig(service.Model);
|
|
|
|
config.Mode.Replicated.Replicas = service.Replicas;
|
|
|
|
ServiceService.update(service, config)
|
|
|
|
.then(function success(data) {
|
|
|
|
Notifications.success('Service successfully scaled', 'New replica count: ' + service.Replicas);
|
|
|
|
$state.reload();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to scale service');
|
|
|
|
service.Scale = false;
|
|
|
|
service.Replicas = service.ReplicaCount;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-15 17:24:40 +00:00
|
|
|
initView();
|
|
|
|
}]);
|