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