Ejemplo n.º 1
0
        public IActionResult isWorkflowSuccess([FromServices] IStonebranchClient stonebranchClient, string workflowInstanceId)
        {
            var stonebranch   = new Stonebranch(stonebranchClient, _validation);
            var workflowTasks = stonebranch.GetCurrentTasks(workflowInstanceId);

            return(Ok(!workflowTasks.Any(task => task.Status != "SUCCESS" && task.Status != "SKIPPED")));
        }
Ejemplo n.º 2
0
        public IActionResult CancelFlowchartRuns([FromServices] IStonebranchClient stonebranchClient, string customerShortName, string projectShortName, Guid jobId, string workflowInstanceId)
        {
            var stoneBranch = new Stonebranch(stonebranchClient, _validation);
            var tasks       = stoneBranch.GetCurrentTasks(workflowInstanceId, "*_CacheDB__*");

            var filter     = JsonConvert.SerializeObject(new { _id = jobId, clientName = customerShortName, projectName = projectShortName });
            var projection = "{\"flowchartRunRequest.flowchartRunUUID\" : 1}";
            var jobs       = _jobProxy.GetJobs(filter, projection);

            var listWorkStatus = new List <WorkStatus>();

            foreach (var orchestrationJob in jobs) // Update status for both analytics run uuid and flowchart run uuids
            {
                orchestrationJob.flowchartRunRequest.ToList().ForEach(x =>
                {
                    if (!tasks.Any(y => y.Name.Contains(x.flowchartRunUUID.ToString()) && y.Status == "SUCCESS"))
                    {
                        var status = new WorkStatus(x.flowchartRunUUID, false, 100, AnalyticsRunStatus.Canceled);

                        status.LoggableMessages.Add(new WorkStatusMessage()
                        {
                            Content           = "Cancelled by user.",
                            Severity          = TraceEventType.Information,
                            Timestamp         = DateTime.Now,
                            ViewLevelProperty = WorkStatusMessage.ViewLevel.Internal
                        });

                        listWorkStatus.Add(status);
                    }
                });
            }

            _workStatusProxy.Add(listWorkStatus);
            return(Ok());
        }
Ejemplo n.º 3
0
        public IActionResult isWorkflowComplete([FromServices] IStonebranchClient stonebranchClient, string workflowInstanceId)
        {
            var stonebranch   = new Stonebranch(stonebranchClient, _validation);
            var workflowTasks = stonebranch.GetCurrentTasks(workflowInstanceId);
            var activeTasks   = workflowTasks.Where(t => t.Status != "FINISHED" && t.Status != "SUCCESS" && t.Status != "SKIPPED");

            return(Ok(activeTasks.Count() == 0));
        }
Ejemplo n.º 4
0
        private void AddTasks(IStonebranchClient stonebranchClient, IOrchestrationJob job, string workflowInstanceId, string finishTaskId)
        {
            int vertexX = 200;
            int vertexY = 450;

            var stonebranch       = new Stonebranch(stonebranchClient, _validation);
            var tasks             = stonebranch.GetCurrentTasks(workflowInstanceId, $"*{_config.CacheDBTaskFilter}*");
            var predecessor       = _config.CacheDBPredecessor;
            var flowchartRunCount = job.flowchartRunRequest.Count;
            var i = 1;

            job.flowchartRunRequest.ToList().ForEach(flowchart =>
            {
                var alias      = $"{job.clientName}_{job.projectName}_CacheDB__{flowchart.flowchartRunUUID}";
                var successors = new List <String>();

                if (i == flowchartRunCount)
                {
                    successors.Add(_config.FinishTask);
                }

                if (!tasks.Any(x => x.Name == alias))
                {
                    var data = new TaskInsert()
                    {
                        Alias        = alias,
                        Name         = "CacheDB",
                        Predecessors = new List <String>()
                        {
                            predecessor
                        },
                        Successors         = successors,
                        VertexX            = vertexX,
                        VertexY            = vertexY,
                        WorkflowInstanceId = workflowInstanceId
                    };

                    var connection = new Uri(new Uri(_config.StonebranchUri), "taskinstance/ops-task-insert");
                    var xml        = data.ToXml();
                    var content    = new StringContent(xml, Encoding.UTF8, "application/xml");

                    var response = stonebranchClient.Client.PostAsync(connection.ToString(), content).Result;

                    _validation.ValidateResponse(response);
                    _validation.ValidateStonebranchResponse(response.Content.ReadAsStringAsync().Result);

                    if (i == flowchartRunCount)
                    {
                        stonebranch.ReleaseTask(workflowInstanceId, finishTaskId);
                    }

                    predecessor = alias;
                    vertexX    += 200;
                }

                i++;
            });
        }
