Search in sources :

Example 11 with StackInfo

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

the class MsoMulticloudUtils method instantiateVdu.

/**
 * VduPlugin interface for instantiate function.
 *
 * Translate the VduPlugin parameters to the corresponding 'createStack' parameters, and then invoke the existing
 * function.
 */
@Override
public VduInstance instantiateVdu(CloudInfo cloudInfo, String instanceName, Map<String, Object> inputs, VduModelInfo vduModel, boolean rollbackOnFailure) throws VduException {
    String cloudSiteId = cloudInfo.getCloudSiteId();
    String cloudOwner = cloudInfo.getCloudOwner();
    String tenantId = cloudInfo.getTenantId();
    // Translate the VDU ModelInformation structure to that which is needed for
    // creating the Heat stack. Loop through the artifacts, looking specifically
    // for MAIN_TEMPLATE and ENVIRONMENT. Any other artifact will
    // be attached as a FILE.
    String heatTemplate = null;
    Map<String, Object> nestedTemplates = new HashMap<>();
    Map<String, Object> files = new HashMap<>();
    String heatEnvironment = null;
    for (VduArtifact vduArtifact : vduModel.getArtifacts()) {
        if (vduArtifact.getType() == ArtifactType.MAIN_TEMPLATE) {
            heatTemplate = new String(vduArtifact.getContent());
        } else if (vduArtifact.getType() == ArtifactType.NESTED_TEMPLATE) {
            nestedTemplates.put(vduArtifact.getName(), new String(vduArtifact.getContent()));
        } else if (vduArtifact.getType() == ArtifactType.ENVIRONMENT) {
            heatEnvironment = new String(vduArtifact.getContent());
        }
    }
    try {
        StackInfo stackInfo = createStack(cloudSiteId, cloudOwner, tenantId, instanceName, vduModel, heatTemplate, // poll
        inputs, // poll
        true, // completion
        vduModel.getTimeoutMinutes(), heatEnvironment, nestedTemplates, files, rollbackOnFailure, false);
        // Populate a vduInstance from the StackInfo
        return stackInfoToVduInstance(stackInfo);
    } catch (Exception e) {
        throw new VduException("MsoMulticloudUtils (instantiateVDU): createStack Exception", e);
    }
}
Also used : HashMap(java.util.HashMap) StackInfo(org.onap.so.openstack.beans.StackInfo) VduArtifact(org.onap.so.adapters.vdu.VduArtifact) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) VduException(org.onap.so.adapters.vdu.VduException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) MalformedURLException(java.net.MalformedURLException) UriBuilderException(javax.ws.rs.core.UriBuilderException) MsoException(org.onap.so.openstack.exceptions.MsoException) VduException(org.onap.so.adapters.vdu.VduException)

Example 12 with StackInfo

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

the class MsoMulticloudUtils method queryVdu.

/**
 * VduPlugin interface for query function.
 */
@Override
public VduInstance queryVdu(CloudInfo cloudInfo, String instanceId) throws VduException {
    String cloudSiteId = cloudInfo.getCloudSiteId();
    String cloudOwner = cloudInfo.getCloudOwner();
    String tenantId = cloudInfo.getTenantId();
    try {
        // Query the Cloudify Deployment object and populate a VduInstance
        StackInfo stackInfo = queryStack(cloudSiteId, cloudOwner, tenantId, instanceId);
        return stackInfoToVduInstance(stackInfo);
    } catch (Exception e) {
        throw new VduException("MsoMulticloudUtils (queryVdu): queryStack Exception ", e);
    }
}
Also used : StackInfo(org.onap.so.openstack.beans.StackInfo) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) VduException(org.onap.so.adapters.vdu.VduException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) MalformedURLException(java.net.MalformedURLException) UriBuilderException(javax.ws.rs.core.UriBuilderException) MsoException(org.onap.so.openstack.exceptions.MsoException) VduException(org.onap.so.adapters.vdu.VduException)

Example 13 with StackInfo

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

the class MsoMulticloudUtils method deleteStack.

