* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* 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
package org.onap.so.bpmn.common.scripts
+import org.onap.so.logger.LoggingAnchor
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.logger.ErrorCode
+
import javax.ws.rs.core.Response
import org.apache.commons.lang3.*
import org.camunda.bpm.engine.delegate.BpmnError
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.client.HttpClient
import org.onap.so.logger.MessageEnum
-import org.onap.so.logger.MsoLogger
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
import org.onap.so.utils.TargetEntity
import java.util.UUID
-
class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
- private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfAdapterRestV1.class);
+ private static final Logger logger = LoggerFactory.getLogger( VnfAdapterRestV1.class);
ExceptionUtil exceptionUtil = new ExceptionUtil()
def method = getClass().getSimpleName() + '.preProcessRequest(' +
'execution=' + execution.getId() +
')'
- msoLogger.trace('Entered ' + method)
+ logger.trace('Entered ' + method)
def prefix="VNFREST_"
execution.setVariable("prefix", prefix)
Node root = new XmlParser().parseText(request)
String requestType = root.name()
execution.setVariable(prefix + 'requestType', requestType)
- msoLogger.debug(getProcessKey(execution) + ': ' + prefix + 'requestType = ' + requestType)
+ logger.debug(getProcessKey(execution) + ': ' + prefix + 'requestType = ' + requestType)
- msoLogger.debug('VnfAdapterRestV1, request: ' + request)
+ logger.debug('VnfAdapterRestV1, request: ' + request)
// Get the messageId from the request
String messageId = getChildText(root, 'messageId')
if (messageId == null || messageId.isEmpty()) {
String msg = getProcessKey(execution) + ': no messageId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
execution.setVariable('VNFAResponse_CORRELATOR', messageId)
- msoLogger.debug(getProcessKey(execution) + ': VNFAResponse_CORRELATOR = ' + messageId)
+ logger.debug(getProcessKey(execution) + ': VNFAResponse_CORRELATOR = ' + messageId)
// Get the notificationUrl from the request
if (notificationUrl == null || notificationUrl.isEmpty()) {
String msg = getProcessKey(execution) + ': no notificationUrl in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
execution.setVariable(prefix + 'notificationUrl', notificationUrl)
- msoLogger.debug(getProcessKey(execution) + ': ' + prefix + 'notificationUrl = ' + notificationUrl)
+ logger.debug(getProcessKey(execution) + ': ' + prefix + 'notificationUrl = ' + notificationUrl)
// Determine the VnfAdapter endpoint
if (vnfAdapterEndpoint == null || vnfAdapterEndpoint.isEmpty()) {
String msg = getProcessKey(execution) + ': mso:adapters:vnf:rest:endpoint URN mapping is not defined'
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
while (vnfAdapterEndpoint.endsWith('/')) {
if (vnfId == null || vnfId.isEmpty()) {
String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
vnfAdapterMethod = 'POST'
if (vnfId == null || vnfId.isEmpty()) {
String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
String vfModuleId = getChildText(root, 'vfModuleId')
if (vfModuleId == null || vfModuleId.isEmpty()) {
String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
vnfAdapterMethod = 'PUT'
if (vnfId == null || vnfId.isEmpty()) {
String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
String vfModuleId = getChildText(root, 'vfModuleId')
if (vfModuleId == null || vfModuleId.isEmpty()) {
String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
vnfAdapterMethod = 'DELETE'
if (vfModuleRollbackNode == null) {
String msg = getProcessKey(execution) + ': no vfModuleRollback in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
String vnfId = getChildText(vfModuleRollbackNode, 'vnfId')
if (vnfId == null || vnfId.isEmpty()) {
String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
String vfModuleId = getChildText(vfModuleRollbackNode, 'vfModuleId')
if (vfModuleId == null || vfModuleId.isEmpty()) {
String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
vnfAdapterMethod = 'DELETE'
if (volumeGroupId == null || volumeGroupId.isEmpty()) {
String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
vnfAdapterMethod = 'PUT'
if (volumeGroupId == null || volumeGroupId.isEmpty()) {
String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
vnfAdapterMethod = 'DELETE'
if (volumeGroupId == null || volumeGroupId.isEmpty()) {
String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
vnfAdapterMethod = 'DELETE'
} else {
String msg = getProcessKey(execution) + ': Unsupported request type: ' + requestType
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
execution.setVariable(prefix + 'vnfAdapterMethod', vnfAdapterMethod)
- msoLogger.debug(getProcessKey(execution) + ': ' + prefix + 'vnfAdapterMethod = ' + vnfAdapterMethod)
+ logger.debug(getProcessKey(execution) + ': ' + prefix + 'vnfAdapterMethod = ' + vnfAdapterMethod)
execution.setVariable(prefix + 'vnfAdapterUrl', vnfAdapterUrl)
- msoLogger.debug(getProcessKey(execution) + ': ' + prefix + 'vnfAdapterUrl = ' + vnfAdapterUrl)
+ logger.debug(getProcessKey(execution) + ': ' + prefix + 'vnfAdapterUrl = ' + vnfAdapterUrl)
execution.setVariable(prefix + 'vnfAdapterRequest', vnfAdapterRequest)
- msoLogger.debug(getProcessKey(execution) + ': ' + prefix + 'vnfAdapterRequest = \n' + vnfAdapterRequest)
+ logger.debug(getProcessKey(execution) + ': ' + prefix + 'vnfAdapterRequest = \n' + vnfAdapterRequest)
// Get the Basic Auth credentials for the VnfAdapter
String basicAuthValue = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
if (basicAuthValue == null || basicAuthValue.isEmpty()) {
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, getProcessKey(execution) + ": mso:adapters:po:auth URN mapping is not defined", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+ getProcessKey(execution) + ": mso:adapters:po:auth URN mapping is not defined", "BPMN",
+ ErrorCode.UnknownError.getValue());
} else {
try {
def encodedString = utils.getBasicAuth(basicAuthValue, UrnPropertiesReader.getVariable("mso.msoKey", execution))
execution.setVariable(prefix + 'basicAuthHeaderValue', encodedString)
} catch (IOException ex) {
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, getProcessKey(execution) + ": Unable to encode BasicAuth credentials for VnfAdapter", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+ getProcessKey(execution) + ": Unable to encode BasicAuth credentials for VnfAdapter",
+ "BPMN", ErrorCode.UnknownError.getValue(), ex);
}
}
} catch (BpmnError e) {
- msoLogger.debug(" Rethrowing MSOWorkflowException")
+ logger.debug(" Rethrowing MSOWorkflowException")
throw e
} catch (Exception e) {
String msg = 'Caught exception in ' + method + ": " + e
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- msoLogger.debug(msg)
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
}
def method = getClass().getSimpleName() + '.sendRequestToVnfAdapter(' +
'execution=' + execution.getId() +
')'
- msoLogger.trace('Entered ' + method)
+ logger.trace('Entered ' + method)
String prefix = execution.getVariable('prefix')
URL url = new URL(vnfAdapterUrl);
- HttpClient httpClient = new HttpClient(url, "application/xml", TargetEntity.VNF_ADAPTER)
+ HttpClient httpClient = new HttpClientFactory().newXmlClient(url, TargetEntity.VNF_ADAPTER)
httpClient.addAdditionalHeader("Authorization", execution.getVariable(prefix + "basicAuthHeaderValue"))
httpClient.addAdditionalHeader("X-ONAP-RequestID", execution.getVariable("mso-request-id"))
response = httpClient.delete(vnfAdapterRequest)
} else {
String msg = 'Unsupported HTTP method "' + vnfAdapterMethod + '" in ' + method + ": " + e
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
execution.setVariable(prefix + "vnfAdapterStatusCode", response.getStatus())
throw e
} catch (Exception e) {
String msg = 'Caught exception in ' + method + ": " + e
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+ ErrorCode.UnknownError.getValue());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
}
}
def method = getClass().getSimpleName() + '.processCallback(' +
'execution=' + execution.getId() +
')'
- msoLogger.trace('Entered ' + method)
+ logger.trace('Entered ' + method)
String callback = execution.getVariable('VNFAResponse_MESSAGE')
try {
- msoLogger.debug(getProcessKey(execution) + ": received callback:\n" + callback)
+ logger.debug(getProcessKey(execution) + ": received callback:\n" + callback)
// The XML callback is available to the calling flow in any case,
// even if a WorkflowException is generated.
// TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead.
execution.setVariable("WorkflowResponse", callback)
+ callback = utils.removeXmlPreamble(callback)
+
Node root = new XmlParser().parseText(callback)
if (root.name().endsWith('Exception')) {
vnfAdapterWorkflowException(execution, callback)
}
} catch (Exception e) {
- e.printStackTrace()
- callback = callback == null || String.valueOf(callback).isEmpty() ? "NONE" : callback
- String msg = "Received error from VnfAdapter: " + callback
- msoLogger.debug(getProcessKey(execution) + ': ' + msg)
- exceptionUtil.buildWorkflowException(execution, 7020, msg)
+ logger.debug("Error encountered within VnfAdapterRest ProcessCallback method: {}", e.getMessage(), e)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7020, "Error encountered within VnfAdapterRest ProcessCallback method", TargetEntity.SO)
}
}
String rolledBack = getChildText(root, "rolledBack")
rolledBack = rolledBack == null || rolledBack.isEmpty() ? "" : " rolledBack='" + rolledBack + "'"
exceptionUtil.buildWorkflowException(execution, 7020, "Received " + root.name() +
- " from VnfAdapter:" + category + message + rolledBack);
+ " from VnfAdapter:" + category + message + rolledBack, TargetEntity.OPENSTACK);
} catch (Exception e) {
response = response == null || String.valueOf(response).isEmpty() ? "NONE" : response
- exceptionUtil.buildWorkflowException(execution, 7020, "Received error from VnfAdapter: " + response)
+ exceptionUtil.buildWorkflowException(execution, 7020, "Received error from VnfAdapter: " + response, TargetEntity.OPENSTACK)
}
}
Node child = getChild(node, name)
return child == null ? null : child.text()
}
+
+ public Logger getLogger() {
+ return logger;
+ }
}