Added NPE check for audit 56/89056/1
authorBoslet, Cory <cory.boslet@att.com>
Fri, 31 May 2019 15:46:57 +0000 (11:46 -0400)
committerBenjamin, Max (mb388a) <mb388a@us.att.com>
Fri, 31 May 2019 15:47:10 +0000 (11:47 -0400)
Added NPE check so that flow continues when no audit results present

Change-Id: I614dbaff7eaaca86a503da2734d7c5f7a197bb1b
Issue-ID: SO-1959
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java

index dabfc81..870b936 100644 (file)
@@ -153,65 +153,67 @@ public class ExceptionBuilder {
     }
 
     public void processAuditException(DelegateExecutionImpl execution, boolean flowShouldContinue) {
-        logger.info("Building a WorkflowException for Subflow");
+        logger.debug("Processing Audit Results");
+        String auditListString = (String) execution.getVariable("auditInventoryResult");
+        if (auditListString != null) {
+            StringBuilder errorMessage = new StringBuilder();
+            String processKey = getProcessKey(execution.getDelegateExecution());
+            try {
+                ExtractPojosForBB extractPojosForBB = getExtractPojosForBB();
+                VfModule module = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+                String cloudRegionId = execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId();
+
+                GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
+                AAIObjectAuditList auditList =
+                        objectMapper.getMapper().readValue(auditListString, AAIObjectAuditList.class);
+
+                errorMessage = errorMessage.append(auditList.getAuditType() + " VF-Module " + module.getVfModuleId()
+                        + " failed due to incomplete AAI vserver inventory population after stack "
+                        + auditList.getHeatStackName() + " was successfully " + auditList.getAuditType()
+                        + "d in cloud region " + cloudRegionId + ". MSO Audit indicates that the following was not "
+                        + auditList.getAuditType() + "d in AAI: ");
+
+                Stream<AAIObjectAudit> vServerLInterfaceAuditStream = auditList.getAuditList().stream()
+                        .filter(auditObject -> auditObject.getAaiObjectType().equals(AAIObjectType.VSERVER.typeName())
+                                || auditObject.getAaiObjectType().equals(AAIObjectType.L_INTERFACE.typeName()));
+                List<AAIObjectAudit> filteredAuditStream =
+                        vServerLInterfaceAuditStream.filter(a -> !a.isDoesObjectExist()).collect(Collectors.toList());
+
+                for (AAIObjectAudit object : filteredAuditStream) {
+                    if (object.getAaiObjectType().equals(AAIObjectType.L_INTERFACE.typeName())) {
+                        LInterface li = objectMapper.getMapper().convertValue(object.getAaiObject(), LInterface.class);
+                        errorMessage = errorMessage
+                                .append(AAIObjectType.L_INTERFACE.typeName() + " " + li.getInterfaceId() + ", ");
+                    } else {
+                        Vserver vs = objectMapper.getMapper().convertValue(object.getAaiObject(), Vserver.class);
+                        errorMessage =
+                                errorMessage.append(AAIObjectType.VSERVER.typeName() + " " + vs.getVserverId() + ", ");
+                    }
+                }
 
-        StringBuilder errorMessage = new StringBuilder();
-        String processKey = getProcessKey(execution.getDelegateExecution());
-        try {
-            ExtractPojosForBB extractPojosForBB = getExtractPojosForBB();
-            VfModule module = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
-            String cloudRegionId = execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId();
-
-            GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
-            String auditListString = (String) execution.getVariable("auditInventoryResult");
-            AAIObjectAuditList auditList =
-                    objectMapper.getMapper().readValue(auditListString, AAIObjectAuditList.class);
-
-            errorMessage = errorMessage.append(auditList.getAuditType() + " VF-Module " + module.getVfModuleId()
-                    + " failed due to incomplete A&AI vserver inventory population after stack "
-                    + auditList.getHeatStackName() + " was successfully " + auditList.getAuditType()
-                    + "d in cloud region " + cloudRegionId + ". MSO Audit indicates that AIC RO did not "
-                    + auditList.getAuditType() + " ");
-
-            Stream<AAIObjectAudit> vServerLInterfaceAuditStream = auditList.getAuditList().stream()
-                    .filter(auditObject -> auditObject.getAaiObjectType().equals(AAIObjectType.VSERVER.typeName())
-                            || auditObject.getAaiObjectType().equals(AAIObjectType.L_INTERFACE.typeName()));
-            List<AAIObjectAudit> filteredAuditStream =
-                    vServerLInterfaceAuditStream.filter(a -> !a.isDoesObjectExist()).collect(Collectors.toList());
-
-            for (AAIObjectAudit object : filteredAuditStream) {
-                if (object.getAaiObjectType().equals(AAIObjectType.L_INTERFACE.typeName())) {
-                    LInterface li = objectMapper.getMapper().convertValue(object.getAaiObject(), LInterface.class);
-                    errorMessage = errorMessage
-                            .append(AAIObjectType.L_INTERFACE.typeName() + " " + li.getInterfaceId() + ", ");
-                } else {
-                    Vserver vs = objectMapper.getMapper().convertValue(object.getAaiObject(), Vserver.class);
-                    errorMessage =
-                            errorMessage.append(AAIObjectType.VSERVER.typeName() + " " + vs.getVserverId() + ", ");
+                if (errorMessage.length() > 0) {
+                    errorMessage.setLength(errorMessage.length() - 2);
+                    errorMessage = errorMessage.append(".");
                 }
-            }
 
-            if (errorMessage.length() > 0) {
-                errorMessage.setLength(errorMessage.length() - 2);
-                errorMessage = errorMessage.append(" in AAI. ");
+            } catch (IOException | BBObjectNotFoundException e) {
+                errorMessage = errorMessage.append("process objects in AAI. ");
             }
 
-        } catch (IOException | BBObjectNotFoundException e) {
-            errorMessage = errorMessage.append("process objects in AAI. ");
-        }
-
-        errorMessage.append(
-                "Recommendation - Wait for nightly RO Audit to run and fix the data issue and resume vf-module creation in VID. If problem persists then report problem to AIC/RO Ops.");
+            if (flowShouldContinue) {
+                execution.setVariable("StatusMessage", errorMessage.toString());
+            } else {
+                WorkflowException exception = new WorkflowException(processKey, 400, errorMessage.toString());
+                execution.setVariable("WorkflowException", exception);
+                execution.setVariable("WorkflowExceptionErrorMessage", errorMessage.toString());
+                logger.info("Outgoing WorkflowException is {}", exception);
+                logger.info("Throwing MSOWorkflowException");
+                throw new BpmnError("AAIInventoryFailure");
+            }
 
-        if (flowShouldContinue) {
-            execution.setVariable("StatusMessage", errorMessage.toString());
         } else {
-            WorkflowException exception = new WorkflowException(processKey, 400, errorMessage.toString());
-            execution.setVariable("WorkflowException", exception);
-            execution.setVariable("WorkflowExceptionErrorMessage", errorMessage.toString());
-            logger.info("Outgoing WorkflowException is {}", exception);
-            logger.info("Throwing MSOWorkflowException");
-            throw new BpmnError("AAIInventoryFailure");
+            logger.debug("Unable to process audit results due to auditInventoryResult being null");
         }
     }
+
 }
index 549f16b..5f9aef6 100644 (file)
@@ -138,7 +138,7 @@ public class ExceptionBuilderTest extends BaseTest {
             WorkflowException we = execution.getVariable("WorkflowException");
             assertNotNull(we);
             assertEquals(
-                    "create VF-Module testVfModuleId1 failed due to incomplete A&AI vserver inventory population after stack testStackName was successfully created in cloud region testLcpCloudRegionId. MSO Audit indicates that AIC RO did not create vserver testVServerId in AAI. Recommendation - Wait for nightly RO Audit to run and fix the data issue and resume vf-module creation in VID. If problem persists then report problem to AIC/RO Ops.",
+                    "create VF-Module testVfModuleId1 failed due to incomplete AAI vserver inventory population after stack testStackName was successfully created in cloud region testLcpCloudRegionId. MSO Audit indicates that the following was not created in AAI: vserver testVServerId.",
                     we.getErrorMessage());
         }
     }
@@ -151,7 +151,7 @@ public class ExceptionBuilderTest extends BaseTest {
             String sm = execution.getVariable("StatusMessage");
             assertNotNull(sm);
             assertEquals(
-                    "create VF-Module testVfModuleId1 failed due to incomplete A&AI vserver inventory population after stack testStackName was successfully created in cloud region testLcpCloudRegionId. MSO Audit indicates that AIC RO did not create vserver testVServerId in AAI. Recommendation - Wait for nightly RO Audit to run and fix the data issue and resume vf-module creation in VID. If problem persists then report problem to AIC/RO Ops.",
+                    "create VF-Module testVfModuleId1 failed due to incomplete AAI vserver inventory population after stack testStackName was successfully created in cloud region testLcpCloudRegionId. MSO Audit indicates that the following was not created in AAI: vserver testVServerId.",
                     sm);
         } catch (BpmnError bpmnException) {
             fail();