5a7550cc4e04bb5769b2da8d36c1eda3ea907474
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-core / src / main / java / org / openecomp / 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.openecomp.appc.executor.impl;
26
27
28 import org.openecomp.appc.domainmodel.lcm.ActionLevel;
29 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
30 import org.openecomp.appc.domainmodel.lcm.VNFOperation;
31 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
32 import org.openecomp.appc.requesthandler.RequestHandler;
33 import org.openecomp.appc.workflow.WorkFlowManager;
34
35
36
37
38 public class CommandTaskFactory {
39
40 //    private LCMCommandTask lcmCommandTask;
41 //    private LCMReadonlyCommandTask LCMReadonlyCommandTask;
42
43     private RequestHandler vnfRequestHandler;
44     private RequestHandler vmRequestHandler;
45     private WorkFlowManager workflowManager;
46     private LifecycleManager lifecyclemanager;
47
48
49     public void setWorkflowManager(WorkFlowManager workflowManager) {
50         this.workflowManager = workflowManager;
51     }
52
53     public void setVnfRequestHandler(RequestHandler vnfRequestHandler) {
54         this.vnfRequestHandler = vnfRequestHandler;
55     }
56
57     public void setVmRequestHandler(RequestHandler vmRequestHandler) {
58         this.vmRequestHandler = vmRequestHandler;
59     }
60
61     public void setLifecyclemanager(LifecycleManager lifecyclemanager) {
62         this.lifecyclemanager = lifecyclemanager;
63     }
64
65
66     public synchronized CommandTask getExecutionTask(RuntimeContext runtimeContext){
67         String action = runtimeContext.getRequestContext().getAction().name();
68         ActionLevel actionLevel = runtimeContext.getRequestContext().getActionLevel();
69         RequestHandler requestHandler = readRequestHandler(actionLevel);
70         if(ActionLevel.VM.equals(actionLevel)){
71             return new LCMReadonlyCommandTask(runtimeContext,requestHandler,workflowManager);
72         }
73         switch (runtimeContext.getRequestContext().getAction().getOperationType()){
74             case ReadOnly:
75             case OperationStatusUpdate:
76                 return new LCMReadonlyCommandTask(runtimeContext,requestHandler,workflowManager);
77             default:
78                 return new LCMCommandTask(runtimeContext,requestHandler,workflowManager,
79                         lifecyclemanager);
80         }
81     }
82
83     private RequestHandler readRequestHandler(ActionLevel actionLevel) {
84         if (ActionLevel.VM.equals(actionLevel)) {
85             return vmRequestHandler;
86         }
87         return vnfRequestHandler;
88     }
89
90 }