use of org.onap.sdc.toscaparser.api.elements.Metadata in project so by onap.
the class ToscaResourceInstaller method processPnfResources.
/**
* This is used to process the PNF specific resource, including resource and resource_customization.
* {@link IEntityDetails} based API is used to retrieve information. Please check {@link ISdcCsarHelper} for
* details.
*/
protected void processPnfResources(ToscaResourceStructure toscaResourceStruct, Service service, PnfResourceStructure resourceStructure) throws Exception {
logger.info("Processing PNF resource: {}", resourceStructure.getResourceInstance().getResourceUUID());
ISdcCsarHelper sdcCsarHelper = toscaResourceStruct.getSdcCsarHelper();
EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build();
TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
List<IEntityDetails> entityDetailsList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
for (IEntityDetails entityDetails : entityDetailsList) {
Metadata metadata = entityDetails.getMetadata();
String customizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
String modelUuid = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
String notifCustomizationUUID = resourceStructure.getResourceInstance().getResourceCustomizationUUID();
if (customizationUUID != null && customizationUUID.equals(notifCustomizationUUID)) {
logger.info("Resource customization UUID: {} is the same as notified resource customizationUUID: {}", customizationUUID, notifCustomizationUUID);
if (checkExistingPnfResourceCutomization(customizationUUID)) {
logger.info("Resource customization UUID: {} already deployed", customizationUUID);
} else {
PnfResource pnfResource = findExistingPnfResource(service, modelUuid);
if (pnfResource == null) {
pnfResource = createPnfResource(entityDetails);
}
PnfResourceCustomization pnfResourceCustomization = createPnfResourceCustomization(entityDetails, pnfResource);
pnfResource.getPnfResourceCustomizations().add(pnfResourceCustomization);
toscaResourceStruct.setPnfResourceCustomization(pnfResourceCustomization);
service.getPnfCustomizations().add(pnfResourceCustomization);
}
} else {
logger.warn("Resource customization UUID: {} is NOT the same as notified resource customizationUUID: {}", customizationUUID, notifCustomizationUUID);
}
}
}
use of org.onap.sdc.toscaparser.api.elements.Metadata in project so by onap.
the class ToscaResourceInstaller method processAllottedResources.
protected void processAllottedResources(List<IEntityDetails> arEntityDetails, ToscaResourceStructure toscaResourceStruct, Service service) throws ArtifactInstallerException {
List<IEntityDetails> pnfAREntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.PNF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
for (IEntityDetails pnfEntity : pnfAREntityList) {
Metadata metadata = pnfEntity.getMetadata();
String category = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
if (ALLOTTED_RESOURCE.equalsIgnoreCase(category)) {
arEntityDetails.add(pnfEntity);
}
}
if (arEntityDetails != null) {
for (IEntityDetails arEntity : arEntityDetails) {
AllottedResourceCustomization allottedResource = createAllottedResource(arEntity, toscaResourceStruct, service);
String resourceInput = getResourceInput(toscaResourceStruct, allottedResource.getModelCustomizationUUID());
if (!"{}".equals(resourceInput)) {
allottedResource.setResourceInput(resourceInput);
}
if (!service.getAllottedCustomizations().contains(allottedResource)) {
service.getAllottedCustomizations().add(allottedResource);
}
}
}
}
use of org.onap.sdc.toscaparser.api.elements.Metadata 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.elements.Metadata in project so by onap.
the class ToscaResourceInputTest method processResourceSequenceTest.
@Test
public void processResourceSequenceTest() {
ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
ArrayList<Input> inputs = new ArrayList<>();
Service service = new Service();
HashMap<String, Object> hashMap = new HashMap();
hashMap.put("name", "node1");
Metadata metadata = new Metadata(hashMap);
when(entityDetails.getMetadata()).thenReturn(metadata);
when(sdcCsarHelper.getServiceInputs()).thenReturn(inputs);
when(toscaResourceInstaller.getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false)).thenReturn(Arrays.asList(entityDetails));
when(entityDetails.getRequirements()).thenReturn(null);
toscaResourceInstaller.processResourceSequence(toscaResourceStructure, service);
assertEquals(service.getResourceOrder(), "");
}
use of org.onap.sdc.toscaparser.api.elements.Metadata 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);
}
Aggregations