2016-09-23 04:54:58 +00:00
|
|
|
angular.module('services', [])
|
2017-09-21 14:00:53 +00:00
|
|
|
.controller('ServicesController', ['$q', '$scope', '$transition$', '$state', 'Service', 'ServiceService', 'ServiceHelper', 'Notifications', 'Pagination', 'Task', 'Node', 'NodeHelper', 'ModalService', 'ResourceControlService',
|
|
|
|
function ($q, $scope, $transition$, $state, Service, ServiceService, ServiceHelper, Notifications, Pagination, Task, Node, NodeHelper, ModalService, ResourceControlService) {
|
2016-09-23 04:54:58 +00:00
|
|
|
$scope.state = {};
|
|
|
|
$scope.state.selectedItemCount = 0;
|
2017-01-24 01:28:40 +00:00
|
|
|
$scope.state.pagination_count = Pagination.getPaginationCount('services');
|
2016-09-23 04:54:58 +00:00
|
|
|
$scope.sortType = 'Name';
|
|
|
|
$scope.sortReverse = false;
|
2017-01-24 01:28:40 +00:00
|
|
|
|
|
|
|
$scope.changePaginationCount = function() {
|
|
|
|
Pagination.setPaginationCount('services', $scope.state.pagination_count);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.order = function (sortType) {
|
|
|
|
$scope.sortReverse = ($scope.sortType === sortType) ? !$scope.sortReverse : false;
|
|
|
|
$scope.sortType = sortType;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.selectItem = function (item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
$scope.state.selectedItemCount++;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
2016-09-23 04:54:58 +00:00
|
|
|
|
|
|
|
$scope.scaleService = function scaleService(service) {
|
|
|
|
$('#loadServicesSpinner').show();
|
|
|
|
var config = ServiceHelper.serviceToConfig(service.Model);
|
|
|
|
config.Mode.Replicated.Replicas = service.Replicas;
|
|
|
|
Service.update({ id: service.Id, version: service.Version }, config, function (data) {
|
|
|
|
$('#loadServicesSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Service successfully scaled', 'New replica count: ' + service.Replicas);
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.reload();
|
2016-09-23 04:54:58 +00:00
|
|
|
}, function (e) {
|
|
|
|
$('#loadServicesSpinner').hide();
|
|
|
|
service.Scale = false;
|
|
|
|
service.Replicas = service.ReplicaCount;
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', e, 'Unable to scale service');
|
2016-09-23 04:54:58 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-30 09:22:59 +00:00
|
|
|
$scope.removeAction = function() {
|
|
|
|
ModalService.confirmDeletion(
|
2017-04-25 08:20:57 +00:00
|
|
|
'Do you want to remove the selected service(s)? All the containers associated to the selected service(s) will be removed too.',
|
2017-03-30 09:22:59 +00:00
|
|
|
function onConfirm(confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
removeServices();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function removeServices() {
|
2016-09-23 04:54:58 +00:00
|
|
|
$('#loadServicesSpinner').show();
|
|
|
|
var counter = 0;
|
|
|
|
var complete = function () {
|
|
|
|
counter = counter - 1;
|
|
|
|
if (counter === 0) {
|
|
|
|
$('#loadServicesSpinner').hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.services, function (service) {
|
|
|
|
if (service.Checked) {
|
|
|
|
counter = counter + 1;
|
2017-05-23 18:56:10 +00:00
|
|
|
ServiceService.remove(service)
|
|
|
|
.then(function success(data) {
|
|
|
|
Notifications.success('Service successfully deleted');
|
|
|
|
var index = $scope.services.indexOf(service);
|
|
|
|
$scope.services.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove service');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
2016-09-23 04:54:58 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-03-30 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
function mapUsersToServices(users) {
|
|
|
|
angular.forEach($scope.services, function (service) {
|
|
|
|
if (service.Metadata) {
|
|
|
|
var serviceRC = service.Metadata.ResourceControl;
|
2017-03-16 10:32:07 +00:00
|
|
|
if (serviceRC && serviceRC.OwnerId !== $scope.user.ID) {
|
2017-03-12 16:24:15 +00:00
|
|
|
angular.forEach(users, function (user) {
|
|
|
|
if (serviceRC.OwnerId === user.Id) {
|
|
|
|
service.Owner = user.Username;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
function initView() {
|
2016-09-23 04:54:58 +00:00
|
|
|
$('#loadServicesSpinner').show();
|
2017-03-12 17:24:41 +00:00
|
|
|
$q.all({
|
|
|
|
services: Service.query({}).$promise,
|
|
|
|
tasks: Task.query({filters: {'desired-state': ['running']}}).$promise,
|
2017-05-23 18:56:10 +00:00
|
|
|
nodes: Node.query({}).$promise
|
2017-03-12 17:24:41 +00:00
|
|
|
})
|
|
|
|
.then(function success(data) {
|
2017-03-28 13:12:54 +00:00
|
|
|
$scope.swarmManagerIP = NodeHelper.getManagerIP(data.nodes);
|
2017-03-12 17:24:41 +00:00
|
|
|
$scope.services = data.services.map(function (service) {
|
|
|
|
var serviceTasks = data.tasks.filter(function (task) {
|
2017-05-23 18:56:10 +00:00
|
|
|
return task.ServiceID === service.ID && task.Status.State === 'running';
|
2017-03-12 17:24:41 +00:00
|
|
|
});
|
|
|
|
var taskNodes = data.nodes.filter(function (node) {
|
|
|
|
return node.Spec.Availability === 'active' && node.Status.State === 'ready';
|
|
|
|
});
|
|
|
|
return new ServiceViewModel(service, serviceTasks, taskNodes);
|
2016-09-23 04:54:58 +00:00
|
|
|
});
|
2017-03-12 17:24:41 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2016-10-08 01:59:58 +00:00
|
|
|
$scope.services = [];
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve services');
|
2017-03-12 17:24:41 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadServicesSpinner').hide();
|
2016-09-23 04:54:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
initView();
|
2016-09-23 04:54:58 +00:00
|
|
|
}]);
|