From 01e7a30219bcb92f983d3f4eb9a061e108119257 Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Thu, 17 Jan 2019 08:08:00 +0000 Subject: Fix unit tests for appc-command-executor-core Increase line coverage of package from 43% to 93% Issue-ID: APPC-1329 Change-Id: I0a4e2a0a85f6761becde4a74609358267530d92d Signed-off-by: Joss Armstrong --- .../appc/executor/impl/CommandExecutorImpl.java | 20 +++---- .../org/onap/appc/executor/impl/CommandTask.java | 70 +++++++++++----------- 2 files changed, 45 insertions(+), 45 deletions(-) (limited to 'appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main') diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandExecutorImpl.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandExecutorImpl.java index 5b3df9e14..9c12f4741 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandExecutorImpl.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandExecutorImpl.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (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. @@ -76,26 +78,19 @@ public class CommandExecutorImpl implements CommandExecutor { */ @Override public void executeCommand (CommandExecutorInput commandExecutorInput) throws APPCException{ - if (logger.isTraceEnabled()) { - logger.trace("Entering to executeCommand with CommandExecutorInput = "+ ObjectUtils.toString(commandExecutorInput)); - } + logger.trace("Entering to executeCommand with CommandExecutorInput = "+ ObjectUtils.toString(commandExecutorInput)); CommandTask commandTask; try { - commandTask= new CommandTask(requestHandler,workflowManager); + commandTask= getCommandTask(requestHandler, workflowManager); commandTask.setCommandRequest(new CommandRequest(commandExecutorInput)); long remainingTTL = getRemainingTTL(commandTask.getCommandRequest()); - if (logger.isTraceEnabled()) { - logger.trace("Queuing request with CommandRequest = "+ ObjectUtils.toString(commandTask.getCommandRequest())); - } + logger.trace("Queuing request with CommandRequest = "+ ObjectUtils.toString(commandTask.getCommandRequest())); executionQueueService.putMessage(commandTask,remainingTTL, TimeUnit.MILLISECONDS); } catch (Exception e) { logger.error("Exception: "+e.getMessage()); throw new APPCException(e); } - - if (logger.isTraceEnabled()) { - logger.trace("Exiting from executeCommand"); - } + logger.trace("Exiting from executeCommand"); } private long getRemainingTTL(CommandRequest request) { @@ -104,4 +99,7 @@ public class CommandExecutorImpl implements CommandExecutor { return ttl*1000 + requestTimestamp.getTime() - System.currentTimeMillis(); } + protected CommandTask getCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager) { + return new CommandTask(requestHandler, workflowManager); + } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandTask.java index 458814dab..cfd4ff8d0 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandTask.java @@ -5,6 +5,8 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (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. @@ -23,6 +25,11 @@ package org.onap.appc.executor.impl; +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.net.InetAddress; +import java.util.UUID; import org.onap.appc.domainmodel.lcm.Status; import org.onap.appc.domainmodel.lcm.VNFOperation; import org.onap.appc.executor.impl.objects.CommandRequest; @@ -31,8 +38,6 @@ import org.onap.appc.requesthandler.RequestHandler; import org.onap.appc.domainmodel.lcm.RuntimeContext; import org.onap.appc.workflow.WorkFlowManager; import org.onap.appc.workflow.objects.WorkflowRequest; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.core.sli.SvcLogicResource; @@ -44,10 +49,7 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; import org.slf4j.MDC; -import java.net.InetAddress; -import java.util.UUID; -import static com.att.eelf.configuration.Configuration.*; /** * This abstract class is base class for all Command tasks. All command task must inherit this class. @@ -96,23 +98,21 @@ public class CommandTask implements Runnable { } else { logger.info("AAIService error from bundlecontext"); logger.warn("Cannot find service reference for org.onap.ccsdk.sli.adaptors.aai.AAIService"); - } } @Override public void run() { - logger.debug("Starting execution of command :"+ commandRequest); + logger.debug("Starting execution of command :" + commandRequest); setInitialLogProperties(commandRequest); final RuntimeContext runtimeContext = commandRequest.getCommandExecutorInput().getRuntimeContext(); - WorkflowRequest workflowRequest = new WorkflowRequest(); workflowRequest.setRequestContext(runtimeContext.getRequestContext()); workflowRequest.setResponseContext(runtimeContext.getResponseContext()); workflowRequest.setVnfContext(runtimeContext.getVnfContext()); - logger.debug("Executing workflow :"+ workflowRequest); + logger.debug("Executing workflow :" + workflowRequest); workflowManager.executeWorkflow(workflowRequest); logger.debug("Completed execution workflow with response:"+ commandRequest.getCommandExecutorInput().getRuntimeContext().getResponseContext()); try { @@ -135,32 +135,30 @@ public class CommandTask implements Runnable { private void updateAAIForTerminate(CommandRequest commandRequest) throws AAIServiceException { final int statusCode = commandRequest.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus().getCode(); - if (logger.isDebugEnabled()) { - logger.debug("Workflow Execution Status = "+ statusCode); - } + logger.debug("Workflow Execution Status = "+ statusCode); if (statusCode == 100 || statusCode == 400) { SvcLogicContext ctx = new SvcLogicContext(); ctx = getVnfdata(commandRequest.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId(), "vnf", ctx); - deleteGenericVnfData(commandRequest.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId(), ctx.getAttribute("vnf.resource-version")); - + deleteGenericVnfData(commandRequest.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId(), + ctx.getAttribute("vnf.resource-version")); } } private SvcLogicContext getVnfdata(String vnf_id, String prefix,SvcLogicContext ctx) { - String key="generic-vnf.vnf-id = '"+ vnf_id+"'"+" AND http-header.Real-Time = 'true'"; - logger.debug("inside getVnfdata=== "+key); + String key="generic-vnf.vnf-id = '" + vnf_id + "'" + " AND http-header.Real-Time = 'true'"; + logger.debug("inside getVnfdata=== " + key); try { SvcLogicResource.QueryStatus response = aaiService.query("generic-vnf", false, null, key,prefix, null, ctx); if(SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)){ logger.warn("VNF " + vnf_id + " not found while updating A&AI"); - throw new RuntimeException("VNF not found for vnf_id = "+ vnf_id); + throw new RuntimeException("VNF not found for vnf_id = " + vnf_id); } else if(SvcLogicResource.QueryStatus.FAILURE.equals(response)){ - throw new RuntimeException("Error Querying AAI with vnfID = " +vnf_id); + throw new RuntimeException("Error Querying AAI with vnfID = " + vnf_id); } logger.info("AAIResponse: " + response.toString()); } catch (SvcLogicException e) { - logger.error("Error in getVnfdata "+ e); + logger.error("Error in getVnfdata " + e); throw new RuntimeException(e); } return ctx; @@ -171,39 +169,43 @@ public class CommandTask implements Runnable { String reqId = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getRequestId(); try { - MDC.put(MDC_KEY_REQUEST_ID, UUID.fromString(reqId).toString()); + MDC.put(Configuration.MDC_KEY_REQUEST_ID, UUID.fromString(reqId).toString()); //reaching here without exception means existing RequestId is //valid UUID as per ECOMP logging standards } catch (Exception e) { String reqIdUUID = UUID.randomUUID().toString(); - MDC.put(MDC_KEY_REQUEST_ID, reqIdUUID); + MDC.put(Configuration.MDC_KEY_REQUEST_ID, reqIdUUID); logger.info("Replaced invalid requestID of " + reqId + ". New value is " + reqIdUUID + "."); } - if (request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getActionIdentifiers().getServiceInstanceId() != null) - MDC.put(MDC_SERVICE_INSTANCE_ID, request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getActionIdentifiers().getServiceInstanceId()); - MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getOriginatorId()); - MDC.put(MDC_SERVICE_NAME, request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getAction().name()); + if (request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getActionIdentifiers().getServiceInstanceId() != null) { + MDC.put(Configuration.MDC_SERVICE_INSTANCE_ID, + request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getActionIdentifiers().getServiceInstanceId()); + MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, + request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getOriginatorId()); + MDC.put(Configuration.MDC_SERVICE_NAME, + request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getAction().name()); + } try { - MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); - MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress()); + MDC.put(Configuration.MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); + MDC.put(Configuration.MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress()); } catch (Exception e) { - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } - MDC.put(MDC_INSTANCE_UUID, ""); // make instanse_UUID generation once during APPC-instanse deploying + MDC.put(Configuration.MDC_INSTANCE_UUID, ""); // make instanse_UUID generation once during APPC-instance deploying } private void clearRequestLogProperties() { try { - MDC.remove(MDC_KEY_REQUEST_ID); - MDC.remove(MDC_SERVICE_INSTANCE_ID); - MDC.remove(MDC_SERVICE_NAME); + MDC.remove(Configuration.MDC_KEY_REQUEST_ID); + MDC.remove(Configuration.MDC_SERVICE_INSTANCE_ID); + MDC.remove(Configuration.MDC_SERVICE_NAME); MDC.remove(LoggingConstants.MDCKeys.PARTNER_NAME); } catch (Exception e) { - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } - + public boolean deleteGenericVnfData(String vnf_id, String resourceVersion) throws AAIServiceException { boolean response = false; -- cgit 1.2.3-korg