Skip to content

Commit

Permalink
Merge pull request #46 from cognitree/master-fixes
Browse files Browse the repository at this point in the history
Fixed workflow statistics, include skipped tasks in stats
  • Loading branch information
girishkarthik authored Jun 3, 2019
2 parents f5ac228 + 3363775 commit 8ff093a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

import com.cognitree.kronos.executor.handlers.MockSuccessTaskHandler;
import com.cognitree.kronos.model.Task;
import com.cognitree.kronos.scheduler.model.Job;
import com.cognitree.kronos.scheduler.model.Namespace;
import com.cognitree.kronos.scheduler.model.Workflow;
import com.cognitree.kronos.scheduler.model.WorkflowStatistics;
import com.cognitree.kronos.scheduler.model.WorkflowTrigger;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -186,6 +188,78 @@ public void testTaskWithContextFromWorkflow() throws Exception {
}
}

@Test
public void testGetWorkflowStatistics() throws Exception {
final WorkflowTrigger workflowTriggerOne = scheduleWorkflow("workflows/workflow-template.yaml");
final WorkflowTrigger workflowTriggerTwo = scheduleWorkflow("workflows/workflow-template-failed-handler.yaml");

final Scheduler scheduler = WorkflowSchedulerService.getService().getScheduler();
// wait for both the job to be triggered
waitForTriggerToComplete(workflowTriggerOne, scheduler);
waitForTriggerToComplete(workflowTriggerTwo, scheduler);
// wait for tasks status to be consumed from queue
Thread.sleep(5000);

WorkflowStatistics workflowOneStatistics = WorkflowService.getService()
.getStatistics(workflowTriggerOne.getNamespace(), workflowTriggerOne.getWorkflow(),
0, System.currentTimeMillis());
Assert.assertEquals(workflowOneStatistics.getJobs().getTotal(), 1);
Assert.assertEquals(workflowOneStatistics.getJobs().getActive(), 0);
Assert.assertEquals(workflowOneStatistics.getJobs().getFailed(), 0);
Assert.assertEquals(workflowOneStatistics.getJobs().getSkipped(), 0);
Assert.assertEquals(workflowOneStatistics.getJobs().getSuccessful(), 1);

Assert.assertEquals(workflowOneStatistics.getTasks().getTotal(), 3);
Assert.assertEquals(workflowOneStatistics.getTasks().getActive(), 0);
Assert.assertEquals(workflowOneStatistics.getTasks().getFailed(), 0);
Assert.assertEquals(workflowOneStatistics.getTasks().getSkipped(), 0);
Assert.assertEquals(workflowOneStatistics.getTasks().getSuccessful(), 3);

WorkflowStatistics workflowOneStatisticsByNs = WorkflowService.getService()
.getStatistics(workflowTriggerOne.getNamespace(), 0, System.currentTimeMillis());
Assert.assertEquals(workflowOneStatisticsByNs.getJobs().getTotal(), 1);
Assert.assertEquals(workflowOneStatisticsByNs.getJobs().getActive(), 0);
Assert.assertEquals(workflowOneStatisticsByNs.getJobs().getFailed(), 0);
Assert.assertEquals(workflowOneStatisticsByNs.getJobs().getSkipped(), 0);
Assert.assertEquals(workflowOneStatisticsByNs.getJobs().getSuccessful(), 1);

Assert.assertEquals(workflowOneStatisticsByNs.getTasks().getTotal(), 3);
Assert.assertEquals(workflowOneStatisticsByNs.getTasks().getActive(), 0);
Assert.assertEquals(workflowOneStatisticsByNs.getTasks().getFailed(), 0);
Assert.assertEquals(workflowOneStatisticsByNs.getTasks().getSkipped(), 0);
Assert.assertEquals(workflowOneStatisticsByNs.getTasks().getSuccessful(), 3);


WorkflowStatistics workflowTwoStatistics = WorkflowService.getService()
.getStatistics(workflowTriggerTwo.getNamespace(), workflowTriggerTwo.getWorkflow(),
0, System.currentTimeMillis());
Assert.assertEquals(workflowTwoStatistics.getJobs().getTotal(), 1);
Assert.assertEquals(workflowTwoStatistics.getJobs().getActive(), 0);
Assert.assertEquals(workflowTwoStatistics.getJobs().getFailed(), 1);
Assert.assertEquals(workflowTwoStatistics.getJobs().getSkipped(), 0);
Assert.assertEquals(workflowTwoStatistics.getJobs().getSuccessful(), 0);

Assert.assertEquals(workflowTwoStatistics.getTasks().getTotal(), 3);
Assert.assertEquals(workflowTwoStatistics.getTasks().getActive(), 0);
Assert.assertEquals(workflowTwoStatistics.getTasks().getFailed(), 1);
Assert.assertEquals(workflowTwoStatistics.getTasks().getSkipped(), 1);
Assert.assertEquals(workflowTwoStatistics.getTasks().getSuccessful(), 1);

WorkflowStatistics workflowTwoStatisticsByNs = WorkflowService.getService()
.getStatistics(workflowTriggerTwo.getNamespace(), 0, System.currentTimeMillis());
Assert.assertEquals(workflowTwoStatisticsByNs.getJobs().getTotal(), 1);
Assert.assertEquals(workflowTwoStatisticsByNs.getJobs().getActive(), 0);
Assert.assertEquals(workflowTwoStatisticsByNs.getJobs().getFailed(), 1);
Assert.assertEquals(workflowTwoStatisticsByNs.getJobs().getSkipped(), 0);
Assert.assertEquals(workflowTwoStatisticsByNs.getJobs().getSuccessful(), 0);


Assert.assertEquals(workflowTwoStatisticsByNs.getTasks().getTotal(), 3);
Assert.assertEquals(workflowTwoStatisticsByNs.getTasks().getActive(), 0);
Assert.assertEquals(workflowTwoStatisticsByNs.getTasks().getFailed(), 1);
Assert.assertEquals(workflowTwoStatisticsByNs.getTasks().getSkipped(), 1);
Assert.assertEquals(workflowTwoStatisticsByNs.getTasks().getSuccessful(), 1);
}

@Test(expected = ValidationException.class)
public void testDuplicatePolicyOfSameType() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private WorkflowStatistics getWorkflowStatistics(Map<Job.Status, Integer> jobSta
taskExecutionCounters.setActive(activeTasks);
taskExecutionCounters.setSuccessful(taskStatusMap.getOrDefault(Task.Status.SUCCESSFUL, 0));
taskExecutionCounters.setFailed(taskStatusMap.getOrDefault(Task.Status.FAILED, 0));
taskExecutionCounters.setFailed(taskStatusMap.getOrDefault(Task.Status.SKIPPED, 0));
taskExecutionCounters.setSkipped(taskStatusMap.getOrDefault(Task.Status.SKIPPED, 0));
workflowStatistics.setTasks(taskExecutionCounters);

workflowStatistics.setFrom(createdAfter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ExecutionCounters {
private int active;
private int successful;
private int failed;
private int skipped;

public int getActive() {
return active;
Expand Down Expand Up @@ -55,13 +56,22 @@ public void setFailed(int failed) {
this.failed = failed;
}

public int getSkipped() {
return skipped;
}

public void setSkipped(int skipped) {
this.skipped = skipped;
}

@Override
public String toString() {
return "ExecutionCounters{" +
"total=" + total +
", active=" + active +
", successful=" + successful +
", failed=" + failed +
", skipped=" + skipped +
'}';
}
}

0 comments on commit 8ff093a

Please sign in to comment.