Add workflowName and operationName to v8 of 74/105674/1
authorKuleshov, Elena <evn@att.com>
Tue, 7 Apr 2020 19:50:32 +0000 (15:50 -0400)
committerMax Benjamin <max.benjamin@att.com>
Thu, 9 Apr 2020 21:58:16 +0000 (21:58 +0000)
Add workflowName and operationName to v8 of orchestrationRequests
response.
Fix typo in the schema for infra_active_requests.
Change version matching for the new interface fields.

Issue-ID: SO-2799
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Icc7f3c6271023a578df2c1d969c807a578cc9577
(cherry picked from commit 654db79e01a20632cf1d7c3c6a786160aaa82eed)

14 files changed:
adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java
adapters/mso-requests-db-adapter/src/main/resources/db/migration/V8.3__Add_Columns_Workflow_Name_Operation_Name.sql [new file with mode: 0644]
common/src/main/java/org/onap/so/serviceinstancebeans/Request.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java
mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_Response.json
mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_pnf_Response.json
mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql
mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql
mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/ArchivedInfraRequests.java
mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java
mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java

index 9f48144..4fe49e3 100644 (file)
@@ -143,6 +143,8 @@ public class ArchiveInfraRequestsScheduler {
                 archivedInfra.setProductFamilyName(iar.getProductFamilyName());
                 archivedInfra.setTenantName(iar.getTenantName());
                 archivedInfra.setResourceStatusMessage(iar.getResourceStatusMessage());
+                archivedInfra.setWorkflowName(iar.getWorkflowName());
+                archivedInfra.setOperationName(iar.getOperationName());
 
                 newArchivedReqs.add(archivedInfra);
                 oldInfraReqs.add(iar);
diff --git a/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V8.3__Add_Columns_Workflow_Name_Operation_Name.sql b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V8.3__Add_Columns_Workflow_Name_Operation_Name.sql
new file mode 100644 (file)
index 0000000..d493bc0
--- /dev/null
@@ -0,0 +1,7 @@
+use requestdb;
+
+ALTER TABLE infra_active_requests ADD COLUMN IF NOT EXISTS WORKFLOW_NAME varchar(200);
+ALTER TABLE archived_infra_requests ADD COLUMN IF NOT EXISTS WORKFLOW_NAME varchar(200);
+
+ALTER TABLE infra_active_requests ADD COLUMN IF NOT EXISTS OPERATION_NAME varchar(200);
+ALTER TABLE archived_infra_requests ADD COLUMN IF NOT EXISTS OPERATION_NAME varchar(200);
\ No newline at end of file
index 75a6ba8..2d8b12c 100644 (file)
@@ -35,6 +35,8 @@ public class Request {
     protected String finishTime;
     protected String requestScope;
     protected String requestType;
+    protected String workflowName;
+    protected String operationName;
     protected String originalRequestId;
     protected RequestDetails requestDetails;
     protected InstanceReferences instanceReferences;
@@ -83,6 +85,22 @@ public class Request {
         this.requestType = requestType;
     }
 
+    public String getWorkflowName() {
+        return workflowName;
+    }
+
+    public void setWorkflowName(String workflowName) {
+        this.workflowName = workflowName;
+    }
+
+    public String getOperationName() {
+        return operationName;
+    }
+
+    public void setOperationName(String operationName) {
+        this.operationName = operationName;
+    }
+
     public RequestStatus getRequestStatus() {
         return requestStatus;
     }
@@ -136,9 +154,9 @@ public class Request {
     public String toString() {
         return new ToStringBuilder(this).append("requestId", requestId).append("startTime", startTime)
                 .append("finishTime", finishTime).append("requestScope", requestScope)
-                .append("requestType", requestType).append("requestDetails", requestDetails)
-                .append("instanceReferences", instanceReferences).append("requestStatus", requestStatus)
-                .append("requestProcessingData", requestProcessingData).append("cloudRequestData", cloudRequestData)
-                .append("originalRequestId", originalRequestId).toString();
+                .append("requestType", requestType).append("workflowName", workflowName)
+                .append("requestDetails", requestDetails).append("instanceReferences", instanceReferences)
+                .append("requestStatus", requestStatus).append("requestProcessingData", requestProcessingData)
+                .append("cloudRequestData", cloudRequestData).append("originalRequestId", originalRequestId).toString();
     }
 }
index 3007ddd..f39a95e 100644 (file)
@@ -197,6 +197,7 @@ public class InstanceManagement {
             vnfId = sir.getVnfInstanceId();
         }
 
+        currentActiveReq = setWorkflowNameAndOperationName(currentActiveReq, workflowUuid);
         saveCurrentActiveRequest(currentActiveReq);
 
         RequestClientParameter requestClientParameter;
@@ -293,6 +294,7 @@ public class InstanceManagement {
 
         RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid);
 
+        currentActiveReq = setWorkflowNameAndOperationName(currentActiveReq, workflowUuid);
         saveCurrentActiveRequest(currentActiveReq);
 
         RequestClientParameter requestClientParameter;
@@ -357,4 +359,14 @@ public class InstanceManagement {
         }
         return null;
     }
+
+    protected InfraActiveRequests setWorkflowNameAndOperationName(InfraActiveRequests currentActiveReq,
+            String workflowUuid) {
+        Workflow workflow = catalogDbClient.findWorkflowByArtifactUUID(workflowUuid);
+        if (workflow != null) {
+            currentActiveReq.setWorkflowName(workflow.getName());
+            currentActiveReq.setOperationName(workflow.getOperationName());
+        }
+        return currentActiveReq;
+    }
 }
