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));
        }
예제 #2
0
 protected async Task <CloudResource> GetVirtualMachineResourceEntry(int id, UserOperation operation, CancellationToken cancellation = default)
 {
     return(await _cloudResourceReadService.GetByIdAsync(id, operation));
 }