Search in sources :

Example 26 with Stack

use of com.woorea.openstack.heat.model.Stack in project so by onap.

the class MsoHeatUtils method deleteStack.

/**
 * Delete a stack (by Name/ID) in a tenant. If the stack is not found, it will be considered a successful deletion.
 * The return value is a StackInfo object which contains the current stack status.
 *
 * The client may choose to let the adapter poll Openstack for completion of the stack deletion, or may handle
 * polling itself via separate query calls. In either case, a StackInfo object will be returned. When polling is
 * enabled, a final status of NOTFOUND is expected. When not polling, a status of DELETING is expected.
 *
 * There is no rollback from a successful stack deletion. A deletion failure will also result in an undefined stack
 * state - the components may or may not have been all or partially deleted, so the resulting stack must be
 * considered invalid.
 *
 * @param tenantId The Openstack ID of the tenant in which to perform the delete
 * @param cloudOwner the cloud owner of the cloud site in which to delete the stack
 * @param cloudSiteId The cloud identifier (may be a region) from which to delete the stack.
 * @param stackName The name/id of the stack to delete. May be simple or canonical
 * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client
 * @return A StackInfo object
 * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception.
 * @throws MsoCloudSiteNotFound
 */
public StackInfo deleteStack(String tenantId, String cloudOwner, String cloudSiteId, String stackName, boolean pollForCompletion, int timeoutMinutes) throws MsoException {
    Stack currentStack = queryHeatStack(stackName, cloudSiteId, tenantId);
    StackInfo stackInfo = null;
    if (currentStack == null || DELETE_COMPLETE.equals(currentStack.getStackStatus())) {
        stackInfo = new StackInfo(stackName, HeatStatus.NOTFOUND);
        stackInfo.setOperationPerformed(false);
    } else {
        currentStack = deleteStack(currentStack, timeoutMinutes, cloudSiteId, tenantId, pollForCompletion);
        stackInfo = new StackInfoMapper(currentStack).map();
        stackInfo.setName(stackName);
        stackInfo.setOperationPerformed(true);
        if (currentStack != null) {
            stackInfo.setCanonicalName(currentStack.getStackName() + "/" + currentStack.getId());
        }
    }
    return stackInfo;
}
Also used : StackInfoMapper(org.onap.so.openstack.mappers.StackInfoMapper) StackInfo(org.onap.so.openstack.beans.StackInfo) Stack(com.woorea.openstack.heat.model.Stack)

Example 27 with Stack

use of com.woorea.openstack.heat.model.Stack in project so by onap.

the class MsoHeatUtils method postProcessStackCreate.

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;
        }
    }
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) Stack(com.woorea.openstack.heat.model.Stack)

Example 28 with Stack

use of com.woorea.openstack.heat.model.Stack in project so by onap.

the class MsoHeatUtils method createStack.

protected Stack createStack(CreateStackParam stack, String cloudSiteId, String tenantId) throws MsoException {
    try {
        OpenStackRequest<Stack> request = getHeatClient(cloudSiteId, tenantId).getStacks().create(stack);
        saveStackRequest(stack, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), stack.getStackName());
        return executeAndRecordOpenstackRequest(request);
    } catch (OpenStackResponseException e) {
        if (e.getStatus() == 409) {
            MsoStackAlreadyExists me = new MsoStackAlreadyExists(stack.getStackName(), tenantId, cloudSiteId);
            me.addContext(CREATE_STACK);
            throw me;
        } else {
            logger.error("ERROR STATUS = {},\n{}\n{}", e.getStatus(), e.getMessage(), e.getLocalizedMessage());
            throw heatExceptionToMsoException(e, CREATE_STACK);
        }
    } catch (OpenStackConnectException e) {
        throw heatExceptionToMsoException(e, CREATE_STACK);
    } catch (RuntimeException e) {
        throw runtimeExceptionToMsoException(e, CREATE_STACK);
    }
}
Also used : MsoStackAlreadyExists(org.onap.so.openstack.exceptions.MsoStackAlreadyExists) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) Stack(com.woorea.openstack.heat.model.Stack)

