diff options
Diffstat (limited to 'bpmn')
10 files changed, 124 insertions, 706 deletions
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 fd2054c3d0..09a5424d47 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 @@ -144,9 +144,20 @@ public class ExecuteBuildingBlockRainyDay { // keep default workStep value } + String serviceRole = ASTERISK; + try { + serviceRole = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0) + .getModelInfoServiceInstance().getServiceRole(); + if (serviceRole == null || serviceRole.isEmpty()) { + serviceRole = ASTERISK; + } + } catch (Exception ex) { + // keep default serviceRole value + } + RainyDayHandlerStatus rainyDayHandlerStatus; rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatus(bbName, serviceType, vnfType, - errorCode, workStep, errorMessage); + errorCode, workStep, errorMessage, serviceRole); if (rainyDayHandlerStatus == null) { handlingCode = "Abort"; 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 80373eb760..18e08917ed 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 @@ -105,7 +105,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setWorkStep(ASTERISK); doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", - "st1", "vnft1", "7000", "*", "errorMessage"); + "st1", "vnft1", "7000", "*", "errorMessage", "*"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); assertEquals("Rollback", delegateExecution.getVariable("handlingCode")); @@ -128,7 +128,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setWorkStep(ASTERISK); doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", - "st1", "vnft1", ASTERISK, ASTERISK, "errorMessage"); + "st1", "vnft1", ASTERISK, ASTERISK, "errorMessage", "*"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); assertEquals("Rollback", delegateExecution.getVariable("handlingCode")); assertEquals(5, delegateExecution.getVariable("maxRetries")); @@ -141,7 +141,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { vnf.setVnfType("vnft1"); delegateExecution.setVariable("aLaCarte", true); doReturn(null).when(MOCK_catalogDbClient).getRainyDayHandlerStatus(isA(String.class), isA(String.class), - isA(String.class), isA(String.class), isA(String.class), isA(String.class)); + isA(String.class), isA(String.class), isA(String.class), isA(String.class), isA(String.class)); delegateExecution.setVariable("suppressRollback", false); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); @@ -152,7 +152,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { @Test public void queryRainyDayTableExceptionTest() { doThrow(RuntimeException.class).when(MOCK_catalogDbClient).getRainyDayHandlerStatus(isA(String.class), - isA(String.class), isA(String.class), isA(String.class), isA(String.class), isA(String.class)); + isA(String.class), isA(String.class), isA(String.class), isA(String.class), isA(String.class), + isA(String.class)); delegateExecution.setVariable("aLaCarte", true); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); delegateExecution.setVariable("suppressRollback", false); @@ -178,7 +179,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setSecondaryPolicy("Abort"); doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", - "st1", "vnft1", "7000", "*", "errorMessage"); + "st1", "vnft1", "7000", "*", "errorMessage", "*"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, false); @@ -203,7 +204,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setSecondaryPolicy("Abort"); doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", - "st1", "vnft1", "7000", "*", "errorMessage"); + "st1", "vnft1", "7000", "*", "errorMessage", "*"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); @@ -229,7 +230,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setSecondaryPolicy("Abort"); doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", - "st1", "vnft1", "7000", "*", "errorMessage"); + "st1", "vnft1", "7000", "*", "errorMessage", "*"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); @@ -255,7 +256,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setSecondaryPolicy("Abort"); doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", - "st1", "vnft1", "7000", "*", "errorMessage"); + "st1", "vnft1", "7000", "*", "errorMessage", "*"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); @@ -272,4 +273,52 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { assertEquals("Abort", delegateExecution.getVariable("handlingCode")); } + @Test + public void queryRainyDayTableServiceRoleNotDefined() throws Exception { + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + serviceInstance.getModelInfoServiceInstance().setServiceType("st1"); + serviceInstance.getModelInfoServiceInstance().setServiceRole("sr1"); + 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"); + rainyDayHandlerStatus.setServiceType("st1"); + rainyDayHandlerStatus.setVnfType("vnft1"); + rainyDayHandlerStatus.setPolicy("Rollback"); + rainyDayHandlerStatus.setWorkStep(ASTERISK); + + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", + "st1", "vnft1", "7000", "*", "errorMessage", "sr1"); + + executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); + assertEquals("Rollback", delegateExecution.getVariable("handlingCode")); + } + + @Test + public void queryRainyDayTableServiceRoleNC() throws Exception { + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + serviceInstance.getModelInfoServiceInstance().setServiceType("st1"); + serviceInstance.getModelInfoServiceInstance().setServiceRole("NETWORK-COLLECTION"); + vnf.setVnfType("vnft1"); + delegateExecution.setVariable("aLaCarte", true); + delegateExecution.setVariable("suppressRollback", false); + delegateExecution.setVariable("WorkflowExceptionCode", "7000"); + RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus(); + rainyDayHandlerStatus.setErrorCode("7000"); + rainyDayHandlerStatus.setFlowName("ActivateServiceInstanceBB"); + rainyDayHandlerStatus.setServiceType("st1"); + rainyDayHandlerStatus.setVnfType("vnft1"); + rainyDayHandlerStatus.setPolicy("Abort"); + rainyDayHandlerStatus.setWorkStep(ASTERISK); + + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", + "st1", "vnft1", "7000", "*", "errorMessage", "NETWORK-COLLECTION"); + + executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); + assertEquals("Abort", delegateExecution.getVariable("handlingCode")); + } + } diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/BaseTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/BaseTask.java deleted file mode 100644 index 1442099286..0000000000 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/BaseTask.java +++ /dev/null @@ -1,422 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.core; - -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.delegate.Expression; -import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.so.bpmn.core.internal.VariableNameExtractor; - -/** - * Base class for service tasks. - */ -public class BaseTask implements JavaDelegate { - - /** - * Get the value of a required field. This method throws MissingInjectedFieldException if the expression is null, - * and BadInjectedFieldException if the expression evaluates to a null value. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value - */ - protected Object getField(Expression expression, DelegateExecution execution, String fieldName) { - return getFieldImpl(expression, execution, fieldName, false); - } - - /** - * Gets the value of an optional field. There are three conditions in which this method returns null: - * <p> - * <ol> - * <li>The expression itself is null (i.e. the field is missing altogether.</li> - * <li>The expression evaluates to a null value.</li> - * <li>The expression references a single variable which has not been set.</li> - * </ol> - * <p> - * Examples:<br> - * Expression ${x} when x is null: return null<br> - * Expression ${x} when x is unset: return null<br> - * Expression ${x+y} when x and/or y are unset: exception<br> - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value, possibly null - */ - protected Object getOptionalField(Expression expression, DelegateExecution execution, String fieldName) { - return getFieldImpl(expression, execution, fieldName, true); - } - - /** - * Get the value of a required output variable field. This method throws MissingInjectedFieldException if the - * expression is null, and BadInjectedFieldException if the expression produces a null or illegal variable name. - * Legal variable names contain only letters, numbers, and the underscore character ('_'). - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the output variable name - */ - protected String getOutputField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, false); - if (o instanceof String) { - String variable = (String) o; - if (!isLegalVariable(variable)) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "'" + variable + "' is not a legal variable name"); - } - return variable; - } else { - if (o != null) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "expected a variable name string, got object of type " + o.getClass().getName()); - } else { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "expected a variable name string, got null object"); - } - } - } - - /** - * Get the value of an optional output variable field. This method throws BadInjectedFieldException if the - * expression produces an illegal variable name. Legal variable names contain only letters, numbers, and the - * underscore character ('_'). - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the output variable name, possibly null - */ - protected String getOptionalOutputField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, true); - if (o instanceof String) { - String variable = (String) o; - if (!isLegalVariable(variable)) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "'" + variable + "' is not a legal variable name"); - } - return variable; - } else if (o == null) { - return null; - } else { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "expected a variable name string, got object of type " + o.getClass().getName()); - } - } - - /** - * Get the value of a required string field. This method throws MissingInjectedFieldException if the expression is - * null, and BadInjectedFieldException if the expression evaluates to a null value. - * <p> - * Note: the result is coerced to a string value, if necessary. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value - */ - protected String getStringField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, false); - if (o instanceof String) { - return (String) o; - } else if (o != null) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "cannot convert '" + o.toString() + "' to Integer"); - } else { - throw new MissingInjectedFieldException(fieldName, getTaskName()); - } - } - - /** - * Gets the value of an optional string field. There are three conditions in which this method returns null: - * <p> - * <ol> - * <li>The expression itself is null (i.e. the field is missing altogether.</li> - * <li>The expression evaluates to a null value.</li> - * <li>The expression references a single variable which has not been set.</li> - * </ol> - * <p> - * Examples:<br> - * Expression ${x} when x is null: return null<br> - * Expression ${x} when x is unset: return null<br> - * Expression ${x+y} when x and/or y are unset: exception<br> - * <p> - * Note: the result is coerced to a string value, if necessary. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value, possibly null - */ - protected String getOptionalStringField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, true); - if (o instanceof String) { - return (String) o; - } else if (o == null) { - return null; - } else { - return o.toString(); - } - } - - /** - * Get the value of a required integer field. This method throws MissingInjectedFieldException if the expression is - * null, and BadInjectedFieldException if the expression evaluates to a null value or a value that cannot be coerced - * to an integer. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value - */ - protected Integer getIntegerField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, false); - if (o instanceof Integer) { - return (Integer) o; - } else { - try { - return Integer.parseInt(o.toString()); - } catch (NumberFormatException e) { - if (o != null) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "cannot convert '" + o.toString() + "' to Integer"); - } else { - throw new MissingInjectedFieldException(fieldName, getTaskName()); - } - } - } - } - - /** - * Gets the value of an optional integer field. There are three conditions in which this method returns null: - * <p> - * <ol> - * <li>The expression itself is null (i.e. the field is missing altogether.</li> - * <li>The expression evaluates to a null value.</li> - * <li>The expression references a single variable which has not been set.</li> - * </ol> - * <p> - * Examples:<br> - * Expression ${x} when x is null: return null<br> - * Expression ${x} when x is unset: return null<br> - * Expression ${x+y} when x and/or y are unset: exception<br> - * <p> - * Note: the result is coerced to an integer value, if necessary. This method throws BadInjectedFieldException if - * the result cannot be coerced to an integer. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value, possibly null - */ - protected Integer getOptionalIntegerField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, true); - if (o instanceof Integer) { - return (Integer) o; - } else if (o == null) { - return null; - } else { - try { - return Integer.parseInt(o.toString()); - } catch (NumberFormatException e) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "cannot convert '" + o.toString() + "' to Integer"); - } - } - } - - /** - * Gets the value of an optional long field. There are three conditions in which this method returns null: - * <p> - * <ol> - * <li>The expression itself is null (i.e. the field is missing altogether.</li> - * <li>The expression evaluates to a null value.</li> - * <li>The expression references a single variable which has not been set.</li> - * </ol> - * <p> - * Examples:<br> - * Expression ${x} when x is null: return null<br> - * Expression ${x} when x is unset: return null<br> - * Expression ${x+y} when x and/or y are unset: exception<br> - * <p> - * Note: the result is coerced to a long value, if necessary. This method throws BadInjectedFieldException if the - * result cannot be coerced to a long. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value, possibly null - */ - protected Long getOptionalLongField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, true); - if (o instanceof Long) { - return (Long) o; - } else if (o == null) { - return null; - } else { - try { - return Long.parseLong(o.toString()); - } catch (NumberFormatException e) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "cannot convert '" + o.toString() + "' to Long"); - } - } - } - - /** - * Get the value of a required long field. This method throws MissingInjectedFieldException if the expression is - * null, and BadInjectedFieldException if the expression evaluates to a null value or a value that cannot be coerced - * to a long. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @return the field value - */ - protected Long getLongField(Expression expression, DelegateExecution execution, String fieldName) { - Object o = getFieldImpl(expression, execution, fieldName, false); - if (o instanceof Long) { - return (Long) o; - } else { - try { - return Long.parseLong(o.toString()); - } catch (NumberFormatException e) { - if (o != null) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "cannot convert '" + o.toString() + "' to Long"); - } else { - throw new MissingInjectedFieldException(fieldName, getTaskName()); - } - } - } - } - - /** - * Common implementation for field "getter" methods. - * - * @param expression the expression - * @param execution the execution - * @param fieldName the field name (for logging and exceptions) - * @param optional true if the field is optional - * @return the field value, possibly null - */ - private Object getFieldImpl(Expression expression, DelegateExecution execution, String fieldName, - boolean optional) { - if (expression == null) { - if (!optional) { - throw new MissingInjectedFieldException(fieldName, getTaskName()); - } - return null; - } - - Object value = null; - - try { - value = expression.getValue(execution); - } catch (Exception e) { - if (!optional) { - throw new BadInjectedFieldException(fieldName, getTaskName(), e.getClass().getSimpleName(), e); - } - - // At this point, we have an exception that occurred while - // evaluating an expression for an optional field. A common - // problem is that the expression is a simple reference to a - // variable which has never been set, e.g. the expression is - // ${x}. The normal activiti behavior is to throw an exception, - // but we don't like that, so we have the following workaround, - // which parses the expression text to see if it is a "simple" - // variable reference, and if so, returns null. If the - // expression is anything other than a single variable - // reference, then an exception is thrown, as it would have - // been without this workaround. - - // Get the expression text so we can parse it - String s = expression.getExpressionText(); - new VariableNameExtractor(s).extract().ifPresent(name -> { - if (execution.hasVariable(name)) { - throw new BadInjectedFieldException(fieldName, getTaskName(), e.getClass().getSimpleName(), e); - } - }); - } - - if (value == null && !optional) { - throw new BadInjectedFieldException(fieldName, getTaskName(), "required field has null value"); - } - - return value; - } - - /** - * Tests if a character is a "word" character. - * - * @param c the character - * @return true if the character is a "word" character. - */ - private static boolean isWordCharacter(char c) { - return (Character.isLetterOrDigit(c) || c == '_'); - } - - /** - * Tests if the specified string is a legal flow variable name. - * - * @param name the string - * @return true if the string is a legal flow variable name - */ - private boolean isLegalVariable(String name) { - if (name == null) { - return false; - } - - int len = name.length(); - - if (len == 0) { - return false; - } - - char c = name.charAt(0); - - if (!Character.isLetter(c) && c != '_') { - return false; - } - - for (int i = 1; i < len; i++) { - c = name.charAt(i); - if (!Character.isLetterOrDigit(c) && c != '_') { - return false; - } - } - - return true; - } - - /** - * Returns the name of the task (normally the java class name). - * - * @return the name of the task - */ - public String getTaskName() { - return getClass().getSimpleName(); - } - - @Override - public void execute(DelegateExecution execution) throws Exception {} -} diff --git a/bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/BaseTaskTest.java b/bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/BaseTaskTest.java deleted file mode 100644 index a9f33f20c5..0000000000 --- a/bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/BaseTaskTest.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 AT&T Intellectual - * Property. All rights reserved. ================================================================================ - * 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. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.core; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import org.camunda.bpm.engine.ProcessEngineServices; -import org.camunda.bpm.engine.RepositoryService; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.delegate.Expression; -import org.camunda.bpm.engine.repository.ProcessDefinition; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class BaseTaskTest { - - private String prefix = "PRE_"; - private String processKey = "AnyProcessKey"; - private String definitionId = "100"; - private String anyVariable = "anyVariable"; - private String anyValueString = "anyValue"; - private String badValueString = "123abc"; - private int anyValueInt = 123; - private Integer anyValueInteger = Integer.valueOf(anyValueInt); - private long anyValuelong = 123L; - private Long anyValueLong = Long.valueOf(anyValuelong); - - private DelegateExecution mockExecution; - private Expression mockExpression; - private BaseTask baseTask; - private Object obj1; - private Object obj2; - private Object objectString; - private Object objectInteger; - private Object objectLong; - private Object objectBoolean; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void before() throws Exception { - baseTask = new BaseTask(); - ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class); - when(mockProcessDefinition.getKey()).thenReturn(processKey); - RepositoryService mockRepositoryService = mock(RepositoryService.class); - when(mockRepositoryService.getProcessDefinition(definitionId)).thenReturn(mockProcessDefinition); - ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class); - when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService); - mockExecution = mock(DelegateExecution.class); - when(mockExecution.getId()).thenReturn(definitionId); - when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices); - when(mockExecution.getProcessEngineServices().getRepositoryService() - .getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition); - when(mockExecution.getVariable("prefix")).thenReturn(prefix); - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true"); - mockExpression = mock(Expression.class); - } - - @Test - public void testExecution() throws Exception { - baseTask.execute(mockExecution); - assertEquals("BaseTask", baseTask.getTaskName()); - } - - @Test - public void testGetFieldAndMissingInjectedException() throws Exception { - objectString = new String(anyValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj1 = baseTask.getField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueString, obj1.toString()); - - expectedException.expect(MissingInjectedFieldException.class); - obj2 = baseTask.getField(null, mockExecution, anyVariable); - } - - @Test - public void testGetFieldAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - obj1 = baseTask.getField(mockExpression, mockExecution, null); - } - - @Test - public void testGetOptionalField() throws Exception { - objectString = new String(anyValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj1 = baseTask.getOptionalField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueString, obj1.toString()); - } - - @Test - public void testGetStringFieldAndMissingInjectedFieldException() throws Exception { - objectString = new String(anyValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj1 = baseTask.getStringField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueString, obj1.toString()); - - expectedException.expect(MissingInjectedFieldException.class); - Object objectBoolean = Boolean.valueOf(true); // bad data - when(mockExpression.getValue(mockExecution)).thenReturn(objectBoolean); - obj2 = baseTask.getStringField(null, mockExecution, anyVariable); - } - - @Test - public void testGetStringFieldAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - obj1 = baseTask.getStringField(mockExpression, mockExecution, null); - } - - @Test - public void testGetOptionalStringField() throws Exception { - objectString = new String(anyValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj1 = baseTask.getOptionalStringField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueString, obj1.toString()); - } - - @Test - public void testGetIntegerFieldAndMissingInjectedFieldException() throws Exception { - objectInteger = Integer.valueOf(anyValueInt); - when(mockExpression.getValue(mockExecution)).thenReturn(objectInteger); - obj1 = baseTask.getIntegerField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueInteger, (Integer) obj1); - - expectedException.expect(MissingInjectedFieldException.class); - objectString = new String(badValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj2 = baseTask.getIntegerField(null, mockExecution, anyVariable); - } - - @Test - public void testGetIntegerFieldAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - obj1 = baseTask.getIntegerField(mockExpression, mockExecution, null); - } - - - @Test - public void testGetOptionalIntegerField() throws Exception { - objectInteger = Integer.valueOf(anyValueInt); - when(mockExpression.getValue(mockExecution)).thenReturn(objectInteger); - obj1 = baseTask.getOptionalIntegerField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueInteger, (Integer) obj1); - } - - @Test - public void testGetOptionalIntegerFieldAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - objectBoolean = Boolean.valueOf(true); - when(mockExpression.getValue(mockExecution)).thenReturn(objectBoolean); - obj1 = baseTask.getOptionalIntegerField(mockExpression, mockExecution, anyVariable); - } - - @Test - public void testGetLongFieldAndMissingInjectedFieldException() throws Exception { - objectLong = Long.valueOf(anyValuelong); - when(mockExpression.getValue(mockExecution)).thenReturn(objectLong); - obj1 = baseTask.getLongField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueLong, (Long) obj1); - - expectedException.expect(MissingInjectedFieldException.class); - objectString = new String(badValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj2 = baseTask.getLongField(null, mockExecution, anyVariable); - } - - @Test - public void testGetLongFieldAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - obj2 = baseTask.getLongField(mockExpression, mockExecution, null); - } - - @Test - public void testGetOptionalLongField() throws Exception { - objectLong = Long.valueOf(anyValuelong); - when(mockExpression.getValue(mockExecution)).thenReturn(objectLong); - obj1 = baseTask.getOptionalLongField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueLong, (Long) obj1); - } - - @Test - public void testGetOptionalLongFieldAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - objectBoolean = Boolean.valueOf(true); - when(mockExpression.getValue(mockExecution)).thenReturn(objectBoolean); - obj1 = baseTask.getOptionalLongField(mockExpression, mockExecution, anyVariable); - } - - @Test - public void testGetOutputAndMissingInjectedFieldException() throws Exception { - objectString = new String(anyValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj1 = baseTask.getOutputField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueString, obj1.toString()); - - expectedException.expect(MissingInjectedFieldException.class); - objectString = new String(anyValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj2 = baseTask.getOutputField(null, mockExecution, anyVariable); - } - - @Test - public void testGetOutputAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - obj2 = baseTask.getOutputField(null, mockExecution, anyVariable); - } - - @Test - public void testGetOptionalOutputField() throws Exception { - objectString = new String(anyValueString); - when(mockExpression.getValue(mockExecution)).thenReturn(objectString); - obj1 = baseTask.getOptionalOutputField(mockExpression, mockExecution, anyVariable); - assertEquals(anyValueString, obj1.toString()); - } - - @Test - public void testGetOptionalOutputFieldAndBadInjectedFieldException() throws Exception { - expectedException.expect(BadInjectedFieldException.class); - objectBoolean = Boolean.valueOf(true); - when(mockExpression.getValue(mockExecution)).thenReturn(objectBoolean); - obj1 = baseTask.getOptionalOutputField(mockExpression, mockExecution, anyVariable); - } - -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy index 30b5cc8567..573cd0a533 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy @@ -57,7 +57,7 @@ public class ActivateSDNCNetworkResource extends AbstractServiceTaskProcessor { MsoUtils msoUtils = new MsoUtils() - public void preProcessRequest(DelegateExecution execution) { + void preProcessRequest(DelegateExecution execution) { logger.info(" ***** Started preProcessRequest *****") try { @@ -106,7 +106,7 @@ public class ActivateSDNCNetworkResource extends AbstractServiceTaskProcessor { } } - public void prepareUpdateAfterActivateSDNCResource(DelegateExecution execution) { + void prepareUpdateAfterActivateSDNCResource(DelegateExecution execution) { logger.info("started prepareUpdateAfterActivateSDNCResource ") ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(execution.getVariable(Prefix + "resourceInput"), ResourceInput.class) @@ -163,7 +163,7 @@ public class ActivateSDNCNetworkResource extends AbstractServiceTaskProcessor { return new JSONObject(paramMap).toString() } - public void prepareSDNCRequest (DelegateExecution execution) { + void prepareSDNCRequest (DelegateExecution execution) { logger.info("Started prepareSDNCRequest ") try { @@ -451,7 +451,7 @@ public class ActivateSDNCNetworkResource extends AbstractServiceTaskProcessor { logger.info(" ***** Exit prepareSDNCRequest *****") } - public void postActivateSDNCCall(DelegateExecution execution) { + void postActivateSDNCCall(DelegateExecution execution) { logger.info("started postCreateSDNCCall ") String responseCode = execution.getVariable(Prefix + "sdncCreateReturnCode") @@ -460,7 +460,7 @@ public class ActivateSDNCNetworkResource extends AbstractServiceTaskProcessor { logger.info("response from sdnc, response code :" + responseCode + " response object :" + responseObj) } - public void sendSyncResponse(DelegateExecution execution) { + void sendSyncResponse(DelegateExecution execution) { logger.info("started sendsyncResp") try { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java index f7708b69d3..f933277f3c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.logger.LoggingAnchor; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.methods.CloseableHttpResponse; @@ -41,7 +42,6 @@ import org.json.JSONObject; import org.onap.msb.sdk.discovery.common.RouteException; import org.onap.msb.sdk.httpclient.RestServiceCreater; import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; -import org.onap.so.bpmn.core.BaseTask; import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi; import org.onap.so.db.request.beans.ResourceOperationStatus; @@ -56,7 +56,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -public abstract class AbstractSdncOperationTask extends BaseTask { +public abstract class AbstractSdncOperationTask implements JavaDelegate { private static final Logger logger = LoggerFactory.getLogger(AbstractSdncOperationTask.class); @@ -284,7 +284,7 @@ public abstract class AbstractSdncOperationTask extends BaseTask { logger.info("exception: AbstractSdncOperationTask.updateProgress fail!"); logger.error("exception: AbstractSdncOperationTask.updateProgress fail:", exception); logger.error(LoggingAnchor.FIVE, MessageEnum.GENERAL_EXCEPTION.toString(), - " updateProgress catch exception: ", this.getTaskName(), ErrorCode.UnknownError.getValue(), + " updateProgress catch exception: ", ErrorCode.UnknownError.getValue(), exception.getClass().toString()); } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/SdncUnderlayVpnPreprocessTask.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/SdncUnderlayVpnPreprocessTask.java index 5b7f3bb432..16bd194f99 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/SdncUnderlayVpnPreprocessTask.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/SdncUnderlayVpnPreprocessTask.java @@ -22,12 +22,12 @@ package org.onap.so.bpmn.infrastructure.workflow.serviceTask; import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.onap.so.bpmn.core.BaseTask; +import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.db.request.beans.ResourceOperationStatus; import org.springframework.stereotype.Component; @Component -public class SdncUnderlayVpnPreprocessTask extends BaseTask { +public class SdncUnderlayVpnPreprocessTask implements JavaDelegate { public static final String RESOURCE_OPER_TYPE = "resourceOperType"; @Override diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java index a436f7b5c2..9340609ffc 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java @@ -59,9 +59,18 @@ public class ExecuteActivity implements JavaDelegate { private static final String VNF_ID = "vnfId"; private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; private static final String WORKFLOW_SYNC_ACK_SENT = "workflowSyncAckSent"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String EXECUTE_BUILDING_BLOCK = "ExecuteBuildingBlock"; + private static final String RETRY_COUNT = "retryCount"; + private static final String A_LA_CARTE = "aLaCarte"; + private static final String SUPPRESS_ROLLBACK = "suppressRollback"; + private static final String WORKFLOW_EXCEPTION = "WorkflowException"; + private static final String HANDLING_CODE = "handlingCode"; + private static final String ABORT_HANDLING_CODE = "Abort"; private static final String SERVICE_TASK_IMPLEMENTATION_ATTRIBUTE = "implementation"; private static final String ACTIVITY_PREFIX = "activity:"; + private static final String EXECUTE_ACTIVITY_ERROR_MESSAGE = "ExecuteActivityErrorMessage"; private ObjectMapper mapper = new ObjectMapper(); @@ -75,7 +84,8 @@ public class ExecuteActivity implements JavaDelegate { @Override public void execute(DelegateExecution execution) throws Exception { final String requestId = (String) execution.getVariable(G_REQUEST_ID); - + WorkflowException workflowException = null; + String handlingCode = null; try { Boolean workflowSyncAckSent = (Boolean) execution.getVariable(WORKFLOW_SYNC_ACK_SENT); if (workflowSyncAckSent == null || workflowSyncAckSent == false) { @@ -95,31 +105,44 @@ public class ExecuteActivity implements JavaDelegate { ExecuteBuildingBlock executeBuildingBlock = buildExecuteBuildingBlock(execution, requestId, buildingBlock); Map<String, Object> variables = new HashMap<>(); - variables.put("buildingBlock", executeBuildingBlock); - variables.put(G_REQUEST_ID, requestId); - variables.put("retryCount", 1); - variables.put("aLaCarte", true); - variables.put("suppressRollback", true); - execution.getVariables().forEach((key, value) -> { - if (value instanceof Serializable) { - variables.put(key, (Serializable) value); - } - }); + if (execution.getVariables() != null) { + execution.getVariables().forEach((key, value) -> { + if (value instanceof Serializable) { + variables.put(key, (Serializable) value); + } + }); + } + + variables.put(BUILDING_BLOCK, executeBuildingBlock); + variables.put(G_REQUEST_ID, requestId); + variables.put(RETRY_COUNT, 1); + variables.put(A_LA_CARTE, true); + variables.put(SUPPRESS_ROLLBACK, true); ProcessInstanceWithVariables buildingBlockResult = - runtimeService.createProcessInstanceByKey("ExecuteBuildingBlock").setVariables(variables) + runtimeService.createProcessInstanceByKey(EXECUTE_BUILDING_BLOCK).setVariables(variables) .executeWithVariablesInReturn(); VariableMap variableMap = buildingBlockResult.getVariables(); - WorkflowException workflowException = (WorkflowException) variableMap.get("WorklfowException"); + workflowException = (WorkflowException) variableMap.get(WORKFLOW_EXCEPTION); if (workflowException != null) { logger.error("Workflow exception is: {}", workflowException.getErrorMessage()); } - execution.setVariable("WorkflowException", workflowException); + + handlingCode = (String) variableMap.get(HANDLING_CODE); + logger.debug("Handling code: " + handlingCode); + + execution.setVariable(WORKFLOW_EXCEPTION, workflowException); } catch (Exception e) { buildAndThrowException(execution, e.getMessage()); } + + if (workflowException != null && handlingCode != null && handlingCode.equals(ABORT_HANDLING_CODE)) { + logger.debug("Aborting execution of the custom workflow"); + buildAndThrowException(execution, workflowException.getErrorMessage()); + } + } protected BuildingBlock buildBuildingBlock(String activityName) { @@ -161,7 +184,7 @@ public class ExecuteActivity implements JavaDelegate { protected void buildAndThrowException(DelegateExecution execution, String msg) { logger.error(msg); - execution.setVariable("ExecuteActuvityErrorMessage", msg); + execution.setVariable(EXECUTE_ACTIVITY_ERROR_MESSAGE, msg); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java index 7466df53b2..c9a937b824 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java @@ -30,8 +30,6 @@ import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAINetworkResources; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -61,10 +59,10 @@ public class UnassignNetworkBB { * @param execution - BuildingBlockExecution * @param relatedToValue - String, ex: vf-module * @return void - nothing - * @throws Exception + * */ - public void checkRelationshipRelatedTo(BuildingBlockExecution execution, String relatedToValue) throws Exception { + public void checkRelationshipRelatedTo(BuildingBlockExecution execution, String relatedToValue) { try { L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); AAIResultWrapper aaiResultWrapper = aaiNetworkResources.queryNetworkWrapperById(l3network); @@ -85,10 +83,10 @@ public class UnassignNetworkBB { * * @param execution - BuildingBlockExecution * @return void - nothing - * @throws Exception + * */ - public void getCloudSdncRegion(BuildingBlockExecution execution) throws Exception { + public void getCloudSdncRegion(BuildingBlockExecution execution) { try { String cloudRegionSdnc = networkBBUtils.getCloudRegion(execution, SourceSystem.SDNC); execution.setVariable("cloudRegionSdnc", cloudRegionSdnc); @@ -107,7 +105,7 @@ public class UnassignNetworkBB { String msg; boolean isRollbackNeeded = execution.getVariable("isRollbackNeeded") != null ? execution.getVariable("isRollbackNeeded") : false; - if (isRollbackNeeded == true) { + if (isRollbackNeeded) { msg = execution.getVariable("ErrorUnassignNetworkBB") + messageErrorRollback; } else { msg = execution.getVariable("ErrorUnassignNetworkBB"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java index 21c0b971b8..d07574a1ad 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java @@ -57,10 +57,10 @@ public class SniroClient { * * @param homingRequest * @return - * @throws JsonProcessingException + * @throws BadResponseException * @throws BpmnError */ - public void postDemands(SniroManagerRequest homingRequest) throws BadResponseException, JsonProcessingException { + public void postDemands(SniroManagerRequest homingRequest) throws BadResponseException { logger.trace("Started Sniro Client Post Demands"); String url = managerProperties.getHost() + managerProperties.getUri().get("v2"); logger.debug("Post demands url: {}", url); |