Пример #1
0
        private async Task DelayAddContainerGroup(string appName, ContainerGroupCollection containerGroupCollection, ContainerGroup containerGroup)
        {
            await Task.Delay(ContainerGroupCreationMillisecondsDelay);

            containerGroupCollection.AddContainerGroup(containerGroup);
            _containerGroupCollections[appName] = containerGroupCollection;
        }
Пример #2
0
        public async Task CreateApp(string appName, dynamic appDefinition)
        {
            await _lock.WaitAsync();

            try
            {
                if (_containerGroupCollections.ContainsKey(appName))
                {
                    throw new Exception($"{appName} exists already");
                }

                var containerGroupDefinition = appDefinition.containerGroup;
                var containerDefinitions     = containerGroupDefinition.containers;

                var containerGroupName = ACIUtils.GetContainerGroupNameForAppName(appName);
                var containerGroup     = new ContainerGroup(containerGroupName, _config.Region, "");
                foreach (var containerDefinition in containerDefinitions)
                {
                    string containerName            = containerDefinition.name;
                    string image                    = containerDefinition.image;
                    var    container                = new Container(containerName, image);
                    var    containerPortsDefinition = containerDefinition.ports;

                    foreach (var containerPortDefinition in containerPortsDefinition)
                    {
                        uint   port          = containerPortDefinition.port;
                        string typeString    = containerPortDefinition.type;
                        var    isPublic      = typeString.Equals("public", StringComparison.OrdinalIgnoreCase);
                        var    containerPort = new ContainerPort(port, isPublic);
                        container.AddPort(containerPort);
                    }
                    containerGroup.AddContainer(container);
                }

                containerGroup.IpAddress = await CreateContainerGroup(containerGroup);

                var containerGroupCollection = new ContainerGroupCollection(appName);
                containerGroupCollection.AddContainerGroup(containerGroup);
                _containerGroupCollections[appName] = containerGroupCollection;
                await Task.Delay(ContainerGroupCreationMillisecondsDelay);
            }
            finally
            {
                _lock.Release();
            }
        }