Ejemplo n.º 5
0
        public IActionResult FinishRun([FromServices] IStonebranchClient stonebranchClient, Guid id, string workflowInstanceId, string workflowName)
        {
            var workflow = ParseWorkflow(workflowName);
            var status   = string.Empty;

            switch (workflow)
            {
            case WorkflowType.AnalyticsRun:

                var stonebranch = new Stonebranch(stonebranchClient, _validation);
                var tasks       = stonebranch.GetCurrentTasks(workflowInstanceId);

                if (tasks.Any(x => x.Type == "Workflow" && x.Status == "RUNNING/PROBLEMS"))
                {
                    status = "There are CacheDB workflows that did not finish successfully.";     // ae status did by fail run above
                }
                else
                {
                    _workStatusProxy.Add(new WorkStatus(id, 100, AnalyticsRunStatus.RanToCompletion));
                    status = "finished";
                }

                break;

            case WorkflowType.CacheDB:

                _workStatusProxy.Add(new WorkStatus(id, 100, AnalyticsRunStatus.RanToCompletion));
                status = "finished";

                break;

            default:
                _logging.Log($"Run finished status not processed due to failure to parse workflow name to type: { workflowName }", Orchestration.Shared.Domain.Log.LogLevels.Error);
                break;
            }

            return(Ok(status));
        }
Ejemplo n.º 6
0
        public IActionResult FailRun([FromServices] IStonebranchClient stonebranchClient, string customerShortName, string projectShortName, string workflowInstanceId, string workflowName, string taskName, Guid jobId)
        {
            var workflow   = ParseWorkflow(workflowName);
            var prevStatus = _workStatusProxy.GetLastStatus(customerShortName, projectShortName, jobId);

            var filter     = JsonConvert.SerializeObject(new { _id = jobId, clientName = customerShortName, projectName = projectShortName });
            var projection = "{\"flowchartRunRequest.flowchartRunUUID\" : 1}";
            var jobs       = _jobProxy.GetJobs(filter, projection);

            switch (workflow)
            {
            case WorkflowType.AnalyticsRun:     // fail analytics run and fail all the flowchart runs in the analytics run

                var statuses = new List <WorkStatus>();

                statuses.Add(new WorkStatus(jobId, true, prevStatus.Progress, AnalyticsRunStatus.Running));

                if (taskName != _config.FinishTask)
                {
                    jobs.ToList().ForEach(job => job.flowchartRunRequest.ToList().ForEach(flowchartRun =>
                    {
                        statuses.Add(new WorkStatus(flowchartRun.flowchartRunUUID, prevStatus.Progress, AnalyticsRunStatus.Running));
                    }));
                }

                _workStatusProxy.Add(statuses);
                break;

            case WorkflowType.CacheDB:     // just fail flowchart run if in cachedb

                var flowchartRunId = Guid.Parse(workflowName.Substring(workflowName.IndexOf("_CacheDB__") + 10));
                _workStatusProxy.Add(new WorkStatus(flowchartRunId, prevStatus.Progress, AnalyticsRunStatus.Running));

                var stoneBranch = new Stonebranch(stonebranchClient, _validation);
                var tasks       = stoneBranch.GetCurrentTasks(workflowInstanceId);

                var requests = jobs.First().flowchartRunRequest;
                var index    = requests.IndexOf(requests.FirstOrDefault(x => x.flowchartRunUUID == flowchartRunId));

                if (index == requests.Count() - 1)
                {
                    var finishTask = tasks.FirstOrDefault(x => x.Name == _config.FinishTask);
                    stoneBranch.ClearPredecessors(finishTask.Id);
                }
                else
                {
                    var nextRun  = requests[index + 1];
                    var nextTask = tasks.FirstOrDefault(x => x.Name.Contains(nextRun.flowchartRunUUID.ToString()));

                    stoneBranch.ClearPredecessors(nextTask.Id);
                }

                break;

            default:
                _logging.Log($"Run failed status not processed due to failure to parse workflow name to type: { workflowName }", Orchestration.Shared.Domain.Log.LogLevels.Error);
                break;
            }

            return(Ok());
        }