private EndPointModel createEndPoint(int currentDepth, int maxDepth, string name, ref List <IComponent> componentList)
        {
            if (currentDepth > maxDepth)
            {
                throw new Exception("current depth should not be larger than max tree depth");
            }

            IComponent leftEndPoint  = null;
            IComponent rightEndPoint = null;

            if (currentDepth < maxDepth)
            {
                leftEndPoint  = this.createEndPoint(currentDepth + 1, maxDepth, name + "0", ref componentList);
                rightEndPoint = this.createEndPoint(currentDepth + 1, maxDepth, name + "1", ref componentList);
            }
            else
            {
                leftEndPoint  = _containerService.CreateContainer(currentDepth + 1, name + "0");
                rightEndPoint = _containerService.CreateContainer(currentDepth + 1, name + "1");

                componentList.Add(leftEndPoint);
                componentList.Add(rightEndPoint);
            }

            EndPointModel endPoint = _endPointService.CreateEndPoint(currentDepth, name, leftEndPoint, rightEndPoint);

            componentList.Add(endPoint);

            return(endPoint);
        }
        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 async Task <IActionResult> Update(ContainerCreateViewModel container)
        {
            await _containerService.CreateContainer(container.Name);

            return(RedirectToAction("Index"));
        }