Пример #1
0
        public ushort StartContainerProcess(ComputeConfigurationItem config)
        {
            ushort port = this.GetNextPort(config.MinPort, config);
            var    newContainerProcess = this.StartNewContainerProcess(port, config);

            return(newContainerProcess.Port);
        }
Пример #2
0
        private ushort GetNextPort(ushort prevPort, ComputeConfigurationItem config)
        {
            ushort?currPort = this.FindAvailablePortInClosedInterval((ushort)(prevPort + 1), config.MaxPort);

            return(currPort
                   ?? this.FindAvailablePortInClosedInterval(config.MinPort, (ushort)(prevPort - 1))
                   ?? throw new Exception($"Could not find available ports in range [{config.MinPort}, {config.MaxPort}]"));
        }
Пример #3
0
        /// <summary>
        /// Starts number of containers as defined in config file
        /// </summary>
        public void StartContainerProcesses(ComputeConfigurationItem config)
        {
            ushort currPort = this.GetNextPort(prevPort: config.MinPort, config);

            for (int i = 0; i < config.NumberOfContainersToStart; ++i)
            {
                var newProcess = this.StartNewContainerProcess(currPort, config);
                currPort = this.GetNextPort(prevPort: newProcess.Port, config);
            }
        }
        private static void Stop(ComputeConfigurationItem configItem)
        {
            var closeServerTask            = Task.Run(() => roleEnvironmentHost.Close());
            var closeComputeManagementTask = Task.Run(() => computeManagementHost.Close());

            packageWatcher.Stop();
            containerHealthMonitor.Stop();

            processManager.StopAllProcesses();

            new PackageController().DeletePackage(configItem.PackageTempFullFolderPath);

            closeServerTask.GetAwaiter().GetResult();
            closeComputeManagementTask.GetAwaiter().GetResult();
        }
Пример #5
0
        /// <summary>
        /// Starts up new container process with given port as it's argument
        /// </summary>
        /// <returns>New container process</returns>
        /// <exception cref="InvalidOperationException"></exception>
        /// <exception cref="System.IO.FileNotFoundException"></exception>
        /// <exception cref="ObjectDisposedException"></exception>
        /// <exception cref="System.ComponentModel.Win32Exception"></exception>
        private ContainerProcess StartNewContainerProcess(ushort port, ComputeConfigurationItem config)
        {
            if (!this.IsPortAvailable(port))
            {
                throw new InvalidOperationException($"port={port} is already taken by another process!");
            }

            var newProcess = Process.Start(fileName: config.ContainerFullFilePath, arguments: $"{port}");

            this.containerProcessDictByPort[port] = new ContainerProcess(newProcess, port);

            Debug.WriteLine($"{typeof(ProcessManager).Name}: added container[{port}] ({DateTime.Now})");

            return(this.containerProcessDictByPort[port]);
        }
Пример #6
0
 public void ResetAllProcesses(ComputeConfigurationItem config)
 {
     this.StopAllProcesses();
     this.StartContainerProcesses(config);
 }