Search in sources :

Example 1 with HeatTemplate

use of org.onap.so.db.catalog.beans.HeatTemplate in project so by onap.

the class ToscaResourceInstaller method createHeatTemplateFromArtifact.

protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure, ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
    HeatTemplate existingHeatTemplate = heatRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
    if (existingHeatTemplate == null) {
        HeatTemplate heatTemplate = new HeatTemplate();
        List<String> typeList = new ArrayList<>();
        typeList.add(ASDCConfiguration.HEAT_NESTED);
        typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
        heatTemplate.setTemplateBody(verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
        heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
        if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
            heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
        } else {
            heatTemplate.setTimeoutMinutes(240);
        }
        heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
        heatTemplate.setVersion(BigDecimalVersion.castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
        heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
        if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
            heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
        } else {
            heatTemplate.setArtifactChecksum(MANUAL_RECORD);
        }
        Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID());
        heatTemplate.setParameters(heatParam);
        vfModuleArtifact.setHeatTemplate(heatTemplate);
    } else {
        if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
            existingHeatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
        }
        vfModuleArtifact.setHeatTemplate(existingHeatTemplate);
    }
}
Also used : HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) ArrayList(java.util.ArrayList) HeatTemplateParam(org.onap.so.db.catalog.beans.HeatTemplateParam)

Example 2 with HeatTemplate

use of org.onap.so.db.catalog.beans.HeatTemplate in project so by onap.

the class MsoHeatUtils method getNetworkHeatTimeoutValue.

public int getNetworkHeatTimeoutValue(String modelCustomizationUuid, String networkType) {
    int timeoutMinutes = DEFAULT_POLLING_TIMEOUT;
    try {
        NetworkResource networkResource = null;
        if (isBlank(modelCustomizationUuid)) {
            if (isNotBlank(networkType)) {
                networkResource = catalogClient.getNetworkResourceByModelName(networkType);
            }
        } else {
            NetworkResourceCustomization nrc = catalogClient.getNetworkResourceCustomizationByModelCustomizationUUID(modelCustomizationUuid);
            if (nrc != null) {
                networkResource = nrc.getNetworkResource();
            }
        }
        if (networkResource != null) {
            networkResource.getHeatTemplate().getTimeoutMinutes();
            HeatTemplate heat = networkResource.getHeatTemplate();
            if (heat != null && heat.getTimeoutMinutes() != null) {
                if (heat.getTimeoutMinutes() < DEFAULT_POLLING_TIMEOUT) {
                    timeoutMinutes = heat.getTimeoutMinutes();
                }
            }
        } else {
            logger.debug("Unable to find Network Resource with model customization uuid {} or network type {}. Using default timeout {}", modelCustomizationUuid, networkType, timeoutMinutes);
        }
    } catch (Exception e) {
        logger.warn("Exception occured while getting heat timeout value. Using default timeout {}", timeoutMinutes, e);
    }
    return timeoutMinutes;
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) 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)

Example 3 with HeatTemplate

use of org.onap.so.db.catalog.beans.HeatTemplate in project so by onap.

the class MsoHeatUtilsTest method testGetNetworkHeatTimeoutValue.

@Test
public void testGetNetworkHeatTimeoutValue() {
    NetworkResourceCustomization mc = new NetworkResourceCustomization();
    NetworkResource nr = new NetworkResource();
    HeatTemplate heat = new HeatTemplate();
    heat.setTimeoutMinutes(110);
    nr.setHeatTemplate(heat);
    mc.setNetworkResource(nr);
    Mockito.when(catalogDbClient.getNetworkResourceCustomizationByModelCustomizationUUID("uuid")).thenReturn(mc);
    int timeout = heatUtils.getNetworkHeatTimeoutValue("uuid", "type");
    assertEquals(110, timeout);
    Mockito.verify(catalogDbClient, times(1)).getNetworkResourceCustomizationByModelCustomizationUUID("uuid");
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) Test(org.junit.Test)

Example 4 with HeatTemplate

use of org.onap.so.db.catalog.beans.HeatTemplate in project so by onap.

the class MsoHeatUtilsUnitTest method convertInputMapTest.

