/*-
* ============LICENSE_START=======================================================
- * openECOMP : APP-C
+ * ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.appc.executor.impl;
+package org.onap.appc.executor.impl;
+
+import java.util.HashMap;
+import java.util.Map;
import org.apache.commons.lang3.StringUtils;
-import org.openecomp.appc.domainmodel.lcm.CommonHeader;
-import org.openecomp.appc.domainmodel.lcm.Status;
-import org.openecomp.appc.domainmodel.lcm.VNFOperation;
-import org.openecomp.appc.executor.UnstableVNFException;
-import org.openecomp.appc.executor.objects.CommandExecutorInput;
-import org.openecomp.appc.executor.objects.CommandResponse;
-import org.openecomp.appc.executor.objects.LCMCommandStatus;
-import org.openecomp.appc.executor.objects.Params;
-import org.openecomp.appc.executor.objects.UniqueRequestIdentifier;
-import org.openecomp.appc.lifecyclemanager.LifecycleManager;
-import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
-import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
-import org.openecomp.appc.lifecyclemanager.objects.VNFOperationOutcome;
-import org.openecomp.appc.requesthandler.RequestHandler;
-import org.openecomp.appc.workflow.WorkFlowManager;
-import org.openecomp.appc.workflow.objects.WorkflowResponse;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.openecomp.sdnc.sli.SvcLogicException;
-import org.openecomp.sdnc.sli.SvcLogicResource;
-import org.openecomp.sdnc.sli.aai.AAIService;
+import org.onap.appc.domainmodel.lcm.CommonHeader;
+import org.onap.appc.domainmodel.lcm.RuntimeContext;
+import org.onap.appc.domainmodel.lcm.Status;
+import org.onap.appc.domainmodel.lcm.VNFOperation;
+import org.onap.appc.executor.UnstableVNFException;
+import org.onap.appc.executor.objects.CommandResponse;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.executor.objects.Params;
+import org.onap.appc.executor.objects.UniqueRequestIdentifier;
+import org.onap.appc.lifecyclemanager.LifecycleManager;
+import org.onap.appc.lifecyclemanager.objects.LifecycleException;
+import org.onap.appc.lifecyclemanager.objects.NoTransitionDefinedException;
+import org.onap.appc.lifecyclemanager.objects.VNFOperationOutcome;
+import org.onap.appc.logging.LoggingConstants;
+import org.onap.appc.requesthandler.RequestHandler;
+import org.onap.appc.workflow.WorkFlowManager;
+import org.onap.appc.workflow.objects.WorkflowResponse;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.onap.ccsdk.sli.adaptors.aai.AAIService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
+import org.slf4j.MDC;
-import java.util.HashMap;
-import java.util.Map;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.net.InetAddress;
+import static com.att.eelf.configuration.Configuration.*;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
public class LCMCommandTask extends CommandTask {
- private AAIService aaiService;
- private LifecycleManager lifecyclemanager;
+ private final AAIService aaiService;
+ private final LifecycleManager lifecyclemanager;
private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMCommandTask.class);
- public LCMCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager,
- LifecycleManager lifecyclemanager){
- setRequestHandler(requestHandler);
- setWorkflowManager(workflowManager);
- setLifecyclemanager(lifecyclemanager);
- getAAIservice();
- }
-
- public void setLifecyclemanager(LifecycleManager lifecyclemanager) {
- this.lifecyclemanager = lifecyclemanager;
- }
+ public LCMCommandTask(RuntimeContext commandRequest, RequestHandler requestHandler, WorkFlowManager workflowManager,
+ LifecycleManager lifecyclemanager) {
+ super(commandRequest, requestHandler, workflowManager);
+ this.lifecyclemanager = lifecyclemanager;
-
- private void getAAIservice() {
BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext();
// Get AAIadapter reference
ServiceReference sref = bctx.getServiceReference(AAIService.class.getName());
} else {
logger.info("AAIService error from bundlecontext");
logger.warn("Cannot find service reference for org.openecomp.sdnc.sli.aai.AAIService");
-
+ aaiService = null;
}
}
@Override
- public void onRequestCompletion(CommandExecutorInput request, CommandResponse response) {
-
- boolean isAAIUpdated = false;
+ public void onRequestCompletion(CommandResponse response) {
+ final RuntimeContext request = commandRequest;
+ boolean isAAIUpdated = false;
try {
- final int statusCode = request.getRuntimeContext().getResponseContext().getStatus().getCode();
+ final int statusCode = request.getResponseContext().getStatus().getCode();
if (logger.isDebugEnabled()) {
logger.debug("Workflow Execution Status = "+ statusCode);
boolean isSuccess = statusCode == 100 || statusCode == 400;
- if (isSuccess && VNFOperation.Terminate == request.getRuntimeContext().getRequestContext().getAction()) {
+ if (isSuccess && VNFOperation.Terminate == request.getRequestContext().getAction()) {
SvcLogicContext ctx = new SvcLogicContext();
- ctx = getVnfdata(request.getRuntimeContext().getVnfContext().getId(), "vnf", ctx);
- isAAIUpdated = aaiService.deleteGenericVnfData(request.getRuntimeContext().getVnfContext().getId(), ctx.getAttribute("vnf.resource-version"));
+ ctx = getVnfdata(request.getVnfContext().getId(), "vnf", ctx);
+ isAAIUpdated = aaiService.deleteGenericVnfData(request.getVnfContext().getId(), ctx.getAttribute("vnf.resource-version"));
}
else{
- isAAIUpdated = updateAAI(request.getRuntimeContext().getVnfContext().getId() , false, isSuccess);
+ isAAIUpdated = updateAAI(request.getVnfContext().getId() , false, isSuccess);
}
logger.debug("isAAIUpdated = " + isAAIUpdated);
+ if(!isAAIUpdated){
+ throw new Exception();
+ }
}
catch(Exception e1) {
logger.error("Exception = " + e1);
+ // In case of any errors we are updating the response status code and message
+ Status updatedStatus = new Status(401, "Fail to update VNF status in A&AI");
+ request.getResponseContext().setStatus(updatedStatus);
throw new RuntimeException(e1);
}
finally {
- super.onRequestCompletion(request, response , isAAIUpdated);
+ super.onRequestCompletion(response, isAAIUpdated);
}
}
@Override
public void run() {
- CommandExecutorInput request = getCommandRequest();
- boolean isAAIUpdated;
- final String vnfId = request.getRuntimeContext().getVnfContext().getId();
- final String vnfType = request.getRuntimeContext().getVnfContext().getType();
+ final RuntimeContext request = commandRequest;
+ setInitialLogProperties(request);
+ boolean isAAIUpdated = false;
+ final String vnfId = request.getVnfContext().getId();
+ final String vnfType = request.getVnfContext().getType();
try {
- final CommonHeader commonHeader = request.getRuntimeContext().getRequestContext().getCommonHeader();
+ final CommonHeader commonHeader = request.getRequestContext().getCommonHeader();
final boolean forceFlag = commonHeader.getFlags().isForce();
UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(),
commonHeader.getRequestId(), commonHeader.getSubRequestId());
String requestIdentifierString = requestIdentifier.toIdentifierString();
requestHandler.onRequestExecutionStart(vnfId,false, requestIdentifierString, forceFlag);
- final String currentStatus = request.getRuntimeContext().getVnfContext().getStatus();
- final VNFOperation action = request.getRuntimeContext().getRequestContext().getAction();
+ final String currentStatus = request.getVnfContext().getStatus();
+ final VNFOperation action = request.getRequestContext().getAction();
final String nextState = lifecyclemanager.getNextState(vnfType, currentStatus, action.name());
} catch (NoTransitionDefinedException e) {
logger.error("Error getting Next State for AAI Update: " + e.getMessage(), e);
Params params = new Params().addParam("actionName",e.event).addParam("currentState",e.currentState);
- request.getRuntimeContext().getResponseContext().setStatus(LCMCommandStatus.NO_TRANSITION_DEFINE_FAILURE.toStatus(params));
+ request.getResponseContext().setStatus(LCMCommandStatus.NO_TRANSITION_DEFINE_FAILURE.toStatus(params));
isAAIUpdated = false;
} catch (UnstableVNFException e) {
logger.error(e.getMessage(), e);
Params params = new Params().addParam("vnfId",vnfId);
- request.getRuntimeContext().getResponseContext().setStatus(LCMCommandStatus.UNSTABLE_VNF_FAILURE.toStatus(params));
+ request.getResponseContext().setStatus(LCMCommandStatus.UNSTABLE_VNF_FAILURE.toStatus(params));
isAAIUpdated = false;
}catch (Exception e) {
logger.error("Error before Request Execution starts.", e);
String errorMsg = StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage();
Params params = new Params().addParam("errorMsg",errorMsg);
- request.getRuntimeContext().getResponseContext().setStatus(LCMCommandStatus.UNEXPECTED_FAILURE.toStatus(params));
+ request.getResponseContext().setStatus(LCMCommandStatus.UNEXPECTED_FAILURE.toStatus(params));
isAAIUpdated = false;
}
String errorMsg = "Error updating A& AI before Workflow execution";
logger.error(errorMsg);
WorkflowResponse response = new WorkflowResponse();
- response.setResponseContext(request.getRuntimeContext().getResponseContext());
- CommandResponse commandResponse = super.buildCommandResponse(request, response);
- this.onRequestCompletion(request,commandResponse);
+ response.setResponseContext(request.getResponseContext());
+ CommandResponse commandResponse = super.buildCommandResponse(response);
+ this.onRequestCompletion(commandResponse);
}
- }
+ clearRequestLogProperties();
+ }
- private boolean updateAAI(String vnf_id , boolean isTTLEnd , boolean executionStatus)
+ private boolean updateAAI(String vnf_id, boolean isTTLEnd, boolean executionStatus)
{
String orchestrationStatus = null;
String nextState;
private SvcLogicContext getVnfdata(String vnf_id, String prefix,SvcLogicContext ctx) {
- String key="vnf-id = '"+ vnf_id+"'";
+ String key="generic-vnf.vnf-id = '"+ vnf_id+"'"+" AND http-header.Real-Time = 'true'";
logger.debug("inside getVnfdata=== "+key);
try {
SvcLogicResource.QueryStatus response = aaiService.query("generic-vnf", false, null, key,prefix, null, ctx);
return false;
}
+ protected void setInitialLogProperties(RuntimeContext request)
+ {
+ MDC.put(MDC_KEY_REQUEST_ID, request.getRequestContext().getCommonHeader().getRequestId());
+ if (request.getRequestContext().getActionIdentifiers().getServiceInstanceId() != null)
+ MDC.put(MDC_SERVICE_INSTANCE_ID, request.getRequestContext().getActionIdentifiers().getServiceInstanceId());
+ MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, request.getRequestContext().getCommonHeader().getOriginatorId());
+ MDC.put(MDC_SERVICE_NAME, request.getRequestContext().getAction().name());
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ logger.debug(e.getMessage());
+ }
+ MDC.put(MDC_INSTANCE_UUID, ""); //TODO make instanse_UUID generation once during APPC-instanse deploying
+ }
+
+ protected void clearRequestLogProperties()
+ {
+ try {
+ MDC.remove(MDC_KEY_REQUEST_ID);
+ MDC.remove(MDC_SERVICE_INSTANCE_ID);
+ MDC.remove(MDC_SERVICE_NAME);
+ MDC.remove(LoggingConstants.MDCKeys.PARTNER_NAME);
+ } catch (Exception e) {
+
+ }
+ }
}