Пример #1
0
        public ClusterManager(IOptions <MyConfig> config, ILogger <AppManager> logger)
        {
            _config     = config.Value;
            _endPoint   = _config.ClusterEndPoint;
            _portNumber = int.Parse(this._config.ClusterPort);

            _client             = new HttpClient(new LoggingHandler(new HttpClientHandler(), logger));
            _client.BaseAddress = new Uri(string.Format(ClusterEndpointTemplate, _endPoint, _portNumber));
        }
Пример #2
0
 protected BaseApp(HttpClient client, MyConfig config, ILogger logger, SitePropsWrapper sitePropsWrapper, Language language)
 {
     Client     = client;
     _config    = config;
     _siteProps = sitePropsWrapper.SiteProps;
     AppName    = _siteProps.name;
     Language   = language;
     _logger    = logger;
 }
Пример #3
0
        public static async Task <BaseApp> CreateApp(HttpClient client, MyConfig config, ILogger <AppManager> logger, string appName)
        {
            using (var response = await client.PutAsJsonAsync(
                       $"/subscriptions/{config.Subscription}/resourceGroups/{config.ResourceGroup}/providers/Microsoft.Web/sites/{appName}?api-version=2016-03-01",
                       new
            {
                location = config.Region,
                properties = new
                {
                    siteConfig = new
                    {
                        appSettings = new[]
                        {
                            new
                            {
                                name = "DOCKER_CUSTOM_IMAGE_NAME",
                                value = config.DockerImageName
                            },
                            new
                            {
                                name = "DOCKER_REGISTRY_SERVER_URL",
                                value = config.DockerServerURL
                            },
                            new
                            {
                                name = "DOCKER_REGISTRY_SERVER_USERNAME",
                                value = config.DockerRegistryUserName
                            },
                            new
                            {
                                name = "DOCKER_REGISTRY_SERVER_PASSWORD",
                                value = config.DockerRegistryPassword
                            }
                        },
                        appCommandLine = "",
                        linuxFxVersion = $"DOCKER|{config.DockerImageName}"
                    },
                    serverFarmId = config.ServerFarmId,
                }
            }))
            {
                response.EnsureSuccessStatusCode();

                var json = await response.Content.ReadAsAsync <dynamic>();

                var app = new LinuxApp(client, config, logger, json.properties);

                await app.CompleteCreation();

                return(app);
            }
        }
Пример #4
0
        public RawACIManager(IOptions <MyConfig> config, ILogger <RawACIManager> logger)
        {
            _config = config.Value;

            string token = AuthenticationHelpers.AcquireTokenBySPN(
                _config.TenantId, _config.ClientId, _config.ClientSecret).Result;

            _client = new HttpClient(new LoggingHandler(new HttpClientHandler(), logger));
            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            _client.BaseAddress = new Uri("https://management.azure.com/");

//            CreateResourceGroup(_config.ResourceGroup).Wait();
        }
Пример #5
0
        public AppManager(IOptions <MyConfig> config, ILogger <AppManager> logger)
        {
            _config = config.Value;
            Logger  = logger;

            string token = AuthenticationHelpers.AcquireTokenBySPN(
                _config.TenantId, _config.ClientId, _config.ClientSecret).Result;

            _client = new HttpClient(new LoggingHandler(new HttpClientHandler(), logger));
            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            _client.BaseAddress = new Uri("https://management.azure.com/");

            _allFreeApps.Add(Language.Node, new Queue <BaseApp>());
            _allFreeApps.Add(Language.Ruby, new Queue <BaseApp>());

            Init().Wait();

            CreateNewAppsIfNeeded().Wait();

            Logger.LogInformation("Setting up background timer");
            _timer = new Timer(_ => BackgroundMaintenance().Wait(), null, 0, 60000);
        }
Пример #6
0
        public static async Task <BaseApp> CreateApp(HttpClient client, MyConfig config, ILogger <AppManager> logger, string appName)
        {
            return(await OperationManager.AttemptAsync(async() =>
            {
                using (var response = await client.PutAsJsonAsync(
                           $"/subscriptions/{config.Subscription}/resourceGroups/{config.ResourceGroup}/providers/Microsoft.Web/sites/{appName}?api-version=2016-03-01",
                           new
                {
                    location = config.Region,
                    kind = "functionapp",
                    properties = new
                    {
                        siteConfig = new
                        {
                            appSettings = new[]
                            {
                                new
                                {
                                    name = "FUNCFILE",
                                    value = "D:/local/funclite/index.js"
                                }
                            }
                        }
                    }
                }))
                {
                    response.EnsureSuccessStatusCode();

                    logger.LogInformation($"App {appName} was created successfully");

                    var json = await response.Content.ReadAsAsync <dynamic>();
                    var app = new WindowsApp(client, config, logger, json.properties);

                    await app.CompleteCreation();

                    return app;
                }
            }, 5, 2000));
        }
Пример #7
0
        public ACIManager(IOptions <MyConfig> config, ILogger <ACIManager> logger)
        {
            _config = config.Value;
            Logger  = logger;

            _lock = new SemaphoreSlim(1, 1);
            _backgroundTaskLock        = new SemaphoreSlim(1, 1);
            _containerGroupCollections = new ConcurrentDictionary <string, ContainerGroupCollection>(StringComparer.OrdinalIgnoreCase);
            _appUsageTimes             = new ConcurrentDictionary <string, List <long> >(StringComparer.OrdinalIgnoreCase);

            string token = AuthenticationHelpers.AcquireTokenBySPN(
                _config.TenantId, _config.ClientId, _config.ClientSecret).Result;

            _client = new HttpClient(new LoggingHandler(new HttpClientHandler(), logger));
            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            _client.BaseAddress = new Uri("https://management.azure.com/");

            _functionsHttpClient = new HttpClient();

            LoadExistingApps().Wait();

            _timer = new Timer(async _ => await BackgroundMaintenance(), null, 0, 60000); // 60 seconds
        }
Пример #8
0
 public WindowsApp(HttpClient client, MyConfig config, ILogger logger, dynamic siteProps) : base(client, config, logger, new SitePropsWrapper(siteProps), Language.Node)
 {
     _config = config;
 }
Пример #9
0
 public LinuxApp(HttpClient client, MyConfig config, ILogger <AppManager> logger, dynamic siteProps) : base(client, config, logger, new SitePropsWrapper(siteProps), Language.Ruby)
 {
 }