Example usage for com.amazonaws.services.simpleworkflow.model WorkflowExecution setWorkflowId

List of usage examples for com.amazonaws.services.simpleworkflow.model WorkflowExecution setWorkflowId

Introduction

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

Prototype


public void setWorkflowId(String workflowId) 

Source Link

Document

The user defined identifier associated with the workflow execution.

Usage

From source file:com.eucalyptus.cloudformation.CloudFormationService.java

License:Open Source License

public DeleteStackResponseType deleteStack(final DeleteStackType request) throws CloudFormationException {
    DeleteStackResponseType reply = request.getReply();
    try {//  w ww  .j  a v a  2  s.c  om
        final Context ctx = Contexts.lookup();
        final User user = ctx.getUser();
        final String userId = user.getUserId();
        final String accountId = ctx.getAccountNumber();
        final String accountAlias = ctx.getAccountAlias();
        final String stackName = request.getStackName();
        if (stackName == null)
            throw new ValidationErrorException("Stack name is null");
        StackEntity stackEntity = StackEntityManager.getNonDeletedStackByNameOrId(stackName, accountId);
        if (stackEntity == null && ctx.isAdministrator() && stackName.startsWith(STACK_ID_PREFIX)) {
            stackEntity = StackEntityManager.getNonDeletedStackByNameOrId(stackName, null);
        }
        if (stackEntity != null) {
            if (!RestrictedTypes.filterPrivileged().apply(stackEntity)) {
                throw new AccessDeniedException("Not authorized.");
            }
            final String stackAccountId = stackEntity.getAccountId();

            // check to see if there has been a delete workflow.  If one exists and is still going on, just quit:
            boolean existingOpenDeleteWorkflow = false;
            List<StackWorkflowEntity> deleteWorkflows = StackWorkflowEntityManager.getStackWorkflowEntities(
                    stackEntity.getStackId(), StackWorkflowEntity.WorkflowType.DELETE_STACK_WORKFLOW);
            if (deleteWorkflows != null && !deleteWorkflows.isEmpty()) {
                if (deleteWorkflows.size() > 1) {
                    throw new ValidationErrorException(
                            "More than one delete workflow exists for " + stackEntity.getStackId()); // TODO: InternalFailureException (?)
                }
                // see if the workflow is open
                try {
                    AmazonSimpleWorkflow simpleWorkflowClient = WorkflowClientManager.getSimpleWorkflowClient();
                    StackWorkflowEntity deleteStackWorkflowEntity = deleteWorkflows.get(0);
                    DescribeWorkflowExecutionRequest describeWorkflowExecutionRequest = new DescribeWorkflowExecutionRequest();
                    describeWorkflowExecutionRequest.setDomain(deleteStackWorkflowEntity.getDomain());
                    WorkflowExecution execution = new WorkflowExecution();
                    execution.setRunId(deleteStackWorkflowEntity.getRunId());
                    execution.setWorkflowId(deleteStackWorkflowEntity.getWorkflowId());
                    describeWorkflowExecutionRequest.setExecution(execution);
                    WorkflowExecutionDetail workflowExecutionDetail = simpleWorkflowClient
                            .describeWorkflowExecution(describeWorkflowExecutionRequest);
                    if ("OPEN".equals(workflowExecutionDetail.getExecutionInfo().getExecutionStatus())) {
                        existingOpenDeleteWorkflow = true;
                    }
                } catch (Exception ex) {
                    LOG.error("Unable to get status of delete workflow for " + stackEntity.getStackId()
                            + ", assuming not open");
                    LOG.debug(ex);
                }
            }
            if (!existingOpenDeleteWorkflow) {
                String stackId = stackEntity.getStackId();
                StackWorkflowTags stackWorkflowTags = new StackWorkflowTags(stackId, stackName, stackAccountId,
                        accountAlias);

                WorkflowClientFactory workflowClientFactory = new WorkflowClientFactory(
                        WorkflowClientManager.getSimpleWorkflowClient(), CloudFormationProperties.SWF_DOMAIN,
                        CloudFormationProperties.SWF_TASKLIST);
                WorkflowDescriptionTemplate workflowDescriptionTemplate = new DeleteStackWorkflowDescriptionTemplate();
                InterfaceBasedWorkflowClient<DeleteStackWorkflow> client = workflowClientFactory
                        .getNewWorkflowClient(DeleteStackWorkflow.class, workflowDescriptionTemplate,
                                stackWorkflowTags);
                DeleteStackWorkflow deleteStackWorkflow = new DeleteStackWorkflowClient(client);
                deleteStackWorkflow.deleteStack(stackId, stackAccountId,
                        stackEntity.getResourceDependencyManagerJson(), userId);
                StackWorkflowEntityManager.addOrUpdateStackWorkflowEntity(stackEntity.getStackId(),
                        StackWorkflowEntity.WorkflowType.DELETE_STACK_WORKFLOW,
                        CloudFormationProperties.SWF_DOMAIN, client.getWorkflowExecution().getWorkflowId(),
                        client.getWorkflowExecution().getRunId());
            }
        }
    } catch (Exception ex) {
        handleException(ex);
    }
    return reply;
}

From source file:com.swf.common.WorkflowExecutionFlowThreadDumper.java

