Search in sources :

Example 26 with StackInfo

use of org.onap.so.openstack.beans.StackInfo in project so by onap.

the class MsoHeatUtils method queryStackForOutputs.

// TODO enhancement - just have this return the stack then we dont have to query again in deleteStack
public Map<String, Object> queryStackForOutputs(String cloudSiteId, String cloudOwner, String tenantId, String stackName) throws MsoException {
    logger.debug("MsoHeatUtils.queryStackForOutputs)");
    StackInfo heatStack = this.queryStack(cloudSiteId, cloudOwner, tenantId, stackName);
    if (heatStack == null || heatStack.getStatus() == HeatStatus.NOTFOUND) {
        return null;
    }
    return heatStack.getOutputs();
}
Also used : StackInfo(org.onap.so.openstack.beans.StackInfo)

Example 27 with StackInfo

use of org.onap.so.openstack.beans.StackInfo in project so by onap.

the class MsoHeatUtils method deleteVdu.

/**
 * VduPlugin interface for delete function.
 */
@Override
public VduInstance deleteVdu(CloudInfo cloudInfo, String instanceId, int timeoutMinutes) throws VduException {
    String cloudSiteId = cloudInfo.getCloudSiteId();
    String cloudOwner = cloudInfo.getCloudOwner();
    String tenantId = cloudInfo.getTenantId();
    try {
        // Delete the Heat stack
        StackInfo stackInfo = deleteStack(tenantId, cloudOwner, cloudSiteId, instanceId, true, timeoutMinutes);
        // Populate a VduInstance based on the deleted Cloudify Deployment object
        VduInstance vduInstance = stackInfoToVduInstance(stackInfo);
        // Override return state to DELETED (HeatUtils sets to NOTFOUND)
        vduInstance.getStatus().setState(VduStateType.DELETED);
        return vduInstance;
    } catch (Exception e) {
        throw new VduException("Delete VDU Exception", e);
    }
}
Also used : VduInstance(org.onap.so.adapters.vdu.VduInstance) StackInfo(org.onap.so.openstack.beans.StackInfo) VduException(org.onap.so.adapters.vdu.VduException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) VduException(org.onap.so.adapters.vdu.VduException)

Example 28 with StackInfo

use of org.onap.so.openstack.beans.StackInfo 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 29 with StackInfo

use of org.onap.so.openstack.beans.StackInfo 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 30 with StackInfo

use of org.onap.so.openstack.beans.StackInfo in project so by onap.

the class StackInfoMapperTest method checkOutputToMap.

@Test
public void checkOutputToMap() throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper jacksonMapper = new ObjectMapper();
    Stack sample = jacksonMapper.readValue(this.getJson("stack-example.json"), Stack.class);
    StackInfoMapper mapper = new StackInfoMapper(sample);
    StackInfo result = mapper.map();
    Map<String, Object> map = result.getOutputs();
    assertEquals(true, map.containsKey("key2"));
    assertEquals("value1", map.get("key1"));
}
Also used : StackInfo(org.onap.so.openstack.beans.StackInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Stack(com.woorea.openstack.heat.model.Stack) Test(org.junit.Test)

Aggregations

StackInfo (org.onap.so.openstack.beans.StackInfo)38 MsoException (org.onap.so.openstack.exceptions.MsoException)17 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 Stack (com.woorea.openstack.heat.model.Stack)9 CloudSite (org.onap.so.db.catalog.beans.CloudSite)8 MsoOpenstackException (org.onap.so.openstack.exceptions.MsoOpenstackException)8 VduException (org.onap.so.adapters.vdu.VduException)7 BaseTest (org.onap.so.BaseTest)6 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)6 Heat (com.woorea.openstack.heat.Heat)4 MalformedURLException (java.net.MalformedURLException)4 Response (javax.ws.rs.core.Response)4 UriBuilderException (javax.ws.rs.core.UriBuilderException)4 RestClient (org.onap.so.client.RestClient)4 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)4 StackInfoMapper (org.onap.so.openstack.mappers.StackInfoMapper)4 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)3 OpenStackRequest (com.woorea.openstack.base.client.OpenStackRequest)3 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)3