* ================================================================================
* 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
* ============LICENSE_END=========================================================
*/
-package org.onap.so.bpmn.vcpe.scripts;
+package org.onap.so.bpmn.vcpe.scripts
-import org.onap.so.bpmn.common.scripts.*;
-import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
-import org.onap.so.bpmn.core.WorkflowException
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
-import org.onap.so.bpmn.common.scripts.AaiUtil
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
-import org.onap.so.rest.APIResponse
-
-import java.util.UUID;
-import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.apache.commons.lang3.*
-import org.springframework.web.util.UriUtils;
-import static org.apache.commons.lang3.StringUtils.*
-import org.onap.so.bpmn.core.UrnPropertiesReader;
-
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.bpmn.core.WorkflowException
+import org.onap.so.logger.ErrorCode
import org.onap.so.logger.MessageEnum
-import org.onap.so.logger.MsoLogger
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
/**
* This groovy class supports the <class>DoDeleteAllottedResourceTXC.bpmn</class> process.
*
*/
public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{
- private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteAllottedResourceTXC.class);
+ private static final Logger logger = LoggerFactory.getLogger(DoDeleteAllottedResourceTXC.class);
String Prefix="DDARTXC_"
ExceptionUtil exceptionUtil = new ExceptionUtil()
public void preProcessRequest (DelegateExecution execution) {
String msg = ""
- msoLogger.trace("start preProcessRequest")
+ logger.trace("start preProcessRequest")
try {
execution.setVariable("prefix", Prefix)
String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
if (isBlank(sdncCallbackUrl)) {
msg = "mso.workflow.sdncadapter.callback is null"
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
}
execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
- msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
+ logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
//Request Inputs
if (isBlank(execution.getVariable("serviceInstanceId"))){
msg = "Input serviceInstanceId is null"
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
}
if (isBlank(execution.getVariable("allottedResourceId"))){
msg = "Input allottedResourceId is null"
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
}
}catch(BpmnError b){
- msoLogger.debug("Rethrowing MSOWorkflowException")
+ logger.debug("Rethrowing MSOWorkflowException")
throw b
} catch (Exception ex){
msg = "Exception in preProcessRequest " + ex.getMessage()
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- msoLogger.trace("end preProcessRequest")
+ logger.trace("end preProcessRequest")
}
public void getAaiAR (DelegateExecution execution) {
- msoLogger.trace("start getAaiAR")
+ logger.trace("start getAaiAR")
String allottedResourceId = execution.getVariable("allottedResourceId")
- AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
- String ar = arUtils.getARbyId(execution, allottedResourceId)
+ AllottedResourceUtils arUtils = getAllottedResourceUtils()
+ boolean ifExistsAR = arUtils.ifExistsAR(execution, allottedResourceId)
String errorMsg = ""
- if (isBlank(ar)) // AR was !found
- {
- errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
- }
- else
- {
+ if (ifExistsAR){
String aaiARPath = execution.getVariable("aaiARPath")
String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
}
+ else{
+ errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
+ }
if (!isBlank(errorMsg)) {
- msoLogger.debug(errorMsg)
+ logger.debug(errorMsg)
exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
}
- msoLogger.trace("end getAaiAR")
+ logger.trace("end getAaiAR")
+
+ }
+ public AllottedResourceUtils getAllottedResourceUtils(){
+ return new AllottedResourceUtils(this)
}
// aaiARPath set during query (existing AR)
public void updateAaiAROrchStatus(DelegateExecution execution, String status){
- msoLogger.trace("start updateAaiAROrchStatus")
+ logger.trace("start updateAaiAROrchStatus")
AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
- msoLogger.trace("end updateAaiAROrchStatus")
+ logger.trace("end updateAaiAROrchStatus")
}
public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
String msg = ""
- msoLogger.trace("start buildSDNCRequest")
+ logger.trace("start buildSDNCRequest")
String sdncReq = null
try {
</sdncadapterworkflow:SDNCRequestData>
</sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
- msoLogger.debug("sdncRequest:\n" + sdncReq)
+ logger.debug("sdncRequest:\n" + sdncReq)
sdncReq = utils.formatXml(sdncReq)
} catch(Exception ex) {
msg = "Exception in buildSDNCRequest. " + ex.getMessage()
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- msoLogger.trace("end buildSDNCRequest")
+ logger.trace("end buildSDNCRequest")
return sdncReq
}
public void preProcessSDNCUnassign(DelegateExecution execution) {
String msg = ""
- msoLogger.trace("start preProcessSDNCUnassign")
+ logger.trace("start preProcessSDNCUnassign")
try {
String sdncRequestId = UUID.randomUUID().toString()
String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
- msoLogger.debug("sdncUnassignRequest: " + sdncUnassignReq)
+ logger.debug("sdncUnassignRequest: " + sdncUnassignReq)
} catch (BpmnError e) {
throw e;
} catch(Exception ex) {
msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- msoLogger.trace("end preProcessSDNCUnassign")
+ logger.trace("end preProcessSDNCUnassign")
}
public void preProcessSDNCDelete(DelegateExecution execution) {
String msg = ""
- msoLogger.trace("start preProcessSDNCDelete")
+ logger.trace("start preProcessSDNCDelete")
try {
String sdncRequestId = UUID.randomUUID().toString()
String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
- msoLogger.debug("sdncDeleteReq: " + sdncDeleteReq)
+ logger.debug("sdncDeleteReq: " + sdncDeleteReq)
} catch (BpmnError e) {
throw e;
} catch(Exception ex) {
msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- msoLogger.trace("end preProcessSDNCDelete")
+ logger.trace("end preProcessSDNCDelete")
}
public void preProcessSDNCDeactivate(DelegateExecution execution) {
String msg = ""
- msoLogger.trace("start preProcessSDNCDeactivate")
+ logger.trace("start preProcessSDNCDeactivate")
try {
String sdncRequestId = UUID.randomUUID().toString()
String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
- msoLogger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
+ logger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
} catch (BpmnError e) {
throw e;
} catch(Exception ex) {
msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- msoLogger.trace("end preProcessSDNCDeactivate")
+ logger.trace("end preProcessSDNCDeactivate")
}
public void validateSDNCResp(DelegateExecution execution, String response, String method){
- msoLogger.trace("start ValidateSDNCResponse Process")
+ logger.trace("start ValidateSDNCResponse Process")
String msg = ""
try {
WorkflowException workflowException = execution.getVariable("WorkflowException")
- msoLogger.debug("workflowException: " + workflowException)
+ logger.debug("workflowException: " + workflowException)
boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
- msoLogger.debug("SDNCResponse: " + response)
+ logger.debug("SDNCResponse: " + response)
SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
- msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
-
+ logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n"
+ + response)
}else{
String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
- msoLogger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode)
+ logger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:"
+ + sdncRespCode)
if (sdncRespCode.equals("404") && "deactivate".equals(method))
{
execution.setVariable("ARNotFoundInSDNC", true)
if ("true".equals(execution.getVariable("failNotFound")))
{
msg = "Allotted Resource Not found in SDNC"
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
else
throw e;
} catch(Exception ex) {
msg = "Exception in validateSDNCResp. " + ex.getMessage()
- msoLogger.debug(msg)
+ logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- msoLogger.trace("end Exit ValidateSDNCResp Process")
+ logger.trace("end Exit ValidateSDNCResp Process")
}
public void deleteAaiAR(DelegateExecution execution){
- msoLogger.trace("start deleteAaiAR")
+ logger.trace("start deleteAaiAR")
try{
AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
- String ar = null //need to get resource-version again
String arLink = execution.getVariable("aaiARPath")
- if (!isBlank(arLink))
- {
- ar = arUtils.getARbyLink(execution, arLink, "")
- }
- arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
+ arUtils.deleteAR(execution, arLink)
} catch (BpmnError e) {
throw e;
}catch(Exception ex){
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + ex);
+ logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+ "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN",
+ ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
}
- msoLogger.trace("end deleteAaiAR")
+ logger.trace("end deleteAaiAR")
}
}