5e4904b6e80d9d11ec6f4d57e691c9329720dcea
[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  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.executor.impl;
24
25 import org.openecomp.appc.domainmodel.lcm.Status;
26 import org.openecomp.appc.executor.objects.CommandResponse;
27 import org.openecomp.appc.executor.objects.LCMCommandStatus;
28 import org.openecomp.appc.executor.objects.Params;
29 import org.openecomp.appc.requesthandler.RequestHandler;
30 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
31 import org.openecomp.appc.workflow.WorkFlowManager;
32 import org.openecomp.appc.workflow.objects.WorkflowRequest;
33 import org.openecomp.appc.workflow.objects.WorkflowResponse;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
36
37 /**
38  * This abstract class is base class for all Command tasks. All command task must inherit this class.
39  */
40
41 public abstract class CommandTask implements Runnable {
42
43     protected final RequestHandler requestHandler;
44     protected final WorkFlowManager workflowManager;
45     protected final RuntimeContext commandRequest;
46
47     protected CommandTask(RuntimeContext commandRequest, RequestHandler requestHandler,
48             WorkFlowManager workflowManager) {
49         super();
50         this.commandRequest = commandRequest;
51         this.requestHandler = requestHandler;
52         this.workflowManager = workflowManager;
53     }
54
55     private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class);
56
57     public void onRequestCompletion(CommandResponse response, boolean isAAIUpdated) {
58         logger.debug("Entry: onRequestCompletion()");
59         requestHandler.onRequestExecutionEnd(commandRequest, isAAIUpdated);
60     }
61
62     public abstract void onRequestCompletion(CommandResponse response);
63
64     protected CommandResponse buildCommandResponse(WorkflowResponse response) {
65
66         return new CommandResponse(commandRequest);
67     }
68
69
70     public void execute() {
71         final RuntimeContext runtimeContext = commandRequest;
72         WorkflowRequest workflowRequest = new WorkflowRequest();
73         workflowRequest.setRequestContext(runtimeContext.getRequestContext());
74         workflowRequest.setResponseContext(runtimeContext.getResponseContext());
75         workflowRequest.setVnfContext(runtimeContext.getVnfContext());
76
77         WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest);
78
79         CommandResponse commandResponse = buildCommandResponse(response);
80         this.onRequestCompletion(commandResponse);
81     }
82
83 }