private async Task <TesTask> CreateCwlTesTaskAsync(string cwlFileContent, TesResources tesResourcesReceivedFromCromwell)
        {
            var tesTask = new TesTask()
            {
                Name      = "test.cwl",
                Executors = new List <TesExecutor> {
                    new TesExecutor {
                        Image = "ubuntu"
                    }
                },
                Inputs = new List <TesInput> {
                    new TesInput {
                        Path = "/cromwell-executions/test.cwl/daf1a044-d741-4db9-8eb5-d6fd0519b1f1/call-hello/execution/script"
                    }
                },
                Resources = tesResourcesReceivedFromCromwell
            };

            var azureProxy = new Mock <IAzureProxy>();

            azureProxy.Setup(a => a.TryReadCwlFile(It.IsAny <string>(), out cwlFileContent)).Returns(true);
            var controller = this.GetTaskServiceApiController(azureProxy.Object);

            await controller.CreateTaskAsync(tesTask);

            return(tesTask);
        }
Beispiel #2
0
        /// <summary>
        /// Get the backend parameter value for the specified parameter
        /// </summary>
        /// <returns>The value if it exists; null otherwise</returns>
        public static string GetBackendParameterValue(this TesResources resources, TesResources.SupportedBackendParameters parameter)
        {
            string backendParameterValue = null;

            resources.BackendParameters?.TryGetValue(parameter.ToString(), out backendParameterValue);
            return(backendParameterValue);
        }
        private static async Task <TesState> GetNewTesTaskStateAsync(TesResources resources, AzureProxyReturnValues azureProxyReturnValues)
        {
            var tesTask = GetTesTask();

            tesTask.Resources = resources;

            await ProcessTesTaskAndGetBatchJobArgumentsAsync(tesTask, GetMockConfig(), GetMockAzureProxy(azureProxyReturnValues));

            return(tesTask.State);
        }
        /// <summary>
        /// Gets the cheapest available VM size that satisfies the <see cref="TesTask"/> execution requirements
        /// </summary>
        /// <param name="tesResources"><see cref="TesResources"/></param>
        /// <returns>The virtual machine info</returns>
        private async Task <VirtualMachineInfo> GetVmSizeAsync(TesResources tesResources)
        {
            var requiredNumberOfCores = tesResources.CpuCores.GetValueOrDefault(DefaultCoreCount);
            var requiredMemoryInGB    = tesResources.RamGb.GetValueOrDefault(DefaultMemoryGb);
            var requiredDiskSizeInGB  = tesResources.DiskGb.GetValueOrDefault(DefaultDiskGb);
            var preemptible           = usePreemptibleVmsOnly || tesResources.Preemptible.GetValueOrDefault(false);

            var virtualMachineInfoList = await azureProxy.GetVmSizesAndPricesAsync();

            var selectedVm = virtualMachineInfoList
                             .Where(x =>
                                    x.LowPriority == preemptible &&
                                    x.NumberOfCores >= requiredNumberOfCores &&
                                    x.MemoryInGB >= requiredMemoryInGB &&
                                    x.ResourceDiskSizeInGB >= requiredDiskSizeInGB)
                             .OrderBy(x => x.PricePerHour)
                             .FirstOrDefault();

            if (selectedVm == null)
            {
                var alternateVm = virtualMachineInfoList
                                  .Where(x =>
                                         x.LowPriority == !preemptible &&
                                         x.NumberOfCores >= requiredNumberOfCores &&
                                         x.MemoryInGB >= requiredMemoryInGB &&
                                         x.ResourceDiskSizeInGB >= requiredDiskSizeInGB)
                                  .OrderBy(x => x.PricePerHour)
                                  .FirstOrDefault();

                var noVmFoundMessage = $"No VM (out of {virtualMachineInfoList.Count}) available with the required resources (cores: {requiredNumberOfCores}, memory: {requiredMemoryInGB} GB, disk: {requiredDiskSizeInGB} GB, preemptible: {preemptible})";

                if (alternateVm != null)
                {
                    noVmFoundMessage += $" Please note that a VM with LowPriority={!preemptible} WAS found however.";
                }

                logger.LogError(noVmFoundMessage);
                throw new AzureBatchVirtualMachineAvailabilityException(noVmFoundMessage);
            }

            return(selectedVm);
        }
Beispiel #5
0
 /// <summary>
 /// Checks if a backend parameter was present
 /// </summary>
 /// <returns>True if the parameter value is not null or whitespace; false otherwise</returns>
 public static bool ContainsBackendParameterValue(this TesResources resources, TesResources.SupportedBackendParameters parameter)
 {
     return(!string.IsNullOrWhiteSpace(resources.GetBackendParameterValue(parameter)));
 }