Change code in appc dispatcher for new LCMs in R6
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / main / java / org / onap / appc / requesthandler / impl / RequestValidatorImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications Copyright (C) 2019 Ericsson
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.requesthandler.impl;
26
27 import com.att.eelf.i18n.EELFResourceManager;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import com.fasterxml.jackson.databind.node.ObjectNode;
31
32 import org.apache.commons.io.IOUtils;
33 import org.apache.commons.lang.ObjectUtils;
34 import org.apache.commons.lang.StringUtils;
35 import org.apache.http.HttpResponse;
36 import org.onap.appc.domainmodel.lcm.Flags;
37 import org.onap.appc.domainmodel.lcm.RequestContext;
38 import org.onap.appc.domainmodel.lcm.RuntimeContext;
39 import org.onap.appc.domainmodel.lcm.TransactionRecord;
40 import org.onap.appc.domainmodel.lcm.VNFContext;
41 import org.onap.appc.domainmodel.lcm.VNFOperation;
42 import org.onap.appc.exceptions.APPCException;
43 import org.onap.appc.executor.objects.LCMCommandStatus;
44 import org.onap.appc.executor.objects.Params;
45 import org.onap.appc.i18n.Msg;
46 import org.onap.appc.lockmanager.api.LockException;
47 import org.onap.appc.lockmanager.api.LockManager;
48 import org.onap.appc.logging.LoggingConstants;
49 import org.onap.appc.logging.LoggingUtils;
50 import org.onap.appc.requesthandler.exceptions.DGWorkflowNotFoundException;
51 import org.onap.appc.requesthandler.exceptions.LCMOperationsDisabledException;
52 import org.onap.appc.requesthandler.exceptions.MissingVNFDataInAAIException;
53 import org.onap.appc.requesthandler.exceptions.RequestValidationException;
54 import org.onap.appc.requesthandler.exceptions.VNFNotFoundException;
55 import org.onap.appc.requesthandler.exceptions.WorkflowNotFoundException;
56 import org.onap.appc.requesthandler.model.ActionIdentifierModel;
57 import org.onap.appc.requesthandler.model.Input;
58 import org.onap.appc.requesthandler.model.Request;
59 import org.onap.appc.requesthandler.model.RequestData;
60 import org.onap.appc.requesthandler.model.RequestModel;
61 import org.onap.appc.requesthandler.model.ScopeOverlapModel;
62 import org.onap.appc.rest.client.RestClientInvoker;
63 import org.onap.appc.validationpolicy.RequestValidationPolicy;
64 import org.onap.appc.validationpolicy.executors.RuleExecutor;
65 import org.onap.appc.validationpolicy.objects.RuleResult;
66 import org.onap.appc.workflow.WorkFlowManager;
67 import org.onap.appc.workflow.objects.WorkflowExistsOutput;
68 import org.onap.appc.workflow.objects.WorkflowRequest;
69 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
70 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
71 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
72 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
73 import org.osgi.framework.BundleContext;
74 import org.osgi.framework.FrameworkUtil;
75 import org.osgi.framework.ServiceReference;
76
77 import java.io.IOException;
78 import java.net.MalformedURLException;
79 import java.net.URL;
80 import java.util.ArrayList;
81 import java.util.Date;
82 import java.util.List;
83 import java.util.Properties;
84 import java.util.stream.Collectors;
85
86 public class RequestValidatorImpl extends AbstractRequestValidatorImpl {
87
88     private WorkFlowManager workflowManager;
89     private LockManager lockManager;
90     private AAIService aaiService;
91     private RequestValidationPolicy requestValidationPolicy;
92     private RestClientInvoker client;
93     private String path;
94     private int transactionWindowInterval=0;
95
96     static final String SCOPE_OVERLAP_ENDPOINT = "appc.LCM.scopeOverlap.endpoint";
97     static final String ODL_USER = "appc.LCM.provider.user";
98     static final String ODL_PASS = "appc.LCM.provider.pass";
99     static final String TRANSACTION_WINDOW_HOURS = "appc.inProgressTransactionWindow.hours";
100
101     public void initialize() throws APPCException {
102         logger.info("Initializing RequestValidatorImpl.");
103         String endpoint = null;
104         String user = null;
105         String pass = null;
106         String transactionWindow = null;
107         Properties properties = configuration.getProperties();
108         if (properties != null) {
109             endpoint = properties.getProperty(SCOPE_OVERLAP_ENDPOINT);
110             user = properties.getProperty(ODL_USER);
111             pass = properties.getProperty(ODL_PASS);
112             transactionWindow = properties.getProperty(TRANSACTION_WINDOW_HOURS);
113         }
114         if (endpoint == null) {
115             String message = "End point is not defined for scope over lap service in appc.properties.";
116             logger.error(message);
117             // TODO throw following exception (and remove the "return") when
118             // entry in appc.properties file is made for scope overlap service
119             // endpoint
120             // and remove @Ignore in unit tests:
121             // testInitializeWithNullConfigProps,
122             // testInitializeWithoutEndpointProp
123             // throw new APPCException(message);
124             return;
125         }
126
127         if (StringUtils.isNotBlank(transactionWindow)) {
128             logger.info("RequestValidatorImpl::TransactionWindow defined !!!");
129             try {
130                 transactionWindowInterval = Integer.parseInt(transactionWindow);
131             }
132             catch (NumberFormatException e) {
133                 String message = "RequestValidatorImpl:::Error parsing transaction window interval!";
134                 logger.error(message, e);
135                 throw new APPCException(message);
136             }
137         }
138
139         try {
140             URL url = new URL(endpoint);
141             client = new RestClientInvoker(url);
142             client.setAuthentication(user, pass);
143             path = url.getPath();
144
145         } catch (MalformedURLException e) {
146             String message = "Invalid endpoint " + endpoint;
147             logger.error(message, e);
148             // TODO throw following exception when entry in appc.properties file
149             // is made for scope overlap service endpoint
150             // and remove @Ignore in unit test:
151             // testInitializeWithMalFormatEndpoint
152             // throw new APPCException(message);
153         }
154     }
155
156     private void getAAIservice() {
157         BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext();
158         // Get AAIadapter reference
159         ServiceReference sref = bctx.getServiceReference(AAIService.class.getName());
160         if (sref != null) {
161             logger.info("AAIService from bundlecontext");
162             aaiService = (AAIService) bctx.getService(sref);
163
164         } else {
165             logger.error("Cannot find service reference for org.onap.ccsdk.sli.adaptors.aai.AAIService");
166
167         }
168     }
169
170     public void setLockManager(LockManager lockManager) {
171         this.lockManager = lockManager;
172     }
173
174     public void setClient(RestClientInvoker client) {
175         this.client = client;
176     }
177
178     public void setWorkflowManager(WorkFlowManager workflowManager) {
179         this.workflowManager = workflowManager;
180     }
181
182     public void setRequestValidationPolicy(RequestValidationPolicy requestValidationPolicy) {
183         this.requestValidationPolicy = requestValidationPolicy;
184     }
185
186     public void validateRequest(RuntimeContext runtimeContext) throws Exception {
187         if (logger.isTraceEnabled()) {
188             logger.trace(
189                     "Entering to validateRequest with RequestHandlerInput = " + ObjectUtils.toString(runtimeContext));
190         }
191         if (!lcmStateManager.isLCMOperationEnabled()) {
192             LoggingUtils.logErrorMessage(LoggingConstants.TargetNames.REQUEST_VALIDATOR,
193                     EELFResourceManager.format(Msg.LCM_OPERATIONS_DISABLED), this.getClass().getCanonicalName());
194             throw new LCMOperationsDisabledException("APPC LCM operations have been administratively disabled");
195         }
196
197         getAAIservice();
198         validateInput(runtimeContext);
199         String vnfId = runtimeContext.getRequestContext().getActionIdentifiers().getVnfId();
200         VNFContext vnfContext = queryAAI(vnfId);
201         runtimeContext.setVnfContext(vnfContext);
202         runtimeContext.getTransactionRecord().setTargetType(vnfContext.getType());
203
204         VNFOperation operation = runtimeContext.getRequestContext().getAction();
205         if (operation.isBuiltIn()) {
206             return;
207         }
208
209         validateVNFLock(runtimeContext);
210         checkWorkflowExists(vnfContext, runtimeContext.getRequestContext());
211
212         if (runtimeContext.getRequestContext().getCommonHeader().getFlags().isForce()) {
213             return;
214         }
215
216         List<TransactionRecord> inProgressTransactionsAll = transactionRecorder
217                 .getInProgressRequests(runtimeContext.getTransactionRecord(), 0);
218         List<TransactionRecord> inProgressTransactions = transactionRecorder
219                 .getInProgressRequests(runtimeContext.getTransactionRecord(), transactionWindowInterval);
220         long inProgressTransactionsAllCount = inProgressTransactionsAll == null ? 0 : inProgressTransactionsAll.size();
221         long inProgressTransactionsRelevant = inProgressTransactions == null ? 0 : inProgressTransactions.size();
222         logger.debug("In progress requests " + inProgressTransactions.toString());
223
224         if (inProgressTransactionsRelevant == 0) { //No need for further checks
225             return;
226         }
227
228         if (logger.isInfoEnabled()) {
229             logger.info(logInProgressTransactions(inProgressTransactions, inProgressTransactionsAllCount,
230                     inProgressTransactionsRelevant));
231         }
232
233         Long exclusiveRequestCount = inProgressTransactions.stream()
234                 .filter(record -> record.getMode().equals(Flags.Mode.EXCLUSIVE.name())).count();
235         if (exclusiveRequestCount > 0) {
236             String message = "Request rejected - Existing request in progress with exclusive mode for VNF: " + vnfId;
237             throw new RequestValidationException(message, LCMCommandStatus.EXLCUSIVE_REQUEST_IN_PROGRESS,
238                     (new Params()).addParam("errorMsg", message));
239         }
240
241         Boolean scopeOverLap = checkScopeOverLap(runtimeContext.getRequestContext(), inProgressTransactions);
242         logger.debug("Scope overlap " + scopeOverLap);
243         if (scopeOverLap) {
244             List<VNFOperation> inProgressActions = inProgressTransactions.stream().map(TransactionRecord::getOperation)
245                     .collect(Collectors.toList());
246
247             RuleExecutor ruleExecutor = requestValidationPolicy.getInProgressRuleExecutor();
248             RuleResult result = ruleExecutor.executeRule(operation.name(), inProgressActions);
249             logger.debug("Policy validation result " + result);
250             if (RuleResult.REJECT == result) {
251                 String message = "Request rejected as per the request validation policy";
252                 throw new RequestValidationException(message, LCMCommandStatus.POLICY_VALIDATION_FAILURE,
253                         (new Params()).addParam("errorMsg", message));
254             }
255         }
256     }
257
258     private void validateVNFLock(RuntimeContext runtimeContext) throws LockException {
259         String vnfId = runtimeContext.getRequestContext().getActionIdentifiers().getVnfId();
260         String lockOwner = lockManager.getLockOwner(vnfId);
261         logger.debug("Current lock owner is " + lockOwner + " for vnf " + vnfId);
262         if (lockOwner != null
263                 && !lockOwner.equals(runtimeContext.getRequestContext().getCommonHeader().getRequestId())) {
264             String message = new StringBuilder("VNF : ").append(vnfId).append(" is locked by request id :")
265                     .append(lockOwner).toString();
266             throw new LockException(message);
267         }
268     }
269
270     /*
271      * Do not remove this method, this is actual method for invoking scope
272      * overlap service When the service becomes available, its dummy
273      * implementation should be removed and this implementation should be used.
274      */
275     private Boolean checkScopeOverLap(RequestContext requestContext, List<TransactionRecord> inProgressTransactions)
276             throws APPCException {
277         Boolean scopeOverlap = null;
278         try {
279             JsonNode inputJSON = convertToJsonInput(requestContext, inProgressTransactions);
280             logger.debug("Input to scope overlap service " + inputJSON.toString());
281             HttpResponse response = client.doPost(path, inputJSON.toString());
282             int httpCode = response.getStatusLine().getStatusCode();
283             if (httpCode < 200 || httpCode >= 300) {
284                 logger.debug("http error code " + httpCode);
285                 throw new APPCException("Exception occurred on invoking check scope overlap api");
286             }
287             String respBody = IOUtils.toString(response.getEntity().getContent());
288             logger.debug("response body " + respBody);
289             ObjectMapper mapper = new ObjectMapper();
290             JsonNode outputJSON = mapper.readTree(respBody);
291             scopeOverlap = readScopeOverlap(outputJSON);
292         } catch (IOException e) {
293             String message = "Error accessing check scope overlap service";
294             logger.error(message, e);
295             throw new APPCException(message);
296         }
297         return scopeOverlap;
298     }
299
300     private Boolean readScopeOverlap(JsonNode outputJSON) throws APPCException {
301         logger.debug("Response JSON " + outputJSON.toString());
302         String message = "Error reading response JSON from scope overlap service ";
303         JsonNode outputNode = outputJSON.get("output");
304         JsonNode statusNode = outputNode.get("status");
305         if (statusNode == null) {
306             throw new APPCException(message);
307         }
308
309         if (null == statusNode.get("message"))
310             throw new APPCException(message + "Status message is null.");
311         String responseStatusMessage = statusNode.get("message").textValue();
312
313         if (null == statusNode.get("code"))
314             throw new APPCException(message + "Status code is null.");
315         String code = statusNode.get("code").textValue();
316
317         JsonNode responseInfoNode = outputNode.get("response-info");
318         JsonNode blockNode = responseInfoNode.get("block");
319         String requestOverlapValue = null;
320
321         if (null != blockNode)
322             requestOverlapValue = blockNode.textValue();
323
324         logger.debug("Response JSON " + requestOverlapValue);
325
326         if (code.equals("400")) {
327             if(null==requestOverlapValue)
328                 throw new APPCException("Response code is 400 but requestOverlapValue is null ");
329             if (requestOverlapValue.contains("true")) {
330                 return Boolean.TRUE;
331             } else if (requestOverlapValue.contains("false")) {
332                 return Boolean.FALSE;
333             } else {
334                 throw new APPCException(
335                         message + "requestOverlap value is other than True and False, it is " + requestOverlapValue);
336             }
337         } else if (code.equals("401")) {
338             throw new APPCException(message + responseStatusMessage);
339         } else {
340             throw new APPCException(message + "Status code is neither 400 nor 401, it is " + code);
341         }
342
343     }
344
345     private JsonNode convertToJsonInput(RequestContext requestContext, List<TransactionRecord> inProgressTransactions) {
346         ObjectMapper objectMapper = new ObjectMapper();
347         ScopeOverlapModel scopeOverlapModel = getScopeOverlapModel(requestContext, inProgressTransactions);
348         // Added for change in interface for action level
349
350         JsonNode jsonObject = objectMapper.valueToTree(scopeOverlapModel);
351
352         return jsonObject;
353     }
354
355     public ScopeOverlapModel getScopeOverlapModel(RequestContext requestContext,
356             List<TransactionRecord> inProgressTransactions) {
357         ScopeOverlapModel scopeOverlapModel = new ScopeOverlapModel();
358         RequestData requestData = new RequestData();
359
360         List<RequestModel> inProgressRequests = new ArrayList<>();
361         RequestModel requestModel = new RequestModel();
362         ActionIdentifierModel actionIdentifierModel = extractActionIdentifierModel(requestContext);
363         requestModel.setAction(requestContext.getAction().toString());
364         requestModel.setActionIdentifier(actionIdentifierModel);
365
366         if (requestModel.getActionIdentifier().getVnfId() != null) {
367             requestData.setVnfID(requestModel.getActionIdentifier().getVnfId());
368         }
369
370         if (requestModel.getActionIdentifier().getVnfcName() != null
371                 || requestModel.getActionIdentifier().getVfModuleId() != null
372                 || requestModel.getActionIdentifier().getVserverId() != null) {
373
374             requestModel.getActionIdentifier().setVnfId(null);
375         }
376
377         requestData.setCurrentRequest(requestModel);
378
379         for (TransactionRecord record : inProgressTransactions) {
380             RequestModel request = new RequestModel();
381             ActionIdentifierModel actionIdentifier = new ActionIdentifierModel();
382
383             actionIdentifier.setServiceInstanceId(record.getServiceInstanceId());
384             actionIdentifier.setVnfId(record.getTargetId());
385             actionIdentifier.setVnfcName(record.getVnfcName());
386             actionIdentifier.setVfModuleId(record.getVfModuleId());
387             actionIdentifier.setVserverId(record.getVserverId());
388
389             request.setAction(record.getOperation().name());
390             request.setActionIdentifier(actionIdentifier);
391             if (request.getActionIdentifier().getVnfcName() != null
392                         || request.getActionIdentifier().getVfModuleId() != null
393                         || request.getActionIdentifier().getVserverId() != null) {
394
395                     request.getActionIdentifier().setVnfId(null);
396             }
397             request.setTargetId(record.getTargetId());
398             inProgressRequests.add(request);
399         }
400
401         requestData.setInProgressRequests(inProgressRequests);
402
403         Request request = new Request();
404
405         Date date = new Date();
406         request.setRequestID("RequestId-ScopeOverlap " + date.toString());
407         request.setAction("isScopeOverlap");
408         ObjectMapper objectMapper = new ObjectMapper();
409         JsonNode json = objectMapper.valueToTree(requestData);
410         request.setRequestData(json.toString());
411         Input input = new Input();
412         input.setRequest(request);
413         scopeOverlapModel.setInput(input);
414
415         return scopeOverlapModel;
416     }
417
418     private ActionIdentifierModel extractActionIdentifierModel(RequestContext requestContext) {
419         ActionIdentifierModel actionIdentifierModel = new ActionIdentifierModel();
420         actionIdentifierModel.setServiceInstanceId(requestContext.getActionIdentifiers().getServiceInstanceId());
421         actionIdentifierModel.setVnfId(requestContext.getActionIdentifiers().getVnfId());
422         actionIdentifierModel.setVnfcName(requestContext.getActionIdentifiers().getVnfcName());
423         actionIdentifierModel.setVfModuleId(requestContext.getActionIdentifiers().getVfModuleId());
424         actionIdentifierModel.setVserverId(requestContext.getActionIdentifiers().getVserverId());
425         return actionIdentifierModel;
426     }
427
428     private VNFContext queryAAI(String vnfId) throws VNFNotFoundException, MissingVNFDataInAAIException {
429         SvcLogicContext ctx = new SvcLogicContext();
430         ctx = getVnfdata(vnfId, "vnf", ctx);
431
432         VNFContext vnfContext = new VNFContext();
433         populateVnfContext(vnfContext, ctx);
434
435         return vnfContext;
436     }
437
438     private SvcLogicContext getVnfdata(String vnf_id, String prefix, SvcLogicContext ctx) throws VNFNotFoundException {
439         if (logger.isTraceEnabled()) {
440             logger.trace("Entering to getVnfdata with vnfid = " + ObjectUtils.toString(vnf_id) + ", prefix = "
441                     + ObjectUtils.toString(prefix) + ", SvcLogicContext" + ObjectUtils.toString(ctx));
442         }
443         String key = "vnf-id = '" + vnf_id + "'";
444         logger.debug("inside getVnfdata=== " + key);
445         try {
446             Date beginTimestamp = new Date();
447             SvcLogicResource.QueryStatus response = aaiService.query("generic-vnf", false, null, key, prefix, null,
448                     ctx);
449             Date endTimestamp = new Date();
450             String status = SvcLogicResource.QueryStatus.SUCCESS.equals(response)
451                     ? LoggingConstants.StatusCodes.COMPLETE : LoggingConstants.StatusCodes.ERROR;
452             LoggingUtils.logMetricsMessage(beginTimestamp.toInstant(), endTimestamp.toInstant(),
453                     LoggingConstants.TargetNames.AAI, LoggingConstants.TargetServiceNames.AAIServiceNames.QUERY, status,
454                     "", response.name(), this.getClass().getCanonicalName());
455             if (SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)) {
456                 throw new VNFNotFoundException("VNF not found for vnf_id = " + vnf_id, vnf_id);
457             } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
458                 throw new RuntimeException("Error Querying AAI with vnfID = " + vnf_id);
459             }
460             logger.info("AAIResponse: " + response.toString());
461         } catch (SvcLogicException e) {
462
463             LoggingUtils.logErrorMessage(LoggingConstants.TargetServiceNames.AAIServiceNames.GET_VNF_DATA,
464                     "Error in getVnfdata" + e, this.getClass().getCanonicalName());
465
466             throw new RuntimeException(e);
467         }
468         if (logger.isTraceEnabled()) {
469             logger.trace("Exiting from getVnfdata with (SvcLogicContext = " + ObjectUtils.toString(ctx) + ")");
470         }
471         return ctx;
472     }
473
474     private void populateVnfContext(VNFContext vnfContext, SvcLogicContext ctx) throws MissingVNFDataInAAIException {
475         String vnfType = ctx.getAttribute("vnf.vnf-type");
476         if (StringUtils.isEmpty(vnfType)) {
477             throw new MissingVNFDataInAAIException("vnf-type", ctx.getAttribute("vnf.vnf-id"));
478         }
479         vnfContext.setType(vnfType);
480         vnfContext.setId(ctx.getAttribute("vnf.vnf-id"));
481     }
482
483     private void checkWorkflowExists(VNFContext vnfContext, RequestContext requestContext)
484             throws WorkflowNotFoundException, DGWorkflowNotFoundException {
485         WorkflowExistsOutput workflowExistsOutput = workflowManager
486                 .workflowExists(getWorkflowQueryParams(vnfContext, requestContext));
487         if (!workflowExistsOutput.isMappingExist()) {
488             if (logger.isDebugEnabled()) {
489                 logger.debug("WorkflowManager : Workflow mapping not found for vnfType = " + vnfContext.getType()
490                         + ", version = " + vnfContext.getVersion() + ", command = "
491                         + requestContext.getAction().name());
492             }
493             LoggingUtils.logErrorMessage(LoggingConstants.TargetNames.WORKFLOW_MANAGER, EELFResourceManager
494                     .format(Msg.APPC_WORKFLOW_NOT_FOUND, vnfContext.getType(), requestContext.getAction().name()),
495                     this.getClass().getCanonicalName());
496             throw new WorkflowNotFoundException(
497                     "Workflow mapping not found for vnfType = " + vnfContext.getType() + ", command = "
498                     + requestContext.getAction().name(),
499                     vnfContext.getType(), requestContext.getAction().name());
500         }
501         if (!workflowExistsOutput.isDgExist()) {
502             if (logger.isDebugEnabled()) {
503                 logger.debug("WorkflowManager : DG Workflow not found for vnfType = " + vnfContext.getType()
504                         + ", version = " + vnfContext.getVersion() + ", command = " + requestContext.getAction().name()
505                         + " " + workflowExistsOutput);
506             }
507             LoggingUtils.logErrorMessage(LoggingConstants.TargetNames.WORKFLOW_MANAGER, EELFResourceManager
508                     .format(Msg.APPC_WORKFLOW_NOT_FOUND, vnfContext.getType(), requestContext.getAction().name()),
509                     this.getClass().getCanonicalName());
510             throw new DGWorkflowNotFoundException(
511                     "Workflow not found for vnfType = " + vnfContext.getType() + ", command = "
512                     + requestContext.getAction().name(),
513                     workflowExistsOutput.getWorkflowModule(), workflowExistsOutput.getWorkflowName(),
514                     workflowExistsOutput.getWorkflowVersion(), vnfContext.getType(), requestContext.getAction().name());
515         }
516     }
517
518     private WorkflowRequest getWorkflowQueryParams(VNFContext vnfContext, RequestContext requestContext) {
519         WorkflowRequest workflowRequest = new WorkflowRequest();
520         workflowRequest.setVnfContext(vnfContext);
521         workflowRequest.setRequestContext(requestContext);
522         if (logger.isTraceEnabled()) {
523             logger.trace("Exiting from getWorkflowQueryParams with (WorkflowRequest = "
524                     + ObjectUtils.toString(workflowRequest) + ")");
525         }
526         return workflowRequest;
527     }
528
529     public String logInProgressTransactions(List<TransactionRecord> inProgressTransactions,
530             long inProgressTransactionsAllCount, long inProgressTransactionsRelevant) {
531         if (inProgressTransactionsAllCount > inProgressTransactionsRelevant) {
532             logger.info("Found Stale Transactions! Ignoring Stale Transactions for target, only considering "
533                     + "transactions within the last " + transactionWindowInterval + " hours as transactions in-progress");
534         }
535         String logMsg = "";
536         for (TransactionRecord tr: inProgressTransactions) {
537             logMsg = ("In Progress transaction for Target ID - " + tr.getTargetId()
538                     + " in state " + tr.getRequestState()
539                     + " with Start time " + tr.getStartTime().toString()
540                     + " for more than configurable time period " + transactionWindowInterval
541                     + " hours [transaction details - Request ID - " + tr.getTransactionId()
542                     + ", Service Instance Id - " + tr.getServiceInstanceId()
543                     + ", Vserver_id - " + tr.getVserverId()
544                     + ", VNFC_name - " + tr.getVnfcName()
545                     + ", VF module Id - " + tr.getVfModuleId()
546                     + " Start time " + tr.getStartTime().toString()
547                     + "]");
548         }
549         return logMsg;
550     }
551 }