aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/main/java/org
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-05 17:11:54 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-05 17:12:15 -0500
commit2a123ff7a50f3147a41135b559452563bca4727b (patch)
tree368a8a87b3bfed5e18bd8760fa7b89f87da7638a /bpmn/so-bpmn-tasks/src/main/java/org
parent632f2ff1ef005a801c0676367e90417f9ca00c57 (diff)
logic to handle null values for vf module index
added logic to handle null values for vf module index Change-Id: I53f4ed8b307a92187c22f19dbc7bb101d037fbd8 Issue-ID: SO-1465 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java45
1 files changed, 35 insertions, 10 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
index 55e74339a4..4dd0147163 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
@@ -21,7 +21,6 @@
package org.onap.so.bpmn.infrastructure.aai.tasks;
import java.util.Arrays;
-import java.util.Set;
import java.util.TreeSet;
import org.camunda.bpm.engine.delegate.BpmnError;
@@ -54,6 +53,8 @@ import org.onap.so.client.orchestration.AAIVolumeGroupResources;
import org.onap.so.client.orchestration.AAIVpnBindingResources;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@@ -62,6 +63,8 @@ import org.springframework.stereotype.Component;
public class AAICreateTasks {
private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAICreateTasks.class);
+ private static final Logger logger = LoggerFactory.getLogger(AAICreateTasks.class.getName());
+
private static final String networkTypeProvider = "PROVIDER";
private static String NETWORK_COLLECTION_NAME = "networkCollectionName";
@Autowired
@@ -452,23 +455,45 @@ public class AAICreateTasks {
if (genericVnf != null && genericVnf.getVfModules() != null && !genericVnf.getVfModules().isEmpty()) {
- Set<Integer> moduleIndices = new TreeSet<>();
+ TreeSet<Integer> moduleIndices = new TreeSet<>();
+ int nullIndexFound = 0;
for (VfModule vfModule : genericVnf.getVfModules()) {
if (vfModule.getModelInfoVfModule() != null) {
if (vfModule.getModelInfoVfModule().getModelInvariantUUID().equals(newVfModuleModelInvariantUUID)) {
- moduleIndices.add(vfModule.getModuleIndex());
+ if (vfModule.getModuleIndex() != null) {
+ moduleIndices.add(vfModule.getModuleIndex());
+ } else {
+ nullIndexFound++;
+ logger.warn("Found null index for vf-module-id {} and model-invariant-uuid {}", vfModule.getVfModuleId(), vfModule.getModelInfoVfModule().getModelInvariantUUID());
+ }
}
}
}
- Object[] array = moduleIndices.toArray();
- for (int i=0; i < array.length; i++) {
- if ((int) array[i] != i) {
- return i;
- }
- }
- return array.length;
+
+ return calculateUnusedIndex(moduleIndices, nullIndexFound);
} else {
return 0;
}
}
+
+ protected int calculateUnusedIndex(TreeSet<Integer> moduleIndices, int nullIndexFound) {
+ //pad array with nulls
+ Integer[] temp = new Integer[moduleIndices.size() + nullIndexFound];
+ Integer[] array = moduleIndices.toArray(temp);
+ int result = 0;
+ //when a null is found skip that potential value
+ //effectively creates something like, [0,1,3,null,null] -> [0,1,null(2),3,null(4)]
+ for (int i=0; i < array.length; i++, result++) {
+ if (Integer.valueOf(result) != array[i]) {
+ if (nullIndexFound > 0) {
+ nullIndexFound--;
+ i--;
+ } else {
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
}