class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {

    public Stack postProcessStackCreate(Stack stack, boolean backout, int timeoutMinutes, boolean cleanUpKeyPair,
            String cloudSiteId, String tenantId, CreateStackParam stackCreate) throws MsoException {
        boolean stackCreationFailed = false;
        boolean stackRollbackFailed = false;
        if (stack == null) {
            throw new StackCreationException("Unknown Error in Stack Creation");
        } else {
            logger.info("Performing post processing backout: {} cleanUpKeyPair: {}, stack {}", backout, cleanUpKeyPair,
                    stack);
            if (!CREATE_COMPLETE.equals(stack.getStackStatus())) {
                if (cleanUpKeyPair && !Strings.isNullOrEmpty(stack.getStackStatusReason())
                        && isKeyPairFailure(stack.getStackStatusReason())) {
                    return handleKeyPairConflict(cloudSiteId, tenantId, stackCreate, timeoutMinutes, backout, stack);
                }
                if (!backout) {
                    logger.info("Status is not CREATE_COMPLETE, stack deletion suppressed");
                    stackCreationFailed = true;
                    String errorMessage =
                            "Stack Creation Failed Openstack Status: " + stack.getStackStatus() + " Status Reason: "
                                    + stack.getStackStatusReason() + ". Stack rollback suppressed, stack not deleted";
                    throw new StackCreationException(errorMessage, stackCreationFailed, stackRollbackFailed);
                } else {
                    logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed");
                    stackCreationFailed = true;
                    String errorMessage = "Stack Creation Failed Openstack Status: " + stack.getStackStatus()
                            + " Status Reason: " + stack.getStackStatusReason();
                    try {
                        Stack deletedStack =
                                handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId);
                        errorMessage = errorMessage + " , Rollback of Stack Creation completed with status: "
                                + deletedStack.getStackStatus() + " Status Reason: "
                                + deletedStack.getStackStatusReason();
                    } catch (MsoException e) {
                        stackRollbackFailed = true;
                        logger.error("Sync Error Deleting Stack during rollback", e);
                        if (e instanceof StackRollbackException) {
                            errorMessage = errorMessage + e.getMessage();
                        } else {
                            errorMessage = errorMessage + " , Rollback of Stack Creation failed with sync error: "
                                    + e.getMessage();
                        }
                    }
                    throw new StackCreationException(errorMessage, stackCreationFailed, stackRollbackFailed);
                }
            } else {
                return stack;
            }
        }
    }

}