@Test
public void convertInputMapTest() throws JsonParseException, JsonMappingException, IOException {
    MsoHeatUtils utils = new MsoHeatUtils();
    Map<String, Object> input = new HashMap<>();
    HeatTemplate template = new HeatTemplate();
    template.setArtifactUuid("my-uuid");
    Set<HeatTemplateParam> parameters = template.getParameters();
    HeatTemplateParam paramNum = new HeatTemplateParam();
    paramNum.setParamType("number");
    paramNum.setParamName("my-number");
    input.put("my-number", "3");
    HeatTemplateParam paramString = new HeatTemplateParam();
    paramString.setParamType("string");
    paramString.setParamName("my-string");
    input.put("my-string", "hello");
    HeatTemplateParam paramJson = new HeatTemplateParam();
    paramJson.setParamType("json");
    paramJson.setParamName("my-json");
    HeatTemplateParam paramJsonEscaped = new HeatTemplateParam();
    paramJsonEscaped.setParamType("json");
    paramJsonEscaped.setParamName("my-json-escaped");
    Map<String, Object> jsonMap = mapper.readValue(getJson("free-form.json"), new TypeReference<Map<String, Object>>() {
    });
    input.put("my-json", jsonMap);
    input.put("my-json-escaped", getJson("free-form.json"));
    parameters.add(paramNum);
    parameters.add(paramString);
    parameters.add(paramJson);
    parameters.add(paramJsonEscaped);
    Map<String, Object> output = utils.convertInputMap(input, template);
    assertEquals(3, output.get("my-number"));
    assertEquals("hello", output.get("my-string"));
    assertTrue("expect no change in type", output.get("my-json") instanceof Map);
    assertTrue("expect string to become jsonNode", output.get("my-json-escaped") instanceof JsonNode);
    JSONAssert.assertEquals(getJson("free-form.json"), mapper.writeValueAsString(output.get("my-json-escaped")), false);
}
Also used : HashMap(java.util.HashMap) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMap(java.util.HashMap) Map(java.util.Map) HeatTemplateParam(org.onap.so.db.catalog.beans.HeatTemplateParam) Test(org.junit.Test)

Example 5 with HeatTemplate

use of org.onap.so.db.catalog.beans.HeatTemplate in project so by onap.

the class MsoHeatUtilsUnitTest method convertInputMapNullsTest.

@Test
public final void convertInputMapNullsTest() {
    MsoHeatUtils utils = new MsoHeatUtils();
    Map<String, Object> inputs = new HashMap<>();
    Set<HeatTemplateParam> params = new HashSet<>();
    HeatTemplate ht = new HeatTemplate();
    HeatTemplateParam htp = new HeatTemplateParam();
    htp.setParamName("vnf_name");
    htp.setParamType("string");
    params.add(htp);
    inputs.put("vnf_name", null);
    htp = new HeatTemplateParam();
    htp.setParamName("image_size");
    htp.setParamType("number");
    params.add(htp);
    inputs.put("image_size", null);
    htp = new HeatTemplateParam();
    htp.setParamName("external");
    htp.setParamType("boolean");
    params.add(htp);
    inputs.put("external", null);
    htp = new HeatTemplateParam();
    htp.setParamName("oam_ips");
    htp.setParamType("comma_delimited_list");
    params.add(htp);
    inputs.put("oam_ips", null);
    htp = new HeatTemplateParam();
    htp.setParamName("oam_prefixes");
    htp.setParamType("json");
    params.add(htp);
    inputs.put("oam_prefixes", null);
    ht.setParameters(params);
    Map<String, Object> output = utils.convertInputMap(inputs, ht);
    assertNull(output.get("vnf_name"));
    assertNull(output.get("image_size"));
    assertEquals(false, output.get("external"));
    assertNull(output.get("oam_ips"));
    assertNull(output.get("oam_prefixes"));
}
Also used : HashMap(java.util.HashMap) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) HeatTemplateParam(org.onap.so.db.catalog.beans.HeatTemplateParam) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)35 VfModuleCustomization (org.onap.so.db.catalog.beans.VfModuleCustomization)22 ArrayList (java.util.ArrayList)21 HeatEnvironment (org.onap.so.db.catalog.beans.HeatEnvironment)20 Test (org.junit.Test)19 List (java.util.List)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 RelationshipList (org.onap.aai.domain.yang.RelationshipList)12 VfModule (org.onap.aai.domain.yang.VfModule)12 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)12 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)12 NorthBoundRequest (org.onap.so.db.catalog.beans.macro.NorthBoundRequest)12 HashMap (java.util.HashMap)10 HeatTemplateParam (org.onap.so.db.catalog.beans.HeatTemplateParam)10 VfModule (org.onap.so.db.catalog.beans.VfModule)8 HashSet (java.util.HashSet)6 VolumeGroup (org.onap.aai.domain.yang.VolumeGroup)6 NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)6