public StackInfo deleteStack(String cloudSiteId, String cloudOwner, String tenantId, String instanceId) throws MsoException {
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Delete multicloud HEAT stack: %s in tenant %s", instanceId, tenantId));
    }
    String stackName = null;
    String stackId = null;
    int offset = instanceId.indexOf('/');
    if (offset > 0 && offset < (instanceId.length() - 1)) {
        stackName = instanceId.substring(0, offset);
        stackId = instanceId.substring(offset + 1);
    } else {
        stackName = instanceId;
        stackId = instanceId;
    }
    StackInfo returnInfo = new StackInfo();
    returnInfo.setName(stackName);
    Response response = null;
    String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId, false);
    RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);
    if (multicloudClient != null) {
        response = multicloudClient.delete();
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Multicloud Delete response is: %s", response.getEntity().toString()));
        }
        if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
            returnInfo.setStatus(HeatStatus.NOTFOUND);
            returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase());
        } else if (response.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) {
            return getStackStatus(cloudSiteId, cloudOwner, tenantId, instanceId);
        } else {
            returnInfo.setStatus(HeatStatus.FAILED);
            returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase());
        }
    }
    returnInfo.setStatus(mapResponseToHeatStatus(response));
    return returnInfo;
}
Also used : Response(javax.ws.rs.core.Response) RestClient(org.onap.so.client.RestClient) StackInfo(org.onap.so.openstack.beans.StackInfo)

Example 14 with StackInfo

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

the class StackInfoMapperTest method mapRemainingFields.

@Test
public void mapRemainingFields() {
    Stack stack = new Stack();
    stack.setStackName("name");
    stack.setId("id");
    stack.setStackStatusReason("message");
    stack.setParameters(new HashMap<String, Object>());
    StackInfoMapper mapper = new StackInfoMapper(stack);
    StackInfo info = mapper.map();
    assertEquals("name", info.getName());
    assertEquals("name/id", info.getCanonicalName());
    assertEquals("message", info.getStatusMessage());
    assertEquals(stack.getParameters(), info.getParameters());
}
Also used : StackInfo(org.onap.so.openstack.beans.StackInfo) Stack(com.woorea.openstack.heat.model.Stack) Test(org.junit.Test)

Example 15 with StackInfo

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

the class MsoHeatUtilsWithUpdateTest method updateStackWithEnvironmentTest.

@Test
public void updateStackWithEnvironmentTest() throws JsonParseException, JsonMappingException, IOException, MsoException {
    String environmentString = "environmentString";
    CloudSite cloudSite = new CloudSite();
    Heat heatClient = new Heat("endpoint");
    Stack heatStack = mapper.readValue(new File(RESOURCE_PATH + "HeatStack.json"), Stack.class);
    Stack updateStack = mapper.readValue(new File(RESOURCE_PATH + "UpdateStack.json"), Stack.class);
    StackInfo expectedStackInfo = new StackInfo("stackName", HeatStatus.UPDATED, "stackStatusReason", null);
    expectedStackInfo.setCanonicalName("stackName/id");
    doReturn(heatClient).when(heatUtils).getHeatClient(isA(String.class), isA(String.class));
    doReturn(null).when(heatUtils).executeAndRecordOpenstackRequest(isA(OpenStackRequest.class));
    doReturn("0").when(environment).getProperty(isA(String.class), isA(String.class));
    doReturn(updateStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class));
    StackInfo actualStackInfo = heatUtils.updateStack(cloudSiteId, cloudOwner, tenantId, stackName, heatTemplate, stackInputs, pollForCompletion, timeoutMinutes, environmentString);
    assertThat(actualStackInfo, sameBeanAs(expectedStackInfo));
}
Also used : Heat(com.woorea.openstack.heat.Heat) CloudSite(org.onap.so.db.catalog.beans.CloudSite) OpenStackRequest(com.woorea.openstack.base.client.OpenStackRequest) File(java.io.File) StackInfo(org.onap.so.openstack.beans.StackInfo) 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