diff options
9 files changed, 100 insertions, 20 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql index 486b53cf8a..13d736e747 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql @@ -813,3 +813,5 @@ VALUES ('ConfigDeployVnfBB', 'NO_VALIDATE', 'CUSTOM'); UPDATE rainy_day_handler_macro SET reg_ex_error_message = '*' WHERE reg_ex_error_message IS null; + +UPDATE rainy_day_handler_macro SET SERVICE_ROLE = '*' WHERE SERVICE_ROLE IS null; diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V6.1.1__AddServiceRoleToRainyDayHandling.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V6.1.1__AddServiceRoleToRainyDayHandling.sql new file mode 100644 index 0000000000..8fe3caf88f --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V6.1.1__AddServiceRoleToRainyDayHandling.sql @@ -0,0 +1,2 @@ +use catalogdb; +ALTER TABLE rainy_day_handler_macro ADD COLUMN IF NOT EXISTS SERVICE_ROLE varchar(300) DEFAULT NULL;
\ No newline at end of file diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index f65f521605..a955a2c3ce 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java @@ -87,7 +87,7 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest { @Test public void testGetRainyDayHandler_Regex() { RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatus("AssignServiceInstanceBB", "*", - "*", "*", "*", "The Flavor ID (nd.c6r16d20) could not be found."); + "*", "*", "*", "The Flavor ID (nd.c6r16d20) could not be found.", "*"); Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy()); } @@ -95,7 +95,8 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest { public void testGetRainyDayHandler__Encoding_Regex() { RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatus("AssignServiceInstanceBB", "*", "*", "*", "*", - "resources.lba_0_dmz_vmi_0: Unknown id: Error: oper 1 url /fqname-to-id body {\"fq_name\": [\"zrdm6bvota05-dmz_sec_group\"], \"type\": \"security-group\"} response Name ['zrdm6bvota05-dmz_sec_group'] not found"); + "resources.lba_0_dmz_vmi_0: Unknown id: Error: oper 1 url /fqname-to-id body {\"fq_name\": [\"zrdm6bvota05-dmz_sec_group\"], \"type\": \"security-group\"} response Name ['zrdm6bvota05-dmz_sec_group'] not found", + "*"); Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy()); } diff --git a/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql b/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql index 58b2983f82..32c51293c2 100644 --- a/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql +++ b/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql @@ -184,8 +184,8 @@ VALUES ( '9bcce658-9b37-11e8-98d0-529269fb1459', 'testVnfcCustomizationDescription', '2018-07-17 14:05:08'); -INSERT INTO `rainy_day_handler_macro` (`FLOW_NAME`,`SERVICE_TYPE`,`VNF_TYPE`,`ERROR_CODE`,`WORK_STEP`,`POLICY`,`SECONDARY_POLICY`,`REG_EX_ERROR_MESSAGE`) -VALUES ('AssignServiceInstanceBB','*','*','*','*','Rollback','Rollback','The Flavor ID.*could not be found.'); +INSERT INTO `rainy_day_handler_macro` (`FLOW_NAME`,`SERVICE_TYPE`,`VNF_TYPE`,`ERROR_CODE`,`WORK_STEP`,`POLICY`,`SECONDARY_POLICY`,`REG_EX_ERROR_MESSAGE`, `SERVICE_ROLE`) +VALUES ('AssignServiceInstanceBB','*','*','*','*','Rollback','Rollback','The Flavor ID.*could not be found.','*'); INSERT INTO `cvnfc_customization` (`id`, 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/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/macro/RainyDayHandlerStatus.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/macro/RainyDayHandlerStatus.java index 1882ad5964..39217c75fa 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/macro/RainyDayHandlerStatus.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/macro/RainyDayHandlerStatus.java @@ -77,12 +77,16 @@ public class RainyDayHandlerStatus implements Serializable { @Column(name = "SECONDARY_POLICY") private String secondaryPolicy; + @BusinessKey + @Column(name = "SERVICE_ROLE") + private String serviceRole; + @Override public String toString() { return new ToStringBuilder(this).append("id", id).append("flowName", flowName) .append("serviceType", serviceType).append("vnfType", vnfType).append("errorCode", errorCode) .append("errorMessage", errorMessage).append("workStep", workStep).append("policy", policy) - .append("secondaryPolicy", secondaryPolicy).toString(); + .append("secondaryPolicy", secondaryPolicy).append("serviceRole", serviceRole).toString(); } @Override @@ -93,13 +97,14 @@ public class RainyDayHandlerStatus implements Serializable { RainyDayHandlerStatus castOther = (RainyDayHandlerStatus) other; return new EqualsBuilder().append(flowName, castOther.flowName).append(serviceType, castOther.serviceType) .append(vnfType, castOther.vnfType).append(errorCode, castOther.errorCode) - .append(workStep, castOther.workStep).append(policy, castOther.policy).isEquals(); + .append(workStep, castOther.workStep).append(policy, castOther.policy) + .append(serviceRole, castOther.serviceRole).isEquals(); } @Override public int hashCode() { return new HashCodeBuilder().append(flowName).append(serviceType).append(vnfType).append(errorCode) - .append(workStep).append(policy).toHashCode(); + .append(workStep).append(policy).append(serviceRole).toHashCode(); } public Integer getId() { @@ -174,5 +179,12 @@ public class RainyDayHandlerStatus implements Serializable { this.errorMessage = errorMessage; } + public String getServiceRole() { + return serviceRole; + } + + public void setServiceRole(String serviceRole) { + this.serviceRole = serviceRole; + } } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index a18f870970..a959f2f5a1 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -137,6 +137,7 @@ public class CatalogDbClient { private static final String CLOUD_OWNER = "cloudOwner"; private static final String FLOW_NAME = "flowName"; private static final String ERROR_MESSAGE = "errorMessage"; + private static final String SERVICE_ROLE = "serviceRole"; private static final String SERVICE_TYPE = "serviceType"; private static final String VNF_TYPE = "vnfType"; private static final String ERROR_CODE = "errorCode"; @@ -638,7 +639,7 @@ public class CatalogDbClient { } public RainyDayHandlerStatus getRainyDayHandlerStatus(String flowName, String serviceType, String vnfType, - String errorCode, String workStep, String errorMessage) { + String errorCode, String workStep, String errorMessage, String serviceRole) { logger.debug( "Get Rainy Day Status - Flow Name {}, Service Type: {} , vnfType {} , errorCode {}, workStep {}, errorMessage {}", flowName, serviceType, vnfType, errorCode, workStep, errorMessage); @@ -646,7 +647,8 @@ public class CatalogDbClient { UriComponentsBuilder.fromUriString(endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findRainyDayHandler) .queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType) .queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep) - .queryParam(ERROR_MESSAGE, errorMessage).build().encode().toUri()); + .queryParam(ERROR_MESSAGE, errorMessage).queryParam(SERVICE_ROLE, serviceRole).build().encode() + .toUri()); } public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action) { diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/RainyDayHandlerStatusRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/RainyDayHandlerStatusRepository.java index 6819657b78..efe078bbfc 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/RainyDayHandlerStatusRepository.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/RainyDayHandlerStatusRepository.java @@ -32,10 +32,11 @@ public interface RainyDayHandlerStatusRepository extends JpaRepository<RainyDayH @Query(value = "SELECT * FROM rainy_day_handler_macro WHERE (FLOW_NAME = :flowName ) AND SERVICE_TYPE IN (:serviceType ,'*') " + " AND VNF_TYPE IN ( :vnfType , '*') AND ERROR_CODE IN (:errorCode ,'*') AND WORK_STEP IN (:workStep , '*' ) " + " AND ( :errorMessage REGEXP rainy_day_handler_macro.REG_EX_ERROR_MESSAGE OR REG_EX_ERROR_MESSAGE = '*') " - + " ORDER BY CASE WHEN :errorMessage REGEXP REG_EX_ERROR_MESSAGE THEN 0 WHEN ERROR_CODE != '*' THEN 1 WHEN VNF_TYPE != '*' THEN 2 WHEN SERVICE_TYPE != '*' THEN 3 ELSE 4 END LIMIT 1;", + + " AND SERVICE_ROLE IN ( :serviceRole , '*') " + + " ORDER BY CASE WHEN :errorMessage REGEXP REG_EX_ERROR_MESSAGE THEN 0 WHEN ERROR_CODE != '*' THEN 1 WHEN VNF_TYPE != '*' THEN 2 WHEN SERVICE_TYPE != '*' THEN 3 WHEN SERVICE_ROLE != '*' THEN 4 ELSE 5 END LIMIT 1;", nativeQuery = true) RainyDayHandlerStatus findRainyDayHandler(@Param("flowName") String flowName, @Param("serviceType") String serviceType, @Param("vnfType") String vnfType, @Param("errorCode") String errorCode, @Param("workStep") String workStep, - @Param("errorMessage") String errorMessage); + @Param("errorMessage") String errorMessage, @Param("serviceRole") String serviceRole); } |