Exemplo n.º 1
0
        private async Task DelayAddContainerGroup(string appName, ContainerGroupCollection containerGroupCollection, ContainerGroup containerGroup)
        {
            await Task.Delay(ContainerGroupCreationMillisecondsDelay);

            containerGroupCollection.AddContainerGroup(containerGroup);
            _containerGroupCollections[appName] = containerGroupCollection;
        }
Exemplo n.º 2
0
        public async Task LoadExistingApps()
        {
            await _lock.WaitAsync();

            try
            {
                var jsonBody = await GetContainerGroups();

                JArray valueArray  = jsonBody.value;
                var    publicPorts = new HashSet <uint>();
                foreach (dynamic value in valueArray)
                {
                    string containerGroupName = value.name;
                    string appName            = ACIUtils.GetAppNameFromContainerGroupName(containerGroupName);
                    var    properties         = value.properties;
                    var    ipAddress          = properties.ipAddress;
                    string ip = ipAddress.ip;
                    if (ip == null)
                    {
                        continue;
                    }
                    var containerGroup = new ContainerGroup(containerGroupName, _config.Region, ip);
                    foreach (var port in ipAddress.ports)
                    {
                        uint portNo = port.port;
                        publicPorts.Add(portNo);
                    }
                    var containers = properties.containers;
                    foreach (var container in containers)
                    {
                        string containerName       = container.name;
                        var    containerProperties = container.properties;
                        string containerImage      = containerProperties.image;
                        var    currentContainer    = new Container(containerName, containerImage);
                        var    containerPorts      = containerProperties.ports;
                        foreach (var containerPort in containerPorts)
                        {
                            uint portNo = containerPort.port;
                            var  cPort  = new ContainerPort(portNo, publicPorts.Contains(portNo));
                            currentContainer.AddPort(cPort);
                        }
                        containerGroup.AddContainer(currentContainer);
                    }
                    ContainerGroupCollection containerGroupCollection;
                    if (!_containerGroupCollections.TryGetValue(appName, out containerGroupCollection))
                    {
                        containerGroupCollection = new ContainerGroupCollection(appName);
                    }
                    containerGroupCollection.AddContainerGroup(containerGroup);
                    _containerGroupCollections[appName] = containerGroupCollection;
                    publicPorts.Clear();
                }
            }
            finally
            {
                _lock.Release();
            }
        }
Exemplo n.º 3
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();
            }
        }