Example usage for com.amazonaws.services.simpleworkflow AmazonSimpleWorkflow describeWorkflowExecution

List of usage examples for com.amazonaws.services.simpleworkflow AmazonSimpleWorkflow describeWorkflowExecution

Introduction

In this page you can find the example usage for com.amazonaws.services.simpleworkflow AmazonSimpleWorkflow describeWorkflowExecution.

Prototype

WorkflowExecutionDetail describeWorkflowExecution(
        DescribeWorkflowExecutionRequest describeWorkflowExecutionRequest);

Source Link

Document

Returns information about the specified workflow execution including its type and some statistics.

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 .  co  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;
}