aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-command-executor/appc-command-executor-core
diff options
context:
space:
mode:
authorPatrick Brady <pb071s@att.com>2017-07-28 11:29:23 -0700
committerPatrick Brady <pb071s@att.com>2017-08-02 15:43:44 +0000
commit38713207b817ed4700f630748c681116338d32f0 (patch)
tree9eb2097cee8d85ac14f17e3a280ae8aefb69d9de /appc-dispatcher/appc-command-executor/appc-command-executor-core
parent771ac55e29d099d8bbf783612de975047d75ab12 (diff)
Merging in bug fixes
Change-Id: I85da90b9ba0d03149f42035a820c76ef0285e413 Signed-off-by: Patrick Brady <pb071s@att.com> Issue: APPC-100
Diffstat (limited to 'appc-dispatcher/appc-command-executor/appc-command-executor-core')
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java30
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java42
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java21
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java2
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml9
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java30
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java43
7 files changed, 125 insertions, 52 deletions
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 55499d75d..5054d34c7 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
@@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.ObjectUtils;
import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
+import org.openecomp.appc.domainmodel.lcm.ActionLevel;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.appc.executionqueue.ExecutionQueueService;
import org.openecomp.appc.executionqueue.impl.ExecutionQueueServiceFactory;
@@ -96,22 +97,6 @@ public class CommandExecutorImpl implements CommandExecutor {
}
RuntimeContext commandRequest;
commandRequest = commandExecutorInput;
- /*
- CommandRequest commandRequest;
-
- switch(commandExecutorInput.getRequestContext().getAction()){
- case Sync:
- case Audit:
- case ConfigBackup:
- case ConfigBackupDelete:
- case ConfigExport:
- commandRequest = new LCMReadOnlyCommandRequest(commandExecutorInput);
- break;
- default:
- commandRequest = new LCMCommandRequest(commandExecutorInput);
- break;
- }
- */
if (logger.isTraceEnabled()) {
logger.trace("Exiting from getCommandRequest with (CommandRequest = "+ ObjectUtils.toString(commandRequest)+")");
}
@@ -125,7 +110,7 @@ public class CommandExecutorImpl implements CommandExecutor {
}
try {
String action = request.getRequestContext().getAction().name();
- CommandTask commandTask = executionTaskFactory.getExecutionTask(action, request);
+ CommandTask commandTask = executionTaskFactory.getExecutionTask(request);
long remainingTTL = getRemainingTTL(request);
executionQueueService.putMessage(commandTask,remainingTTL, TimeUnit.MILLISECONDS);
} catch (Exception e) {
@@ -144,5 +129,16 @@ public class CommandExecutorImpl implements CommandExecutor {
return ChronoUnit.MILLIS.between(Instant.now(), requestTimestamp.plusSeconds(ttl));
}
+ private CommandTask getMessageExecutor(RuntimeContext request){
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to getMessageExecutor with command = "+ request);
+ }
+ CommandTask executionTask = executionTaskFactory.getExecutionTask(request);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting from getMessageExecutor");
+ }
+ return executionTask;
+ }
+
}
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 571f51ed9..c5590f961 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
@@ -25,6 +25,7 @@
package org.openecomp.appc.executor.impl;
+import org.openecomp.appc.domainmodel.lcm.ActionLevel;
import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
import org.openecomp.appc.domainmodel.lcm.VNFOperation;
import org.openecomp.appc.lifecyclemanager.LifecycleManager;
@@ -35,7 +36,12 @@ import org.openecomp.appc.workflow.WorkFlowManager;
public class CommandTaskFactory {
- private RequestHandler requestHandler;
+
+// private LCMCommandTask lcmCommandTask;
+// private LCMReadonlyCommandTask LCMReadonlyCommandTask;
+
+ private RequestHandler vnfRequestHandler;
+ private RequestHandler vmRequestHandler;
private WorkFlowManager workflowManager;
private LifecycleManager lifecyclemanager;
@@ -44,8 +50,12 @@ public class CommandTaskFactory {
this.workflowManager = workflowManager;
}
- public void setRequestHandler(RequestHandler requestHandler) {
- this.requestHandler = requestHandler;
+ public void setVnfRequestHandler(RequestHandler vnfRequestHandler) {
+ this.vnfRequestHandler = vnfRequestHandler;
+ }
+
+ public void setVmRequestHandler(RequestHandler vmRequestHandler) {
+ this.vmRequestHandler = vmRequestHandler;
}
public void setLifecyclemanager(LifecycleManager lifecyclemanager) {
@@ -53,14 +63,30 @@ public class CommandTaskFactory {
}
- public synchronized CommandTask getExecutionTask(String action, RuntimeContext commandRequest){
- if (VNFOperation.Sync.toString().equals(action) || VNFOperation.Audit.toString().equals(action) || VNFOperation.ConfigBackup.toString().equals(action) ||
- VNFOperation.ConfigBackupDelete.toString().equals(action) || VNFOperation.ConfigExport.toString().equals(action)){
- return new LCMReadonlyCommandTask(commandRequest, requestHandler,workflowManager);
+ public synchronized CommandTask getExecutionTask(RuntimeContext runtimeContext){
+ String action = runtimeContext.getRequestContext().getAction().name();
+ ActionLevel actionLevel = runtimeContext.getRequestContext().getActionLevel();
+ RequestHandler requestHandler = readRequestHandler(actionLevel);
+ if(ActionLevel.VM.equals(actionLevel)){
+ return new LCMReadonlyCommandTask(runtimeContext,requestHandler,workflowManager);
+ }
+ if (VNFOperation.Sync.toString().equals(action) ||
+ VNFOperation.Audit.toString().equals(action) ||
+ VNFOperation.ConfigBackup.toString().equals(action) ||
+ VNFOperation.ConfigBackupDelete.toString().equals(action) ||
+ VNFOperation.ConfigExport.toString().equals(action)){
+ return new LCMReadonlyCommandTask(runtimeContext,requestHandler,workflowManager);
}else {
- return new LCMCommandTask(commandRequest, requestHandler,workflowManager,
+ return new LCMCommandTask(runtimeContext,requestHandler,workflowManager,
lifecyclemanager);
}
}
+ private RequestHandler readRequestHandler(ActionLevel actionLevel) {
+ if (ActionLevel.VM.equals(actionLevel)) {
+ return vmRequestHandler;
+ }
+ return vnfRequestHandler;
+ }
+
}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java
index 46a15f1da..7aa4cd167 100644
--- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java
@@ -25,24 +25,39 @@
package org.openecomp.appc.executor.impl;
import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
+import org.openecomp.appc.domainmodel.lcm.ActionLevel;
import org.openecomp.appc.executionqueue.MessageExpirationListener;
import org.openecomp.appc.requesthandler.RequestHandler;
public class ExpiredMessageHandler<M> implements MessageExpirationListener<M>{
- private RequestHandler requestHandler;
+ private RequestHandler vnfRequestHandler;
+
+ private RequestHandler vmRequestHandler;
public ExpiredMessageHandler(){
}
- public void setRequestHandler(RequestHandler requestHandler) {
- this.requestHandler = requestHandler;
+ public void setVnfRequestHandler(RequestHandler vnfRequestHandler) {
+ this.vnfRequestHandler = vnfRequestHandler;
+ }
+
+ public void setVmRequestHandler(RequestHandler vmRequestHandler) {
+ this.vmRequestHandler = vmRequestHandler;
}
@Override
public void onMessageExpiration(M message) {
RuntimeContext commandRequest = (RuntimeContext)message;
+ RequestHandler requestHandler = readRequestHandler(commandRequest);
requestHandler.onRequestTTLEnd(commandRequest, true);
}
+
+ private RequestHandler readRequestHandler(RuntimeContext runtimeContext) {
+ if(ActionLevel.VM.equals(runtimeContext.getRequestContext().getActionLevel())){
+ return vmRequestHandler;
+ }
+ return vnfRequestHandler;
+ }
}
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 bba735a19..aadfd3a9c 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
@@ -55,10 +55,10 @@ import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.slf4j.MDC;
-import java.net.InetAddress;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import java.net.InetAddress;
import static com.att.eelf.configuration.Configuration.*;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index fd99cbe47..f84e97207 100644
--- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -36,18 +36,21 @@
</bean>
<bean id="CommandExecutionTaskFactory" class="org.openecomp.appc.executor.impl.CommandTaskFactory" scope="singleton" >
- <property name="requestHandler" ref="RequestHandlerRef" />
+ <property name="vnfRequestHandler" ref="vnfRequestHandlerService" />
+ <property name="vmRequestHandler" ref="vmRequestHandlerService"/>
<property name="workflowManager" ref="WorkFlowManagerRef" />
<property name="lifecyclemanager" ref="LifecyclemanagerRef" />
</bean>
<bean id="expiredMessageHandlerBean" class="org.openecomp.appc.executor.impl.ExpiredMessageHandler"
scope="singleton">
- <property name="requestHandler" ref="RequestHandlerRef" />
+ <property name="vnfRequestHandler" ref="vnfRequestHandlerService" />
+ <property name="vmRequestHandler" ref="vmRequestHandlerService"/>
</bean>
<reference id="WorkFlowManagerRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.workflow.WorkFlowManager" />
- <reference id="RequestHandlerRef" availability="optional" activation="eager" interface="org.openecomp.appc.requesthandler.RequestHandler" />
+ <reference id="vnfRequestHandlerService" availability="optional" activation="eager" interface="org.openecomp.appc.requesthandler.RequestHandler" filter="(level=VNF)" />
+ <reference id="vmRequestHandlerService" availability="optional" activation="eager" interface="org.openecomp.appc.requesthandler.RequestHandler" filter="(level=VM)" />
<reference id="LifecyclemanagerRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.lifecyclemanager.LifecycleManager" />
<service id="commandExecutorService" interface="org.openecomp.appc.executor.CommandExecutor" ref="commandExecutorBean"/>
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 ee28fa844..460f0e7ad 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
@@ -123,16 +123,23 @@ public class TestCommandExecutionTask {
factory = new CommandTaskFactory();
factory.setLifecyclemanager(lifecyclemanager);
factory.setWorkflowManager(workflowManager);
- factory.setRequestHandler(requestHandler);
+ factory.setVnfRequestHandler(requestHandler);
Mockito.when(workflowManager.executeWorkflow((WorkflowRequest)anyObject())).thenReturn(getWorkflowResponse () );
}
@Test
public void testFactory(){
- CommandTask task = factory.getExecutionTask("Configure", null);
+ CommandTask task;
+ Instant timeStamp = Instant.now();
+ String requestId = "1";
+ RuntimeContext commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
+ task = factory.getExecutionTask(commandExecutorInputConfigure);
assertEquals(LCMCommandTask.class,task.getClass() );
- task = factory.getExecutionTask("Sync", null);
+ RuntimeContext commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
+ task = factory.getExecutionTask(commandExecutorInputSync);
assertEquals(LCMReadonlyCommandTask.class,task.getClass() );
}
@@ -215,6 +222,22 @@ public class TestCommandExecutionTask {
}
+ private RuntimeContext getConfigCommandRequest(String vnfType , Integer ttl , Instant timeStamp, String requestId,
+ Map<String,Object> flags, VNFOperation command , String vnfId, String vnfVersion ){
+
+ RuntimeContext commandExecutorInput = pouplateCommandExecutorInput(vnfType, ttl, vnfVersion, timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", command, vnfId, "");
+
+ return commandExecutorInput;
+ }
+
+ private RuntimeContext getLCMCommandRequest(String vnfType , Integer ttl ,Instant timeStamp, String requestId,
+ Map<String,Object> flags, VNFOperation command , String vnfId, String vnfVersion ){
+
+ RuntimeContext commandExecutorInput = pouplateCommandExecutorInput(vnfType, ttl, vnfVersion, timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", command, vnfId, "");
+
+ return commandExecutorInput;
+ }
+
public WorkflowResponse getWorkflowResponse (){
WorkflowResponse wfResponse = new WorkflowResponse();
ResponseContext responseContext = createResponseContextWithSuObjects();
@@ -275,4 +298,3 @@ public class TestCommandExecutionTask {
}
}
-
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 30b731782..fa9257faa 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
@@ -24,7 +24,7 @@
package org.openecomp.appc.executor;
/**
- *
+ *
*/
@@ -43,31 +43,41 @@ 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;
-import org.openecomp.appc.executor.impl.CommandTaskFactory;
-import org.openecomp.appc.executor.impl.LCMCommandTask;
-import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
+import org.openecomp.appc.executor.impl.*;
import org.openecomp.appc.lifecyclemanager.LifecycleManager;
import org.openecomp.appc.requesthandler.RequestHandler;
import org.openecomp.appc.workflow.WorkFlowManager;
+import org.powermock.api.mockito.PowerMockito;
+
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+import static junit.framework.Assert.assertTrue;
+import static org.powermock.api.support.membermodification.MemberMatcher.method;
@SuppressWarnings("deprecation")
public class TestCommandExecutor {
- private static final String TTL_FLAG= "TTL";
- private static final String API_VERSION= "2.0.0";
- private static final String ORIGINATOR_ID= "1";
+ private static final String TTL_FLAG= "TTL";
+ private static final String API_VERSION= "2.0.0";
+ private static final String ORIGINATOR_ID= "1";
- CommandExecutorImpl commandExecutor;
+ private CommandExecutorImpl commandExecutor;
- CommandTaskFactory executionTaskFactory;
+ private CommandTaskFactory executionTaskFactory;
private RequestHandler requestHandler;
private WorkFlowManager workflowManager;
private LifecycleManager lifecyclemanager;
private ExecutionQueueService executionQueueService;
+ private Instant timeStamp = Instant.now();
+ private String requestId = "1";
+ private RuntimeContext commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30000, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
+ private RuntimeContext commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
@Before
public void init()throws Exception {
@@ -82,16 +92,18 @@ public class TestCommandExecutor {
commandExecutor.setExecutionTaskFactory(executionTaskFactory);
commandExecutor.setExecutionQueueService(executionQueueService);
LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
- LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
- Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null);
- Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null);
+ LCMReadonlyCommandTask lCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
+
+ Mockito.when(executionTaskFactory.getExecutionTask(commandExecutorInputConfigure)).thenReturn(lcmCommandTask);
+ Mockito.when(executionTaskFactory.getExecutionTask(commandExecutorInputSync)).thenReturn(lCMReadonlyCommandTask);
+
// Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
}
-
+
@Test
- public void testPositiveFlow_LCM(){
+ public void testPositiveFlow_LCM() throws Exception {
//Map <String,Object> flags = setTTLInFlags("30");
String requestId = "1";
RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
@@ -153,4 +165,3 @@ public class TestCommandExecutor {
}
-