Skip to content

Commit

Permalink
Merge pull request #137 from NitorCreations/remove-invalid-statistics
Browse files Browse the repository at this point in the history
remove queuedInstances value from statuses where it is not valid
  • Loading branch information
jsyrjala committed Apr 7, 2015
2 parents 69de523 + 1bdd0a5 commit dab55d7
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.nitorcreations.nflow.rest.v1.converter;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.stereotype.Component;

import com.nitorcreations.nflow.engine.workflow.definition.WorkflowDefinitionStatistics;
import com.nitorcreations.nflow.engine.workflow.statistics.Statistics;
import com.nitorcreations.nflow.rest.v1.msg.DefinitionStatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.StatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.WorkflowDefinitionStatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.WorkflowDefinitionStatisticsResponse.StateStatistics;

@Component
public class StatisticsConverter {
Expand All @@ -30,14 +29,37 @@ public StatisticsResponse convert(Statistics stats) {
public WorkflowDefinitionStatisticsResponse convert(Map<String, Map<String, WorkflowDefinitionStatistics>> stats) {
WorkflowDefinitionStatisticsResponse resp = new WorkflowDefinitionStatisticsResponse();
for (Entry<String, Map<String, WorkflowDefinitionStatistics>> entry : stats.entrySet()) {
LinkedHashMap<String, DefinitionStatisticsResponse> statusStats = new LinkedHashMap<>();
resp.stateStatistics.put(entry.getKey(), statusStats);
StateStatistics stateStats = new StateStatistics();
resp.stateStatistics.put(entry.getKey(), stateStats);
for (Entry<String, WorkflowDefinitionStatistics> statusEntry : entry.getValue().entrySet()) {
DefinitionStatisticsResponse statsResponse = new DefinitionStatisticsResponse();
WorkflowDefinitionStatistics statistics = statusEntry.getValue();
statsResponse.allInstances = statistics.allInstances;
statsResponse.queuedInstances = statistics.queuedInstances;
statusStats.put(statusEntry.getKey(), statsResponse);
WorkflowDefinitionStatistics value = statusEntry.getValue();
switch (statusEntry.getKey()) {
case "created":
stateStats.created.allInstances = value.allInstances;
stateStats.created.queuedInstances = value.queuedInstances;
break;
case "inProgress":
stateStats.inProgress.allInstances = value.allInstances;
stateStats.inProgress.queuedInstances = value.queuedInstances;
break;
case "executing":
stateStats.executing.allInstances = value.allInstances;
break;
case "paused":
stateStats.paused.allInstances = value.allInstances;
break;
case "stopped":
stateStats.stopped.allInstances = value.allInstances;
break;
case "manual":
stateStats.manual.allInstances = value.allInstances;
break;
case "finished":
stateStats.finished.allInstances = value.allInstances;
break;
default:
// ignored
}
}
}
return resp;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,23 @@
public class WorkflowDefinitionStatisticsResponse {

@ApiModelProperty(value = "Statistics per state", required=true)
public Map<String, Map<String, DefinitionStatisticsResponse>> stateStatistics = new LinkedHashMap<>();
public Map<String, StateStatistics> stateStatistics = new LinkedHashMap<>();

public static class StateStatistics {
public AllAndQueued created = new AllAndQueued();
public AllAndQueued inProgress = new AllAndQueued();
public All executing = new All();
public All paused = new All();
public All stopped = new All();
public All manual = new All();
public All finished = new All();

public static class AllAndQueued extends All {
public long queuedInstances;
}

public static class All {
public long allInstances;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

import com.nitorcreations.nflow.engine.workflow.definition.WorkflowDefinitionStatistics;
import com.nitorcreations.nflow.engine.workflow.statistics.Statistics;
import com.nitorcreations.nflow.engine.workflow.statistics.Statistics.QueueStatistics;
import com.nitorcreations.nflow.rest.v1.msg.DefinitionStatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.StatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.WorkflowDefinitionStatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.WorkflowDefinitionStatisticsResponse.StateStatistics;


public class StatisticsConverterTest {
Expand All @@ -40,16 +41,44 @@ public void queueStatisticsConvertWorks() {

@Test
public void workflowDefinitionStatisticsConverterWorks() {
WorkflowDefinitionStatistics statistics = new WorkflowDefinitionStatistics();
statistics.allInstances = 1;
statistics.queuedInstances = 2;
Map<String, Map<String, WorkflowDefinitionStatistics>> stats = singletonMap("state", singletonMap("status", statistics));
Map<String, WorkflowDefinitionStatistics> stateStats = new HashMap<>();
WorkflowDefinitionStatistics created = new WorkflowDefinitionStatistics();
created.allInstances = 1;
created.queuedInstances = 2;
stateStats.put("created", created);
WorkflowDefinitionStatistics inProgress = new WorkflowDefinitionStatistics();
inProgress.allInstances = 3;
inProgress.queuedInstances = 4;
stateStats.put("inProgress", inProgress);
WorkflowDefinitionStatistics executing = new WorkflowDefinitionStatistics();
executing.allInstances = 5;
stateStats.put("executing", executing);
WorkflowDefinitionStatistics paused = new WorkflowDefinitionStatistics();
paused.allInstances = 6;
stateStats.put("paused", paused);
WorkflowDefinitionStatistics stopped = new WorkflowDefinitionStatistics();
stopped.allInstances = 7;
stateStats.put("stopped", stopped);
WorkflowDefinitionStatistics manual = new WorkflowDefinitionStatistics();
manual.allInstances = 8;
stateStats.put("manual", manual);
WorkflowDefinitionStatistics finished = new WorkflowDefinitionStatistics();
finished.allInstances = 9;
stateStats.put("finished", finished);
stateStats.put("unknown", new WorkflowDefinitionStatistics());
Map<String, Map<String, WorkflowDefinitionStatistics>> stats = singletonMap("state", stateStats);

WorkflowDefinitionStatisticsResponse response = converter.convert(stats);

Map<String, DefinitionStatisticsResponse> stateStatistics = response.stateStatistics.get("state");
DefinitionStatisticsResponse statusStatistics = stateStatistics.get("status");
assertThat(statusStatistics.allInstances, is(1L));
assertThat(statusStatistics.queuedInstances, is(2L));
StateStatistics stateStatistics = response.stateStatistics.get("state");
assertThat(stateStatistics.created.allInstances, is(1L));
assertThat(stateStatistics.created.queuedInstances, is(2L));
assertThat(stateStatistics.inProgress.allInstances, is(3L));
assertThat(stateStatistics.inProgress.queuedInstances, is(4L));
assertThat(stateStatistics.executing.allInstances, is(5L));
assertThat(stateStatistics.paused.allInstances, is(6L));
assertThat(stateStatistics.stopped.allInstances, is(7L));
assertThat(stateStatistics.manual.allInstances, is(8L));
assertThat(stateStatistics.finished.allInstances, is(9L));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import static org.junit.Assert.assertThat;
import static org.junit.runners.MethodSorters.NAME_ASCENDING;

import java.util.Map;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;

Expand All @@ -24,10 +22,10 @@

import com.nitorcreations.nflow.rest.v1.msg.CreateWorkflowInstanceRequest;
import com.nitorcreations.nflow.rest.v1.msg.CreateWorkflowInstanceResponse;
import com.nitorcreations.nflow.rest.v1.msg.DefinitionStatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.StatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.UpdateWorkflowInstanceRequest;
import com.nitorcreations.nflow.rest.v1.msg.WorkflowDefinitionStatisticsResponse;
import com.nitorcreations.nflow.rest.v1.msg.WorkflowDefinitionStatisticsResponse.StateStatistics;
import com.nitorcreations.nflow.tests.DemoWorkflowTest.DemoConfiguration;
import com.nitorcreations.nflow.tests.runner.NflowServerRule;

Expand Down Expand Up @@ -76,9 +74,9 @@ public void t02_queryStatistics() {
public void t03_queryDefinitionStatistics() {
WorkflowDefinitionStatisticsResponse statistics = getDefinitionStatistics(DEMO_WORKFLOW_TYPE);
assertThat(statistics.stateStatistics, is(notNullValue()));
Map<String, DefinitionStatisticsResponse> map = statistics.stateStatistics.get("begin");
assertThat(map.get("created").allInstances, is(1L));
assertThat(map.get("created").queuedInstances, is(0L));
StateStatistics stats = statistics.stateStatistics.get("begin");
assertThat(stats.created.allInstances, is(1L));
assertThat(stats.created.queuedInstances, is(0L));
}

@Test
Expand Down Expand Up @@ -113,8 +111,8 @@ public void t07_queryStatistics() {
public void t08_queryDefinitionStatistics() {
WorkflowDefinitionStatisticsResponse statistics = getDefinitionStatistics(DEMO_WORKFLOW_TYPE);
assertThat(statistics.stateStatistics, is(notNullValue()));
Map<String, DefinitionStatisticsResponse> map = statistics.stateStatistics.get("begin");
assertThat(map.get("created").allInstances, is(1L));
assertThat(map.get("created").queuedInstances, is(1L));
StateStatistics stats = statistics.stateStatistics.get("begin");
assertThat(stats.created.allInstances, is(1L));
assertThat(stats.created.queuedInstances, is(1L));
}
}

0 comments on commit dab55d7

Please sign in to comment.