index c43a050..3993c65 100644 (file)
@@ -311,6 +311,19 @@ public class OrchestrationRequests {
             request.setOriginalRequestId(originalRequestId);
         }
 
+        if (!version.matches("v[1-7]")) {
+            String workflowName = iar.getWorkflowName();
+            if (workflowName == null) {
+                workflowName = iar.getRequestAction();
+            }
+            request.setWorkflowName(workflowName);
+
+            String operationName = iar.getOperationName();
+            if (operationName != null) {
+                request.setOperationName(operationName);
+            }
+        }
+
         InstanceReferences ir = new InstanceReferences();
         if (iar.getNetworkId() != null)
             ir.setNetworkInstanceId(iar.getNetworkId());
index ba7fe2b..081f235 100644 (file)
@@ -45,9 +45,11 @@ import org.apache.http.HttpStatus;
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.db.request.beans.InfraActiveRequests;
 import org.onap.so.logger.HttpHeadersConstants;
 import org.onap.so.serviceinstancebeans.RequestReferences;
 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
@@ -63,6 +65,9 @@ public class InstanceManagementTest extends BaseTest {
     private final ObjectMapper mapper = new ObjectMapper();
     private ObjectMapper errorMapper = new ObjectMapper();
 
+    @Autowired
+    InstanceManagement instanceManagement;
+
     @Value("${wiremock.server.port}")
     private String wiremockPort;
 
@@ -201,4 +206,18 @@ public class InstanceManagementTest extends BaseTest {
         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
     }
+
+    @Test
+    public void workflowAndOperationNameTest() {
+        wireMockServer.stubFor(get(urlMatching(
+                ".*/workflow/search/findByArtifactUUID[?]artifactUUID=71526781-e55c-4cb7-adb3-97e09d9c76be"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBody(getWiremockResponseForCatalogdb("workflow_Response.json"))
+                                .withStatus(org.apache.http.HttpStatus.SC_OK)));
+        InfraActiveRequests activeReq = new InfraActiveRequests();
+        activeReq =
+                instanceManagement.setWorkflowNameAndOperationName(activeReq, "71526781-e55c-4cb7-adb3-97e09d9c76be");
+        assertEquals(activeReq.getWorkflowName(), "testingWorkflow");
+        assertEquals(activeReq.getOperationName(), "testOperation");
+    }
 }
index 3db2b2d..fdaca35 100644 (file)
@@ -85,6 +85,9 @@ public class OrchestrationRequestsUnitTest {
     private static final String RETRY_STATUS_MESSAGE = "RetryStatusMessage";
     private static final String ROLLBACK_STATUS_MESSAGE = "RollbackStatusMessage";
     private static final String TASK_INFORMATION = " TASK INFORMATION: Last task executed: Call SDNC";
+    private static final String WORKFLOW_NAME = "testWorkflowName";
+    private static final String OPERATION_NAME = "testOperationName";
+    private static final String REQUEST_ACTION = "createInstance";
     private InfraActiveRequests iar;
     boolean includeCloudRequest = false;
     private static final String ROLLBACK_EXT_SYSTEM_ERROR_SOURCE = "SDNC";
@@ -152,11 +155,79 @@ public class OrchestrationRequestsUnitTest {
         expected.setRequestScope(SERVICE);
         expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
 
+        iar.setWorkflowName(WORKFLOW_NAME);
+        iar.setOperationName(OPERATION_NAME);
+
         Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest,
                 OrchestrationRequestFormat.DETAIL.toString(), "v7");
         assertThat(result, sameBeanAs(expected));
     }
 
+    @Test
+    public void mapInfraActiveRequestToRequestWithWorkflowNameAndOperationNameTest() throws ApiException {
+        doReturn("Last task executed: Call SDNC").when(camundaRequestHandler).getTaskName(REQUEST_ID);
+        InstanceReferences instanceReferences = new InstanceReferences();
+        instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
+        RequestStatus requestStatus = new RequestStatus();
+        requestStatus.setRequestState(iar.getRequestStatus());
+        requestStatus.setStatusMessage(
+                String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s",
+                        FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE,
+                        "The vf module already exist"));
+
+        Request expected = new Request();
+        expected.setRequestId(REQUEST_ID);
+        expected.setOriginalRequestId(ORIGINAL_REQUEST_ID);
+        expected.setInstanceReferences(instanceReferences);
+        expected.setRequestStatus(requestStatus);
+        expected.setRequestScope(SERVICE);
+        expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
+        expected.setWorkflowName(WORKFLOW_NAME);
+        expected.setOperationName(OPERATION_NAME);
+
+        iar.setOriginalRequestId(ORIGINAL_REQUEST_ID);
+        iar.setWorkflowName(WORKFLOW_NAME);
+        iar.setOperationName(OPERATION_NAME);
+
+        Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest,
+                OrchestrationRequestFormat.DETAIL.toString(), "v8");
+        assertThat(result, sameBeanAs(expected));
+    }
+
+    @Test
+    public void mapInfraActiveRequestToRequestWithNoWorkflowNameAndNoOperationNameTest() throws ApiException {
+        doReturn("Last task executed: Call SDNC").when(camundaRequestHandler).getTaskName(REQUEST_ID);
+        InstanceReferences instanceReferences = new InstanceReferences();
+        instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
+        RequestStatus requestStatus = new RequestStatus();
+        requestStatus.setRequestState(iar.getRequestStatus());
+        requestStatus.setStatusMessage(
+                String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s",
+                        FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE,
+                        "The vf module already exist"));
+
+        Request expected = new Request();
+        expected.setRequestId(REQUEST_ID);
+        expected.setOriginalRequestId(ORIGINAL_REQUEST_ID);
+        expected.setInstanceReferences(instanceReferences);
+        expected.setRequestStatus(requestStatus);
+        expected.setRequestScope(SERVICE);
+        expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
+
+
+        expected.setWorkflowName(REQUEST_ACTION);
+        expected.setRequestType(REQUEST_ACTION);
+
+        iar.setOriginalRequestId(ORIGINAL_REQUEST_ID);
+        iar.setRequestAction(REQUEST_ACTION);
+        iar.setWorkflowName(null);
+        iar.setOperationName(null);
+
+        Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest,
+                OrchestrationRequestFormat.DETAIL.toString(), "v8");
+        assertThat(result, sameBeanAs(expected));
+    }
+
     @Test
     public void mapRequestStatusAndExtSysErrSrcToRequestFalseTest() throws ApiException {
         doReturn("Last task executed: Call SDNC").when(camundaRequestHandler).getTaskName(REQUEST_ID);
index d6ed585..5877f43 100644 (file)
@@ -1,5 +1,6 @@
 {
   "artifactUUID": "71526781-e55c-4cb7-adb3-97e09d9c76be",
   "artifactName": "testingWorkflow.bpmn",
-  "name": "testingWorkflow" 
+  "name": "testingWorkflow",
+  "operationName":  "testOperation"
 }
\ No newline at end of file
index 133d8be..1d6cd43 100644 (file)
@@ -1,5 +1,6 @@
 {
   "artifactUUID": "81526781-e55c-4cb7-adb3-97e09d9c76bf",
   "artifactName": "testingPNFWorkflow.bpmn",
-  "name": "testingPNFWorkflow" 
+  "name": "testingPNFWorkflow",
+  "operationName": "testPnfOperation" 
 }
\ No newline at end of file
index 19855bc..fd8c273 100644 (file)
@@ -1300,6 +1300,8 @@ CREATE TABLE `infra_active_requests` (
   `TENANT_NAME` varchar(200) DEFAULT NULL,
   `PRODUCT_FAMILY_NAME` varchar(200) DEFAULT NULL,
   `RESOURCE_STATUS_MESSAGE` longtext,
+  `WORKFLOW_NAME` varchar(200) DEFAULT NULL,
+  `OPERATION_NAME` varchar(200) DEFAULT NULL,
   PRIMARY KEY (`REQUEST_ID`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
index 4c376c7..e8f2002 100644 (file)
@@ -103,8 +103,9 @@ CREATE TABLE IF NOT EXISTS PUBLIC.INFRA_ACTIVE_REQUESTS(
     ROLLBACK_EXT_SYSTEM_ERROR_SOURCE VARCHAR SELECTIVITY 1,
     TENANT_NAME VARCHAR SELECTIVITY 1,
     PRODUCT_FAMILY_NAME VARCHAR SELECTIVITY 1,
-    RESOURCE_STATUS_MESSAGE VARCHAR SELECTIVITY 36
-    
+    RESOURCE_STATUS_MESSAGE VARCHAR SELECTIVITY 36,
+    WORKFLOW_NAME VARCHAR SELECTIVITY 1,
+    OPERATION_NAME VARCHAR SELECTIVITY 1    
 );          
 
 INSERT INTO PUBLIC.INFRA_ACTIVE_REQUESTS(REQUEST_ID, REQUEST_STATUS, STATUS_MESSAGE, PROGRESS, START_TIME, END_TIME, SOURCE, VNF_ID, VNF_NAME, VNF_TYPE, SERVICE_TYPE, TENANT_ID, VNF_PARAMS, VNF_OUTPUTS, REQUEST_BODY, RESPONSE_BODY, LAST_MODIFIED_BY, MODIFY_TIME, VOLUME_GROUP_ID, VOLUME_GROUP_NAME, VF_MODULE_ID, VF_MODULE_NAME, VF_MODULE_MODEL_NAME, CLOUD_REGION, CALLBACK_URL, CORRELATOR, NETWORK_ID, NETWORK_NAME, NETWORK_TYPE, REQUEST_SCOPE, REQUEST_ACTION, SERVICE_INSTANCE_ID, SERVICE_INSTANCE_NAME, REQUESTOR_ID, CONFIGURATION_ID, CONFIGURATION_NAME, OPERATIONAL_ENV_ID, OPERATIONAL_ENV_NAME, REQUEST_URL) VALUES
@@ -177,7 +178,9 @@ CREATE CACHED TABLE PUBLIC.ARCHIVED_INFRA_REQUESTS(
     REQUEST_URL VARCHAR SELECTIVITY 1,
     TENANT_NAME VARCHAR SELECTIVITY 1,
     PRODUCT_FAMILY_NAME VARCHAR SELECTIVITY 1,
-    RESOURCE_STATUS_MESSAGE VARCHAR SELECTIVITY 36
+    RESOURCE_STATUS_MESSAGE VARCHAR SELECTIVITY 36,
+    WORKFLOW_NAME VARCHAR SELECTIVITY 1,
+    OPERATION_NAME VARCHAR SELECTIVITY 1
 );
 
 CREATE TABLE IF NOT EXISTS cloud_api_requests(
index 8c4d071..019530a 100644 (file)
@@ -78,7 +78,9 @@ public class ArchivedInfraRequests extends InfraRequests {
                 .append("networkName", getNetworkName()).append("networkType", getNetworkType())
                 .append("requestorId", getRequestorId()).append("configurationId", getConfigurationId())
                 .append("configurationName", getConfigurationName()).append("operationalEnvId", getOperationalEnvId())
-                .append("operationalEnvName", getOperationalEnvName()).append("requestUrl", getRequestUrl()).toString();
+                .append("operationalEnvName", getOperationalEnvName()).append("requestUrl", getRequestUrl())
+                .append("tenantName", getTenantName()).append("productFamilyName", getProductFamilyName())
+                .append("workflowName", getWorkflowName()).append("operationName", getOperationName()).toString();
     }
 
 }
index 750fa13..79a18a4 100644 (file)
@@ -90,6 +90,7 @@ public class InfraActiveRequests extends InfraRequests {
                 .append("originalRequestId", getOriginalRequestId())
                 .append("extSystemErrorSource", getExtSystemErrorSource())
                 .append("rollbackExtSystemErrorSource", getRollbackExtSystemErrorSource())
-                .append("tenantName", getTenantName()).append("productFamilyName", getProductFamilyName()).toString();
+                .append("tenantName", getTenantName()).append("productFamilyName", getProductFamilyName())
+                .append("workflowName", getWorkflowName()).append("operationName", getOperationName()).toString();
     }
 }
index a6d6af8..cf6cf68 100644 (file)
@@ -155,6 +155,10 @@ public abstract class InfraRequests implements java.io.Serializable {
     private String tenantName;
     @Column(name = "PRODUCT_FAMILY_NAME", length = 80)
     private String productFamilyName;
+    @Column(name = "WORKFLOW_NAME", length = 200)
+    private String workflowName;
+    @Column(name = "OPERATION_NAME", length = 200)
+    private String operationName;
 
     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
     @JoinColumn(name = "SO_REQUEST_ID", referencedColumnName = "REQUEST_ID", updatable = false)
@@ -580,6 +584,22 @@ public abstract class InfraRequests implements java.io.Serializable {
         this.productFamilyName = productFamilyName;
     }
 
+    public String getWorkflowName() {
+        return workflowName;
+    }
+
+    public void setWorkflowName(String workflowName) {
+        this.workflowName = workflowName;
+    }
+
+    public String getOperationName() {
+        return operationName;
+    }
+
+    public void setOperationName(String operationName) {
+        this.operationName = operationName;
+    }
+
     @PrePersist
     protected void onCreate() {
         if (requestScope == null)
@@ -641,6 +661,7 @@ public abstract class InfraRequests implements java.io.Serializable {
                 .append("instanceGroupName", getInstanceGroupName()).append("requestUrl", getRequestUrl())
                 .append("originalRequestId", originalRequestId).append("extSystemErrorSource", extSystemErrorSource)
                 .append("rollbackExtSystemErrorSource", rollbackExtSystemErrorSource).append("tenantName", tenantName)
-                .append("productFamilyName", productFamilyName).toString();
+                .append("productFamilyName", productFamilyName).append("workflowName", workflowName)
+                .append("operationName", operationName).toString();
     }
 }