示例#1
0
        public async Task CreatePool(RenderingEnvironment environment, Pool pool)
        {
            using (var client = await _managementClient.CreateBatchManagementClient(environment.SubscriptionId))
            {
                await client.Pool.CreateAsync(environment.BatchAccount.ResourceGroupName, environment.BatchAccount.Name, pool.Name, pool);
            }

            // TODO: add the pool object to the cache
            var cacheKey = CacheKeys.MakeKey(CacheKeys.PoolList, environment.Name);

            _httpContextAccessor.HttpContext.Session.Remove(cacheKey);
        }
示例#2
0
        private async Task <RequestStatus> PerformRequest(ScaleUpRequestEntity request)
        {
            var env = await _envs.GetEnvironment(request.EnvironmentName);

            if (env == null)
            {
                _logger.LogInformation(
                    "Environment '{0}' has been deleted, discarding scale request '{1}'",
                    request.EnvironmentName,
                    request.ETag);

                return(RequestStatus.Completed);
            }

            using (var batchClient = await _clientProvider.CreateBatchManagementClient(env.SubscriptionId))
            {
                try
                {
                    var pool = await batchClient.Pool.GetAsync(env.BatchAccount.ResourceGroupName, env.BatchAccount.Name, request.PoolName);

                    if (pool == null || pool.ProvisioningState == PoolProvisioningState.Deleting)
                    {
                        _logger.LogInformation(
                            "Pool '{0}' (in environment '{1}') has been deleted, discarding scale request '{2}'",
                            request.PoolName,
                            request.EnvironmentName,
                            request.ETag);

                        return(RequestStatus.Completed);
                    }

                    if (pool.AllocationState == AllocationState.Resizing)
                    {
                        var op = pool.ResizeOperationStatus;
                        if (op != null && ((op.TargetDedicatedNodes ?? 0) + (op.TargetLowPriorityNodes ?? 0)) >= request.TargetNodes)
                        {
                            _logger.LogInformation(
                                "A resize operation on pool '{0}' (in environment '{1}') has made scale request '{2}' redundant, discarding it",
                                request.PoolName,
                                request.EnvironmentName,
                                request.ETag);

                            return(RequestStatus.Completed);
                        }
                        else
                        {
                            _logger.LogInformation(
                                "Pool '{0}' (in environment '{1}') is already being resized. Waiting to apply scale request '{2}'",
                                request.PoolName,
                                request.EnvironmentName,
                                request.ETag);

                            return(RequestStatus.InProgress);
                        }
                    }

                    var targets = CalculateNodeTargets(request, pool);

                    var newPool =
                        new Pool(name: pool.Name)
                    {
                        ScaleSettings =
                            new ScaleSettings
                        {
                            FixedScale =
                                new FixedScaleSettings(
                                    targetLowPriorityNodes: targets.lowPriority,
                                    targetDedicatedNodes: targets.dedicated)
                        }
                    };

                    await batchClient.Pool.UpdateAsync(env.BatchAccount.ResourceGroupName, env.BatchAccount.Name, request.PoolName, newPool);

                    _logger.LogInformation(
                        "Successfully applied scale request '{0}' to pool '{1}' (in environment '{2}')",
                        request.ETag,
                        request.PoolName,
                        request.EnvironmentName);
                }
                catch (CloudException ce) when(ce.ResourceNotFound())
                {
                    // Pool is gone - complete the request to remove it.
                }

                return(RequestStatus.Completed);
            }
        }