use of org.onap.sdc.toscaparser.api.Property in project so by onap.
the class ToscaResourceInstaller method getVnfcResourceInput.
public String getVnfcResourceInput(IEntityDetails vfcEntity, List<Input> inputList) {
Map<String, String> resouceRequest = new HashMap<>();
Map<String, Property> vfcTemplateProperties = vfcEntity.getProperties();
for (String key : vfcTemplateProperties.keySet()) {
Property property = vfcTemplateProperties.get(key);
String resourceValue = getValue(property.getValue(), inputList);
resouceRequest.put(key, resourceValue);
}
String resourceCustomizationUuid = vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
String jsonStr = null;
try {
ObjectMapper objectMapper = new ObjectMapper();
jsonStr = objectMapper.writeValueAsString(resouceRequest);
jsonStr = jsonStr.replace("\"", "\\\"");
logger.debug("vfcResource request for resource customization id {}: {}", resourceCustomizationUuid, jsonStr);
} catch (JsonProcessingException e) {
logger.debug("Json Exception: {}", e.getMessage());
logger.error("Exception occurred", e);
}
return jsonStr;
}
use of org.onap.sdc.toscaparser.api.Property in project so by onap.
the class ToscaResourceInputTest method getListResourceInput.
@Test
public void getListResourceInput() {
ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
LinkedHashMap<String, Property> hashMap = new LinkedHashMap<>();
hashMap.put("key1", property);
Map<String, Object> map = new HashMap<>();
map.put("customizationUUID", "69df3303-d2b3-47a1-9d04-41604d3a95fd");
Metadata metadata = new Metadata(map);
when(entityDetails.getProperties()).thenReturn(hashMap);
when(property.getValue()).thenReturn(getInput);
when(getInput.getInputName()).thenReturn("nameKey");
when(input.getName()).thenReturn("nameKey");
when(input.getDefault()).thenReturn("defaultValue");
when(getInput.toString()).thenReturn("getinput:[sites,INDEX,role]");
when(entityDetails.getMetadata()).thenReturn(metadata);
List<Input> inputs = new ArrayList<>();
inputs.add(input);
String resourceInput = toscaResourceInstaller.getVnfcResourceInput(entityDetails, inputs);
assertEquals("{\\\"key1\\\":\\\"[sites,INDEX,role]|defaultValue\\\"}", resourceInput);
}
use of org.onap.sdc.toscaparser.api.Property in project so by onap.
the class ToscaResourceInputTest method resouceInputGetInputTest.
@Test
public void resouceInputGetInputTest() 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("default_value");
String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
assertEquals("{}", resourceInput);
}
use of org.onap.sdc.toscaparser.api.Property in project so by onap.
the class ToscaResourceInputTest method resouceInputTest.
@Test
public void resouceInputTest() throws ArtifactInstallerException {
ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
Map 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(entityDetails.getMetadata()).thenReturn(metadata);
when(entityDetails.getProperties()).thenReturn(propertyMap);
when(property.getValue()).thenReturn("value1");
String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
assertEquals("{}", resourceInput);
}
use of org.onap.sdc.toscaparser.api.Property in project so by onap.
the class ToscaResourceInstaller method createPnfResourceCustomization.
/**
* Construct the {@link PnfResourceCustomization} from {@link IEntityDetails} object.
*/
private PnfResourceCustomization createPnfResourceCustomization(IEntityDetails entityDetails, PnfResource pnfResource) {
PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization();
Metadata metadata = entityDetails.getMetadata();
Map<String, Property> properties = entityDetails.getProperties();
pnfResourceCustomization.setModelCustomizationUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
pnfResourceCustomization.setModelInstanceName(entityDetails.getName());
pnfResourceCustomization.setNfFunction(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
pnfResourceCustomization.setNfNamingCode(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFCODE)));
pnfResourceCustomization.setNfRole(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFROLE)));
pnfResourceCustomization.setNfType(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
pnfResourceCustomization.setMultiStageDesign(getStringValue(properties.get(MULTI_STAGE_DESIGN)));
pnfResourceCustomization.setBlueprintName(getStringValue(properties.get(SDNC_MODEL_NAME)));
pnfResourceCustomization.setBlueprintVersion(getStringValue(properties.get(SDNC_MODEL_VERSION)));
pnfResourceCustomization.setSkipPostInstConf(getBooleanValue(properties.get(SKIP_POST_INST_CONF)));
pnfResourceCustomization.setControllerActor(getStringValue(properties.get(CONTROLLER_ACTOR)));
pnfResourceCustomization.setDefaultSoftwareVersion(extractDefaultSoftwareVersionFromSwVersions(properties));
pnfResourceCustomization.setPnfResources(pnfResource);
return pnfResourceCustomization;
}
Aggregations