diff options
author | Boslet, Cory <cory.boslet@att.com> | 2019-04-26 21:25:55 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-04-26 21:27:15 -0400 |
commit | cd2687fbd989f2ca23fd82dcb7c70afb401bdd13 (patch) | |
tree | 2c67c7d47affaa7aaae2ac526cdc524b5dc8c68e | |
parent | a8bce119e8900a95f1f1b61b1caa375a19a2f1a1 (diff) |
Do not need to retry on inventory exception
Do not need to retry on inventory exception due to vservers/linterfaces
missing.
Change-Id: I8e1e1d89ebd35e2b84a65e5e6db3e1db3f976982
Issue-ID: SO-1812
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
2 files changed, 30 insertions, 2 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java index 2bddd439a5..4958bbc7f2 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -48,6 +48,7 @@ public class CreateInventoryTask { protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) { setupMDC(externalTask); boolean success = true; + boolean inventoryException = false; String auditInventoryString = externalTask.getVariable("auditInventoryResult"); AAIObjectAuditList auditInventory = null; try { @@ -61,6 +62,10 @@ public class CreateInventoryTask { logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", auditInventory, externalTask.getRetries()); createInventory.createInventory(auditInventory); + } catch (InventoryException e) { + logger.error("Error during inventory of stack", e); + success = false; + inventoryException = true; } catch (Exception e) { logger.error("Error during inventory of stack", e); success = false; @@ -68,6 +73,9 @@ public class CreateInventoryTask { if (success) { externalTaskService.complete(externalTask); logger.debug("The External Task Id: {} Successful", externalTask.getId()); + } else if (inventoryException) { + logger.debug("The External Task Id: {} Failed, Retry not needed", externalTask.getId()); + externalTaskService.handleBpmnError(externalTask, "AAIInventoryFailure"); } else { if (externalTask.getRetries() == null) { logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}", diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java index 03622db655..c358d3f34c 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java @@ -10,6 +10,10 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.so.adapters.audit.AAIObjectAudit; +import org.onap.so.adapters.audit.AAIObjectAuditList; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import com.fasterxml.jackson.core.JsonProcessingException; public class CreateInventoryTaskTest { @@ -17,6 +21,9 @@ public class CreateInventoryTaskTest { ExternalTask externalTask; @Mock + CreateAAIInventory createAAIInventory; + + @Mock ExternalTaskService externalTaskService; @InjectMocks @@ -33,4 +40,17 @@ public class CreateInventoryTaskTest { inventoryTask.executeExternalTask(externalTask, externalTaskService); Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); } + + @Test + public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException { + AAIObjectAuditList object = new AAIObjectAuditList(); + AAIObjectAudit e = new AAIObjectAudit(); + e.setDoesObjectExist(true); + object.getAuditList().add(e); + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); + doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult"); + Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any()); + inventoryTask.executeExternalTask(externalTask, externalTaskService); + Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); + } } |