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);
}
}
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;
}
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");
}
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);
}
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"));
}
Aggregations