diff options
Diffstat (limited to 'appc-dispatcher/appc-command-executor')
8 files changed, 128 insertions, 55 deletions
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/LCMCommandStatus.java b/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/LCMCommandStatus.java index cdff419d1..44588d0df 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/LCMCommandStatus.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/LCMCommandStatus.java @@ -35,10 +35,10 @@ public enum LCMCommandStatus { ACCEPTED(100,"ACCEPTED - request accepted"), - //ERROR(2xx) – request can’t be handled due to some technical error + //ERROR(2xx) - request can't be handled due to some technical error UNEXPECTED_ERROR(200,"UNEXPECTED ERROR - ${errorMsg}"), - //REJECT(3xx) – request has been rejected due to some business reason (e.g. no such service-instance-id, command is not supported, etc) + //REJECT(3xx) - request has been rejected due to some business reason (e.g. no such service-instance-id, command is not supported, etc) REJECTED(300,"REJECTED - ${errorMsg}"), INVALID_INPUT_PARAMETER(301,"INVALID INPUT PARAMETER - ${errorMsg}"),// TODO 77777777 to support "${paramName} with invalid value ${paramValue}" MISSING_MANDATORY_PARAMETER(302,"MISSING MANDATORY PARAMETER - Parameter/s ${paramName} is/are missing" ), @@ -57,7 +57,7 @@ public enum LCMCommandStatus { SUCCESS(400,"SUCCESS - request has been processed successfully"), - // FAILURE(5xx) – request processing results with failure. The FAILURE response is always transmitted asynchronously, via DMaaP. + // FAILURE(5xx) - request processing results with failure. The FAILURE response is always transmitted asynchronously, via DMaaP. DG_FAILURE(401,"DG FAILURE - ${errorMsg}"), NO_TRANSITION_DEFINE_FAILURE(402,"NO TRANSITION DEFINE - No Transition Defined for ${actionName} action and ${currentState} state"), UPDATE_AAI_FAILURE(403,"UPDATE_AAI_FAILURE - failed to update AAI. ${errorMsg}"), 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 { } - |