Example usage for com.amazonaws.services.simpleworkflow.model DescribeWorkflowExecutionRequest setExecution

List of usage examples for com.amazonaws.services.simpleworkflow.model DescribeWorkflowExecutionRequest setExecution

Introduction

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

Prototype


public void setExecution(WorkflowExecution execution) 

Source Link

Document

The workflow execution to describe.

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 {/*from  w  ww .  j av  a2 s.  c o  m*/
        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:org.apache.camel.component.aws.swf.CamelSWFWorkflowClient.java

License:Apache License

public Map<String, Object> describeWorkflowInstance(String workflowId, String runId) {
    DescribeWorkflowExecutionRequest describeRequest = new DescribeWorkflowExecutionRequest();
    describeRequest.setDomain(configuration.getDomainName());
    describeRequest.setExecution(new WorkflowExecution().withWorkflowId(workflowId).withRunId(runId));
    WorkflowExecutionDetail executionDetail = endpoint.getSWClient().describeWorkflowExecution(describeRequest);
    WorkflowExecutionInfo instanceMetadata = executionDetail.getExecutionInfo();

    Map<String, Object> info = new HashMap<String, Object>();
    info.put("closeStatus", instanceMetadata.getCloseStatus());
    info.put("closeTimestamp", instanceMetadata.getCloseTimestamp());
    info.put("executionStatus", instanceMetadata.getExecutionStatus());
    info.put("tagList", instanceMetadata.getTagList());
    info.put("executionDetail", executionDetail);
    return info;//from   ww w. j a  v a2  s .c o m
}