diff options
Diffstat (limited to 'appc-dispatcher/appc-command-executor')
8 files changed, 89 insertions, 127 deletions
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java b/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java index c973fcde1..8009d72d5 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java @@ -26,13 +26,14 @@ import org.openecomp.appc.domainmodel.lcm.RuntimeContext; public class CommandResponse { - private RuntimeContext runtimeContext; + private final RuntimeContext runtimeContext; - public RuntimeContext getRuntimeContext() { - return runtimeContext; + public CommandResponse(RuntimeContext runtimeContext) { + super(); + this.runtimeContext = runtimeContext; } - public void setRuntimeContext(RuntimeContext runtimeContext) { - this.runtimeContext = runtimeContext; + public RuntimeContext getRuntimeContext() { + return runtimeContext; } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java index 0948b2b4d..fcc4f9156 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java @@ -25,7 +25,8 @@ package org.openecomp.appc.executor.impl; -import java.util.Date; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.concurrent.TimeUnit; import org.apache.commons.lang.ObjectUtils; @@ -92,8 +93,8 @@ public class CommandExecutorImpl implements CommandExecutor { logger.trace("Entering to enqueRequest with CommandRequest = "+ ObjectUtils.toString(request)); } try { - CommandTask commandTask = getMessageExecutor(request.getRequestContext().getAction().name()); - commandTask.setCommandRequest(request); + String action = request.getRequestContext().getAction().name(); + CommandTask commandTask = executionTaskFactory.getExecutionTask(action, request); long remainingTTL = getRemainingTTL(request); executionQueueService.putMessage(commandTask,remainingTTL, TimeUnit.MILLISECONDS); } catch (Exception e) { @@ -107,20 +108,9 @@ public class CommandExecutorImpl implements CommandExecutor { } private long getRemainingTTL(RuntimeContext request) { - Date requestTimestamp = request.getRequestContext().getCommonHeader().getTimeStamp(); + Instant requestTimestamp = request.getRequestContext().getCommonHeader().getTimeStamp(); int ttl = request.getRequestContext().getCommonHeader().getFlags().getTtl(); - return ttl*1000 + requestTimestamp.getTime() - System.currentTimeMillis(); - } - - private CommandTask getMessageExecutor(String action){ - if (logger.isTraceEnabled()) { - logger.trace("Entering to getMessageExecutor with command = "+ action); - } - CommandTask executionTask = executionTaskFactory.getExecutionTask(action); - if (logger.isTraceEnabled()) { - logger.trace("Exiting from getMessageExecutor"); - } - return executionTask; + return ChronoUnit.MILLIS.between(Instant.now(), requestTimestamp.plusSeconds(ttl)); } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java index f34746b24..21a00861e 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java @@ -51,44 +51,30 @@ import org.slf4j.MDC; public abstract class CommandTask implements Runnable { - protected RequestHandler requestHandler; - protected WorkFlowManager workflowManager; + protected final RequestHandler requestHandler; + protected final WorkFlowManager workflowManager; + protected final RuntimeContext commandRequest; - private RuntimeContext commandRequest; - - public RuntimeContext getCommandRequest() { - return commandRequest; - } - - public void setCommandRequest(RuntimeContext commandRequest) { + protected CommandTask(RuntimeContext commandRequest, RequestHandler requestHandler, + WorkFlowManager workflowManager) { + super(); this.commandRequest = commandRequest; - } - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class); - - public void setWorkflowManager(WorkFlowManager workflowManager) { - this.workflowManager = workflowManager; - } - - public void setRequestHandler(RequestHandler requestHandler) { this.requestHandler = requestHandler; + this.workflowManager = workflowManager; } - CommandTask(){ - } + private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class); - public void onRequestCompletion(RuntimeContext request, CommandResponse response , boolean isAAIUpdated) { + public void onRequestCompletion(CommandResponse response, boolean isAAIUpdated) { logger.debug("Entry: onRequestCompletion()"); - requestHandler.onRequestExecutionEnd(request, isAAIUpdated); + requestHandler.onRequestExecutionEnd(commandRequest, isAAIUpdated); } - public abstract void onRequestCompletion(RuntimeContext request, CommandResponse response); + public abstract void onRequestCompletion(CommandResponse response); - protected CommandResponse buildCommandResponse(RuntimeContext request, WorkflowResponse response) { + protected CommandResponse buildCommandResponse(WorkflowResponse response) { - CommandResponse commandResponse = new CommandResponse(); - commandResponse.setRuntimeContext(request); - return commandResponse; + return new CommandResponse(commandRequest); } @@ -114,8 +100,8 @@ public abstract class CommandTask implements Runnable { WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest); - CommandResponse commandResponse = buildCommandResponse(commandRequest, response); - this.onRequestCompletion(commandRequest,commandResponse); + CommandResponse commandResponse = buildCommandResponse(response); + this.onRequestCompletion(commandResponse); } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java index 610f0bca3..e5ac79cfa 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java @@ -22,6 +22,7 @@ package org.openecomp.appc.executor.impl; +import org.openecomp.appc.domainmodel.lcm.RuntimeContext; import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.lifecyclemanager.LifecycleManager; import org.openecomp.appc.requesthandler.RequestHandler; @@ -53,11 +54,11 @@ public class CommandTaskFactory { } - public synchronized CommandTask getExecutionTask(String action){ + public synchronized CommandTask getExecutionTask(String action, RuntimeContext commandRequest){ if (VNFOperation.Sync.toString().equals(action) || VNFOperation.Audit.toString().equals(action)){ - return new LCMReadonlyCommandTask(requestHandler,workflowManager); + return new LCMReadonlyCommandTask(commandRequest, requestHandler,workflowManager); }else { - return new LCMCommandTask(requestHandler,workflowManager, + return new LCMCommandTask(commandRequest, requestHandler,workflowManager, lifecyclemanager); } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java index 889bd25da..ef25c67bc 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java @@ -22,10 +22,12 @@ package org.openecomp.appc.executor.impl; +import java.util.HashMap; +import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.openecomp.appc.domainmodel.lcm.CommonHeader; import org.openecomp.appc.domainmodel.lcm.RuntimeContext; -import org.openecomp.appc.domainmodel.lcm.Status; import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.executor.UnstableVNFException; import org.openecomp.appc.executor.objects.CommandResponse; @@ -39,8 +41,6 @@ import org.openecomp.appc.lifecyclemanager.objects.VNFOperationOutcome; import org.openecomp.appc.requesthandler.RequestHandler; import org.openecomp.appc.workflow.WorkFlowManager; import org.openecomp.appc.workflow.objects.WorkflowResponse; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.openecomp.sdnc.sli.SvcLogicContext; import org.openecomp.sdnc.sli.SvcLogicException; import org.openecomp.sdnc.sli.SvcLogicResource; @@ -49,31 +49,22 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; -import java.util.HashMap; -import java.util.Map; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; public class LCMCommandTask extends CommandTask { - private AAIService aaiService; - private LifecycleManager lifecyclemanager; + private final AAIService aaiService; + private final LifecycleManager lifecyclemanager; private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMCommandTask.class); - public LCMCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager, - LifecycleManager lifecyclemanager){ - setRequestHandler(requestHandler); - setWorkflowManager(workflowManager); - setLifecyclemanager(lifecyclemanager); - getAAIservice(); - } - - public void setLifecyclemanager(LifecycleManager lifecyclemanager) { - this.lifecyclemanager = lifecyclemanager; - } + public LCMCommandTask(RuntimeContext commandRequest, RequestHandler requestHandler, WorkFlowManager workflowManager, + LifecycleManager lifecyclemanager) { + super(commandRequest, requestHandler, workflowManager); + this.lifecyclemanager = lifecyclemanager; - - private void getAAIservice() { BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext(); // Get AAIadapter reference ServiceReference sref = bctx.getServiceReference(AAIService.class.getName()); @@ -84,15 +75,15 @@ public class LCMCommandTask extends CommandTask { } else { logger.info("AAIService error from bundlecontext"); logger.warn("Cannot find service reference for org.openecomp.sdnc.sli.aai.AAIService"); - + aaiService = null; } } @Override - public void onRequestCompletion(RuntimeContext request, CommandResponse response) { - - boolean isAAIUpdated = false; + public void onRequestCompletion(CommandResponse response) { + final RuntimeContext request = commandRequest; + boolean isAAIUpdated = false; try { final int statusCode = request.getResponseContext().getStatus().getCode(); @@ -118,14 +109,14 @@ public class LCMCommandTask extends CommandTask { throw new RuntimeException(e1); } finally { - super.onRequestCompletion(request, response , isAAIUpdated); + super.onRequestCompletion(response, isAAIUpdated); } } @Override public void run() { - RuntimeContext request = getCommandRequest(); - boolean isAAIUpdated; + final RuntimeContext request = commandRequest; + boolean isAAIUpdated = false; final String vnfId = request.getVnfContext().getId(); final String vnfType = request.getVnfContext().getType(); try { @@ -169,8 +160,8 @@ public class LCMCommandTask extends CommandTask { logger.error(errorMsg); WorkflowResponse response = new WorkflowResponse(); response.setResponseContext(request.getResponseContext()); - CommandResponse commandResponse = super.buildCommandResponse(request, response); - this.onRequestCompletion(request,commandResponse); + CommandResponse commandResponse = super.buildCommandResponse(response); + this.onRequestCompletion(commandResponse); } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java index a351c4d36..dc61673d0 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java @@ -25,7 +25,6 @@ package org.openecomp.appc.executor.impl; import org.apache.commons.lang3.StringUtils; import org.openecomp.appc.domainmodel.lcm.CommonHeader; import org.openecomp.appc.domainmodel.lcm.RuntimeContext; -import org.openecomp.appc.domainmodel.lcm.Status; import org.openecomp.appc.executor.UnstableVNFException; import org.openecomp.appc.executor.objects.CommandResponse; import org.openecomp.appc.executor.objects.LCMCommandStatus; @@ -33,6 +32,7 @@ import org.openecomp.appc.executor.objects.Params; import org.openecomp.appc.executor.objects.UniqueRequestIdentifier; import org.openecomp.appc.requesthandler.RequestHandler; import org.openecomp.appc.workflow.WorkFlowManager; + import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -40,21 +40,19 @@ public class LCMReadonlyCommandTask extends CommandTask { private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMReadonlyCommandTask.class); - public LCMReadonlyCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager){ - - setRequestHandler(requestHandler); - setWorkflowManager(workflowManager); + public LCMReadonlyCommandTask(RuntimeContext commandRequest, RequestHandler requestHandler, + WorkFlowManager workflowManager) { + super(commandRequest, requestHandler, workflowManager); } - @Override - public void onRequestCompletion(RuntimeContext request, CommandResponse response) { - super.onRequestCompletion(request, response, true); + public void onRequestCompletion(CommandResponse response) { + super.onRequestCompletion(response, true); } @Override public void run() { - RuntimeContext request = getCommandRequest(); + RuntimeContext request = commandRequest; final CommonHeader commonHeader = request.getRequestContext().getCommonHeader(); final boolean forceFlag = commonHeader.getFlags().isForce(); UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(), commonHeader.getRequestId(), commonHeader.getSubRequestId()); diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java index 9757430d8..f2c30990e 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java @@ -54,6 +54,7 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import java.time.Instant; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -71,8 +72,6 @@ public class TestCommandExecutionTask { private static final String TTL_FLAG= "TTL"; private static final String API_VERSION= "2.0.0"; private static final String ORIGINATOR_ID= "1"; - private LCMCommandTask executionTask; - private LCMReadonlyCommandTask LCMReadonlyCommandTask; private CommandTaskFactory factory ; private RequestHandler requestHandler; @@ -118,8 +117,6 @@ public class TestCommandExecutionTask { workflowManager = Mockito.mock(WorkFlowManager.class); lifecyclemanager = Mockito.mock(LifecycleManager.class ); - executionTask = new LCMCommandTask(requestHandler,workflowManager,lifecyclemanager); - LCMReadonlyCommandTask = new LCMReadonlyCommandTask(requestHandler,workflowManager); factory = new CommandTaskFactory(); factory.setLifecyclemanager(lifecyclemanager); factory.setWorkflowManager(workflowManager); @@ -130,9 +127,9 @@ public class TestCommandExecutionTask { @Test public void testFactory(){ - CommandTask task = factory.getExecutionTask("Configure"); + CommandTask task = factory.getExecutionTask("Configure", null); assertEquals(LCMCommandTask.class,task.getClass() ); - task = factory.getExecutionTask("Sync"); + task = factory.getExecutionTask("Sync", null); assertEquals(LCMReadonlyCommandTask.class,task.getClass() ); } @@ -142,37 +139,36 @@ public class TestCommandExecutionTask { @Test public void testOnRequestCompletion(){ Mockito.doNothing().when(requestHandler).onRequestTTLEnd((RuntimeContext) anyObject(),anyBoolean()); - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", ""); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", ""); CommandResponse response = getCommandResponse(VNFOperation.Configure, true, "11", "","1"); - executionTask.onRequestCompletion(request, response); + LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager); + executionTask.onRequestCompletion(response); } @Test public void testRunGetConfig(){ - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); - LCMReadonlyCommandTask.setCommandRequest(request); - LCMReadonlyCommandTask.run(); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); + LCMReadonlyCommandTask readonlyCommandTask = new LCMReadonlyCommandTask(request, requestHandler,workflowManager); + readonlyCommandTask.run(); } @Test public void testRun(){ - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); - executionTask.setCommandRequest(request); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); + LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager); executionTask.run(); } @Test public void testRunNegative(){ - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); - executionTask.setCommandRequest(request); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); + LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager); executionTask.run(); } CommandResponse getCommandResponse(VNFOperation action , boolean success, String responseId, String payload, String vnfId){ - CommandResponse commandResponse = new CommandResponse(); RuntimeContext runtimeContext = new RuntimeContext(); - commandResponse.setRuntimeContext(runtimeContext); ResponseContext responseContext = new ResponseContext(); runtimeContext.setResponseContext(responseContext); RequestContext requestContext = new RequestContext(); @@ -191,9 +187,9 @@ public class TestCommandExecutionTask { responseContext.setStatus(new Status(100, null)); commonHeader.setRequestId(responseId); responseContext.setPayload(payload); - commonHeader.setTimestamp(new Date()); + commonHeader.setTimestamp(Instant.now()); vnfContext.setId(vnfId); - return commandResponse; + return new CommandResponse(runtimeContext); } @@ -201,10 +197,9 @@ public class TestCommandExecutionTask { @Test public void testPositiveFlow_configure() { - Date timeStamp = new Date(); String requestId = "1"; - RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", ""); + RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", ""); } @@ -226,7 +221,7 @@ public class TestCommandExecutionTask { return wfResponse; } - private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ + private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Instant timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects(); RequestContext requestContext = commandExecutorInput.getRequestContext(); ResponseContext responseContext = createResponseContextWithSuObjects(); diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java index bb4e39109..cd33e8b2e 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java @@ -25,12 +25,19 @@ package org.openecomp.appc.executor; */ +import java.time.Instant; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.openecomp.appc.domainmodel.lcm.*; -import org.openecomp.appc.domainmodel.lcm.Flags.Mode; +import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers; +import org.openecomp.appc.domainmodel.lcm.CommonHeader; +import org.openecomp.appc.domainmodel.lcm.Flags; +import org.openecomp.appc.domainmodel.lcm.RequestContext; +import org.openecomp.appc.domainmodel.lcm.RuntimeContext; +import org.openecomp.appc.domainmodel.lcm.VNFContext; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.exceptions.APPCException; import org.openecomp.appc.executionqueue.ExecutionQueueService; import org.openecomp.appc.executor.impl.CommandExecutorImpl; @@ -41,11 +48,6 @@ import org.openecomp.appc.lifecyclemanager.LifecycleManager; import org.openecomp.appc.requesthandler.RequestHandler; import org.openecomp.appc.workflow.WorkFlowManager; -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import static junit.framework.Assert.assertTrue; - @SuppressWarnings("deprecation") public class TestCommandExecutor { @@ -78,8 +80,8 @@ public class TestCommandExecutor { commandExecutor.setExecutionQueueService(executionQueueService); LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class); LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class); - Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure"); - Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync"); + Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null); + Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null); // Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true); } @@ -88,9 +90,8 @@ public class TestCommandExecutor { @Test public void testPositiveFlow_LCM(){ //Map <String,Object> flags = setTTLInFlags("30"); - Date timeStamp = new Date(); String requestId = "1"; - RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ; + RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ; try { commandExecutor.executeCommand(commandExecutorInput); } catch (APPCException e) { @@ -101,10 +102,9 @@ public class TestCommandExecutor { @Test public void testPositiveFlow_GetConfig(){ - Date timeStamp = new Date(); String requestId = "1"; - RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ; + RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ; try { commandExecutor.executeCommand(commandExecutorInput); } catch (APPCException e) { @@ -114,7 +114,7 @@ public class TestCommandExecutor { } - private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ + private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Instant timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects(); RequestContext requestContext = commandExecutorInput.getRequestContext(); requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl)); |