private async Async.Task <(BucketConfig, WorkUnit)?> BuildWorkunit(Task task) { Pool?pool = await _taskOperations.GetPool(task); if (pool == null) { _logTracer.Info($"unable to find pool for task: {task.TaskId}"); return(null); } _logTracer.Info($"scheduling task: {task.TaskId}"); var job = await _jobOperations.Get(task.JobId); if (job == null) { throw new Exception($"invalid job_id {task.JobId} for task {task.TaskId}"); } var taskConfig = await _config.BuildTaskConfig(job, task); var setupContainer = task.Config.Containers?.FirstOrDefault(c => c.Type == ContainerType.Setup) ?? throw new Exception($"task missing setup container: task_type = {task.Config.Task.Type}"); var setupPs1Exist = _containers.BlobExists(setupContainer.Name, "setup.ps1", StorageType.Corpus); var setupShExist = _containers.BlobExists(setupContainer.Name, "setup.sh", StorageType.Corpus); string?setupScript = null; if (task.Os == Os.Windows && await setupPs1Exist) { setupScript = "setup.ps1"; } if (task.Os == Os.Linux && await setupShExist) { setupScript = "setup.sh"; } var reboot = false; var count = 1L; if (task.Config.Pool != null) { count = task.Config.Pool.Count; reboot = task.Config.Task.RebootAfterSetup ?? false; } else if (task.Config.Vm != null) { count = task.Config.Vm.Count; reboot = (task.Config.Vm.RebootAfterSetup ?? false) || (task.Config.Task.RebootAfterSetup ?? false); } else { throw new Exception(); } var workUnit = new WorkUnit( JobId: taskConfig.JobId, TaskId: taskConfig.TaskId, TaskType: taskConfig.TaskType, // todo: make sure that we exclude nulls when serializing // config = task_config.json(exclude_none = True, exclude_unset = True), Config: taskConfig); var bucketConfig = new BucketConfig( count, reboot, setupContainer.Name, setupScript, pool with { ETag = null });
public async Async.Task <ResultVoid <TaskConfigError> > CheckConfig(TaskConfig config) { if (!Defs.TASK_DEFINITIONS.ContainsKey(config.Task.Type)) { return(ResultVoid <TaskConfigError> .Error(new TaskConfigError($"unsupported task type: {config.Task.Type}"))); } if (config.Vm != null && config.Pool != null) { return(ResultVoid <TaskConfigError> .Error(new TaskConfigError($"either the vm or pool must be specified, but not both"))); } var definition = Defs.TASK_DEFINITIONS[config.Task.Type]; var r = await CheckContainers(definition, config); if (!r.IsOk) { return(r); } if (definition.Features.Contains(TaskFeature.SupervisorExe) && config.Task.SupervisorExe == null) { var err = "missing supervisor_exe"; _logTracer.Error(err); return(ResultVoid <TaskConfigError> .Error(new TaskConfigError(err))); } if (definition.Features.Contains(TaskFeature.TargetMustUseInput) && !TargetUsesInput(config)) { return(ResultVoid <TaskConfigError> .Error(new TaskConfigError("{input} must be used in target_env or target_options"))); } if (config.Vm != null) { return(ResultVoid <TaskConfigError> .Error(new TaskConfigError("specifying task config vm is no longer supported"))); } if (config.Pool == null) { return(ResultVoid <TaskConfigError> .Error(new TaskConfigError("pool must be specified"))); } if (!CheckVal(definition.Vm.Compare, definition.Vm.Value, config.Pool !.Count)) { var err = $"invalid vm count: expected {definition.Vm.Compare} {definition.Vm.Value}, got {config.Pool.Count}"; _logTracer.Error(err); return(ResultVoid <TaskConfigError> .Error(new TaskConfigError(err))); } var pool = await _context.PoolOperations.GetByName(config.Pool.PoolName); if (!pool.IsOk) { return(ResultVoid <TaskConfigError> .Error(new TaskConfigError($"invalid pool: {config.Pool.PoolName}"))); } var checkTarget = await CheckTargetExe(config, definition); if (!checkTarget.IsOk) { return(checkTarget); } if (definition.Features.Contains(TaskFeature.GeneratorExe)) { var container = config.Containers !.First(x => x.Type == ContainerType.Tools); if (config.Task.GeneratorExe == null) { return(ResultVoid <TaskConfigError> .Error(new TaskConfigError($"generator_exe is not defined"))); } var tool_paths = new[] { "{tools_dir}/", "{tools_dir}\\" }; foreach (var toolPath in tool_paths) { if (config.Task.GeneratorExe.StartsWith(toolPath)) { var generator = config.Task.GeneratorExe.Replace(toolPath, ""); if (!await _containers.BlobExists(container.Name, generator, StorageType.Corpus)) { var err = $"generator_exe `{config.Task.GeneratorExe}` does not exist in the tools container `{container.Name}`"; _logTracer.Error(err); return(ResultVoid <TaskConfigError> .Error(new TaskConfigError(err))); } } } } if (definition.Features.Contains(TaskFeature.StatsFile)) { if (config.Task.StatsFile != null && config.Task.StatsFormat == null) { var err2 = "using a stats_file requires a stats_format"; _logTracer.Error(err2); return(ResultVoid <TaskConfigError> .Error(new TaskConfigError(err2))); } } return(ResultVoid <TaskConfigError> .Ok()); }