use of org.onap.sdc.toscaparser.api.NodeTemplate in project so by onap.
the class ToscaResourceInstaller method getServiceProperties.
private String getServiceProperties(ToscaResourceStructure toscaResourceStruct) {
String propertiesJson = null;
ObjectMapper objectMapper = new ObjectMapper();
ISdcCsarHelper helper = toscaResourceStruct.getSdcCsarHelper();
String typeName = helper.getServiceSubstitutionMappingsTypeName();
Optional<NodeTemplate> nodeTemplate = helper.getServiceNodeTemplates().stream().findAny();
if (nodeTemplate.isPresent()) {
String serviceUUID = nodeTemplate.get().getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
LinkedHashMap<String, Object> customDef = nodeTemplate.get().getCustomDef();
List<Object> serviceProperties = getPropertiesFromCustomDef(customDef, typeName);
try {
propertiesJson = objectMapper.writeValueAsString(serviceProperties);
propertiesJson = propertiesJson.replace("\"", "\\\"");
} catch (JsonProcessingException e) {
logger.error("serviceProperties could not be deserialized for service uuid: " + serviceUUID);
} catch (Exception ex) {
logger.error("service properties parsing failed. service uuid:" + serviceUUID);
}
} else {
logger.debug("ServiceNodeTemplates is null");
}
return propertiesJson;
}
use of org.onap.sdc.toscaparser.api.NodeTemplate in project so by onap.
the class ToscaResourceInstallerTest method testProcessVNFCGroupSequence.
@Test
public void testProcessVNFCGroupSequence() {
List<Group> groupList = new ArrayList<>();
Group group1 = mock(Group.class);
NodeTemplate node1 = mock(NodeTemplate.class);
List<NodeTemplate> nodeList1 = new ArrayList<>();
nodeList1.add(node1);
doReturn("VfcInstanceGroup..0").when(group1).getName();
doReturn(nodeList1).when(group1).getMemberNodes();
doReturn("deviceV3").when(node1).getName();
Group group2 = mock(Group.class);
NodeTemplate node2 = mock(NodeTemplate.class);
List<NodeTemplate> nodeList2 = new ArrayList<>();
nodeList2.add(node2);
doReturn("VfcInstanceGroup..1").when(group2).getName();
doReturn(nodeList2).when(group2).getMemberNodes();
RequirementAssignments requirements2 = mock(RequirementAssignments.class);
RequirementAssignment requirement2 = mock(RequirementAssignment.class);
List<RequirementAssignment> requirementCollection2 = new ArrayList<>();
requirementCollection2.add(requirement2);
doReturn(requirementCollection2).when(requirements2).getAll();
doReturn("deviceV3").when(requirement2).getNodeTemplateName();
doReturn("SiteV2").when(node2).getName();
Group group3 = mock(Group.class);
NodeTemplate node3 = mock(NodeTemplate.class);
List<NodeTemplate> nodeList3 = new ArrayList<>();
nodeList3.add(node3);
doReturn("VfcInstanceGroup..2").when(group3).getName();
doReturn(nodeList3).when(group3).getMemberNodes();
RequirementAssignments requirements3 = mock(RequirementAssignments.class);
RequirementAssignment requirement3 = mock(RequirementAssignment.class);
List<RequirementAssignment> requirementCollection3 = new ArrayList<>();
requirementCollection3.add(requirement3);
doReturn(requirementCollection3).when(requirements3).getAll();
doReturn("SiteV2").when(requirement3).getNodeTemplateName();
doReturn("siteWanV2").when(node3).getName();
groupList.add(group1);
groupList.add(group2);
groupList.add(group3);
doReturn(csarHelper).when(toscaResourceStructure).getSdcCsarHelper();
ToscaResourceInstaller installer = new ToscaResourceInstaller();
Method[] methods = installer.getClass().getDeclaredMethods();
Method testMethod = null;
for (Method method : methods) {
String name = method.getName();
if (name.equals("processVNFCGroupSequence")) {
method.setAccessible(true);
testMethod = method;
}
}
if (null != testMethod) {
try {
Object seqResult = testMethod.invoke(installer, toscaResourceStructure, groupList);
if (seqResult instanceof List) {
String resultStr = ((List<String>) seqResult).stream().collect(Collectors.joining(","));
assertEquals(((List<String>) seqResult).size(), 3);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of org.onap.sdc.toscaparser.api.NodeTemplate in project so by onap.
the class ToscaResourceInstallerTest method prepareToscaResourceStructure.
private ToscaResourceStructure prepareToscaResourceStructure(boolean prepareVFModuleStructures, ToscaResourceInstaller toscaInstaller) throws ArtifactInstallerException {
Metadata metadata = mock(Metadata.class);
IResourceInstance resourceInstance = mock(ResourceInstance.class);
NodeTemplate nodeTemplate = mock(NodeTemplate.class);
ISdcCsarHelper csarHelper = mock(SdcCsarHelperImpl.class);
IArtifactInfo inputCsar = mock(IArtifactInfo.class);
String artifactUuid = "0122c05e-e13a-4c63-b5d2-475ccf23aa74";
String checkSum = "MGUzNjJjMzk3OTBkYzExYzQ0MDg2ZDc2M2E3ZjZiZmY=";
doReturn(checkSum).when(inputCsar).getArtifactChecksum();
doReturn(artifactUuid).when(inputCsar).getArtifactUUID();
doReturn("1.0").when(inputCsar).getArtifactVersion();
doReturn("TestCsarWithGroupAndVFModule").when(inputCsar).getArtifactName();
doReturn("Test Csar data with Group and VF module inputs").when(inputCsar).getArtifactDescription();
doReturn("http://localhost/dummy/url/test.csar").when(inputCsar).getArtifactURL();
ToscaResourceStructure toscaResourceStructObj = new ToscaResourceStructure();
toscaResourceStructObj.setToscaArtifact(inputCsar);
ToscaCsarRepository toscaCsarRepo = spy(ToscaCsarRepository.class);
ToscaCsar toscaCsar = mock(ToscaCsar.class);
Optional<ToscaCsar> returnValue = Optional.of(toscaCsar);
doReturn(artifactUuid).when(toscaCsar).getArtifactUUID();
doReturn(checkSum).when(toscaCsar).getArtifactChecksum();
doReturn(returnValue).when(toscaCsarRepo).findById(artifactUuid);
ReflectionTestUtils.setField(toscaInstaller, "toscaCsarRepo", toscaCsarRepo);
NotificationDataImpl notificationData = new NotificationDataImpl();
notificationData.setDistributionID("testStatusSuccessfulTosca");
notificationData.setServiceVersion("1234567");
notificationData.setServiceUUID("serviceUUID1");
notificationData.setWorkloadContext("workloadContext1");
String serviceType = "test-type1";
String serviceRole = "test-role1";
String category = "Network L3+";
String description = "Customer Orderable service description";
String name = "Customer_Orderable_Service";
String uuid = "72db5868-4575-4804-b546-0b0d3c3b5ac6";
String invariantUUID = "6f30bbe3-4590-4185-a7e0-4f9610926c6f";
String namingPolicy = "naming Policy1";
String ecompGeneratedNaming = "true";
String environmentContext = "General_Revenue-Bearing1";
String resourceCustomizationUUID = "0177ba22-5547-4e4e-bcf8-178f7f71de3a";
doReturn(serviceType).when(metadata).getValue("serviceType");
doReturn(serviceRole).when(metadata).getValue("serviceRole");
doReturn(category).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
doReturn(description).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION);
doReturn("1.0").when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_VERSION);
doReturn(name).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
doReturn(uuid).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
doReturn(environmentContext).when(metadata).getValue(metadata.getValue("environmentContext"));
doReturn(invariantUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
doReturn(namingPolicy).when(metadata).getValue("namingPolicy");
doReturn(ecompGeneratedNaming).when(metadata).getValue("ecompGeneratedNaming");
doReturn(resourceCustomizationUUID).when(metadata).getValue("vfModuleModelCustomizationUUID");
ServiceRepository serviceRepo = spy(ServiceRepository.class);
VnfResourceRepository vnfRepo = spy(VnfResourceRepository.class);
doReturn(null).when(vnfRepo).findResourceByModelUUID(uuid);
VFModuleRepository vfModuleRepo = spy(VFModuleRepository.class);
InstanceGroupRepository instanceGroupRepo = spy(InstanceGroupRepository.class);
WorkflowResource workflowResource = spy(WorkflowResource.class);
ReflectionTestUtils.setField(toscaInstaller, "serviceRepo", serviceRepo);
ReflectionTestUtils.setField(toscaInstaller, "vnfRepo", vnfRepo);
ReflectionTestUtils.setField(toscaInstaller, "vfModuleRepo", vfModuleRepo);
ReflectionTestUtils.setField(toscaInstaller, "instanceGroupRepo", instanceGroupRepo);
ReflectionTestUtils.setField(toscaInstaller, "workflowResource", workflowResource);
// doReturn(csarHelper).when(toscaResourceStructure).getSdcCsarHelper();
toscaResourceStructObj.setSdcCsarHelper(csarHelper);
doReturn(resourceCustomizationUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
doReturn(uuid).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID);
// vnfc instance group list
List<Group> vnfcInstanceGroupList = new ArrayList<>();
Group vnfcG1 = mock(Group.class);
Map<String, Object> metaProperties = new HashMap<>();
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_UUID, "vnfc_group1_uuid");
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_NAME, "vnfc_group1_uuid");
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID, "vnfc_group1_invariantid");
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_VERSION, "1.0");
Metadata vnfcmetadata = new Metadata(metaProperties);
doReturn(vnfcmetadata).when(vnfcG1).getMetadata();
ArrayList<NodeTemplate> memberList = new ArrayList();
doReturn(memberList).when(vnfcG1).getMemberNodes();
vnfcInstanceGroupList.add(vnfcG1);
SubstitutionMappings submappings = mock(SubstitutionMappings.class);
doReturn(new ArrayList<Input>()).when(submappings).getInputs();
doReturn(submappings).when(nodeTemplate).getSubMappingToscaTemplate();
doReturn(notificationData).when(vfResourceStruct).getNotification();
doReturn(resourceInstance).when(vfResourceStruct).getResourceInstance();
if (prepareVFModuleStructures) {
// VfModule list
List<Group> vfModuleGroups = new ArrayList<>();
Group g1 = mock(Group.class);
doReturn(metadata).when(g1).getMetadata();
vfModuleGroups.add(g1);
doReturn(metadata).when(nodeTemplate).getMetaData();
List<NodeTemplate> nodeList = new ArrayList<>();
nodeList.add(nodeTemplate);
IVfModuleData moduleMetadata = mock(IVfModuleData.class);
doReturn(name).when(moduleMetadata).getVfModuleModelName();
doReturn(invariantUUID).when(moduleMetadata).getVfModuleModelInvariantUUID();
doReturn(Collections.<String>emptyList()).when(moduleMetadata).getArtifacts();
doReturn(resourceCustomizationUUID).when(moduleMetadata).getVfModuleModelCustomizationUUID();
doReturn(uuid).when(moduleMetadata).getVfModuleModelUUID();
doReturn("1.0").when(moduleMetadata).getVfModuleModelVersion();
VfModuleStructure moduleStructure = new VfModuleStructure(vfResourceStruct, moduleMetadata);
List<VfModuleStructure> moduleStructures = new ArrayList<>();
moduleStructures.add(moduleStructure);
doReturn(moduleStructures).when(vfResourceStruct).getVfModuleStructure();
}
toscaResourceStructObj.setServiceMetadata(metadata);
doReturn("resourceInstanceName1").when(resourceInstance).getResourceInstanceName();
doReturn(resourceCustomizationUUID).when(resourceInstance).getResourceCustomizationUUID();
doReturn("resourceName1").when(resourceInstance).getResourceName();
Service service = toscaInstaller.createService(toscaResourceStructObj, vfResourceStruct);
assertNotNull(service);
service.setModelVersion("1.0");
doReturn(service).when(serviceRepo).save(service);
WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository = spy(WatchdogComponentDistributionStatusRepository.class);
ReflectionTestUtils.setField(toscaInstaller, "watchdogCDStatusRepository", watchdogCDStatusRepository);
doReturn(null).when(watchdogCDStatusRepository).save(any(WatchdogComponentDistributionStatus.class));
VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo = spy(VnfcInstanceGroupCustomizationRepository.class);
ReflectionTestUtils.setField(toscaInstaller, "vnfcInstanceGroupCustomizationRepo", vnfcInstanceGroupCustomizationRepo);
doReturn(null).when(vnfcInstanceGroupCustomizationRepo).save(any(VnfcInstanceGroupCustomization.class));
return toscaResourceStructObj;
}
use of org.onap.sdc.toscaparser.api.NodeTemplate in project so by onap.
the class ToscaResourceStructureTest method toscaResourceStructureBeanTest.
@Test
public void toscaResourceStructureBeanTest() {
artifactInfo = mock(ArtifactInfoImpl.class);
sdcCsarHelper = mock(SdcCsarHelperImpl.class);
toscaResourceStructure = new ToscaResourceStructure();
toscaResourceStructure.setHeatTemplateUUID("heatTemplateUUID");
toscaResourceStructure.setAllottedList(new ArrayList<NodeTemplate>());
toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
toscaResourceStructure.setServiceMetadata(new Metadata(new HashMap<>()));
toscaResourceStructure.setCatalogService(new Service());
toscaResourceStructure.setNetworkTypes(new ArrayList<>());
toscaResourceStructure.setVfTypes(new ArrayList<>());
toscaResourceStructure.setCatalogResourceCustomization(new AllottedResourceCustomization());
toscaResourceStructure.setCatalogNetworkResourceCustomization(new NetworkResourceCustomization());
toscaResourceStructure.setCatalogNetworkResource(new NetworkResource());
toscaResourceStructure.setCatalogVfModule(new VfModule());
toscaResourceStructure.setVnfResourceCustomization(new VnfResourceCustomization());
toscaResourceStructure.setVfModuleCustomization(new VfModuleCustomization());
toscaResourceStructure.setAllottedResource(new AllottedResource());
toscaResourceStructure.setAllottedResourceCustomization(new AllottedResourceCustomization());
toscaResourceStructure.setCatalogTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
toscaResourceStructure.setHeatFilesUUID("heatFilesUUID");
toscaResourceStructure.setToscaArtifact(artifactInfo);
toscaResourceStructure.setToscaCsar(new ToscaCsar());
toscaResourceStructure.setVolHeatTemplateUUID("volHeatTemplateUUID");
toscaResourceStructure.setEnvHeatTemplateUUID("envHeatTemplateUUID");
toscaResourceStructure.setServiceVersion("serviceVersion");
toscaResourceStructure.setWorkloadPerformance("workloadPerformance");
toscaResourceStructure.setVfModule(new VfModule());
toscaResourceStructure.setTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
toscaResourceStructure.setSuccessfulDeployment();
assertEquals("heatTemplateUUID", toscaResourceStructure.getHeatTemplateUUID());
assertThat(toscaResourceStructure.getAllottedList(), sameBeanAs(new ArrayList<NodeTemplate>()));
assertEquals(sdcCsarHelper, toscaResourceStructure.getSdcCsarHelper());
assertThat(toscaResourceStructure.getServiceMetadata(), sameBeanAs(new Metadata(new HashMap<>())));
assertThat(toscaResourceStructure.getCatalogService(), sameBeanAs(new Service()));
assertThat(toscaResourceStructure.getNetworkTypes(), sameBeanAs(new ArrayList<>()));
assertThat(toscaResourceStructure.getVfTypes(), sameBeanAs(new ArrayList<>()));
assertThat(toscaResourceStructure.getCatalogResourceCustomization(), sameBeanAs(new AllottedResourceCustomization()));
assertThat(toscaResourceStructure.getCatalogNetworkResourceCustomization(), sameBeanAs(new NetworkResourceCustomization()));
assertThat(toscaResourceStructure.getCatalogNetworkResource(), sameBeanAs(new NetworkResource()));
assertThat(toscaResourceStructure.getCatalogVfModule(), sameBeanAs(new VfModule()));
assertThat(toscaResourceStructure.getVnfResourceCustomization(), sameBeanAs(new VnfResourceCustomization()));
assertThat(toscaResourceStructure.getVfModuleCustomization(), sameBeanAs(new VfModuleCustomization()));
assertThat(toscaResourceStructure.getAllottedResource(), sameBeanAs(new AllottedResource()));
assertThat(toscaResourceStructure.getAllottedResourceCustomization(), sameBeanAs(new AllottedResourceCustomization()));
assertThat(toscaResourceStructure.getCatalogTempNetworkHeatTemplateLookup(), sameBeanAs(new TempNetworkHeatTemplateLookup()));
assertEquals("heatFilesUUID", toscaResourceStructure.getHeatFilesUUID());
assertEquals(artifactInfo, toscaResourceStructure.getToscaArtifact());
assertThat(toscaResourceStructure.getToscaCsar(), sameBeanAs(new ToscaCsar()));
assertEquals("volHeatTemplateUUID", toscaResourceStructure.getVolHeatTemplateUUID());
assertEquals("envHeatTemplateUUID", toscaResourceStructure.getEnvHeatTemplateUUID());
assertEquals("serviceVersion", toscaResourceStructure.getServiceVersion());
assertEquals("workloadPerformance", toscaResourceStructure.getWorkloadPerformance());
assertThat(toscaResourceStructure.getVfModule(), sameBeanAs(new VfModule()));
assertThat(toscaResourceStructure.getTempNetworkHeatTemplateLookup(), sameBeanAs(new TempNetworkHeatTemplateLookup()));
assertEquals(true, toscaResourceStructure.isDeployedSuccessfully());
}
Aggregations