Example usage for com.amazonaws.services.simpleworkflow.model HistoryEvent getEventType

List of usage examples for com.amazonaws.services.simpleworkflow.model HistoryEvent getEventType

Introduction

In this page you can find the example usage for com.amazonaws.services.simpleworkflow.model HistoryEvent getEventType.

Prototype


public String getEventType() 

Source Link

Document

The type of the history event.

Usage

From source file:aws.example.helloswf.WorkflowWorker.java

License:Apache License

/**
 * The goal of this workflow is to execute at least one HelloActivity successfully.
 *
 * We pass the workflow execution's input to the activity, and we use the activity's result
 * as the output of the workflow./*from w w  w . j  a v  a2s. co m*/
 */
private static void executeDecisionTask(String taskToken, List<HistoryEvent> events) throws Throwable {
    List<Decision> decisions = new ArrayList<Decision>();
    String workflow_input = null;
    int scheduled_activities = 0;
    int open_activities = 0;
    boolean activity_completed = false;
    String result = null;

    System.out.println("Executing the decision task for the history events: [");
    for (HistoryEvent event : events) {
        System.out.println("  " + event);
        switch (event.getEventType()) {
        case "WorkflowExecutionStarted":
            workflow_input = event.getWorkflowExecutionStartedEventAttributes().getInput();
            break;
        case "ActivityTaskScheduled":
            scheduled_activities++;
            break;
        case "ScheduleActivityTaskFailed":
            scheduled_activities--;
            break;
        case "ActivityTaskStarted":
            scheduled_activities--;
            open_activities++;
            break;
        case "ActivityTaskCompleted":
            open_activities--;
            activity_completed = true;
            result = event.getActivityTaskCompletedEventAttributes().getResult();
            break;
        case "ActivityTaskFailed":
            open_activities--;
            break;
        case "ActivityTaskTimedOut":
            open_activities--;
            break;
        }
    }
    System.out.println("]");

    if (activity_completed) {
        decisions.add(new Decision().withDecisionType(DecisionType.CompleteWorkflowExecution)
                .withCompleteWorkflowExecutionDecisionAttributes(
                        new CompleteWorkflowExecutionDecisionAttributes().withResult(result)));
    } else {
        if (open_activities == 0 && scheduled_activities == 0) {

            ScheduleActivityTaskDecisionAttributes attrs = new ScheduleActivityTaskDecisionAttributes()
                    .withActivityType(new ActivityType().withName(HelloTypes.ACTIVITY)
                            .withVersion(HelloTypes.ACTIVITY_VERSION))
                    .withActivityId(UUID.randomUUID().toString()).withInput(workflow_input);

            decisions.add(new Decision().withDecisionType(DecisionType.ScheduleActivityTask)
                    .withScheduleActivityTaskDecisionAttributes(attrs));
        } else {
            // an instance of HelloActivity is already scheduled or running. Do nothing, another
            // task will be scheduled once the activity completes, fails or times out
        }
    }

    System.out.println("Exiting the decision task with the decisions " + decisions);

    swf.respondDecisionTaskCompleted(
            new RespondDecisionTaskCompletedRequest().withTaskToken(taskToken).withDecisions(decisions));
}

From source file:example.swf.hellolambda.WorkflowWorker.java

License:Apache License

/**
 * The goal of this workflow is to execute at least one HelloFunction
 * successfully.//from ww  w.  j  a v  a2  s .co m
 *
 * We pass the workflow execution's input to the activity, and we use the
 * activity's result as the output of the workflow.
 */
