summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-workflow-management
diff options
context:
space:
mode:
authorDunietz, Irwin <id1681@att.com>2020-01-16 15:13:14 -0500
committerTakamune Cho <takamune.cho@att.com>2020-01-29 19:44:48 +0000
commitb5fe8a69e90b950c07dc11af481eab7e9bab52c6 (patch)
tree3da81ce60554e65b93776b9aea647f3c6d8679ab /appc-dispatcher/appc-workflow-management
parent9b32cb60360a2a2973c621053510718de0072111 (diff)
Change code in appc dispatcher for new LCMs in R6
Also introduce some minor improvements to robustness, efficiency, & formatting. Issue-ID: APPC-1789 Signed-off-by: Dunietz, Irwin <id1681@att.com> Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50
Diffstat (limited to 'appc-dispatcher/appc-workflow-management')
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java367
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java183
2 files changed, 397 insertions, 153 deletions
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
index 000415c93..659c3fbbb 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
@@ -2,30 +2,28 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
- * ================================================================================
- * Modifications (C) 2019 Ericsson
* =============================================================================
* 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.appc.workflow.impl;
import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
import org.onap.appc.common.constant.Constants;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
@@ -39,8 +37,26 @@ import org.onap.appc.workflow.objects.WorkflowResponse;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
+import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
+import javax.sql.rowset.CachedRowSet;
+import java.sql.SQLException;
+import java.sql.Blob;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import org.slf4j.MDC;
+
+
+
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Enumeration;
@@ -49,6 +65,7 @@ import java.util.Properties;
public class WorkFlowManagerImpl implements WorkFlowManager{
+ private static final String DRIVER_ERROR = "DriverLoadError";
private SvcLogicService svcLogic = null;
private final EELFLogger logger = EELFManager.getInstance().getLogger(WorkFlowManagerImpl.class);
private final Configuration configuration = ConfigurationFactory.getConfiguration();
@@ -68,57 +85,73 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
/**
* Execute workflow and return response.
* This method execute workflow with following steps.
- * Retrieve workflow(DG) details - module, version and mode from database based on command and vnf Type from incoming request.
+ * Retrieve workflow(DG) details - module, version and mode from database
+ * based on command and vnf Type from incoming request.
* Execute workflow (DG) using SVC Logic Service reference
* Return response of workflow (DG) to caller.
*
- * @param workflowRequest workflow execution request which contains vnfType, command, requestId, targetId, payload and (optional) confID;
+ * @param workflowRequest workflow execution request which contains vnfType,
+ * command, requestId, targetId, payload and (optional) confID;
* @return Workflow Response which contains execution status and payload from DG if any
*/
@Override
public WorkflowResponse executeWorkflow(WorkflowRequest workflowRequest) {
- if (logger.isTraceEnabled()) {
- logger.trace("Entering to executeWorkflow with WorkflowRequest = " + ObjectUtils.toString(workflowRequest.toString()));
- }
+ logger.trace("Entering to executeWorkflow with WorkflowRequest = "
+ + ObjectUtils.toString(workflowRequest.toString()));
WorkflowResponse workflowResponse = new WorkflowResponse();
workflowResponse.setResponseContext(workflowRequest.getResponseContext());
try {
- WorkflowKey workflowKey = workflowResolver.resolve(workflowRequest.getRequestContext().getAction().name(), workflowRequest.getVnfContext().getType(), null,workflowRequest.getRequestContext().getCommonHeader().getApiVer());
+ WorkflowKey workflowKey =
+ workflowResolver.resolve(workflowRequest.getRequestContext().getAction().name(),
+ workflowRequest.getVnfContext().getType(), null,
+ workflowRequest.getRequestContext().getCommonHeader().getApiVer());
Properties workflowParams = new Properties();
String actionProperty;
String requestIdProperty;
String vfIdProperty;
- if(!workflowRequest.getRequestContext().getCommonHeader().getApiVer().startsWith("1.")){
+ if (!workflowRequest.getRequestContext().getCommonHeader().getApiVer().startsWith("1.")) {
/*
The following method call (populateDGContext) populates DG context with the
request parameters to maintain backward compatibility with old DGs,
we are not altering the old way of passing (org.onap.appc.vnfId and so on..)
This is still a temporary solution, the end solution should be agreed with
all stakeholders and implemented.
- */
+ */
populateDGContext(workflowParams, workflowRequest);
} else {
- actionProperty = configuration.getProperty("org.onap.appc.workflow.action", String.valueOf(Constants.ACTION));
- requestIdProperty = configuration.getProperty("org.onap.appc.workflow.request.id", String.valueOf(Constants.REQUEST_ID));
- vfIdProperty = configuration.getProperty("org.onap.appc.workflow.vfid", String.valueOf(Constants.VF_ID));
- String vfTypeProperty = configuration.getProperty("org.onap.appc.workflow.vftype", String.valueOf(Constants.VF_TYPE));
- String apiVerProperty = configuration.getProperty("org.onap.appc.workflow.apiVersion", String.valueOf(Constants.API_VERSION));
- String originatorIdProperty = configuration.getProperty("org.onap.appc.workflow.originatorId", Constants.ORIGINATOR_ID);
- String subRequestId = configuration.getProperty("org.onap.appc.workflow.subRequestId", Constants.SUB_REQUEST_ID);
+ actionProperty =
+ configuration.getProperty("org.onap.appc.workflow.action", String.valueOf(Constants.ACTION));
+ requestIdProperty =
+ configuration.getProperty("org.onap.appc.workflow.request.id",
+ String.valueOf(Constants.REQUEST_ID));
+ vfIdProperty =
+ configuration.getProperty("org.onap.appc.workflow.vfid", String.valueOf(Constants.VF_ID));
+ String vfTypeProperty =
+ configuration.getProperty("org.onap.appc.workflow.vftype", String.valueOf(Constants.VF_TYPE));
+ String apiVerProperty =
+ configuration.getProperty("org.onap.appc.workflow.apiVersion",
+ String.valueOf(Constants.API_VERSION));
+ String originatorIdProperty =
+ configuration.getProperty("org.onap.appc.workflow.originatorId", Constants.ORIGINATOR_ID);
+ String subRequestId =
+ configuration.getProperty("org.onap.appc.workflow.subRequestId", Constants.SUB_REQUEST_ID);
workflowParams.put(actionProperty, workflowRequest.getRequestContext().getAction().name());
- workflowParams.put(requestIdProperty, workflowRequest.getRequestContext().getCommonHeader().getRequestId());
+ workflowParams.put(requestIdProperty,
+ workflowRequest.getRequestContext().getCommonHeader().getRequestId());
workflowParams.put(vfIdProperty, workflowRequest.getVnfContext().getId());
workflowParams.put(vfTypeProperty, workflowRequest.getVnfContext().getType());
workflowParams.put(apiVerProperty, workflowRequest.getRequestContext().getCommonHeader().getApiVer());
- workflowParams.put(originatorIdProperty, workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
- workflowParams.put(subRequestId, workflowRequest.getRequestContext().getCommonHeader().getSubRequestId());
+ workflowParams.put(originatorIdProperty,
+ workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
+ workflowParams.put(subRequestId,
+ workflowRequest.getRequestContext().getCommonHeader().getSubRequestId());
Object payloadJson = workflowRequest.getRequestContext().getPayload();
- if(payloadJson != null) {
+ if (payloadJson != null) {
try {
Map<String, String> payloadProperties = ObjectMapper.map(payloadJson);
workflowParams.putAll(payloadProperties);
@@ -128,53 +161,71 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
logger.error("Error parsing payload json string", e);
Properties workflowPrp = new Properties();
workflowPrp.setProperty("error-message", "Error parsing payload json string");
- fillStatus(501, "Error parsing payload json string: " + e.getMessage(), workflowRequest.getResponseContext());
- logger.trace("Exiting from executeWorkflow with (workflowResponse = " + ObjectUtils.toString(workflowResponse) + ")");
+ fillStatus(501, "Error parsing payload json string: " + e.getMessage(),
+ workflowRequest.getResponseContext());
+ logger.trace("Exiting from executeWorkflow with (workflowResponse = "
+ + ObjectUtils.toString(workflowResponse) + ")");
return workflowResponse;
}
}
- logger.debug("DG parameters "+ actionProperty +":"+ workflowRequest.getRequestContext().getAction().name() + ", "+
- requestIdProperty +":"+ workflowRequest.getRequestContext().getCommonHeader().getRequestId() + ", " +
- vfIdProperty + ":" + workflowRequest.getVnfContext().getId());
-
- logger.debug("Starting DG Execution for request "+workflowRequest.getRequestContext().getCommonHeader().getRequestId());
+ logger.debug("DG parameters " + actionProperty + ":"
+ + workflowRequest.getRequestContext().getAction().name() + ", "
+ + requestIdProperty + ":"
+ + workflowRequest.getRequestContext().getCommonHeader().getRequestId() + ", "
+ + vfIdProperty + ":" + workflowRequest.getVnfContext().getId());
+
+ logger.debug("Starting DG Execution for request "
+ + workflowRequest.getRequestContext().getCommonHeader().getRequestId());
}
- if (workflowRequest.getRequestContext().getCommonHeader().getApiVer().startsWith("1.")){
+ if (workflowRequest.getRequestContext().getCommonHeader().getApiVer().startsWith("1.")) {
workflowParams.put("isBwcMode", "true");
} else {
workflowParams.put("isBwcMode", "false");
}
- SVCLogicServiceExecute(workflowKey, workflowRequest.getRequestContext(), workflowParams , workflowResponse);
- logger.trace("Completed DG Execution for Request id: " + workflowRequest.getRequestContext().getCommonHeader().getRequestId()
- + "with response code: " + workflowResponse.getResponseContext().getStatus().getCode());
- }catch (Exception e){
+ SVCLogicServiceExecute(workflowKey, workflowRequest.getRequestContext(), workflowParams,
+ workflowResponse);
+ logger.trace("Completed DG Execution for Request id: "
+ + workflowRequest.getRequestContext().getCommonHeader().getRequestId() + " with response code: "
+ + workflowResponse.getResponseContext().getStatus().getCode());
+ } catch (Exception e) {
logger.error("Error Executing DG " + e.getMessage(), e);
- fillStatus(501, "Error Executing DG "+ e.getMessage(), workflowRequest.getResponseContext());
+ fillStatus(501, "Error Executing DG " + e.getMessage(), workflowRequest.getResponseContext());
}
- logger.trace("Exiting from executeWorkflow with (workflowResponse = " +
- ObjectUtils.toString(workflowResponse.getResponseContext().getStatus().getMessage()) + ")");
+ logger.trace("Exiting from executeWorkflow with (workflowResponse = "
+ + ObjectUtils.toString(workflowResponse.getResponseContext().getStatus().getMessage()) + ")");
return workflowResponse;
}
private void populateDGContext(Properties workflowParams, WorkflowRequest workflowRequest) {
- workflowParams.put("input.common-header.timestamp", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(workflowRequest.getRequestContext().getCommonHeader().getTimeStamp()));
- workflowParams.put("input.common-header.api-ver", workflowRequest.getRequestContext().getCommonHeader().getApiVer());
- workflowParams.put("input.common-header.request-id", workflowRequest.getRequestContext().getCommonHeader().getRequestId());
- workflowParams.put("input.common-header.originator-id", workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
- workflowParams.put("input.common-header.sub-request-id", workflowRequest.getRequestContext().getCommonHeader().getSubRequestId() != null ?
+ workflowParams.put("input.common-header.timestamp",
+ new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ .format(workflowRequest.getRequestContext().getCommonHeader().getTimeStamp()));
+ workflowParams.put("input.common-header.api-ver",
+ workflowRequest.getRequestContext().getCommonHeader().getApiVer());
+ workflowParams.put("input.common-header.request-id",
+ workflowRequest.getRequestContext().getCommonHeader().getRequestId());
+ workflowParams.put("input.common-header.originator-id",
+ workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
+ workflowParams.put("input.common-header.sub-request-id",
+ workflowRequest.getRequestContext().getCommonHeader().getSubRequestId() != null ?
workflowRequest.getRequestContext().getCommonHeader().getSubRequestId() : "");
workflowParams.put("input.action", workflowRequest.getRequestContext().getAction().toString());
- workflowParams.put("input.payload", null != workflowRequest.getRequestContext().getPayload() ?
+ workflowParams.put("input.payload",
+ null != workflowRequest.getRequestContext().getPayload() ?
workflowRequest.getRequestContext().getPayload() : "");
workflowParams.put("input.action-identifiers.vnf-id", workflowRequest.getVnfContext().getId());
- workflowParams.put("input.action-identifiers.vnfc-name", workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName() != null ?
+ workflowParams.put("input.action-identifiers.vnfc-name",
+ workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName() != null ?
workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName() : "");
- workflowParams.put("input.action-identifiers.service-instance-id", workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId() !=null ?
+ workflowParams.put("input.action-identifiers.service-instance-id",
+ workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId() != null ?
workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId() : "");
- workflowParams.put("input.action-identifiers.vserver-id", workflowRequest.getRequestContext().getActionIdentifiers().getVserverId() !=null ?
+ workflowParams.put("input.action-identifiers.vserver-id",
+ workflowRequest.getRequestContext().getActionIdentifiers().getVserverId() != null ?
workflowRequest.getRequestContext().getActionIdentifiers().getVserverId() : "");
- workflowParams.put("input.action-identifiers.vf-module-id",workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId() !=null ?
+ workflowParams.put("input.action-identifiers.vf-module-id",
+ workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId() != null ?
workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId() : "");
final Map<String, String> additionalContext;
if ((additionalContext = workflowRequest.getRequestContext().getAdditionalContext()) != null) {
@@ -192,8 +243,9 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
*/
@Override
public WorkflowExistsOutput workflowExists(WorkflowRequest workflowQueryParams) {
- WorkflowExistsOutput workflowExistsOutput = new WorkflowExistsOutput(false,false);
- logger.trace("Entering to workflowExists with WorkflowRequest = " + ObjectUtils.toString(workflowQueryParams.toString()));
+ WorkflowExistsOutput workflowExistsOutput = new WorkflowExistsOutput(false, false);
+ logger.trace("Entering to workflowExists with WorkflowRequest = "
+ + ObjectUtils.toString(workflowQueryParams.toString()));
try {
WorkflowKey workflowKey = workflowResolver.resolve(
@@ -208,21 +260,24 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
workflowExistsOutput.setWorkflowVersion(workflowKey.version());
if (isDGExists(workflowKey)) {
workflowExistsOutput.setDgExist(true);
- }else{
+ } else {
logger.warn(
- String.format("SLI doesn't have DG for resolved mapping entry: DG module - '%s', DG name - '%s', DG version - '%s'",
- workflowKey.module(), workflowKey.name(), workflowKey.version()));
+ String.format("SLI doesn't have DG for resolved mapping entry: "
+ + "DG module - '%s', DG name - '%s', DG version - '%s'",
+ workflowKey.module(), workflowKey.name(), workflowKey.version()));
}
- }else{
+ } else {
logger.warn(
- String.format("Unable to resolve recipe matching action '%s', VNF type '%s' and VNF version '%s'",
- workflowQueryParams.getRequestContext().getAction().name(), workflowQueryParams.getVnfContext().getType(), null));
+ String.format("Unable to resolve recipe matching action '%s', VNF type '%s'"
+ + " and VNF version '%s'",
+ workflowQueryParams.getRequestContext().getAction().name(),
+ workflowQueryParams.getVnfContext().getType(), null));
}
} catch (RuntimeException e) {
- logger.error("Error querying workflow from database"+e.getMessage());
+ logger.error("Error querying workflow from database" + e.getMessage());
throw e;
- }catch (SvcLogicException e) {
- logger.error("Error querying workflow from database"+e.getMessage());
+ } catch (SvcLogicException e) {
+ logger.error("Error querying workflow from database" + e.getMessage());
throw new RuntimeException(e);
}
logger.trace("Exiting workflowExists");
@@ -234,19 +289,162 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
return svcLogic.hasGraph(workflowKey.module(), workflowKey.name(), workflowKey.version(), "sync");
}
- private void SVCLogicServiceExecute(WorkflowKey workflowKey, RequestContext requestContext, Properties workflowParams, WorkflowResponse workflowResponse) {
+
+ private void restartDbLibProvider() {
+
+ Bundle bundle = FrameworkUtil.getBundle(org.onap.ccsdk.sli.core.dblib.DbLibService.class);
+ try {
+ bundle.stop();
+ bundle.start();
+ //Thread.sleep(5000);
+ } catch (org.osgi.framework.BundleException be) {
+ logger.error("Error restarting db lib" + be.toString());
+ } /*catch (InterruptedException e) {
+ }*/
+ }
+
+ private SvcLogicGraph fetchGraph(String module, String rpc, String version, String mode, StringBuilder sbError)
+ {
+ DbLibService dbLibSvc = null;
+
+ ServiceReference sref = null;
+ BundleContext bctx = null;
+
+ Bundle bundle = FrameworkUtil.getBundle(WorkFlowManagerImpl.class);
+
+ if (bundle != null) {
+ bctx = bundle.getBundleContext();
+
+ if (bctx != null) {
+ sref = bctx.getServiceReference("org.onap.ccsdk.sli.core.dblib.DbLibService");
+ }
+
+ if (sref == null) {
+ logger.warn("Could not find service reference for DBLIB service");
+ } else {
+ dbLibSvc = (DbLibService) bctx.getService(sref);
+ if (dbLibSvc == null) {
+ logger.warn("Could not find service reference for DBLIB service");
+ }
+ }
+ }
+ if (dbLibSvc == null)
+ return null;
+ else
+ logger.info("Retrieving graph(new)");
+
+ SvcLogicGraph retval = null;
+ CachedRowSet results = null;
+
+ String fetchVersionGraphSql = "SELECT graph FROM SVC_LOGIC"
+ + " WHERE module = ? AND rpc = ? AND mode = ? AND version = ?";
+
+ String fetchActiveGraphSql = "SELECT graph FROM SVC_LOGIC"
+ + " WHERE module = ? AND rpc = ? AND mode = ? AND active = 'Y'";
+
+
+ String fetchGraphStmt;
+
+ ArrayList<String> params = new ArrayList<>();
+ params.add(module);
+ params.add(rpc);
+ params.add(mode);
+
+ if (version == null) {
+ fetchGraphStmt = fetchActiveGraphSql;
+ } else {
+ params.add(version);
+ fetchGraphStmt = fetchVersionGraphSql;
+ }
+
+ StringBuilder sqlBuilder = new StringBuilder(fetchGraphStmt);
+ try {
+ results = dbLibSvc.getData(sqlBuilder.toString(), new ArrayList(params), "sdnctl");
+
+ if (results.next()) {
+
+ ObjectInputStream gStream = new ObjectInputStream(results.getBinaryStream("graph"));
+
+ Object graphObj = gStream.readObject();
+ gStream.close();
+
+ if (graphObj instanceof SvcLogicGraph) {
+ retval = (SvcLogicGraph) graphObj;
+ } else {
+ logger.error("invalid type for graph " + graphObj.getClass().getName());
+ return null;
+ }
+
+ } else {
+ return null;
+ }
+ } catch (SQLException e) {
+ logger.error("query " + sqlBuilder + " :: " + e.getMessage() + " Will retry");
+ //sbError.append(DRIVER_ERROR);
+ return null;
+ } catch (IOException e) {
+ logger.error("IOException " + " :: " + e.getMessage() + " Will retry");
+ //sbError.append(DRIVER_ERROR);
+ return null;
+ } catch (Exception e) {
+ logger.error("Exception " + " :: " + e.getMessage() + " Will retry");
+ sbError.append(DRIVER_ERROR);
+ return null;
+ }
+
+
+ return retval;
+ }
+
+ protected Properties workflowExecute(String module, String rpc, String version, String mode, Properties props)
+ throws SvcLogicException {
+ logger.info("Fetching service logic from data store");
+ //logger.info("Trial Restart ");
+ //restartDbLibProvider();
+ //logger.info("Trial Restart End");
+
+ StringBuilder sbError = new StringBuilder();
+ SvcLogicGraph graph = fetchGraph(module, rpc, version, mode, sbError);
+ if (sbError.toString().equals(DRIVER_ERROR))
+ {
+ restartDbLibProvider();
+ sbError = new StringBuilder();
+ graph = fetchGraph(module, rpc, version, mode, sbError);
+ }
+ if (graph == null) {
+ Properties retProps = new Properties();
+ retProps.setProperty("error-code", "401");
+ retProps.setProperty("error-message",
+ "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
+ return (retProps);
+ }
+
+ SvcLogicContext ctx = new SvcLogicContext(props);
+ ctx.setAttribute("currentGraph", graph.toString());
+ ctx.setAttribute("X-ONAP-RequestID", MDC.get("X-ONAP-RequestID"));
+ svcLogic.execute(graph, ctx);
+ return (ctx.toProperties());
+ }
+
+ private void SVCLogicServiceExecute(WorkflowKey workflowKey, RequestContext requestContext,
+ Properties workflowParams, WorkflowResponse workflowResponse) {
logger.trace("Entering SVCLogicServiceExecute");
Properties respProps = null;
try {
- respProps = svcLogic.execute(workflowKey.module(), workflowKey.name(), workflowKey.version(), "sync", workflowParams);
+ respProps = workflowExecute(workflowKey.module(), workflowKey.name(), workflowKey.version(),
+ "sync", workflowParams);
} catch (Exception e) {
- setWorkFlowResponseStatus(workflowResponse.getResponseContext(), "failure", "Unexpected SLI Adapter failure", 200);
+ setWorkFlowResponseStatus(workflowResponse.getResponseContext(), "failure",
+ "Unexpected SLI Adapter failure", 200);
+
+ String stk = "";
if (logger.isDebugEnabled()) {
- logger.debug("Error while executing DG " + e.getMessage() + e.getStackTrace());
- logger.error("Error in DG", e.getMessage() + Arrays.toString(e.getStackTrace()), e);
+ stk = Arrays.toString(e.getStackTrace());
+ logger.debug("Error while executing DG " + e.getMessage() + stk);
}
+ logger.error("Error in DG", e.getMessage() + stk, e);
}
if (respProps != null) {
@@ -262,7 +460,8 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
specificStatusCode = Integer.parseInt(dgOutputStatusCode);
}
- setWorkFlowResponseStatus(workflowResponse.getResponseContext(), commonStatus, specificStatusMessage, specificStatusCode);
+ setWorkFlowResponseStatus(workflowResponse.getResponseContext(), commonStatus, specificStatusMessage,
+ specificStatusCode);
logger.debug("DG Execution Status: " + commonStatus);
}
@@ -276,42 +475,44 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
* @param responseContext response context which you need to fill
* @param respProps DG context in a properties format
*/
- private void fillResponseContextByOutputFieldsFromDgContext(ResponseContext responseContext, Properties respProps) {
+ private void fillResponseContextByOutputFieldsFromDgContext(ResponseContext responseContext,
+ Properties respProps) {
Enumeration<?> e = respProps.propertyNames();
- while (e.hasMoreElements()){
+ while (e.hasMoreElements()) {
String key = (String) e.nextElement();
- if (key.startsWith("output.")){
- if (!key.startsWith("output.common-header.") && !key.startsWith("output.status.")){
+ if (key.startsWith("output.")) {
+ if (!key.startsWith("output.common-header.") && !key.startsWith("output.status.")) {
- if (key.equalsIgnoreCase("output.payload")){
+ if (key.equalsIgnoreCase("output.payload")) {
responseContext.setPayload(respProps.getProperty(key));
} else {
responseContext.addKeyValueToAdditionalContext(key, respProps.getProperty(key));
- }
+ }
}
}
}
}
/**
- * Filling responceContext status code amd message according to responce messages and codes from DG.
+ * Filling responseContext status code and message according to response messages and codes from DG.
*
* @param responseContext response cotext
* @param commonStatus common status message from DG ("success" or "failure")
* @param specificStatusMessage specific status message from specific DG node
* @param specificStatusCode specific status code from specific DG node
*/
- private void setWorkFlowResponseStatus(ResponseContext responseContext, String commonStatus, String specificStatusMessage, int specificStatusCode) {
+ private void setWorkFlowResponseStatus(ResponseContext responseContext, String commonStatus,
+ String specificStatusMessage, int specificStatusCode) {
if (null == specificStatusMessage) { specificStatusMessage = ""; }
- if (commonStatus.equalsIgnoreCase(Constants.DG_STATUS_SUCCESS)){
- if (specificStatusCode != 0 ){
+ if (commonStatus.equalsIgnoreCase(Constants.DG_STATUS_SUCCESS)) {
+ if (specificStatusCode != 0) {
fillStatus(specificStatusCode, specificStatusMessage, responseContext);
} else {
fillStatus(400, commonStatus, responseContext);
}
} else {
- if (specificStatusCode != 0){
+ if (specificStatusCode != 0) {
fillStatus(specificStatusCode, specificStatusMessage, responseContext);
} else {
fillStatus(401, specificStatusMessage, responseContext);
@@ -324,10 +525,12 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
*
* @param code 3-digit status code
* @param message explanation of a status code
- * @param responceContext response context which will be store status code and status message
+ * @param responseContext response context which will be store status code and status message
*/
- private void fillStatus(int code, String message, ResponseContext responceContext) {
- responceContext.getStatus().setCode(code);
- responceContext.getStatus().setMessage(message);
+ private void fillStatus(int code, String message, ResponseContext responseContext) {
+ responseContext.getStatus().setCode(code);
+ responseContext.getStatus().setMessage(message);
}
+
+
}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
index 8689fa70d..ecac32714 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
@@ -11,15 +11,15 @@
* 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=========================================================
*/
@@ -65,16 +65,17 @@ import java.sql.SQLException;
import java.util.Date;
import java.util.Properties;
+import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ConfigurationFactory.class, DBUtils.class, ObjectMapper.class})
+@PrepareForTest({ConfigurationFactory.class, DBUtils.class, ObjectMapper.class, WorkFlowManagerImpl.class})
public class TestWorkFlowManager {
@Rule
public ExpectedException expectedEx = ExpectedException.none();
-
+
public TestWorkFlowManager() {
}
@@ -85,7 +86,7 @@ public class TestWorkFlowManager {
public SvcLogicService svcLogicService;
@Before
- public void init(){
+ public void init() {
PowerMockito.mockStatic(ConfigurationFactory.class);
Configuration mockConfiguration = Mockito.mock(Configuration.class);
PowerMockito.when(ConfigurationFactory.getConfiguration()).thenReturn(mockConfiguration);
@@ -93,87 +94,120 @@ public class TestWorkFlowManager {
this.svcLogicService = Mockito.mock(SvcLogicService.class);
workflowManger.setWorkflowResolver(workflowResolver);
workflowManger.setSvcLogicServiceRef(svcLogicService);
-
}
+
@Test
- public void testExecuteWorkFlow() throws SvcLogicException{
+ public void testExecuteWorkFlow() throws SvcLogicException, Exception {
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
- .thenReturn(createSvcExexuteSuccessResponse());
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getWorkFlowKey());
+ // Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ // .thenReturn(createSvcExexuteSuccessResponse());
- WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ WorkflowRequest workflowRequest =
+ getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
- WorkflowResponse response = workflowManger.executeWorkflow(workflowRequest);
+ WorkFlowManagerImpl mockManager = Mockito.spy(workflowManger);
+ Mockito.when(mockManager.workflowExecute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowResponse response = mockManager.executeWorkflow(workflowRequest);
Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("success"));
}
@Test
- public void testExecuteWorkFlowFalse() throws SvcLogicException{
+ public void testExecuteWorkFlowFalse() throws SvcLogicException, Exception {
+
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getWorkFlowKey());
+ // Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ // .thenReturn(createSvcExexuteFailureResponse());
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
- .thenReturn(createSvcExexuteFailureResponse());
+ WorkflowRequest workflowRequest =
+ getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
- WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ WorkFlowManagerImpl mockManager = Mockito.spy(workflowManger);
+ Mockito.when(mockManager.workflowExecute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteFailureResponse());
- WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ WorkflowResponse response = mockManager.executeWorkflow(workflowRequest);
Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("failure"));
}
@Test
- public void testExecuteWorkFlowAPIVersionStartWithOne() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
- .thenReturn(createSvcExexuteSuccessResponse());
+ public void testExecuteWorkFlowAPIVersionStartWithOne() throws SvcLogicException, Exception {
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getWorkFlowKey());
+ // Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ // .thenReturn(createSvcExexuteSuccessResponse());
- WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "1.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ WorkflowRequest workflowRequest =
+ getWorkflowRequest("vSCP", 300, new Date(), "1.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
- WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ WorkFlowManagerImpl mockManager = Mockito.spy(workflowManger);
+ Mockito.when(mockManager.workflowExecute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowResponse response = mockManager.executeWorkflow(workflowRequest);
Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("success"));
}
@Test
- public void testExecuteWorkFlowException() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
- .thenReturn(createSvcExexuteSuccessResponse());
-
- WorkflowRequest workflowRequest = Mockito.spy(getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD));
+ public void testExecuteWorkFlowException() throws SvcLogicException, Exception {
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getWorkFlowKey());
+ // Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ // .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowRequest workflowRequest =
+ Mockito.spy(getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD));
Mockito.when(workflowRequest.getRequestContext()).thenThrow(new RuntimeException());
- WorkflowResponse response = workflowManger.executeWorkflow(workflowRequest);
+ WorkFlowManagerImpl mockManager = Mockito.spy(workflowManger);
+ Mockito.when(mockManager.workflowExecute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowResponse response = mockManager.executeWorkflow(workflowRequest);
Mockito.verify(workflowRequest, Mockito.times(2)).getResponseContext();
}
@Test
- public void testExecuteWorkAPIVersion1Exception() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
- .thenReturn(createSvcExexuteSuccessResponse());
-
- WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "1.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ public void testExecuteWorkAPIVersion1Exception() throws SvcLogicException, Exception {
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getWorkFlowKey());
+ // Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ // .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowRequest workflowRequest =
+ getWorkflowRequest("vSCP", 300, new Date(), "1.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
PowerMockito.mockStatic(ObjectMapper.class);
PowerMockito.when(ObjectMapper.map(Mockito.any())).thenThrow(new RuntimeException());
- WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ WorkFlowManagerImpl mockManager = Mockito.spy(workflowManger);
+ Mockito.when(mockManager.workflowExecute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowResponse response = mockManager.executeWorkflow(workflowRequest);
Assert.assertEquals(501, response.getResponseContext().getStatus().getCode());
}
@Test
- public void testWorkFlowExist() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString())).thenReturn(true);
+ public void testWorkFlowExist() throws SvcLogicException {
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(true);
- WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ WorkflowRequest workflowRequest =
+ getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
WorkflowExistsOutput response = workflowManger.workflowExists(workflowRequest);
@@ -181,12 +215,15 @@ public class TestWorkFlowManager {
}
@Test
- public void testWorkFlowNotExist() throws SvcLogicException {
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString())).thenReturn(false);
+ public void testWorkFlowNotExist() throws SvcLogicException {
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(false);
- WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ WorkflowRequest workflowRequest =
+ getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
WorkflowExistsOutput response = workflowManger.workflowExists(workflowRequest);
@@ -194,11 +231,14 @@ public class TestWorkFlowManager {
}
@Test
- public void testWorkFlowExistNullKey() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(null);
- Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString())).thenReturn(true);
- WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
- VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ public void testWorkFlowExistNullKey() throws SvcLogicException {
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(null);
+ Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(true);
+ WorkflowRequest workflowRequest =
+ getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
WorkflowExistsOutput response = workflowManger.workflowExists(workflowRequest);
Assert.assertFalse(response.isMappingExist());
}
@@ -219,8 +259,9 @@ public class TestWorkFlowManager {
workflowResolver.resolve("ACTION", "VNF_TYPE", "VNF_VERSION", "API_VERSION");
}
- private WorkflowRequest getWorkflowRequest(String vnfType, int ttl, Date timeStamp, String apiVersion, String requestId,
- String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload) {
+ private WorkflowRequest getWorkflowRequest(String vnfType, int ttl, Date timeStamp, String apiVersion,
+ String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId,
+ String payload) {
WorkflowRequest workflowRequest = new WorkflowRequest();
RuntimeContext runtimeContext = createRuntimeContext();
@@ -241,10 +282,10 @@ public class TestWorkFlowManager {
workflowRequest.setResponseContext(runtimeContext.getResponseContext());
workflowRequest.setVnfContext(runtimeContext.getVnfContext());
- return workflowRequest;
+ return workflowRequest;
}
- private RequestContext creatRequestContext(){
+ private RequestContext creatRequestContext() {
RequestContext requestContext = new RequestContext();
CommonHeader commonHeader = new CommonHeader();
Flags flags = new Flags();
@@ -253,10 +294,10 @@ public class TestWorkFlowManager {
requestContext.setCommonHeader(commonHeader);
requestContext.setActionIdentifiers(actionIdentifiers);
- return requestContext;
+ return requestContext;
}
- private ResponseContext createResponseContext(){
+ private ResponseContext createResponseContext() {
ResponseContext responseContext = new ResponseContext();
CommonHeader commonHeader = new CommonHeader();
Flags flags = new Flags();
@@ -265,10 +306,10 @@ public class TestWorkFlowManager {
responseContext.setStatus(status);
commonHeader.setFlags(flags);
- return responseContext;
+ return responseContext;
}
- private RuntimeContext createRuntimeContext(){
+ private RuntimeContext createRuntimeContext() {
RuntimeContext runtimeContext = new RuntimeContext();
RequestContext requestContext = creatRequestContext();
ResponseContext responseContext = createResponseContext();
@@ -280,13 +321,13 @@ public class TestWorkFlowManager {
return runtimeContext;
}
- public WorkflowKey getWorkFlowKey(){
+ public WorkflowKey getWorkFlowKey() {
WorkflowKey workflowKey = new WorkflowKey("APPCDG", "2.0.0.0", "dgModule");
return workflowKey;
}
- private Properties createSvcExexuteSuccessResponse(){
+ private Properties createSvcExexuteSuccessResponse() {
Properties properties = new Properties();
properties.setProperty("output.payload", "success");
properties.setProperty(Constants.DG_ATTRIBUTE_STATUS, "success");
@@ -296,7 +337,7 @@ public class TestWorkFlowManager {
return properties;
}
- private Properties createSvcExexuteFailureResponse(){
+ private Properties createSvcExexuteFailureResponse() {
Properties properties = new Properties();
properties.setProperty("output.payload", "failure");
properties.setProperty(Constants.DG_ATTRIBUTE_STATUS, "failure");