License:Open Source License

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.err.println("Usage: java " + WorkflowExecutionFlowThreadDumper.class.getName()
                + "<workflow implementation class> <workflowId> <runId>");
        System.exit(1);/*from   w  w w  . ja  v a 2  s . com*/
    }
    ConfigHelper configHelper = ConfigHelper.createConfig();
    AmazonSimpleWorkflow swfService = configHelper.createSWFClient();
    String domain = configHelper.getDomain();

    WorkflowExecution workflowExecution = new WorkflowExecution();
    String workflowId = args[1];
    workflowExecution.setWorkflowId(workflowId);
    String runId = args[2];
    workflowExecution.setRunId(runId);

    String implementationTypeName = args[0];
    @SuppressWarnings("unchecked")
    Class<Object> workflowImplementationType = (Class<Object>) Class.forName(implementationTypeName);
    WorkflowReplayer<Object> replayer = new WorkflowReplayer<Object>(swfService, domain, workflowExecution,
            workflowImplementationType);

    System.out.println("Beginning workflow replay for " + workflowExecution);
    try {
        String flowThreadDump = replayer.getAsynchronousThreadDumpAsString();
        System.out.println("Workflow asynchronous thread dump:");
        System.out.println(flowThreadDump);
    } catch (WorkflowException e) {
        System.out.println("No asynchronous thread dump available as workflow has failed: " + e);
    }
}

From source file:com.swf.common.WorkflowExecutionGetState.java

License:Open Source License

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.err//from  w w  w . j  a v  a  2  s. c om
                .println("Usage: java " + WorkflowExecutionGetState.class.getName() + " <workflowId> <runId>");
        System.exit(1);
    }
    ConfigHelper configHelper = ConfigHelper.createConfig();
    AmazonSimpleWorkflow swfService = configHelper.createSWFClient();
    String domain = configHelper.getDomain();

    WorkflowExecution workflowExecution = new WorkflowExecution();
    String workflowId = args[1];
    workflowExecution.setWorkflowId(workflowId);
    String runId = args[2];
    workflowExecution.setRunId(runId);

    GenericWorkflowClientExternal client = new GenericWorkflowClientExternalImpl(swfService, domain);

    String state = client.getWorkflowState(workflowExecution);

    System.out.println("Current state of " + workflowExecution + ":");
    System.out.println(state);
}

From source file:com.swf.common.WorkflowExecutionHistoryPrinter.java

License:Open Source License

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.err.println(//from   w  w  w  .  j av a 2s. co m
                "Usage: java " + WorkflowExecutionHistoryPrinter.class.getName() + " <workflowId> <runId>");
        System.exit(1);
    }
    ConfigHelper configHelper = ConfigHelper.createConfig();
    AmazonSimpleWorkflow swfService = configHelper.createSWFClient();
    String domain = configHelper.getDomain();

    WorkflowExecution workflowExecution = new WorkflowExecution();
    String workflowId = args[0];
    workflowExecution.setWorkflowId(workflowId);
    String runId = args[1];
    workflowExecution.setRunId(runId);
    System.out.println(WorkflowExecutionUtils.prettyPrintHistory(swfService, domain, workflowExecution, true));
}

From source file:com.swf.common.WorkflowExecutionReplayer.java

License:Open Source License

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.err.println("Usage: java " + WorkflowExecutionReplayer.class.getName()
                + "<workflow implementation class> <workflowId> <runId>");
        System.exit(1);/*www .j a  va2 s.c o m*/
    }
    ConfigHelper configHelper = ConfigHelper.createConfig();
    AmazonSimpleWorkflow swfService = configHelper.createSWFClient();
    String domain = configHelper.getDomain();

    WorkflowExecution workflowExecution = new WorkflowExecution();
    String workflowId = args[1];
    workflowExecution.setWorkflowId(workflowId);
    String runId = args[2];
    workflowExecution.setRunId(runId);

    String implementationTypeName = args[0];
    @SuppressWarnings("unchecked")
    Class<Object> workflowImplementationType = (Class<Object>) Class.forName(implementationTypeName);
    WorkflowReplayer<Object> replayer = new WorkflowReplayer<Object>(swfService, domain, workflowExecution,
            workflowImplementationType);

    System.out.println("Beginning workflow replay for " + workflowExecution);
    Object workflow = replayer.loadWorkflow();
    System.out.println("Workflow implementation object:");
    System.out.println(workflow);

    System.out.println("Done workflow replay for " + workflowExecution);
}

From source file:org.apache.camel.component.aws.swf.CamelSWFWorkflowClient.java

License:Apache License

DynamicWorkflowClientExternal getDynamicWorkflowClient(String workflowId, String runId) {
    GenericWorkflowClientExternalImpl genericClient = new GenericWorkflowClientExternalImpl(
            endpoint.getSWClient(), configuration.getDomainName());
    WorkflowExecution workflowExecution = new WorkflowExecution();
    workflowExecution.setWorkflowId(workflowId != null ? workflowId : genericClient.generateUniqueId());
    workflowExecution.setRunId(runId);/*  w  w w . java  2  s .c o m*/
    return new DynamicWorkflowClientExternalImpl(workflowExecution, null, endpoint.getStartWorkflowOptions(),
            null, genericClient);
}