diff --git a/app/components/createService/createServiceController.js b/app/components/createService/createServiceController.js index ce304ca4f..007df409c 100644 --- a/app/components/createService/createServiceController.js +++ b/app/components/createService/createServiceController.js @@ -1,8 +1,8 @@ // @@OLD_SERVICE_CONTROLLER: this service should be rewritten to use services. // See app/components/templates/templatesController.js as a reference. angular.module('createService', []) -.controller('CreateServiceController', ['$scope', '$state', 'Service', 'Volume', 'Network', 'ImageHelper', 'Authentication', 'ResourceControlService', 'Notifications', -function ($scope, $state, Service, Volume, Network, ImageHelper, Authentication, ResourceControlService, Notifications) { +.controller('CreateServiceController', ['$scope', '$state', 'Service', 'ServiceHelper', 'Volume', 'Network', 'ImageHelper', 'Authentication', 'ResourceControlService', 'Notifications', +function ($scope, $state, Service, ServiceHelper, Volume, Network, ImageHelper, Authentication, ResourceControlService, Notifications) { $scope.formValues = { Ownership: $scope.applicationState.application.authentication ? 'private' : '', @@ -23,6 +23,7 @@ function ($scope, $state, Service, Volume, Network, ImageHelper, Authentication, ExtraNetworks: [], Ports: [], Parallelism: 1, + PlacementConstraints: [], UpdateDelay: 0, FailureAction: 'pause' }; @@ -58,7 +59,18 @@ function ($scope, $state, Service, Volume, Network, ImageHelper, Authentication, $scope.removeEnvironmentVariable = function(index) { $scope.formValues.Env.splice(index, 1); }; - + $scope.addPlacementConstraint = function() { + $scope.formValues.PlacementConstraints.push({ key: '', operator: '==', value: '' }); + }; + $scope.removePlacementConstraint = function(index) { + $scope.formValues.PlacementConstraints.splice(index, 1); + }; + $scope.addPlacementPreference = function() { + $scope.formValues.PlacementPreferences.push({ key: '', operator: '==', value: '' }); + }; + $scope.removePlacementPreference = function(index) { + $scope.formValues.PlacementPreferences.splice(index, 1); + }; $scope.addLabel = function() { $scope.formValues.Labels.push({ name: '', value: ''}); }; @@ -188,6 +200,9 @@ function ($scope, $state, Service, Volume, Network, ImageHelper, Authentication, FailureAction: input.FailureAction }; } + function preparePlacementConfig(config, input) { + config.TaskTemplate.Placement.Constraints = ServiceHelper.translateKeyValueToPlacementConstraints(input.PlacementConstraints); + } function prepareConfiguration() { var input = $scope.formValues; @@ -196,7 +211,8 @@ function ($scope, $state, Service, Volume, Network, ImageHelper, Authentication, TaskTemplate: { ContainerSpec: { Mounts: [] - } + }, + Placement: {} }, Mode: {}, EndpointSpec: {} @@ -210,6 +226,7 @@ function ($scope, $state, Service, Volume, Network, ImageHelper, Authentication, prepareVolumes(config, input); prepareNetworks(config, input); prepareUpdateConfig(config, input); + preparePlacementConfig(config, input); return config; } diff --git a/app/components/createService/createservice.html b/app/components/createService/createservice.html index 60f556d5d..cb5e3a431 100644 --- a/app/components/createService/createservice.html +++ b/app/components/createService/createservice.html @@ -155,6 +155,7 @@
  • Network
  • Labels
  • Update config
  • +
  • Placement
  • @@ -436,6 +437,10 @@
    + + +
    + diff --git a/app/components/createService/includes/placement.html b/app/components/createService/includes/placement.html new file mode 100644 index 000000000..1b4f8b7c2 --- /dev/null +++ b/app/components/createService/includes/placement.html @@ -0,0 +1,31 @@ +
    +
    +
    + + + placement constraint + +
    +
    +
    +
    + name + +
    +
    + +
    +
    + value + +
    + +
    +
    +
    +
    diff --git a/app/components/service/serviceController.js b/app/components/service/serviceController.js index e39ed08fa..a183ab322 100644 --- a/app/components/service/serviceController.js +++ b/app/components/service/serviceController.js @@ -173,7 +173,7 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi if (typeof config.TaskTemplate.Placement === 'undefined') { config.TaskTemplate.Placement = {}; } - config.TaskTemplate.Placement.Constraints = translateKeyValueToConstraints(service.ServiceConstraints); + config.TaskTemplate.Placement.Constraints = ServiceHelper.translateKeyValueToPlacementConstraints(service.ServiceConstraints); config.TaskTemplate.Resources = { Limits: { @@ -382,18 +382,5 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi return []; } - function translateKeyValueToConstraints(keyValueConstraints) { - if (keyValueConstraints) { - var constraints = []; - keyValueConstraints.forEach(function(keyValueConstraint) { - if (keyValueConstraint.key && keyValueConstraint.key !== '' && keyValueConstraint.value && keyValueConstraint.value !== '') { - constraints.push(keyValueConstraint.key + keyValueConstraint.operator + keyValueConstraint.value); - } - }); - return constraints; - } - return []; - } - fetchServiceDetails(); }]); diff --git a/app/helpers/serviceHelper.js b/app/helpers/serviceHelper.js index c5e4a2e58..1b2f453ce 100644 --- a/app/helpers/serviceHelper.js +++ b/app/helpers/serviceHelper.js @@ -12,6 +12,18 @@ angular.module('portainer.helpers') Networks: service.Spec.Networks, EndpointSpec: service.Spec.EndpointSpec }; - } + }, + translateKeyValueToPlacementConstraints: function(keyValueConstraints) { + if (keyValueConstraints) { + var constraints = []; + keyValueConstraints.forEach(function(keyValueConstraint) { + if (keyValueConstraint.key && keyValueConstraint.key !== '' && keyValueConstraint.value && keyValueConstraint.value !== '') { + constraints.push(keyValueConstraint.key + keyValueConstraint.operator + keyValueConstraint.value); + } + }); + return constraints; + } + return []; + } }; }]);