2929import com .uber .cadence .ActivityType ;
3030import com .uber .cadence .Decision ;
3131import com .uber .cadence .DecisionType ;
32- import com .uber .cadence .DescribeWorkflowExecutionRequest ;
33- import com .uber .cadence .DescribeWorkflowExecutionResponse ;
3432import com .uber .cadence .EntityNotExistsError ;
3533import com .uber .cadence .EventType ;
3634import com .uber .cadence .GetWorkflowExecutionHistoryRequest ;
3735import com .uber .cadence .GetWorkflowExecutionHistoryResponse ;
3836import com .uber .cadence .History ;
3937import com .uber .cadence .HistoryEvent ;
4038import com .uber .cadence .HistoryEventFilterType ;
41- import com .uber .cadence .StartWorkflowExecutionRequest ;
4239import com .uber .cadence .TaskList ;
4340import com .uber .cadence .WorkflowExecution ;
4441import com .uber .cadence .WorkflowExecutionCloseStatus ;
45- import com .uber .cadence .WorkflowExecutionContinuedAsNewEventAttributes ;
4642import com .uber .cadence .WorkflowExecutionFailedEventAttributes ;
47- import com .uber .cadence .WorkflowExecutionInfo ;
4843import com .uber .cadence .WorkflowExecutionTerminatedEventAttributes ;
4944import com .uber .cadence .WorkflowExecutionTimedOutEventAttributes ;
5045import com .uber .cadence .WorkflowType ;
@@ -389,42 +384,6 @@ public static boolean isWorkflowExecutionCompleteDecision(Decision decision) {
389384 || decision .getDecisionType () == DecisionType .ContinueAsNewWorkflowExecution ));
390385 }
391386
392- public static boolean isActivityTaskClosedEvent (HistoryEvent event ) {
393- return ((event != null )
394- && (event .getEventType () == EventType .ActivityTaskCompleted
395- || event .getEventType () == EventType .ActivityTaskCanceled
396- || event .getEventType () == EventType .ActivityTaskFailed
397- || event .getEventType () == EventType .ActivityTaskTimedOut ));
398- }
399-
400- public static boolean isExternalWorkflowClosedEvent (HistoryEvent event ) {
401- return ((event != null )
402- && (event .getEventType () == EventType .ChildWorkflowExecutionCompleted
403- || event .getEventType () == EventType .ChildWorkflowExecutionCanceled
404- || event .getEventType () == EventType .ChildWorkflowExecutionFailed
405- || event .getEventType () == EventType .ChildWorkflowExecutionTerminated
406- || event .getEventType () == EventType .ChildWorkflowExecutionTimedOut ));
407- }
408-
409- public static WorkflowExecution getWorkflowIdFromExternalWorkflowCompletedEvent (
410- HistoryEvent event ) {
411- if (event != null ) {
412- if (event .getEventType () == EventType .ChildWorkflowExecutionCompleted ) {
413- return event .getChildWorkflowExecutionCompletedEventAttributes ().getWorkflowExecution ();
414- } else if (event .getEventType () == EventType .ChildWorkflowExecutionCanceled ) {
415- return event .getChildWorkflowExecutionCanceledEventAttributes ().getWorkflowExecution ();
416- } else if (event .getEventType () == EventType .ChildWorkflowExecutionFailed ) {
417- return event .getChildWorkflowExecutionFailedEventAttributes ().getWorkflowExecution ();
418- } else if (event .getEventType () == EventType .ChildWorkflowExecutionTerminated ) {
419- return event .getChildWorkflowExecutionTerminatedEventAttributes ().getWorkflowExecution ();
420- } else if (event .getEventType () == EventType .ChildWorkflowExecutionTimedOut ) {
421- return event .getChildWorkflowExecutionTimedOutEventAttributes ().getWorkflowExecution ();
422- }
423- }
424-
425- return null ;
426- }
427-
428387 public static String getId (HistoryEvent historyEvent ) {
429388 String id = null ;
430389 if (historyEvent != null ) {
@@ -436,67 +395,6 @@ public static String getId(HistoryEvent historyEvent) {
436395 return id ;
437396 }
438397
439- public static String getFailureCause (HistoryEvent historyEvent ) {
440- String failureCause = null ;
441- if (historyEvent != null ) {
442- if (historyEvent .getEventType () == EventType .StartChildWorkflowExecutionFailed ) {
443- failureCause =
444- historyEvent
445- .getStartChildWorkflowExecutionFailedEventAttributes ()
446- .getCause ()
447- .toString ();
448- // } else if (historyEvent.getEventType() ==
449- // EventType.SignalExternalWorkflowExecutionFailed) {
450- // failureCause =
451- // historyEvent.getSignalExternalWorkflowExecutionFailedEventAttributes().getCause();
452- } else {
453- failureCause = "Cannot extract failure cause from " + historyEvent .getEventType ();
454- }
455- }
456-
457- return failureCause ;
458- }
459-
460- /**
461- * Blocks until workflow instance completes. <strong>Never</strong> use in production setting as
462- * polling for worklow instance status is an expensive operation.
463- *
464- * @param workflowExecution result of {@link
465- * IWorkflowService#StartWorkflowExecution(StartWorkflowExecutionRequest)}
466- * @return instance close status
467- */
468- public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletion (
469- IWorkflowService service , String domain , WorkflowExecution workflowExecution )
470- throws EntityNotExistsError {
471- try {
472- return waitForWorkflowInstanceCompletion (
473- service , domain , workflowExecution , 0 , TimeUnit .MILLISECONDS );
474- } catch (TimeoutException e ) {
475- throw new Error ("should never happen" , e );
476- }
477- }
478-
479- /**
480- * Waits up to specified timeout for workflow instance completion. <strong>Never</strong> use in
481- * production setting as polling for worklow instance status is an expensive operation.
482- *
483- * @param workflowExecution result of {@link
484- * IWorkflowService#StartWorkflowExecution(StartWorkflowExecutionRequest)}
485- * @param timeout maximum time to wait for completion. 0 means wait forever.
486- * @return instance close status
487- */
488- public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletion (
489- IWorkflowService service ,
490- String domain ,
491- WorkflowExecution workflowExecution ,
492- long timeout ,
493- TimeUnit unit )
494- throws TimeoutException , EntityNotExistsError {
495- HistoryEvent closeEvent =
496- getInstanceCloseEvent (service , domain , workflowExecution , timeout , unit );
497- return getCloseStatus (closeEvent );
498- }
499-
500398 public static WorkflowExecutionCloseStatus getCloseStatus (HistoryEvent event ) {
501399 switch (event .getEventType ()) {
502400 case WorkflowExecutionCanceled :
@@ -516,88 +414,6 @@ public static WorkflowExecutionCloseStatus getCloseStatus(HistoryEvent event) {
516414 }
517415 }
518416
519- /**
520- * Like {@link #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution,
521- * long, TimeUnit)} , except will wait for continued generations of the original workflow
522- * execution too.
523- *
524- * @see #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution, long,
525- * TimeUnit)
526- */
527- public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletionAcrossGenerations (
528- IWorkflowService service ,
529- String domain ,
530- WorkflowExecution workflowExecution ,
531- long timeout ,
532- TimeUnit unit )
533- throws TimeoutException , EntityNotExistsError {
534-
535- WorkflowExecution lastExecutionToRun = workflowExecution ;
536- long millisecondsAtFirstWait = System .currentTimeMillis ();
537- WorkflowExecutionCloseStatus lastExecutionToRunCloseStatus =
538- waitForWorkflowInstanceCompletion (service , domain , lastExecutionToRun , timeout , unit );
539-
540- // keep waiting if the instance continued as new
541- while (lastExecutionToRunCloseStatus == WorkflowExecutionCloseStatus .CONTINUED_AS_NEW ) {
542- // get the new execution's information
543- HistoryEvent closeEvent =
544- getInstanceCloseEvent (service , domain , lastExecutionToRun , timeout , unit );
545- WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewAttributes =
546- closeEvent .getWorkflowExecutionContinuedAsNewEventAttributes ();
547-
548- WorkflowExecution newGenerationExecution = new WorkflowExecution ();
549- newGenerationExecution .setRunId (continuedAsNewAttributes .getNewExecutionRunId ());
550- newGenerationExecution .setWorkflowId (lastExecutionToRun .getWorkflowId ());
551-
552- // and wait for it
553- long currentTime = System .currentTimeMillis ();
554- long millisecondsSinceFirstWait = currentTime - millisecondsAtFirstWait ;
555- long timeoutInSecondsForNextWait =
556- unit .toMillis (timeout ) - (millisecondsSinceFirstWait / 1000L );
557-
558- lastExecutionToRunCloseStatus =
559- waitForWorkflowInstanceCompletion (
560- service ,
561- domain ,
562- newGenerationExecution ,
563- timeoutInSecondsForNextWait ,
564- TimeUnit .MILLISECONDS );
565- lastExecutionToRun = newGenerationExecution ;
566- }
567-
568- return lastExecutionToRunCloseStatus ;
569- }
570-
571- /**
572- * Like {@link #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution,
573- * long, TimeUnit)} , but with no timeout.*
574- */
575- public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletionAcrossGenerations (
576- IWorkflowService service , String domain , WorkflowExecution workflowExecution )
577- throws InterruptedException , EntityNotExistsError {
578- try {
579- return waitForWorkflowInstanceCompletionAcrossGenerations (
580- service , domain , workflowExecution , 0L , TimeUnit .MILLISECONDS );
581- } catch (TimeoutException e ) {
582- throw new Error ("should never happen" , e );
583- }
584- }
585-
586- public static WorkflowExecutionInfo describeWorkflowInstance (
587- IWorkflowService service , String domain , WorkflowExecution workflowExecution ) {
588- DescribeWorkflowExecutionRequest describeRequest = new DescribeWorkflowExecutionRequest ();
589- describeRequest .setDomain (domain );
590- describeRequest .setExecution (workflowExecution );
591- DescribeWorkflowExecutionResponse executionDetail = null ;
592- try {
593- executionDetail = service .DescribeWorkflowExecution (describeRequest );
594- } catch (TException e ) {
595- throw new RuntimeException (e );
596- }
597- WorkflowExecutionInfo instanceMetadata = executionDetail .getWorkflowExecutionInfo ();
598- return instanceMetadata ;
599- }
600-
601417 public static GetWorkflowExecutionHistoryResponse getHistoryPage (
602418 byte [] nextPageToken ,
603419 IWorkflowService service ,
@@ -621,26 +437,6 @@ public static GetWorkflowExecutionHistoryResponse getHistoryPage(
621437 return history ;
622438 }
623439
624- /** Returns workflow instance history in a human readable format. */
625- public static String prettyPrintHistory (
626- IWorkflowService service , String domain , WorkflowExecution workflowExecution ) {
627- return prettyPrintHistory (service , domain , workflowExecution , true );
628- }
629- /**
630- * Returns workflow instance history in a human readable format.
631- *
632- * @param showWorkflowTasks when set to false workflow task events (decider events) are not
633- * included
634- */
635- public static String prettyPrintHistory (
636- IWorkflowService service ,
637- String domain ,
638- WorkflowExecution workflowExecution ,
639- boolean showWorkflowTasks ) {
640- Iterator <HistoryEvent > events = getHistory (service , domain , workflowExecution );
641- return prettyPrintHistory (events , showWorkflowTasks );
642- }
643-
644440 public static Iterator <HistoryEvent > getHistory (
645441 IWorkflowService service , String domain , WorkflowExecution workflowExecution ) {
646442 return new Iterator <HistoryEvent >() {
@@ -1012,38 +808,6 @@ public static boolean isDecisionEvent(HistoryEvent event) {
1012808 return result ;
1013809 }
1014810
1015- public static EventType getEventTypeForDecision (DecisionType decisionType ) {
1016- switch (decisionType ) {
1017- case ScheduleActivityTask :
1018- return EventType .ActivityTaskScheduled ;
1019- case RequestCancelActivityTask :
1020- return EventType .ActivityTaskCancelRequested ;
1021- case StartTimer :
1022- return EventType .TimerStarted ;
1023- case CompleteWorkflowExecution :
1024- return EventType .WorkflowExecutionCompleted ;
1025- case FailWorkflowExecution :
1026- return EventType .WorkflowExecutionFailed ;
1027- case CancelTimer :
1028- return EventType .TimerCanceled ;
1029- case CancelWorkflowExecution :
1030- return EventType .WorkflowExecutionCanceled ;
1031- case RequestCancelExternalWorkflowExecution :
1032- return EventType .ExternalWorkflowExecutionCancelRequested ;
1033- case RecordMarker :
1034- return EventType .MarkerRecorded ;
1035- case ContinueAsNewWorkflowExecution :
1036- return EventType .WorkflowExecutionContinuedAsNew ;
1037- case StartChildWorkflowExecution :
1038- return EventType .StartChildWorkflowExecutionInitiated ;
1039- case SignalExternalWorkflowExecution :
1040- return EventType .SignalExternalWorkflowExecutionInitiated ;
1041- case UpsertWorkflowSearchAttributes :
1042- return EventType .UpsertWorkflowSearchAttributes ;
1043- }
1044- throw new IllegalArgumentException ("Unknown decisionType" );
1045- }
1046-
1047811 public static WorkflowExecutionHistory readHistoryFromResource (String resourceFileName )
1048812 throws IOException {
1049813 ClassLoader classLoader = WorkflowExecutionUtils .class .getClassLoader ();
0 commit comments