From 4e63348e5b0c9b8df287ee6eba33b69ffd5f2516 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 1 Feb 2019 18:13:35 -0500 Subject: compare resources from openstack to aai Address Review comments on pull request Update Unit test to have proper variable for testing update logic inside bpmn to reflect proper variable Update unit test to check property for audit Add flag to turn on and off audit behavior Add license headers, remove un-used files Update Building Block Tests and Activity Names Fix additional unit tests in so-bpmn-tasks layer Fix broken Junit Test, and correct Bug in if statement Add annotation to ignore class under test profile Additional bug fixes and unit tests for classes Add Additional JUNITS, add more sample data Add Openstack Audit functionality to Adapter Change-Id: I0492063271e991eefc608b56336a5cdf1d5a7778 Issue-ID: SO-1456 Signed-off-by: Benjamin, Max (mb388a) --- .../tasks/ExecuteBuildingBlockRainyDay.java | 87 ++++++++++++++-------- .../onap/so/client/exception/ExceptionBuilder.java | 6 +- .../tasks/ExecuteBuildlingBlockRainyDayTest.java | 10 +-- 3 files changed, 65 insertions(+), 38 deletions(-) (limited to 'bpmn/MSOCommonBPMN') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java index d2e0b07dd1..b210b5ed2f 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java @@ -40,18 +40,19 @@ import org.springframework.stereotype.Component; @Component public class ExecuteBuildingBlockRainyDay { - - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ExecuteBuildingBlockRainyDay.class); + + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, + ExecuteBuildingBlockRainyDay.class); public static final String HANDLING_CODE = "handlingCode"; - + @Autowired private CatalogDbClient catalogDbClient; @Autowired private RequestsDbClient requestDbclient; private static final String ASTERISK = "*"; - + @Autowired - private Environment environment; + private Environment environment; protected String retryDurationPath = "mso.rainyDay.retryDurationMultiplier"; protected String defaultCode = "mso.rainyDay.defaultCode"; @@ -67,7 +68,7 @@ public class ExecuteBuildingBlockRainyDay { throw new BpmnError("Unknown error incrementing retry counter"); } } - + public void queryRainyDayTable(DelegateExecution execution, boolean primaryPolicy) { try { ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock"); @@ -79,18 +80,20 @@ public class ExecuteBuildingBlockRainyDay { boolean aLaCarte = (boolean) execution.getVariable("aLaCarte"); boolean suppressRollback = (boolean) execution.getVariable("suppressRollback"); String handlingCode = ""; - if(suppressRollback){ + if (suppressRollback) { handlingCode = "Abort"; - }else{ + } else { try { - serviceType = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getModelInfoServiceInstance().getServiceType(); + serviceType = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0) + .getModelInfoServiceInstance().getServiceType(); } catch (Exception ex) { // keep default serviceType value } String vnfType = ASTERISK; try { - for(GenericVnf vnf : gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs()) { - if(vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) { + for (GenericVnf vnf : gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0) + .getVnfs()) { + if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) { vnfType = vnf.getVnfType(); } } @@ -104,58 +107,78 @@ public class ExecuteBuildingBlockRainyDay { } catch (Exception ex) { // keep default errorCode value } + try { + errorCode = "" + (String) execution.getVariable("WorkflowExceptionCode"); + } catch (Exception ex) { + // keep default errorCode value + } + String workStep = ASTERISK; try { workStep = workflowException.getWorkStep(); } catch (Exception ex) { // keep default workStep value } - //Extract error data to be returned to WorkflowAction - execution.setVariable("WorkflowExceptionErrorMessage", workflowException.getErrorMessage()); + + try { + // Extract error data to be returned to WorkflowAction + execution.setVariable("WorkflowExceptionErrorMessage", workflowException.getErrorMessage()); + } catch (Exception e) { + msoLogger.error("No WorkflowException Found",e); + } RainyDayHandlerStatus rainyDayHandlerStatus; - rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,serviceType,vnfType,errorCode,workStep); - if(rainyDayHandlerStatus==null){ - rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,ASTERISK,ASTERISK,ASTERISK,ASTERISK); - if(rainyDayHandlerStatus==null){ + rainyDayHandlerStatus = catalogDbClient + .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName, + serviceType, vnfType, errorCode, workStep); + if (rainyDayHandlerStatus == null) { + rainyDayHandlerStatus = catalogDbClient + .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName, + ASTERISK, ASTERISK, errorCode, ASTERISK); + } + + if (rainyDayHandlerStatus == null) { + rainyDayHandlerStatus = catalogDbClient + .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName, + ASTERISK, ASTERISK, ASTERISK, ASTERISK); + if (rainyDayHandlerStatus == null) { handlingCode = "Abort"; - }else{ - if(primaryPolicy){ + } else { + if (primaryPolicy) { handlingCode = rainyDayHandlerStatus.getPolicy(); - }else{ + } else { handlingCode = rainyDayHandlerStatus.getSecondaryPolicy(); } } - }else{ - if(primaryPolicy){ + } else { + if (primaryPolicy) { handlingCode = rainyDayHandlerStatus.getPolicy(); - }else{ + } else { handlingCode = rainyDayHandlerStatus.getSecondaryPolicy(); } } - if(!primaryPolicy){ - try{ + if (!primaryPolicy) { + try { InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); request.setRetryStatusMessage("Retries have been exhausted."); requestDbclient.updateInfraActiveRequests(request); - } catch(Exception ex){ - msoLogger.debug(ex.toString()); - msoLogger.error("Failed to update Request Db Infra Active Requests with Retry Status"); + } catch (Exception ex) { + msoLogger.error("Failed to update Request Db Infra Active Requests with Retry Status",ex); } } - if(handlingCode.equals("RollbackToAssigned")&&!aLaCarte){ + if (handlingCode.equals("RollbackToAssigned") && !aLaCarte) { handlingCode = "Rollback"; } } msoLogger.debug("RainyDayHandler Status Code is: " + handlingCode); execution.setVariable(HANDLING_CODE, handlingCode); } catch (Exception e) { - msoLogger.error("Failed to determine RainyDayHandler Status. Seting handlingCode = Abort"); + msoLogger.error("Failed to determine RainyDayHandler Status. Seting handlingCode = Abort", e); String code = this.environment.getProperty(defaultCode); execution.setVariable(HANDLING_CODE, code); } } - - public void setHandlingStatusSuccess(DelegateExecution execution){ + + public void setHandlingStatusSuccess(DelegateExecution execution) { execution.setVariable(HANDLING_CODE, "Success"); } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java index adffee6d42..459ef66e5b 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java @@ -78,7 +78,6 @@ public class ExceptionBuilder { break; } } - msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, msg.toString()); execution.setVariable(errorVariable, exception.getMessage()); } catch (Exception ex){ @@ -108,6 +107,11 @@ public class ExceptionBuilder { msoLogger.info("Throwing MSOWorkflowException"); throw new BpmnError("MSOWorkflowException"); } + + public void buildAndThrowWorkflowException(DelegateExecution execution, String errorCode, String errorMessage) { + execution.setVariable("WorkflowExceptionErrorMessage", errorMessage); + throw new BpmnError(errorCode,errorMessage); + } public String getProcessKey(DelegateExecution execution) { String testKey = (String) execution.getVariable("testProcessKey"); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java index cb5683dcc8..868aabf6a9 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java @@ -93,7 +93,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { vnf.setVnfType("vnft1"); delegateExecution.setVariable("aLaCarte", true); delegateExecution.setVariable("suppressRollback", false); - + delegateExecution.setVariable("WorkflowExceptionCode", "7000"); RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus(); rainyDayHandlerStatus.setErrorCode("7000"); rainyDayHandlerStatus.setFlowName("AssignServiceInstanceBB"); @@ -116,7 +116,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { vnf.setVnfType("vnft1"); delegateExecution.setVariable("aLaCarte", true); delegateExecution.setVariable("suppressRollback", false); - + delegateExecution.setVariable("WorkflowExceptionCode", ASTERISK); RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus(); rainyDayHandlerStatus.setErrorCode(ASTERISK); rainyDayHandlerStatus.setFlowName("AssignServiceInstanceBB"); @@ -164,7 +164,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { vnf.setVnfType("vnft1"); delegateExecution.setVariable("aLaCarte", true); delegateExecution.setVariable("suppressRollback", false); - + delegateExecution.setVariable("WorkflowExceptionCode", "7000"); RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus(); rainyDayHandlerStatus.setErrorCode("7000"); rainyDayHandlerStatus.setFlowName("AssignServiceInstanceBB"); @@ -188,7 +188,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { vnf.setVnfType("vnft1"); delegateExecution.setVariable("aLaCarte", false); delegateExecution.setVariable("suppressRollback", false); - + delegateExecution.setVariable("WorkflowExceptionCode", "7000"); RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus(); rainyDayHandlerStatus.setErrorCode("7000"); rainyDayHandlerStatus.setFlowName("AssignServiceInstanceBB"); @@ -212,7 +212,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { vnf.setVnfType("vnft1"); delegateExecution.setVariable("aLaCarte", true); delegateExecution.setVariable("suppressRollback", false); - + delegateExecution.setVariable("WorkflowExceptionCode", "7000"); RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus(); rainyDayHandlerStatus.setErrorCode("7000"); rainyDayHandlerStatus.setFlowName("AssignServiceInstanceBB"); -- cgit 1.2.3-korg