use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.
the class ToscaResourceInstaller method processVfModules.
protected void processVfModules(IEntityDetails vfEntityDetails, ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure, Service service, Metadata metadata) throws Exception {
String vfCustomizationCategory = vfEntityDetails.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
logger.debug("VF Category is: {} ", vfCustomizationCategory);
String vfCustomizationUUID = vfEntityDetails.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
logger.debug("VFCustomizationUUID= {}", vfCustomizationUUID);
IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();
// Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before
// comparing their VF Modules UUID's
logger.debug("Checking if Notification VF ResourceCustomizationUUID: {} matches Tosca VF Customization UUID: {}", vfNotificationResource.getResourceCustomizationUUID(), vfCustomizationUUID);
if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) {
logger.debug("vfCustomizationUUID: {} matches vfNotificationResource CustomizationUUID ", vfCustomizationUUID);
VnfResourceCustomization vnfResource = createVnfResource(vfEntityDetails, toscaResourceStruct, service);
if (vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty()) {
Set<CvnfcCustomization> existingCvnfcSet = new HashSet<>();
Set<VnfcCustomization> existingVnfcSet = new HashSet<>();
List<CvnfcConfigurationCustomization> existingCvnfcConfigurationCustom = new ArrayList<>();
for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
logger.debug("vfModuleStructure: {}", vfModuleStructure);
List<IEntityDetails> vfModuleEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder("org.openecomp.groups.VfModule"), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).customizationUUID(vfCustomizationUUID), false);
IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
Optional<IEntityDetails> matchingObject = vfModuleEntityList.stream().peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID"))).filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())).findFirst();
if (matchingObject.isPresent()) {
VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), toscaResourceStruct, vfResourceStructure, vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet, existingCvnfcConfigurationCustom);
vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
} else
throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
}
}
// Check for VNFC Instance Group info and add it if there is
List<IEntityDetails> vfcEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup"), TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(vfCustomizationUUID), false);
Set<VnfcCustomization> existingVnfcGroupSet = new HashSet<>();
for (IEntityDetails groupEntity : vfcEntityList) {
VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(groupEntity, vfEntityDetails, vnfResource, toscaResourceStruct, existingVnfcGroupSet);
vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
}
List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, vfcEntityList);
if (!CollectionUtils.isEmpty(seqResult)) {
String resultStr = seqResult.stream().collect(Collectors.joining(","));
vnfResource.setVnfcInstanceGroupOrder(resultStr);
logger.debug("vnfcGroupOrder result for service uuid {}: {}", service.getModelUUID(), resultStr);
}
// add this vnfResource with existing vnfResource for this service
addVnfCustomization(service, vnfResource);
} else {
logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " + "Tosca VF Customization UUID: " + vfCustomizationUUID);
}
}
use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.
the class ToscaResourceInstaller method getResourceInput.
String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
Map<String, String> resouceRequest = new HashMap<>();
ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
List<IEntityDetails> nodeTemplateEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
List<Input> serInput = iSdcCsarHelper.getServiceInputs();
Optional<IEntityDetails> nodeTemplateOpt = nodeTemplateEntityList.stream().filter(e -> e.getMetadata().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
if (nodeTemplateOpt.isPresent()) {
IEntityDetails entityDetails = nodeTemplateOpt.get();
Map<String, Property> resourceProperties = entityDetails.getProperties();
for (String key : resourceProperties.keySet()) {
Property property = resourceProperties.get(key);
String value = getValue(property.getValue(), serInput);
resouceRequest.put(key, value);
}
}
try {
ObjectMapper objectMapper = new ObjectMapper();
String jsonStr = objectMapper.writeValueAsString(resouceRequest);
jsonStr = jsonStr.replace("\"", "\\\"");
logger.debug("resource request for resource customization id {}: {}", resourceCustomizationUuid, jsonStr);
return jsonStr;
} catch (JsonProcessingException e) {
logger.error("resource input could not be deserialized for resource customization id (" + resourceCustomizationUuid + ")");
throw new ArtifactInstallerException("resource input could not be parsed", e);
}
}
use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.
the class ToscaResourceInstaller method setHeatInformationForVfModule.
protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization, Metadata vfMetadata) {
Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream().filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID().equalsIgnoreCase(vfMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID))).findFirst();
if (matchingObject.isPresent()) {
List<HeatFiles> heatFilesList = new ArrayList<>();
List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<>();
List<HeatTemplate> heatChildTemplates = new ArrayList<>();
HeatTemplate parentHeatTemplate = new HeatTemplate();
String parentArtifactType = null;
Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts());
for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
List<HeatTemplate> childNestedHeatTemplates = new ArrayList<>();
if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) {
checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact, childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure);
}
if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) {
parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact);
if (!childNestedHeatTemplates.isEmpty()) {
if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) {
volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0));
} else {
heatChildTemplates.add(childNestedHeatTemplates.get(0));
}
}
}
}
if (!heatFilesList.isEmpty()) {
vfModule.setHeatFiles(heatFilesList);
}
// Set all Child Templates related to HEAT_VOLUME
if (!volumeHeatChildTemplates.isEmpty()) {
if (vfModule.getVolumeHeatTemplate() != null) {
vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates);
} else {
logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()");
}
}
// Set all Child Templates related to HEAT
if (!heatChildTemplates.isEmpty()) {
if (vfModule.getModuleHeatTemplate() != null) {
vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates);
} else {
logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()");
}
}
}
}
use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.
the class ToscaResourceInputTest method resouceInputGetInputDefaultIntegerTest.
@Test
public void resouceInputGetInputDefaultIntegerTest() throws ArtifactInstallerException {
ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
HashMap hashMap = new HashMap();
hashMap.put("customizationUUID", "id1");
Metadata metadata = new Metadata(hashMap);
Map<String, Property> propertyMap = new HashMap<String, Property>();
propertyMap.put("prop1", property);
when(toscaResourceInstaller.getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false)).thenReturn(Arrays.asList(entityDetails));
when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
when(entityDetails.getMetadata()).thenReturn(metadata);
when(entityDetails.getProperties()).thenReturn(propertyMap);
when(property.getValue()).thenReturn(getInput);
when(getInput.getInputName()).thenReturn("res_key");
when(input.getName()).thenReturn("res_key");
when(input.getDefault()).thenReturn(new Integer(10));
String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
assertEquals("{}", resourceInput);
}
use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.
the class ToscaResourceInputTest method resouceInputGetInputNoPropertyTest.
@Test
public void resouceInputGetInputNoPropertyTest() throws ArtifactInstallerException {
ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
HashMap hashMap = new HashMap();
hashMap.put("customizationUUID", "id1");
Metadata metadata = new Metadata(hashMap);
LinkedHashMap propertyMap = new LinkedHashMap();
when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
when(nodeTemplate.getMetaData()).thenReturn(metadata);
when(nodeTemplate.getProperties()).thenReturn(propertyMap);
String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
assertEquals("{}", resourceInput);
}
Aggregations