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.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;
49 * This abstract class is base class for all Command tasks. All command task must inherit this class.
52 public abstract class CommandTask implements Runnable {
54 protected RequestHandler requestHandler;
55 protected WorkFlowManager workflowManager;
57 private RuntimeContext commandRequest;
59 public RuntimeContext getCommandRequest() {
60 return commandRequest;
63 public void setCommandRequest(RuntimeContext commandRequest) {
64 this.commandRequest = commandRequest;
67 private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class);
69 public void setWorkflowManager(WorkFlowManager workflowManager) {
70 this.workflowManager = workflowManager;
73 public void setRequestHandler(RequestHandler requestHandler) {
74 this.requestHandler = requestHandler;
80 public void onRequestCompletion(RuntimeContext request, CommandResponse response , boolean isAAIUpdated) {
81 logger.debug("Entry: onRequestCompletion()");
82 requestHandler.onRequestExecutionEnd(request, isAAIUpdated);
85 public abstract void onRequestCompletion(RuntimeContext request, CommandResponse response);
87 protected CommandResponse buildCommandResponse(RuntimeContext request, WorkflowResponse response) {
89 CommandResponse commandResponse = new CommandResponse();
90 commandResponse.setRuntimeContext(request);
91 return commandResponse;
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());
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());
106 logger.debug(e.getMessage());
108 MDC.put(MDC_INSTANCE_UUID, ""); //TODO make instanse_UUID generation once during APPC-instanse deploying
110 WorkflowRequest workflowRequest = new WorkflowRequest();
111 workflowRequest.setRequestContext(runtimeContext.getRequestContext());
112 workflowRequest.setResponseContext(runtimeContext.getResponseContext());
113 workflowRequest.setVnfContext(runtimeContext.getVnfContext());
115 WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest);
117 CommandResponse commandResponse = buildCommandResponse(commandRequest, response);
118 this.onRequestCompletion(commandRequest,commandResponse);