Search in sources :

Example 6 with RequirementAssignment

use of org.onap.sdc.toscaparser.api.RequirementAssignment 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();
        }
    }
}
Also used : Group(org.onap.sdc.toscaparser.api.Group) ArrayList(java.util.ArrayList) RequirementAssignments(org.onap.sdc.toscaparser.api.RequirementAssignments) Method(java.lang.reflect.Method) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) ExpectedException(org.junit.rules.ExpectedException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) RequirementAssignment(org.onap.sdc.toscaparser.api.RequirementAssignment) NodeTemplate(org.onap.sdc.toscaparser.api.NodeTemplate) List(java.util.List) ArrayList(java.util.ArrayList) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 7 with RequirementAssignment

use of org.onap.sdc.toscaparser.api.RequirementAssignment in project so by onap.

the class ToscaResourceInstaller method processVNFCGroupSequence.

private List<String> processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure, List<IEntityDetails> groupEntityDetails) {
    if (CollectionUtils.isEmpty(groupEntityDetails)) {
        return Collections.emptyList();
    }
    ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
    List<String> strSequence = new ArrayList<>(groupEntityDetails.size());
    List<IEntityDetails> tempEntityList = new ArrayList<>(groupEntityDetails.size());
    List<IEntityDetails> entities = new ArrayList<>();
    tempEntityList.addAll(groupEntityDetails);
    for (IEntityDetails vnfcEntityDetails : groupEntityDetails) {
        List<IEntityDetails> vnfcMemberNodes = vnfcEntityDetails.getMemberNodes();
        boolean hasRequirements = false;
        for (IEntityDetails vnfcDetails : vnfcMemberNodes) {
            List<RequirementAssignment> requirements = vnfcDetails.getRequirements();
            if (requirements != null && !requirements.isEmpty()) {
                hasRequirements = true;
                break;
            }
        }
        if (!hasRequirements) {
            strSequence.add(vnfcEntityDetails.getName());
            tempEntityList.remove(vnfcEntityDetails);
            entities.addAll(vnfcMemberNodes);
        }
    }
    getVNFCGroupSequenceList(strSequence, tempEntityList, entities, iSdcCsarHelper);
    return strSequence;
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) ArrayList(java.util.ArrayList) RequirementAssignment(org.onap.sdc.toscaparser.api.RequirementAssignment)

Aggregations

ArrayList (java.util.ArrayList)7 RequirementAssignment (org.onap.sdc.toscaparser.api.RequirementAssignment)7 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)6 ISdcCsarHelper (org.onap.sdc.tosca.parser.api.ISdcCsarHelper)3 HashSet (java.util.HashSet)2 List (java.util.List)2 LockAcquisitionException (org.hibernate.exception.LockAcquisitionException)2 NodeTemplate (org.onap.sdc.toscaparser.api.NodeTemplate)2 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)2 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)2 ConfigurationResource (org.onap.so.db.catalog.beans.ConfigurationResource)2 CvnfcConfigurationCustomization (org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization)2 CvnfcCustomization (org.onap.so.db.catalog.beans.CvnfcCustomization)2 VfModule (org.onap.so.db.catalog.beans.VfModule)2 VfModuleCustomization (org.onap.so.db.catalog.beans.VfModuleCustomization)2 VnfcCustomization (org.onap.so.db.catalog.beans.VnfcCustomization)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Method (java.lang.reflect.Method)1 Timestamp (java.sql.Timestamp)1