コード例 #1
0
        public void DestroyContainer(ContainerHandle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }

            Container removed;

            if (containers.TryRemove(handle, out removed))
            {
                try
                {
                    removed.Destroy();
                }
                catch
                {
                    log.Error("Error destroying container! Re-adding to collection.");
                    containers[handle] = removed;
                    throw;
                }
            }
            else
            {
                throw new WardenException("Could not remove container '{0}' from collection!", handle);
            }
        }
コード例 #2
0
        public Container()
        {
            this.handle    = new ContainerHandle();
            this.user      = new ContainerUser(handle, shouldCreate: true);
            this.directory = new ContainerDirectory(this.handle, this.user, true);
            this.state     = ContainerState.Born;

            this.processManager = new ProcessManager(this.user);
        }
コード例 #3
0
        private static Tuple <DirectoryInfo, string> GetContainerDirectoryInfo(ContainerHandle handle)
        {
            var config = new WardenConfig();

            string containerBasePath  = config.ContainerBasePath;
            string containerDirectory = Path.Combine(containerBasePath, handle);

            return(new Tuple <DirectoryInfo, string>(new DirectoryInfo(containerBasePath), containerDirectory));
        }
コード例 #4
0
        public Container GetContainer(string handle)
        {
            var       cHandle = new ContainerHandle(handle);
            Container retrieved;

            if (!containers.TryGetValue(cHandle, out retrieved))
            {
                // TODO: throw exception with message that matches ruby warden
                log.Warn("Expected to find container with handle '{0}'", handle);
            }
            return(retrieved);
        }
コード例 #5
0
        private static DirectoryInfo FindContainerDirectory(ContainerHandle handle)
        {
            var dirInfo = GetContainerDirectoryInfo(handle);

            if (Directory.Exists(dirInfo.Item2))
            {
                return(new DirectoryInfo(dirInfo.Item2));
            }
            else
            {
                throw new WardenException("Directory '{0}' does not exist!", dirInfo.Item2);
            }
        }
コード例 #6
0
        public async Task DestroyContainerAsync(ContainerHandle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }

            IContainerClient removed;

            if (containerClients.TryRemove(handle, out removed))
            {
                await removed.Destroy();
            }
        }
コード例 #7
0
        public ContainerDirectory(ContainerHandle handle, ContainerUser user, bool shouldCreate = false)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }

            if (shouldCreate)
            {
                this.containerDirectory = CreateContainerDirectory(handle, user);
            }
            else
            {
                this.containerDirectory = FindContainerDirectory(handle);
            }
        }
コード例 #8
0
        private static DirectoryInfo CreateContainerDirectory(ContainerHandle handle, ContainerUser user)
        {
            var dirInfo = GetContainerDirectoryInfo(handle);

            var inheritanceFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
            var accessRule       = new FileSystemAccessRule(user, FileSystemRights.FullControl, inheritanceFlags,
                                                            PropagationFlags.None, AccessControlType.Allow);

            DirectoryInfo     containerBaseInfo = dirInfo.Item1;
            DirectorySecurity security          = containerBaseInfo.GetAccessControl();

            security.AddAccessRule(accessRule);

            string containerDirectory = dirInfo.Item2;

            return(Directory.CreateDirectory(containerDirectory, security));
        }
コード例 #9
0
        /// <summary>
        /// Used for restore.
        /// </summary>
        private Container(string handle, ContainerState containerState)
        {
            if (handle.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("handle");
            }
            this.handle = new ContainerHandle(handle);

            if (containerState == null)
            {
                throw new ArgumentNullException("containerState");
            }
            this.state = containerState;

            this.user      = new ContainerUser(handle);
            this.directory = new ContainerDirectory(this.handle, this.user);

            this.processManager = new ProcessManager(this.user);

            if (this.state == ContainerState.Active)
            {
                this.RestoreProcesses();
            }
        }