2018-08-22 15:33:06 +00:00
|
|
|
function ServiceViewModel(data, runningTasks, allTasks) {
|
2017-01-31 23:26:29 +00:00
|
|
|
this.Model = data;
|
|
|
|
this.Id = data.ID;
|
2017-10-15 17:24:40 +00:00
|
|
|
this.Tasks = [];
|
2017-01-31 23:26:29 +00:00
|
|
|
this.Name = data.Spec.Name;
|
2017-03-20 20:28:09 +00:00
|
|
|
this.CreatedAt = data.CreatedAt;
|
|
|
|
this.UpdatedAt = data.UpdatedAt;
|
2017-01-31 23:26:29 +00:00
|
|
|
this.Image = data.Spec.TaskTemplate.ContainerSpec.Image;
|
|
|
|
this.Version = data.Version.Index;
|
|
|
|
if (data.Spec.Mode.Replicated) {
|
|
|
|
this.Mode = 'replicated' ;
|
|
|
|
this.Replicas = data.Spec.Mode.Replicated.Replicas;
|
|
|
|
} else {
|
|
|
|
this.Mode = 'global';
|
2017-11-06 14:50:59 +00:00
|
|
|
if (allTasks) {
|
|
|
|
this.Replicas = allTasks.length;
|
2017-03-12 17:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (runningTasks) {
|
|
|
|
this.Running = runningTasks.length;
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|
2017-03-20 20:28:09 +00:00
|
|
|
if (data.Spec.TaskTemplate.Resources) {
|
|
|
|
if (data.Spec.TaskTemplate.Resources.Limits) {
|
|
|
|
this.LimitNanoCPUs = data.Spec.TaskTemplate.Resources.Limits.NanoCPUs;
|
|
|
|
this.LimitMemoryBytes = data.Spec.TaskTemplate.Resources.Limits.MemoryBytes;
|
|
|
|
}
|
|
|
|
if (data.Spec.TaskTemplate.Resources.Reservations) {
|
|
|
|
this.ReservationNanoCPUs = data.Spec.TaskTemplate.Resources.Reservations.NanoCPUs;
|
|
|
|
this.ReservationMemoryBytes = data.Spec.TaskTemplate.Resources.Reservations.MemoryBytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.Spec.TaskTemplate.RestartPolicy) {
|
2017-11-23 09:47:39 +00:00
|
|
|
this.RestartCondition = data.Spec.TaskTemplate.RestartPolicy.Condition || 'any';
|
|
|
|
this.RestartDelay = data.Spec.TaskTemplate.RestartPolicy.Delay || 5000000000;
|
|
|
|
this.RestartMaxAttempts = data.Spec.TaskTemplate.RestartPolicy.MaxAttempts || 0;
|
|
|
|
this.RestartWindow = data.Spec.TaskTemplate.RestartPolicy.Window || 0;
|
2017-03-20 20:28:09 +00:00
|
|
|
} else {
|
2017-11-23 09:47:39 +00:00
|
|
|
this.RestartCondition = 'any';
|
|
|
|
this.RestartDelay = 5000000000;
|
2017-03-20 20:28:09 +00:00
|
|
|
this.RestartMaxAttempts = 0;
|
|
|
|
this.RestartWindow = 0;
|
|
|
|
}
|
2017-12-22 09:05:31 +00:00
|
|
|
|
|
|
|
if (data.Spec.TaskTemplate.LogDriver) {
|
|
|
|
this.LogDriverName = data.Spec.TaskTemplate.LogDriver.Name || '';
|
|
|
|
this.LogDriverOpts = data.Spec.TaskTemplate.LogDriver.Options || [];
|
|
|
|
} else {
|
|
|
|
this.LogDriverName = '';
|
|
|
|
this.LogDriverOpts = [];
|
|
|
|
}
|
2018-06-20 13:53:58 +00:00
|
|
|
|
2017-03-20 20:28:09 +00:00
|
|
|
this.Constraints = data.Spec.TaskTemplate.Placement ? data.Spec.TaskTemplate.Placement.Constraints || [] : [];
|
2017-07-10 07:33:09 +00:00
|
|
|
this.Preferences = data.Spec.TaskTemplate.Placement ? data.Spec.TaskTemplate.Placement.Preferences || [] : [];
|
|
|
|
this.Platforms = data.Spec.TaskTemplate.Placement ? data.Spec.TaskTemplate.Placement.Platforms || [] : [];
|
2017-01-31 23:26:29 +00:00
|
|
|
this.Labels = data.Spec.Labels;
|
2017-10-15 17:24:40 +00:00
|
|
|
if (this.Labels && this.Labels['com.docker.stack.namespace']) {
|
|
|
|
this.StackName = this.Labels['com.docker.stack.namespace'];
|
|
|
|
}
|
2017-03-20 20:28:09 +00:00
|
|
|
|
|
|
|
var containerSpec = data.Spec.TaskTemplate.ContainerSpec;
|
|
|
|
if (containerSpec) {
|
|
|
|
this.ContainerLabels = containerSpec.Labels;
|
|
|
|
this.Command = containerSpec.Command;
|
2017-05-18 21:32:04 +00:00
|
|
|
this.Arguments = containerSpec.Args;
|
2017-07-10 07:33:09 +00:00
|
|
|
this.Hostname = containerSpec.Hostname;
|
|
|
|
this.Env = containerSpec.Env;
|
|
|
|
this.Dir = containerSpec.Dir;
|
|
|
|
this.User = containerSpec.User;
|
|
|
|
this.Groups = containerSpec.Groups;
|
|
|
|
this.TTY = containerSpec.TTY;
|
|
|
|
this.OpenStdin = containerSpec.OpenStdin;
|
|
|
|
this.ReadOnly = containerSpec.ReadOnly;
|
|
|
|
this.Mounts = containerSpec.Mounts || [];
|
|
|
|
this.StopSignal = containerSpec.StopSignal;
|
|
|
|
this.StopGracePeriod = containerSpec.StopGracePeriod;
|
|
|
|
this.HealthCheck = containerSpec.HealthCheck || {};
|
|
|
|
this.Hosts = containerSpec.Hosts;
|
|
|
|
this.DNSConfig = containerSpec.DNSConfig;
|
2017-03-20 20:28:09 +00:00
|
|
|
this.Secrets = containerSpec.Secrets;
|
2017-11-06 08:47:31 +00:00
|
|
|
this.Configs = containerSpec.Configs;
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|
2017-03-30 09:39:37 +00:00
|
|
|
if (data.Endpoint) {
|
|
|
|
this.Ports = data.Endpoint.Ports;
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|
2017-03-20 20:28:09 +00:00
|
|
|
|
2017-07-10 07:33:09 +00:00
|
|
|
this.LogDriver = data.Spec.TaskTemplate.LogDriver;
|
|
|
|
this.Runtime = data.Spec.TaskTemplate.Runtime;
|
2017-03-20 20:28:09 +00:00
|
|
|
|
|
|
|
this.VirtualIPs = data.Endpoint ? data.Endpoint.VirtualIPs : [];
|
|
|
|
|
2017-01-31 23:26:29 +00:00
|
|
|
if (data.Spec.UpdateConfig) {
|
|
|
|
this.UpdateParallelism = (typeof data.Spec.UpdateConfig.Parallelism !== undefined) ? data.Spec.UpdateConfig.Parallelism || 0 : 1;
|
|
|
|
this.UpdateDelay = data.Spec.UpdateConfig.Delay || 0;
|
|
|
|
this.UpdateFailureAction = data.Spec.UpdateConfig.FailureAction || 'pause';
|
2017-08-09 13:30:50 +00:00
|
|
|
this.UpdateOrder = data.Spec.UpdateConfig.Order || 'stop-first';
|
2017-01-31 23:26:29 +00:00
|
|
|
} else {
|
|
|
|
this.UpdateParallelism = 1;
|
|
|
|
this.UpdateDelay = 0;
|
|
|
|
this.UpdateFailureAction = 'pause';
|
2017-08-09 13:30:50 +00:00
|
|
|
this.UpdateOrder = 'stop-first';
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 07:33:09 +00:00
|
|
|
this.RollbackConfig = data.Spec.RollbackConfig;
|
|
|
|
|
2017-01-31 23:26:29 +00:00
|
|
|
this.Checked = false;
|
|
|
|
this.Scale = false;
|
|
|
|
this.EditName = false;
|
2017-03-12 16:24:15 +00:00
|
|
|
|
|
|
|
if (data.Portainer) {
|
|
|
|
if (data.Portainer.ResourceControl) {
|
2017-05-23 18:56:10 +00:00
|
|
|
this.ResourceControl = new ResourceControlViewModel(data.Portainer.ResourceControl);
|
2017-03-12 16:24:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|