コード例 #1
0
        public async Task <List <SandboxResourceLight> > GetSandboxResourcesLight(int sandboxId)
        {
            var sandboxFromDb = await _sandboxModelService.GetByIdForResourcesAsync(sandboxId);

            //Filter out deleted resources
            var resourcesFiltered = sandboxFromDb.Resources
                                    .Where(r => !SoftDeleteUtil.IsMarkedAsDeleted(r) ||
                                           (
                                               SoftDeleteUtil.IsMarkedAsDeleted(r) &&
                                               !r.Operations.Where(o => o.OperationType == CloudResourceOperationType.DELETE && o.Status == CloudResourceOperationState.DONE_SUCCESSFUL).Any())

                                           ).ToList();

            var resourcesMapped = _mapper.Map <List <SandboxResourceLight> >(resourcesFiltered);

            return(resourcesMapped);
        }
コード例 #2
0
        public async Task <SandboxResourceLight> RetryResourceFailedOperation(int resourceId)
        {
            var resource = await _cloudResourceReadService.GetByIdAsync(resourceId, UserOperation.Study_Crud_Sandbox);

            var operationToRetry = FindOperationToRetry(resource);

            if (operationToRetry == null)
            {
                throw new BadRequestException(ReScheduleResourceLogPrefix(resource, "Could not locate any relevant operation to retry"));
            }

            if (resource.ResourceType == AzureResourceType.VirtualMachine)
            {
                var sandbox = await _sandboxModelService.GetByIdForResourcesAsync(resource.SandboxId.Value);

                if (!AllSandboxResourcesOkay(sandbox))
                {
                    throw new NullReferenceException(ReScheduleResourceLogPrefix(resource, $"Cannot retry VM creation for {resource.ResourceName} when Sandbox is not setup properly", operationToRetry));
                }

                await EnsureOperationIsReadyForRetryAndEnqueue(resource, operationToRetry);
            }
            else if (resource.SandboxControlled)
            {
                if (operationToRetry.OperationType == CloudResourceOperationType.CREATE)
                {
                    //Must re-start all succeeding operations
                    await ReScheduleSandboxResourceCreation(resource.Sandbox.Id);
                }

                else
                {
                    await EnsureOperationIsReadyForRetryAndEnqueue(resource, operationToRetry);
                }
            }
            else
            {
                throw new ArgumentException($"Retry is not supported for resource type: {resource.ResourceType} ");
            }

            return(_mapper.Map <SandboxResourceLight>(resource));
        }