Remove CommandExecutorInput
[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 static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
25 import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
26 import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
27 import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
28 import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
29 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
30 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
31
32 import java.net.InetAddress;
33
34 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
35 import org.openecomp.appc.domainmodel.lcm.Status;
36 import org.openecomp.appc.executor.objects.CommandResponse;
37 import org.openecomp.appc.executor.objects.LCMCommandStatus;
38 import org.openecomp.appc.executor.objects.Params;
39 import org.openecomp.appc.logging.LoggingConstants;
40 import org.openecomp.appc.requesthandler.RequestHandler;
41 import org.openecomp.appc.workflow.WorkFlowManager;
42 import org.openecomp.appc.workflow.objects.WorkflowRequest;
43 import org.openecomp.appc.workflow.objects.WorkflowResponse;
44 import com.att.eelf.configuration.EELFLogger;
45 import com.att.eelf.configuration.EELFManager;
46 import org.slf4j.MDC;
47
48 /**
49  * This abstract class is base class for all Command tasks. All command task must inherit this class.
50  */
51
52 public abstract class CommandTask implements Runnable {
53
54     protected RequestHandler requestHandler;
55     protected WorkFlowManager workflowManager;
56
57     private RuntimeContext commandRequest;
58
59     public RuntimeContext getCommandRequest() {
60         return commandRequest;
61     }
62
63     public void setCommandRequest(RuntimeContext commandRequest) {
64         this.commandRequest = commandRequest;
65     }
66
67     private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class);
68
69     public void setWorkflowManager(WorkFlowManager workflowManager) {
70         this.workflowManager = workflowManager;
71     }
72
73     public void setRequestHandler(RequestHandler requestHandler) {
74         this.requestHandler = requestHandler;
75     }
76
77     CommandTask(){
78     }
79
80     public void onRequestCompletion(RuntimeContext request, CommandResponse response , boolean isAAIUpdated) {
81         logger.debug("Entry: onRequestCompletion()");
82         requestHandler.onRequestExecutionEnd(request, isAAIUpdated);
83     }
84
85     public abstract void onRequestCompletion(RuntimeContext request, CommandResponse response);
86
87     protected CommandResponse buildCommandResponse(RuntimeContext request, WorkflowResponse response) {
88
89         CommandResponse commandResponse = new CommandResponse();
90         commandResponse.setRuntimeContext(request);
91         return commandResponse;
92     }
93
94
95     public void execute() {
96         final RuntimeContext runtimeContext = commandRequest;
97         MDC.put(MDC_KEY_REQUEST_ID, runtimeContext.getRequestContext().getCommonHeader().getRequestId());
98         if (runtimeContext.getRequestContext().getActionIdentifiers().getServiceInstanceId() != null)
99             MDC.put(MDC_SERVICE_INSTANCE_ID, runtimeContext.getRequestContext().getActionIdentifiers().getServiceInstanceId());
100         MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, runtimeContext.getRequestContext().getCommonHeader().getOriginatorId());
101         MDC.put(MDC_SERVICE_NAME, runtimeContext.getRequestContext().getAction().name());
102         try {
103             MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); //Don't change it to a .getLocalHostName() again please. It's wrong!
104             MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
105         }catch(Exception e){
106             logger.debug(e.getMessage());
107         }
108         MDC.put(MDC_INSTANCE_UUID, ""); //TODO make instanse_UUID generation once during APPC-instanse deploying
109
110         WorkflowRequest workflowRequest = new WorkflowRequest();
111         workflowRequest.setRequestContext(runtimeContext.getRequestContext());
112         workflowRequest.setResponseContext(runtimeContext.getResponseContext());
113         workflowRequest.setVnfContext(runtimeContext.getVnfContext());
114
115         WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest);
116
117         CommandResponse commandResponse =  buildCommandResponse(commandRequest, response);
118         this.onRequestCompletion(commandRequest,commandResponse);
119     }
120
121 }