use of org.onap.sdc.toscaparser.api.Property 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.sdc.toscaparser.api.Property in project so by onap.
the class ToscaResourceInstaller method createVNFCInstanceGroup.
protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(IEntityDetails vfcInstanceEntity, IEntityDetails vfEntityDetails, VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure, Set<VnfcCustomization> existingVnfcGroupSet) {
Metadata instanceMetadata = vfcInstanceEntity.getMetadata();
InstanceGroup existingInstanceGroup = instanceGroupRepo.findByModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
VFCInstanceGroup vfcInstanceGroup;
if (existingInstanceGroup == null) {
// Populate InstanceGroup
vfcInstanceGroup = new VFCInstanceGroup();
vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
vfcInstanceGroup.setToscaNodeType(vfcInstanceEntity.getToscaType());
// Set Role
vfcInstanceGroup.setRole("SUB-INTERFACE");
// Set type
vfcInstanceGroup.setType(InstanceGroupType.VNFC);
} else {
vfcInstanceGroup = (VFCInstanceGroup) existingInstanceGroup;
}
// Populate VNFCInstanceGroupCustomization
VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
vnfResourceCustomization.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
vfcInstanceGroup.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
String getInputName = null;
Map<String, Property> groupProperties = vfcInstanceEntity.getProperties();
for (String key : groupProperties.keySet()) {
Property property = groupProperties.get(key);
String vfcName = property.getName();
if (vfcName != null) {
if (vfcName.equals("vfc_instance_group_function")) {
String vfcValue = property.getValue().toString();
int getInputIndex = vfcValue.indexOf("{get_input=");
if (getInputIndex > -1) {
getInputName = vfcValue.substring(getInputIndex + 11, vfcValue.length() - 1);
}
}
}
}
List<IEntityDetails> serviceEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(SdcTypes.VF).customizationUUID(vnfResourceCustomization.getModelCustomizationUUID()), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
if (serviceEntityList != null && !serviceEntityList.isEmpty()) {
vfcInstanceGroupCustom.setFunction(getLeafPropertyValue(serviceEntityList.get(0), getInputName));
}
vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
List<Input> inputs = vfEntityDetails.getInputs();
createVFCInstanceGroupMembers(vfcInstanceGroupCustom, vfcInstanceEntity, inputs, existingVnfcGroupSet);
return vfcInstanceGroupCustom;
}
use of org.onap.sdc.toscaparser.api.Property in project so by onap.
the class ToscaResourceInstaller method createNetworkCollection.
protected CollectionNetworkResourceCustomization createNetworkCollection(IEntityDetails cnrEntity, ToscaResourceStructure toscaResourceStructure, Service service) {
CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization();
// **** Build Object to populate Collection_Resource table
CollectionResource collectionResource = new CollectionResource();
collectionResource.setModelName(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
collectionResource.setModelInvariantUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
collectionResource.setModelUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
collectionResource.setModelVersion(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
collectionResource.setDescription(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
collectionResource.setToscaNodeType(cnrEntity.getToscaType());
toscaResourceStructure.setCatalogCollectionResource(collectionResource);
// **** Build object to populate Collection_Resource_Customization table
NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization();
ncfc.setFunction(getLeafPropertyValue(cnrEntity, "cr_function"));
ncfc.setRole(getLeafPropertyValue(cnrEntity, "cr_role"));
ncfc.setType(getLeafPropertyValue(cnrEntity, "cr_type"));
ncfc.setModelInstanceName(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
ncfc.setModelCustomizationUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>();
networkResourceCustomizationSet.add(collectionNetworkResourceCustomization);
ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet);
ncfc.setCollectionResource(collectionResource);
toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc);
// *** Build object to populate the Instance_Group table
List<IEntityDetails> ncEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder("org.openecomp.groups.NetworkCollection"), TopologyTemplateQuery.newBuilder(SdcTypes.CR).customizationUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)), false);
List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>();
List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<>();
for (IEntityDetails ncGroupEntity : ncEntityList) {
NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup();
Metadata instanceMetadata = ncGroupEntity.getMetadata();
networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
networkInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
networkInstanceGroup.setToscaNodeType(ncGroupEntity.getToscaType());
// Set
networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString());
// Role
// Set
networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK);
// type
networkInstanceGroup.setCollectionResource(collectionResource);
// ****Build object to populate
// Collection_Resource_Instance_Group_Customization table
CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup);
crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
crInstanceGroupCustomization.setModelCustomizationUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
// Loop through the template policy to find the subinterface_network_quantity property name. Then extract
// the value for it.
List<IEntityDetails> policyEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder("org.openecomp.policies.scaling.Fixed"), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), true);
if (policyEntityList != null) {
for (IEntityDetails policyEntity : policyEntityList) {
for (String policyNetworkCollection : policyEntity.getTargets()) {
if (policyNetworkCollection.equalsIgnoreCase(ncGroupEntity.getName())) {
Map<String, Property> propMap = policyEntity.getProperties();
if (propMap.get("quantity") != null) {
String quantity = getLeafPropertyValue(cnrEntity, getPropertyInput(propMap.get("quantity").toString()));
if (quantity != null) {
crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(quantity));
}
}
}
}
}
}
crInstanceGroupCustomization.setDescription(getLeafPropertyValue(cnrEntity, instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) + "_network_collection_description"));
crInstanceGroupCustomization.setFunction(getLeafPropertyValue(cnrEntity, instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) + "_network_collection_function"));
crInstanceGroupCustomization.setCollectionResourceCust(ncfc);
collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization);
networkInstanceGroup.setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList);
networkInstanceGroupList.add(networkInstanceGroup);
toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
List<IEntityDetails> networkEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(SdcTypes.VL), TopologyTemplateQuery.newBuilder(SdcTypes.CR).customizationUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)), false);
List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>();
// *****Build object to populate the NetworkResource table
NetworkResource networkResource = new NetworkResource();
for (IEntityDetails networkEntity : networkEntityList) {
String providerNetwork = getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
if ("true".equalsIgnoreCase(providerNetwork)) {
networkResource.setNeutronNetworkType(PROVIDER);
} else {
networkResource.setNeutronNetworkType(BASIC);
}
networkResource.setModelName(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
networkResource.setModelInvariantUUID(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
networkResource.setModelUUID(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
networkResource.setModelVersion(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
networkResource.setAicVersionMax(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
if (tempNetworkLookUp != null) {
HeatTemplate heatTemplate = heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid());
networkResource.setHeatTemplate(heatTemplate);
networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin());
}
networkResource.setToscaNodeType(networkEntity.getToscaType());
networkResource.setDescription(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
networkResource.setOrchestrationMode(HEAT);
// Collection_Network_Resource_Customization table
for (IEntityDetails networkMemberEntity : ncGroupEntity.getMemberNodes()) {
collectionNetworkResourceCustomization.setModelInstanceName(networkMemberEntity.getName());
}
collectionNetworkResourceCustomization.setModelCustomizationUUID(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
collectionNetworkResourceCustomization.setNetworkTechnology(getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
collectionNetworkResourceCustomization.setNetworkType(getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
collectionNetworkResourceCustomization.setNetworkRole(getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
collectionNetworkResourceCustomization.setNetworkScope(getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup);
collectionNetworkResourceCustomization.setNetworkResource(networkResource);
collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc);
collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization);
}
}
return collectionNetworkResourceCustomization;
}
use of org.onap.sdc.toscaparser.api.Property 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);
}
Aggregations