Esempio n. 1
0
    //TODO: suggest by Cheick: this can probably be optimize by query all NodesTasks then query the all machine in single request
    public async IAsyncEnumerable <Node> GetNodesByTaskId(Guid taskId, INodeOperations nodeOps)
    {
        await foreach (var entry in QueryAsync($"task_id eq '{taskId}'"))
        {
            var node = await nodeOps.GetByMachineId(entry.MachineId);

            if (node is not null)
            {
                yield return(node);
            }
        }
    }
Esempio n. 2
0
    public async IAsyncEnumerable <NodeAssignment> GetNodeAssignments(Guid taskId, INodeOperations nodeOps)
    {
        await foreach (var entry in QueryAsync($"task_id eq '{taskId}'"))
        {
            var node = await nodeOps.GetByMachineId(entry.MachineId);

            if (node is not null)
            {
                var nodeAssignment = new NodeAssignment(node.MachineId, node.ScalesetId, entry.State);
                yield return(nodeAssignment);
            }
        }
    }
Esempio n. 3
0
    public async Async.Task <HttpResponseData> Run([HttpTrigger] HttpRequestData req)
    {
        var request = await RequestHandling.ParseRequest <CanScheduleRequest>(req);

        if (!request.IsOk || request.OkV == null)
        {
            return(await RequestHandling.NotOk(req, request.ErrorV, typeof(CanScheduleRequest).ToString(), _log));
        }

        var canScheduleRequest = request.OkV;

        var node = await _nodeOperations.GetByMachineId(canScheduleRequest.MachineId);

        if (node == null)
        {
            return(await RequestHandling.NotOk(
                       req,
                       new Error(
                           ErrorCode.UNABLE_TO_FIND,
                           new string[] {
                "unable to find node"
            }
                           ),
                       canScheduleRequest.MachineId.ToString(),
                       _log
                       ));
        }

        var allowed     = true;
        var workStopped = false;

        if (!await _nodeOperations.CanProcessNewWork(node))
        {
            allowed = false;
        }

        var task = await _taskOperations.GetByTaskId(canScheduleRequest.TaskId);

        workStopped = task == null || TaskStateHelper.ShuttingDown.Contains(task.State);

        if (allowed)
        {
            allowed = (await _nodeOperations.AcquireScaleInProtection(node)).IsOk;
        }

        return(await RequestHandling.Ok(
                   req,
                   new BaseResponse[] {
            new CanSchedule(allowed, workStopped)
        }));
    }
        public async Task <HttpResponseData> GetByMachineId([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "testhooks/nodeOperations/getByMachineId")] HttpRequestData req)
        {
            _log.Info("Get node by machine id");

            var query     = UriExtension.GetQueryComponents(req.Url);
            var machineId = query["machineId"];

            var node = await _nodeOps.GetByMachineId(Guid.Parse(machineId));

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

            return(resp);
        }