aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-controller/src
diff options
context:
space:
mode:
authorzm330 <zhangminyj@chinamobile.com>2019-04-23 10:46:53 +0800
committerZhang Min <zhangminyj@chinamobile.com>2019-04-23 03:37:36 +0000
commit458cc8d407f27bc360f9d7c93164bae6b764947f (patch)
treefcecd1b8fcec5302acc0c4a60e4565c1e3a0711d /asdc-controller/src
parentbe61cb67952b83ebac6f16b84cd5d94ebd638bad (diff)
add vnfcInstanceGroup sequence
Issue-ID: SO-1393 Change-Id: Ife3b71dcfa543a693564779da44800f1dd8486e9 Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Diffstat (limited to 'asdc-controller/src')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java123
-rw-r--r--asdc-controller/src/test/resources/schema.sql1
2 files changed, 122 insertions, 2 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
index aba70f33e3..ddf1f3d84b 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
@@ -26,6 +26,7 @@ package org.onap.so.asdc.installer.heat;
import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -142,6 +143,7 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.util.CollectionUtils;
@Component
public class ToscaResourceInstaller {
@@ -983,7 +985,13 @@ public class ToscaResourceInstaller {
vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
}
-
+ List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, groupList);
+ if (!CollectionUtils.isEmpty(seqResult)) {
+ String resultStr = seqResult.stream().collect(Collectors.joining(","));
+ vnfResource.setVnfcInstanceGroupOrder(resultStr);
+ logger.debug(
+ "vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr);
+ }
// add this vnfResource with existing vnfResource for this service
addVnfCustomization(service, vnfResource);
} else {
@@ -994,6 +1002,85 @@ public class ToscaResourceInstaller {
}
}
+ private List<String> processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure,
+ List<Group> groupList) {
+ if (CollectionUtils.isEmpty(groupList)) {
+ return Collections.emptyList();
+ }
+
+ ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
+ List<String> strSequence = new ArrayList<>(groupList.size());
+ List<Group> tempGroupList = new ArrayList<>(groupList.size());
+ List<NodeTemplate> nodes = new ArrayList<>();
+ tempGroupList.addAll(groupList);
+
+ for (Group group : groupList) {
+ List<NodeTemplate> nodeList = group.getMemberNodes();
+ boolean hasRequirements = false;
+ for (NodeTemplate node : nodeList) {
+ RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(node);
+ if (requirements != null && requirements.getAll() != null && !requirements.getAll().isEmpty()) {
+ hasRequirements = true;
+ break;
+ }
+ }
+
+ if (!hasRequirements) {
+ strSequence.add(group.getName());
+ tempGroupList.remove(group);
+ nodes.addAll(nodeList);
+ }
+ }
+
+ getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
+
+ return strSequence;
+
+ }
+
+ private void getVNFCGroupSequenceList(List<String> strSequence, List<Group> groupList, List<NodeTemplate> nodes,
+ ISdcCsarHelper iSdcCsarHelper) {
+ if (CollectionUtils.isEmpty(groupList)) {
+ return;
+ }
+
+ List<Group> tempGroupList = new ArrayList<>();
+ tempGroupList.addAll(groupList);
+
+ for (Group group : groupList) {
+ ArrayList<NodeTemplate> members = group.getMemberNodes();
+ for (NodeTemplate memberNode : members) {
+ boolean isAllExists = true;
+ RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(memberNode);
+ if (requirements == null || requirements.getAll() == null || requirements.getAll().isEmpty()) {
+ continue;
+ }
+ List<RequirementAssignment> rqaList = requirements.getAll();
+ for (RequirementAssignment rqa : rqaList) {
+ String name = rqa.getNodeTemplateName();
+ for (NodeTemplate node : nodes) {
+ if (name.equals(node.getName())) {
+ break;
+ }
+ }
+
+ isAllExists = false;
+ break;
+ }
+
+ if (isAllExists) {
+ strSequence.add(group.getName());
+ tempGroupList.remove(group);
+ nodes.addAll(group.getMemberNodes());
+ }
+ }
+
+ if (tempGroupList.size() != 0 && tempGroupList.size() < groupList.size()) {
+ getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
+ }
+ }
+ }
+
public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
String consumerId) {
WatchdogServiceModVerIdLookup modVerIdLookup =
@@ -1704,12 +1791,37 @@ public class ToscaResourceInstaller {
vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper()
.getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
-
+ createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group);
return vfcInstanceGroupCustom;
}
+ private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group) {
+ List<NodeTemplate> members = group.getMemberNodes();
+ if (!CollectionUtils.isEmpty(members)) {
+ for (NodeTemplate vfcTemplate : members) {
+ VnfcCustomization vnfcCustomization = new VnfcCustomization();
+
+ Metadata metadata = vfcTemplate.getMetaData();
+ vnfcCustomization
+ .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+ vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
+ vnfcCustomization.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+ vnfcCustomization
+ .setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+ vnfcCustomization.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
+ vnfcCustomization.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
+ vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
+ vnfcCustomization
+ .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
+
+ // @After vfcInstanceGroupCustom merged
+ // vfcInstanceGroupCustom.getVnfcCustomizations().add(vnfcCustomization);
+ }
+ }
+ }
+
protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service,
@@ -2229,6 +2341,13 @@ public class ToscaResourceInstaller {
}
+ if (vnfResourceCustomization.getMinInstances() == null && vnfResourceCustomization.getMaxInstances() == null) {
+ vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
+ .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
+ vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
+ .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
+ }
+
toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
return vnfResourceCustomization;
diff --git a/asdc-controller/src/test/resources/schema.sql b/asdc-controller/src/test/resources/schema.sql
index 8cc5ee9d49..a50b275c20 100644
--- a/asdc-controller/src/test/resources/schema.sql
+++ b/asdc-controller/src/test/resources/schema.sql
@@ -1109,6 +1109,7 @@ CREATE TABLE `vnf_resource_customization` (
`CREATION_TIMESTAMP` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`VNF_RESOURCE_MODEL_UUID` varchar(200) NOT NULL,
`SERVICE_MODEL_UUID` varchar(200) NOT NULL,
+ `VNFCINSTANCEGROUP_ORDER` varchar(200) default NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `UK_vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`,`SERVICE_MODEL_UUID`),
KEY `fk_vnf_resource_customization__vnf_resource1_idx` (`VNF_RESOURCE_MODEL_UUID`),