Merge of new rebased code
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-core / src / main / java / org / openecomp / appc / executor / impl / CommandTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.executor.impl;
23
24 import org.openecomp.appc.domainmodel.lcm.Status;
25 import org.openecomp.appc.executor.objects.CommandResponse;
26 import org.openecomp.appc.executor.objects.LCMCommandStatus;
27 import org.openecomp.appc.executor.objects.Params;
28 import org.openecomp.appc.requesthandler.RequestHandler;
29 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
30 import org.openecomp.appc.workflow.WorkFlowManager;
31 import org.openecomp.appc.workflow.objects.WorkflowRequest;
32 import org.openecomp.appc.workflow.objects.WorkflowResponse;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35
36 /**
37  * This abstract class is base class for all Command tasks. All command task must inherit this class.
38  */
39
40 public abstract class CommandTask implements Runnable {
41
42     protected final RequestHandler requestHandler;
43     protected final WorkFlowManager workflowManager;
44     protected final RuntimeContext commandRequest;
45
46     protected CommandTask(RuntimeContext commandRequest, RequestHandler requestHandler,
47             WorkFlowManager workflowManager) {
48         super();
49         this.commandRequest = commandRequest;
50         this.requestHandler = requestHandler;
51         this.workflowManager = workflowManager;
52     }
53
54     private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class);
55
56     public void onRequestCompletion(CommandResponse response, boolean isAAIUpdated) {
57         logger.debug("Entry: onRequestCompletion()");
58         requestHandler.onRequestExecutionEnd(commandRequest, isAAIUpdated);
59     }
60
61     public abstract void onRequestCompletion(CommandResponse response);
62
63     protected CommandResponse buildCommandResponse(WorkflowResponse response) {
64
65         return new CommandResponse(commandRequest);
66     }
67
68
69     public void execute() {
70         final RuntimeContext runtimeContext = commandRequest;
71         WorkflowRequest workflowRequest = new WorkflowRequest();
72         workflowRequest.setRequestContext(runtimeContext.getRequestContext());
73         workflowRequest.setResponseContext(runtimeContext.getResponseContext());
74         workflowRequest.setVnfContext(runtimeContext.getVnfContext());
75
76         WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest);
77
78         CommandResponse commandResponse = buildCommandResponse(response);
79         this.onRequestCompletion(commandResponse);
80     }
81
82 }