public async Task <HttpResponseData> GetJob([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "testhooks/jobOps/job")] HttpRequestData req)
        {
            _log.Info("Get job info");

            var query = UriExtension.GetQueryComponents(req.Url);
            var jobId = Guid.Parse(query["jobId"]);

            var job = await _jobOps.Get(jobId);

            var msg  = JsonSerializer.Serialize(job, EntityConverter.GetJsonSerializerOptions());
            var resp = req.CreateResponse(HttpStatusCode.OK);
            await resp.WriteStringAsync(msg);

            return(resp);
        }
Beispiel #2
0
    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
        });