private static void executeDecisionTask(String taskToken, List<HistoryEvent> events) throws Throwable {
    List<Decision> decisions = new ArrayList<Decision>();
    String workflow_input = null;
    int scheduled_functions = 0;
    int running_functions = 0;
    boolean function_completed = false;
    String result = null;

    System.out.println("Executing the decision task for the history events: [");
    for (HistoryEvent event : events) {
        System.out.println("  " + event);
        EventType event_type = EventType.fromValue(event.getEventType());
        switch (event_type) {
        case WorkflowExecutionStarted:
            workflow_input = event.getWorkflowExecutionStartedEventAttributes().getInput();
            break;
        case LambdaFunctionScheduled:
            scheduled_functions++;
            break;
        case ScheduleLambdaFunctionFailed:
            scheduled_functions--;
            break;
        case LambdaFunctionStarted:
            scheduled_functions--;
            running_functions++;
            break;
        case LambdaFunctionCompleted:
            running_functions--;
            function_completed = true;
            result = event.getLambdaFunctionCompletedEventAttributes().getResult();
            break;
        case LambdaFunctionFailed:
            running_functions--;
            break;
        case LambdaFunctionTimedOut:
            running_functions--;
            break;
        }
    }
    System.out.println("]");

    if (function_completed) {
        decisions.add(new Decision().withDecisionType(DecisionType.CompleteWorkflowExecution)
                .withCompleteWorkflowExecutionDecisionAttributes(
                        new CompleteWorkflowExecutionDecisionAttributes().withResult(result)));
    } else {
        if (running_functions == 0 && scheduled_functions == 0) {
            AWSLambda lam = AWSLambdaClientBuilder.defaultClient();
            GetFunctionConfigurationResult function_config = lam.getFunctionConfiguration(
                    new GetFunctionConfigurationRequest().withFunctionName("HelloFunction"));
            String function_arn = function_config.getFunctionArn();

            ScheduleLambdaFunctionDecisionAttributes attrs = new ScheduleLambdaFunctionDecisionAttributes()
                    .withId("HelloFunction (Lambda task example)").withName(function_arn)
                    .withInput(workflow_input);

            decisions.add(new Decision().withDecisionType(DecisionType.ScheduleLambdaFunction)
                    .withScheduleLambdaFunctionDecisionAttributes(attrs));
        } else {
            // an instance of HelloFunction is already scheduled or running.
            // Do nothing, another task will be scheduled once the activity
            // completes, fails or times out
        }
    }

    System.out.println("Exiting the decision task with the decisions " + decisions);

    swf.respondDecisionTaskCompleted(
            new RespondDecisionTaskCompletedRequest().withTaskToken(taskToken).withDecisions(decisions));
}

From source file:org.diksha.common.dyutils.SchedulerUDE.java

License:Apache License

public static void listActivitiesInWEI(SchedulerConfig schedulerConfig,
        List<WorkflowExecutionInfo> listWorkflowExecutionInfo) {

    AmazonSimpleWorkflowClient amazonSimpleWorkflowClient = new AmazonSimpleWorkflowClient(
            DyDBUtils.getAwsCredentials());
    amazonSimpleWorkflowClient.setEndpoint(schedulerConfig.getEndPoint());

    for (int cnt2 = 0; cnt2 < listWorkflowExecutionInfo.size(); cnt2++) {

        WorkflowExecutionInfo workflowExecutionInfo = listWorkflowExecutionInfo.get(cnt2);
        WorkflowExecution workflowExecution = workflowExecutionInfo.getExecution();
        //             System.out.println(workflowExecution);

        GetWorkflowExecutionHistoryRequest getWorkflowExecutionHistoryRequest = new GetWorkflowExecutionHistoryRequest()
                .withDomain(schedulerConfig.getDomain()).withExecution(workflowExecution);

        History history = amazonSimpleWorkflowClient
                .getWorkflowExecutionHistory(getWorkflowExecutionHistoryRequest);

        List<HistoryEvent> historyEvents;
        String nextPageToken;//w w  w  . j  a  v  a2s .co m

        do {
            historyEvents = history.getEvents();
            for (int cnt3 = 0; cnt3 < historyEvents.size(); cnt3++) {

                // , , , , , , 

                HistoryEvent he = historyEvents.get(cnt3);
                String eventType = historyEvents.get(cnt3).getEventType();
                if (eventType.equals("ActivityTaskStarted") || eventType.equals("ActivityTaskCompleted")
                        || eventType.equals("ActivityTaskFailed") || eventType.equals("ActivityTaskTimedOut")
                        || eventType.equals("ActivityTaskCanceled")
                        || eventType.equals("ActivityTaskCancelRequested")

                ) {

                    if (he.getEventType().equals("ActivityTaskCompleted"))
                        System.out.format("\n         %30s       %20s      ", he.getEventType(),
                                he.getEventTimestamp());

                }
            }
            nextPageToken = history.getNextPageToken();
            history.setNextPageToken(nextPageToken);
        } while (nextPageToken != null);

    }

}