2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.appc.executor.impl;
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;
32 import java.net.InetAddress;
34 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
35 import org.openecomp.appc.domainmodel.lcm.Status;
36 import org.openecomp.appc.executor.impl.objects.CommandRequest;
37 import org.openecomp.appc.executor.objects.CommandResponse;
38 import org.openecomp.appc.executor.objects.LCMCommandStatus;
39 import org.openecomp.appc.executor.objects.Params;
40 import org.openecomp.appc.logging.LoggingConstants;
41 import org.openecomp.appc.requesthandler.RequestHandler;
42 import org.openecomp.appc.workflow.WorkFlowManager;
43 import org.openecomp.appc.workflow.objects.WorkflowRequest;
44 import org.openecomp.appc.workflow.objects.WorkflowResponse;
45 import com.att.eelf.configuration.EELFLogger;
46 import com.att.eelf.configuration.EELFManager;
50 * This abstract class is base class for all Command tasks. All command task must inherit this class.
53 public abstract class CommandTask<M> implements Runnable {
55 protected RequestHandler requestHandler;
56 protected WorkFlowManager workflowManager;
58 private CommandRequest commandRequest;
60 public CommandRequest getCommandRequest() {
61 return commandRequest;
64 public void setCommandRequest(CommandRequest commandRequest) {
65 this.commandRequest = commandRequest;
68 private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class);
70 public void setWorkflowManager(WorkFlowManager workflowManager) {
71 this.workflowManager = workflowManager;
74 public void setRequestHandler(RequestHandler requestHandler) {
75 this.requestHandler = requestHandler;
81 public void onRequestCompletion(CommandRequest request, CommandResponse response , boolean isAAIUpdated) {
82 logger.debug("Entry: onRequestCompletion()");
83 requestHandler.onRequestExecutionEnd(request.getCommandExecutorInput().getRuntimeContext(), isAAIUpdated);
86 public abstract void onRequestCompletion(CommandRequest request, CommandResponse response);
88 protected CommandResponse buildCommandResponse(CommandRequest request, WorkflowResponse response) {
90 CommandResponse commandResponse = new CommandResponse();
91 commandResponse.setRuntimeContext(request.getCommandExecutorInput().getRuntimeContext());
92 return commandResponse;
96 public void execute() {
97 final RuntimeContext runtimeContext = commandRequest.getCommandExecutorInput().getRuntimeContext();
98 MDC.put(MDC_KEY_REQUEST_ID, runtimeContext.getRequestContext().getCommonHeader().getRequestId());
99 if (runtimeContext.getRequestContext().getActionIdentifiers().getServiceInstanceId() != null)
100 MDC.put(MDC_SERVICE_INSTANCE_ID, runtimeContext.getRequestContext().getActionIdentifiers().getServiceInstanceId());
101 MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, runtimeContext.getRequestContext().getCommonHeader().getOriginatorId());
102 MDC.put(MDC_SERVICE_NAME, runtimeContext.getRequestContext().getAction().name());
104 MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); //Don't change it to a .getLocalHostName() again please. It's wrong!
105 MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
107 logger.debug(e.getMessage());
109 MDC.put(MDC_INSTANCE_UUID, ""); //TODO make instanse_UUID generation once during APPC-instanse deploying
111 WorkflowRequest workflowRequest = new WorkflowRequest();
112 workflowRequest.setRequestContext(runtimeContext.getRequestContext());
113 workflowRequest.setResponseContext(runtimeContext.getResponseContext());
114 workflowRequest.setVnfContext(runtimeContext.getVnfContext());
116 WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest);
118 CommandResponse commandResponse = buildCommandResponse(commandRequest, response);
119 this.onRequestCompletion(commandRequest,commandResponse);