AWS SWF (Simple Workflow Service) : I want a status !

Hello,

This post will include a block of code to help you to monitor your SWF executions in your own console (rather than the AWS console itself).

You can include this simple class in your own code (do not notice me, use it) and transform it to fit your monitoring needs.

This code will :
– find the registered domain matching the domain name you want
– get and store the open executions in a list
– append and store the closed execution in the same list

If you issue workflowsFollowUp.toString (), you will get hierarchical and detailed data about :
– each step (DecisionTask or ActivityTask)
– the list of activities which were run, in order
– the datetime values (when it was started)
– if there are, the exceptions unmarshalled as real exceptions…

Example of result in the console :

----
Workflow type DemoWorfklowDecider.launch/1.0
Workflow bd4852d2-862f-4d7b-a837-2aca62ea09f2 with runId 2209T4DgTTd6iB82nZdAPXeKQ8iEv6S1dailgO3x9Jq/U=
Workflow status : CLOSED ; result : COMPLETED

Step 1 : WorkflowExecutionStarted ; date : Wed Oct 14 15:10:43 CEST 2015 ; input : ["[Ljava.lang.Object;",[10,true]]
Step 2 : DecisionTaskScheduled ; date : Wed Oct 14 15:10:43 CEST 2015
Step 3 : DecisionTaskStarted ; date : Wed Oct 14 15:10:43 CEST 2015
Step 4 : DecisionTaskCompleted ; date : Wed Oct 14 15:10:44 CEST 2015
Step 5 : ActivityTaskScheduled ; date : Wed Oct 14 15:10:44 CEST 2015 ; activity : DemoWorkflowActivity.waitForThenFailOrSuccess ; input : ["[Ljava.lang.Object;",[10,true]]
Step 6 : ActivityTaskStarted ; date : Wed Oct 14 15:10:44 CEST 2015
Step 7 : ActivityTaskCompleted ; date : Wed Oct 14 15:10:54 CEST 2015 ; result : true
Step 8 : DecisionTaskScheduled ; date : Wed Oct 14 15:10:54 CEST 2015
Step 9 : DecisionTaskStarted ; date : Wed Oct 14 15:10:54 CEST 2015
Step 10 : DecisionTaskCompleted ; date : Wed Oct 14 15:10:55 CEST 2015
Step 11 : WorkflowExecutionCompleted ; date : Wed Oct 14 15:10:55 CEST 2015

Activities run :
- DemoWorkflowActivity.waitForThenFailOrSuccess
----
Workflow type DemoWorfklowDecider.launch/1.0
Workflow 338b088e-b8be-48c7-996e-84a493788347 with runId 22+BzfJcLaGosAT44+kZkyATWB8uXnx7lLE5/bCJOKmZ4=
Workflow status : CLOSED ; result : FAILED

Step 1 : WorkflowExecutionStarted ; date : Wed Oct 14 14:39:51 CEST 2015 ; input :
Step 2 : DecisionTaskScheduled ; date : Wed Oct 14 14:39:51 CEST 2015
Step 3 : DecisionTaskStarted ; date : Wed Oct 14 14:39:52 CEST 2015
Step 4 : DecisionTaskCompleted ; date : Wed Oct 14 14:39:53 CEST 2015
Step 5 : WorkflowExecutionFailed ; date : Wed Oct 14 14:39:53 CEST 2015 ; reason : com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: java.io.StringReader@762c40ce; line: 1, column: 1] when mapping key "null"
com.amazonaws.services.simpleworkflow.flow.DataConverterException: null when mapping key "null"
at com.amazonaws.services.simpleworkflow.flow.JsonDataConverter.fromData(JsonDataConverter.java:102)
at com.amazonaws.services.simpleworkflow.flow.pojo.POJOWorkflowDefinition$1.doTry(POJOWorkflowDefinition.java:74)
at --- continuation ---.(:0)
at com.amazonaws.services.simpleworkflow.flow.pojo.POJOWorkflowDefinition.execute(POJOWorkflowDefinition.java:66)
at com.amazonaws.services.simpleworkflow.flow.worker.AsyncDecider$WorkflowExecuteAsyncScope.doAsync(AsyncDecider.java:70)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: N/A
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3036)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2978)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2098)
at com.amazonaws.services.simpleworkflow.flow.JsonDataConverter.fromData(JsonDataConverter.java:96)
at com.amazonaws.services.simpleworkflow.flow.pojo.POJOWorkflowDefinition$1.doTry(POJOWorkflowDefinition.java:74)
at com.amazonaws.services.simpleworkflow.flow.core.TryCatchFinallyContext.run(TryCatchFinallyContext.java:163)
at com.amazonaws.services.simpleworkflow.flow.core.AsyncEventLoop.executeQueuedTask(AsyncEventLoop.java:44)
at com.amazonaws.services.simpleworkflow.flow.core.AsyncEventLoop.executeAllQueued(AsyncEventLoop.java:33)
at com.amazonaws.services.simpleworkflow.flow.core.AsyncScopeContext.eventLoop(AsyncScopeContext.java:151)
at com.amazonaws.services.simpleworkflow.flow.core.AsyncScope.eventLoop(AsyncScope.java:74)
at com.amazonaws.services.simpleworkflow.flow.worker.AsyncDecider.eventLoop(AsyncDecider.java:327)
at com.amazonaws.services.simpleworkflow.flow.worker.AsyncDecider.decide(AsyncDecider.java:497)
at com.amazonaws.services.simpleworkflow.flow.worker.AsyncDecisionTaskHandler.handleDecisionTask(AsyncDecisionTaskHandler.java:50)
at com.amazonaws.services.simpleworkflow.flow.worker.DecisionTaskPoller.pollAndProcessSingleTask(DecisionTaskPoller.java:201)
at com.amazonaws.services.simpleworkflow.flow.worker.GenericWorker$PollServiceTask.run(GenericWorker.java:94)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Please find this code in Gist : https://gist.github.com/libetl/b117b321cda6bf539986

I wish you a happy monitoring.