Example 29 with Stack

use of com.woorea.openstack.heat.model.Stack in project so by onap.

the class MsoHeatUtils method queryStack.

/**
 * Query for a single stack (by Name) in a tenant. This call will always return a StackInfo object. If the stack
 * does not exist, an "empty" StackInfo will be returned - containing only the stack name and a status of NOTFOUND.
 *
 * @param tenantId The Openstack ID of the tenant in which to query
 * @param cloudSiteId The cloud identifier (may be a region) in which to query
 * @param cloudOwner the cloud owner of the cloud site in which to query
 * @param stackName The name of the stack to query (may be simple or canonical)
 * @return A StackInfo object
 * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception.
 */
public StackInfo queryStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName) throws MsoException {
    logger.debug("Query HEAT stack: {} in tenant {}", stackName, tenantId);
    Heat heatClient = null;
    try {
        heatClient = getHeatClient(cloudSiteId, tenantId);
    } catch (MsoTenantNotFound e) {
        // Tenant doesn't exist, so stack doesn't either
        logger.debug("Tenant with id " + tenantId + "not found.", e);
        return new StackInfo(stackName, HeatStatus.NOTFOUND);
    } catch (MsoException me) {
        // Got an Openstack error. Propagate it
        logger.error("{} {} Openstack Exception on Token request: ", MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.AvailabilityError.getValue(), me);
        me.addContext("QueryStack");
        throw me;
    }
    // Query the Stack.
    // An MsoException will propagate transparently to the caller.
    Stack heatStack = queryHeatStack(heatClient, stackName);
    if (heatStack == null) {
        // Stack does not exist. Return a StackInfo with status NOTFOUND
        return new StackInfo(stackName, HeatStatus.NOTFOUND);
    }
    return new StackInfoMapper(heatStack).map();
}
Also used : StackInfoMapper(org.onap.so.openstack.mappers.StackInfoMapper) Heat(com.woorea.openstack.heat.Heat) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoTenantNotFound(org.onap.so.openstack.exceptions.MsoTenantNotFound) StackInfo(org.onap.so.openstack.beans.StackInfo) Stack(com.woorea.openstack.heat.model.Stack)

Example 30 with Stack

use of com.woorea.openstack.heat.model.Stack in project so by onap.

the class PollService method pollCreateResource.

private StackInfo pollCreateResource(int pollingTimeout, String cloudSiteId, String tenantId, String stackId, MutableBoolean success) throws MsoException {
    Stack currentStack = createCurrentStack(stackId);
    Stack stack = msoHeatUtils.pollStackForStatus(pollingTimeout, currentStack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false);
    msoHeatUtils.postProcessStackCreate(stack, false, 0, false, cloudSiteId, tenantId, null);
    success.setTrue();
    return new StackInfoMapper(stack).map();
}
Also used : StackInfoMapper(org.onap.so.openstack.mappers.StackInfoMapper) Stack(com.woorea.openstack.heat.model.Stack)

Aggregations

Stack (com.woorea.openstack.heat.model.Stack)41 Test (org.junit.Test)26 CreateStack (com.woorea.openstack.heat.StackResource.CreateStack)15 DeleteStack (com.woorea.openstack.heat.StackResource.DeleteStack)15 CreateStackParam (com.woorea.openstack.heat.model.CreateStackParam)10 Heat (com.woorea.openstack.heat.Heat)9 StackInfo (org.onap.so.openstack.beans.StackInfo)9 StackInfoMapper (org.onap.so.openstack.mappers.StackInfoMapper)7 MsoException (org.onap.so.openstack.exceptions.MsoException)5 OpenStackRequest (com.woorea.openstack.base.client.OpenStackRequest)3 File (java.io.File)3 HashMap (java.util.HashMap)3 CloudSite (org.onap.so.db.catalog.beans.CloudSite)3 MsoOpenstackException (org.onap.so.openstack.exceptions.MsoOpenstackException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 RequestProcessingData (org.onap.so.db.request.beans.RequestProcessingData)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)1 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)1 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)1