Design Services updates
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-core / src / main / java / org / onap / appc / executor / impl / CommandTaskFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.executor.impl;
26
27
28 import org.onap.appc.domainmodel.lcm.ActionLevel;
29 import org.onap.appc.domainmodel.lcm.RuntimeContext;
30 import org.onap.appc.lifecyclemanager.LifecycleManager;
31 import org.onap.appc.requesthandler.RequestHandler;
32 import org.onap.appc.workflow.WorkFlowManager;
33
34
35
36
37 public class CommandTaskFactory {
38
39 //    private LCMCommandTask lcmCommandTask;
40 //    private LCMReadonlyCommandTask LCMReadonlyCommandTask;
41
42     private RequestHandler vnfRequestHandler;
43     private RequestHandler vmRequestHandler;
44     private WorkFlowManager workflowManager;
45     private LifecycleManager lifecyclemanager;
46
47
48     public void setWorkflowManager(WorkFlowManager workflowManager) {
49         this.workflowManager = workflowManager;
50     }
51
52     public void setVnfRequestHandler(RequestHandler vnfRequestHandler) {
53         this.vnfRequestHandler = vnfRequestHandler;
54     }
55
56     public void setVmRequestHandler(RequestHandler vmRequestHandler) {
57         this.vmRequestHandler = vmRequestHandler;
58     }
59
60     public void setLifecyclemanager(LifecycleManager lifecyclemanager) {
61         this.lifecyclemanager = lifecyclemanager;
62     }
63
64
65     public synchronized CommandTask getExecutionTask(RuntimeContext runtimeContext){
66         String action = runtimeContext.getRequestContext().getAction().name();
67         ActionLevel actionLevel = runtimeContext.getRequestContext().getActionLevel();
68         RequestHandler requestHandler = readRequestHandler(actionLevel);
69         if(ActionLevel.VM.equals(actionLevel)){
70             return new LCMReadonlyCommandTask(runtimeContext,requestHandler,workflowManager);
71         }
72         switch (runtimeContext.getRequestContext().getAction().getOperationType()){
73             case ReadOnly:
74             case OperationStatusUpdate:
75                 return new LCMReadonlyCommandTask(runtimeContext,requestHandler,workflowManager);
76             default:
77                 return new LCMCommandTask(runtimeContext,requestHandler,workflowManager,
78                         lifecyclemanager);
79         }
80     }
81
82     private RequestHandler readRequestHandler(ActionLevel actionLevel) {
83         if (ActionLevel.VM.equals(actionLevel)) {
84             return vmRequestHandler;
85         }
86         return vnfRequestHandler;
87     }
88
89 }