Search in sources :

Example 6 with VduArtifact

use of org.onap.so.adapters.vdu.VduArtifact in project so by onap.

the class VfModuleCustomizationToVduMapper method mapCloudFiles.

private void mapCloudFiles(VfModuleCustomization vfModuleCustom, VduModelInfo vduModel) {
    // TODO: These catalog objects will be refactored to be non-Heat-specific
    List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
    // Attached Files
    List<HeatFiles> heatFiles = vfModuleCustom.getVfModule().getHeatFiles();
    if (heatFiles != null) {
        for (HeatFiles file : heatFiles) {
            vduArtifacts.add(mapCloudFileToVduArtifact(file, ArtifactType.TEXT_FILE));
        }
    }
}
Also used : HeatFiles(org.onap.so.db.catalog.beans.HeatFiles) VduArtifact(org.onap.so.adapters.vdu.VduArtifact)

Example 7 with VduArtifact

use of org.onap.so.adapters.vdu.VduArtifact in project so by onap.

the class MsoHeatUtils method instantiateVdu.

/**
 *****************************************************************************
 *
 * Methods (and associated utilities) to implement the VduPlugin interface
 *
 ******************************************************************************
 */
/**
 * 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("MsoHeatUtils (instantiateVDU): createStack Exception", e);
    }
}
Also used : HashMap(java.util.HashMap) StackInfo(org.onap.so.openstack.beans.StackInfo) VduArtifact(org.onap.so.adapters.vdu.VduArtifact) 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 8 with VduArtifact

use of org.onap.so.adapters.vdu.VduArtifact in project so by onap.

the class MsoHeatUtilsITTest method instantiateVduTest.

@Test
public void instantiateVduTest() throws MsoException, IOException {
    VduInstance expected = new VduInstance();
    expected.setVduInstanceId("name/da886914-efb2-4917-b335-c8381528d90b");
    expected.setVduInstanceName("name");
    VduStatus status = new VduStatus();
    status.setState(VduStateType.INSTANTIATED);
    status.setLastAction((new PluginAction("create", "complete", null)));
    expected.setStatus(status);
    CloudInfo cloudInfo = new CloudInfo();
    cloudInfo.setCloudSiteId("MTN13");
    cloudInfo.setTenantId("tenantId");
    VduModelInfo vduModel = new VduModelInfo();
    vduModel.setModelCustomizationUUID("blueprintId");
    vduModel.setTimeoutMinutes(1);
    VduArtifact artifact = new VduArtifact();
    artifact.setName("name");
    artifact.setType(ArtifactType.MAIN_TEMPLATE);
    byte[] content = new byte[1];
    artifact.setContent(content);
    List<VduArtifact> artifacts = new ArrayList<>();
    artifacts.add(artifact);
    vduModel.setArtifacts(artifacts);
    Map<String, byte[]> blueprintFiles = new HashMap<>();
    blueprintFiles.put(artifact.getName(), artifact.getContent());
    String instanceName = "stackname";
    Map<String, Object> inputs = new HashMap<>();
    boolean rollbackOnFailure = true;
    StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
    StubOpenStack.mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack_Created.json");
    wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/stackname/stackId")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("OpenstackResponse_StackId.json").withStatus(HttpStatus.SC_OK)));
    VduInstance actual = heatUtils.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure);
    assertThat(actual, sameBeanAs(expected));
}
Also used : CloudInfo(org.onap.so.adapters.vdu.CloudInfo) HashMap(java.util.HashMap) VduInstance(org.onap.so.adapters.vdu.VduInstance) VduStatus(org.onap.so.adapters.vdu.VduStatus) ArrayList(java.util.ArrayList) VduModelInfo(org.onap.so.adapters.vdu.VduModelInfo) PluginAction(org.onap.so.adapters.vdu.PluginAction) VduArtifact(org.onap.so.adapters.vdu.VduArtifact) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Aggregations

VduArtifact (org.onap.so.adapters.vdu.VduArtifact)8 HashMap (java.util.HashMap)3 VduException (org.onap.so.adapters.vdu.VduException)2 StackInfo (org.onap.so.openstack.beans.StackInfo)2 MsoException (org.onap.so.openstack.exceptions.MsoException)2 MsoOpenstackException (org.onap.so.openstack.exceptions.MsoOpenstackException)2 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)1 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 UriBuilderException (javax.ws.rs.core.UriBuilderException)1 Test (org.junit.Test)1 BaseTest (org.onap.so.BaseTest)1 CloudInfo (org.onap.so.adapters.vdu.CloudInfo)1 PluginAction (org.onap.so.adapters.vdu.PluginAction)1 VduInstance (org.onap.so.adapters.vdu.VduInstance)1 VduModelInfo (org.onap.so.adapters.vdu.VduModelInfo)1 VduStatus (org.onap.so.adapters.vdu.VduStatus)1 HeatFiles (org.onap.so.db.catalog.beans.HeatFiles)1