private void container_down(object sender, RoutedEventArgs e) { if ((this.selection is null) || (this.selection.is_category) || (!this.state.items.ContainsKey(this.selection.name))) { return; } ElementReference <ItemSpec> item_ref = this.state.items[this.selection.name]; if (item_ref.ref_count > 0) { return; } int idx = this.container_list.SelectedIndex; if ((idx < 0) || (idx >= this.containers.Count - 1)) { return; } ContainerSpec container = this.containers[idx]; this.containers[idx] = this.containers[idx + 1]; this.containers[idx + 1] = container; ItemSpecContainerRow row = this.container_rows[idx]; this.container_rows[idx] = this.container_rows[idx + 1]; this.container_rows[idx + 1] = row; this.container_list.Items.Refresh(); this.set_dirty(); }
public override Task <Response> HandleAsync() { return(Task.Run <Response>(async() => { var config = new WardenConfig(); var handle = new ContainerHandle(); var containerService = new ContainerService( config.ContainerBasePath, config.WardenUsersGroup); var containerSpec = new ContainerSpec { Handle = handle, BindMounts = GetBindMounts(request).ToArray(), }; var container = containerService.CreateContainer(containerSpec); var containerClient = new ContainerClient(containerService, container, new FileSystemManager()); await containerClient.InitializeAsync(null, null, null); containerManager.AddContainer(containerClient); return new CreateResponse { Handle = handle }; })); }
private byte[][] PopulateInitialState() { if (this.parameters.CurrentAllocations != null && this.parameters.CurrentAllocations.Length != 0) { ILookup <string, string> allocationByMachine = this.parameters.CurrentAllocations .ToLookup(c => c.Machine.Name, d => d.ContainerSpec.Name); for (int i = 0; i < this.Rows; i++) { string machine = this.parameters.Machines[i].Name; IDictionary <string, string> containersByName = allocationByMachine[machine].ToDictionary(c => c); for (int j = 0; j < this.Columns; j++) { ContainerSpec container = this.parameters.ContainerSpecs[j]; if (containersByName.ContainsKey(container.Name)) { this.initialState[i][j] = 1; } } } } return(this.initialState); }
public Properties() { ContainerSpec = new ContainerSpec { Handle = Container1Handle, }; }
public ImpersonateContainerUser() { ContainerSpec = new ContainerSpec { Handle = Container1Handle, }; }
private void container_edit(object sender, RoutedEventArgs e) { if ((this.selection is null) || (this.selection.is_category) || (!this.state.items.ContainsKey(this.selection.name))) { return; } ElementReference <ItemSpec> item_ref = this.state.items[this.selection.name]; if (item_ref.ref_count > 0) { return; } int idx = this.container_list.SelectedIndex; if ((idx < 0) || (idx >= this.containers.Count)) { return; } ContainerSpec container = this.containers[idx]; QueryPrompt[] prompts = new QueryPrompt[] { new QueryPrompt("Name:", QueryType.STRING, container.name), new QueryPrompt("Weight Factor:", QueryType.FLOAT, (double)(container.weight_factor), step: 0.125), new QueryPrompt("Weight Capacity:", QueryType.FLOAT, (double)(container.weight_capacity ?? 0)), }; object[] results = SimpleDialog.askCompound("Edit Container", prompts, this); if (results is null) { return; } string name = results[0] as string; double?weight_factor = results[1] as double?, weight_capacity = results[2] as double?; if ((name is null) || (weight_factor is null)) { return; } if (weight_capacity == 0) { weight_capacity = null; } container.name = name; container.weight_factor = (decimal)weight_factor; container.weight_capacity = (decimal?)weight_capacity; ItemSpecContainerRow row = this.container_rows[idx]; row._name = name; row._weight_factor = container.weight_factor.ToString(); row._weight_capacity = container.weight_capacity.ToString(); this.container_list.Items.Refresh(); this.fix_listview_column_widths(this.container_list); this.set_dirty(); }
public WithContainer(AcceptanceFixture fixture) : base(fixture) { var spec = new ContainerSpec { Handle = Guid.NewGuid().ToString("N"), }; Container = Service.CreateContainer(spec); WriteUserFileToContainer("run.bat", RunBatFileContent); }
public IContainer CreateContainer(string handle) { var environment = new Dictionary <string, string> { { "CONTAINER_HANDLE", handle }, { "CONTAINER_ENV1", "ENV1" } }; var spec = new ContainerSpec { Environment = environment, Handle = handle }; return(CreateContainer(spec)); }
public CreateResponse Create(ContainerSpecApiModel spec) { if (spec.Env == null) { spec.Env = new List <string>(); } var containerSpec = new ContainerSpec { Handle = spec.Handle, Properties = spec.Properties, Environment = ContainerService.EnvsFromList(spec.Env) }; try { var container = containerService.CreateContainer(containerSpec); container.SetActiveProcessLimit(CONTAINER_ACTIVE_PROCESS_LIMIT); container.SetPriorityClass(ProcessPriorityClass.BelowNormal); if (spec.Limits.MemoryLimits.LimitInBytes != null) { container.LimitMemory(spec.Limits.MemoryLimits.LimitInBytes.Value); } if (spec.Limits.CpuLimits.Weight != null) { container.LimitCpu(spec.Limits.CpuLimits.Weight.Value); } if (spec.Limits.DiskLimits.ByteHard != null) { container.LimitDisk(spec.Limits.DiskLimits.ByteHard.Value); } return(new CreateResponse { Handle = container.Handle }); } catch (PrincipalExistsException) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Conflict, string.Format("handle already exists: {0}", spec.Handle))); } catch (Exception ex) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public CreateResponse Create(ContainerSpecApiModel spec) { if (spec.Env == null) { spec.Env = new List <string>(); } var containerSpec = new ContainerSpec { Handle = spec.Handle, Properties = spec.Properties, Environment = ContainerService.EnvsFromList(spec.Env), BindMounts = spec.BindMounts.Select(b => b.ToIronFrame()).ToArray() }; try { var container = containerService.CreateContainer(containerSpec); container.SetActiveProcessLimit(CONTAINER_ACTIVE_PROCESS_LIMIT); container.SetPriorityClass(ProcessPriorityClass.BelowNormal); container.LimitCpu(CONTAINER_DEFAULT_CPU_WEIGHT); if (spec.Limits.MemoryLimits.LimitInBytes != null) { container.LimitMemory(spec.Limits.MemoryLimits.LimitInBytes.Value); } if (spec.Limits.DiskLimits.ByteHard != null) { container.LimitDisk(spec.Limits.DiskLimits.ByteHard.Value); } if (spec.GraceTime.HasValue) { container.SetProperty("GraceTime", spec.GraceTime.Value.ToString()); } return(new CreateResponse { Handle = container.Handle }); } catch (PrincipalExistsException) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Conflict, string.Format("handle already exists: {0}", spec.Handle))); } }
public ContainerSpec[] BuildMany(int count) { ContainerSpec[] containers = new ContainerSpec[count]; int seed = Random.Next(); for (int i = 0; i < count; i++) { ContainerSpec container = new ContainerSpec { Name = "Container" + seed + i, ResourceUsages = this.Resources.ToArray().Copy(), DesiredInstanceCount = this.desiredInstanceCount }; containers[i] = container; } return(containers); }
private void container_add(object sender, RoutedEventArgs e) { if ((this.selection is null) || (this.selection.is_category) || (!this.state.items.ContainsKey(this.selection.name))) { return; } ElementReference <ItemSpec> item_ref = this.state.items[this.selection.name]; if (item_ref.ref_count > 0) { return; } QueryPrompt[] prompts = new QueryPrompt[] { new QueryPrompt("Name:", QueryType.STRING), new QueryPrompt("Weight Factor:", QueryType.FLOAT, 1.0, step: 0.125), new QueryPrompt("Weight Capacity:", QueryType.FLOAT), }; object[] results = SimpleDialog.askCompound("Add Container", prompts, this); if (results is null) { return; } string name = results[0] as string; double?weight_factor = results[1] as double?, weight_capacity = results[2] as double?; if ((name is null) || (weight_factor is null)) { return; } if (weight_capacity == 0) { weight_capacity = null; } ContainerSpec container = new ContainerSpec(name, (decimal)weight_factor, (decimal?)weight_capacity); this.containers.Add(container); this.container_rows.Add(new ItemSpecContainerRow(container.name, container.weight_factor.ToString(), container.weight_capacity.ToString())); this.container_list.Items.Refresh(); this.fix_listview_column_widths(this.container_list); this.set_dirty(); }
/// <inheritdoc/> public void Normalize() { ContainerSpec = ContainerSpec ?? new ServiceContainerSpec(); Resources = Resources ?? new ServiceResources(); RestartPolicy = RestartPolicy ?? new ServiceRestartPolicy(); Placement = Placement ?? new ServicePlacement(); Networks = Networks ?? new List <ServiceNetwork>(); EndpointSpec = EndpointSpec ?? new ServiceEndpointSpec(); ContainerSpec?.Normalize(); Resources?.Normalize(); RestartPolicy?.Normalize(); Placement?.Normalize(); LogDriver?.Normalize(); EndpointSpec?.Normalize(); foreach (var item in Networks) { item?.Normalize(); } }
public void CanCreateContainer() { var spec = new ContainerSpec { Handle = Guid.NewGuid().ToString("N"), }; IContainer container = null; try { container = Service.CreateContainer(spec); Assert.NotNull(container); } finally { if (container != null) { Service.DestroyContainer(container.Handle); } } }
public IContainer CreateContainer(ContainerSpec spec) { var container = ContainerService.CreateContainer(spec); return container; }
public IContainer CreateContainer(string handle) { var environment = new Dictionary<string, string> { {"CONTAINER_HANDLE", handle}, {"CONTAINER_ENV1", "ENV1"} }; var spec = new ContainerSpec { Environment = environment, Handle = handle }; return CreateContainer(spec); }
public IContainer CreateContainer(ContainerSpec spec) { var container = ContainerService.CreateContainer(spec); return(container); }
private void AssignInstancesToMaximizeResourceUtilization() { Machine[] machinesWithResourceToMaximize = this.parameters.Machines .Where(c => c.AvailableResources.Any(x => x.Requires(this.parameters.MaximizeResourceUsageFor.Value))) .ToArray(); ContainerSpec[] containersWithResourceToMaximize = this.parameters.ContainerSpecs .Where(c => c.ResourceUsages.Any(x => x.Requires(this.parameters.MaximizeResourceUsageFor.Value))) .ToArray(); int numerator = GetTotalResourceAmount(this.parameters.MaximizeResourceUsageFor.Value, machinesWithResourceToMaximize); int denominator0 = GetTotalResourceRequirement(this.parameters.MaximizeResourceUsageFor.Value, containersWithResourceToMaximize); if (denominator0 == 0) { return; } int approximateInstances = numerator / denominator0; Dictionary <string, ContainerSpec> excluded = new Dictionary <string, ContainerSpec>(); foreach (ContainerSpec container in containersWithResourceToMaximize) { if (container.DesiredInstanceCount > approximateInstances) { excluded.Add(container.Name, container); } } int resourceAmountForAllExcludedContainerInstances = excluded.Sum(c => c.Value.ResourceUsages.Where(ru => ru.Kind == this.parameters.MaximizeResourceUsageFor.Value).Select(ru => ru.Value * c.Value.DesiredInstanceCount).Sum()); int totalResourceAmount = GetTotalResourceAmount(this.parameters.MaximizeResourceUsageFor.Value, machinesWithResourceToMaximize) - resourceAmountForAllExcludedContainerInstances; int resourceAmountForExcludedContainerTypes = excluded.Sum(c => c.Value.ResourceUsages.Where(ru => ru.Kind == this.parameters.MaximizeResourceUsageFor.Value).Select(ru => ru.Value).Sum()); int denominator = GetTotalResourceRequirement(this.parameters.MaximizeResourceUsageFor.Value, containersWithResourceToMaximize) - resourceAmountForExcludedContainerTypes; if (denominator == 0) { return; } int instancesPerContainer = totalResourceAmount / denominator; int remainingResourceAmount = totalResourceAmount % denominator; for (int i = 0; i < this.desiredContainerInstanceCounts.Length; i++) { ContainerSpec container = this.parameters.ContainerSpecs[i]; if (container.ResourceUsages.Any(c => c.Requires(this.parameters.MaximizeResourceUsageFor.Value))) { if (!excluded.ContainsKey(container.Name)) { int instances = instancesPerContainer; int resourcePerContainer = container.ResourceUsages.First(c => c.Requires(this.parameters.MaximizeResourceUsageFor.Value)).Value; if (remainingResourceAmount >= resourcePerContainer) { instances++; remainingResourceAmount -= resourcePerContainer; } this.desiredContainerInstanceCounts[i] = instances; } } } }