import javax.xml.parsers.DocumentBuilderFactory
import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.runtime.Execution
+import org.camunda.bpm.engine.delegate.DelegateExecution
import org.openecomp.mso.bpmn.common.scripts.AaiUtil
import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
import org.xml.sax.InputSource
import org.w3c.dom.Node
import org.w3c.dom.NodeList;
+import org.openecomp.mso.rest.RESTClient
+import org.openecomp.mso.rest.RESTConfig
/* Subflow for Delete VF Module. When no DoDeleteVfModuleRequest is specified on input,
* @param - cloudConfiguration*
* @param - sdncVersion ("1610")
* @param - retainResources
+* @param - aLaCarte
*
* Outputs:
* @param - WorkflowException
ExceptionUtil exceptionUtil = new ExceptionUtil()
JsonUtils jsonUtil = new JsonUtils()
- public void initProcessVariables(Execution execution) {
+ public void initProcessVariables(DelegateExecution execution) {
execution.setVariable("prefix",Prefix)
execution.setVariable("DoDVfMod_contrailNetworkPolicyFqdnList", null)
execution.setVariable("DoDVfMod_oamManagementV4Address", null)
// parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
// and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
- public void preProcessRequest(Execution execution) {
+ public void preProcessRequest(DelegateExecution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
initProcessVariables(execution)
if (retainResources == null) {
retainResources = false
}
- execution.setVariable("retainResources", retainResources)
+ execution.setVariable("retainResources", retainResources)
}
else {
// build a SDNC vnf-topology-operation request for the specified action
// (note: the action passed is expected to be 'changedelete' or 'delete')
- public void prepSDNCAdapterRequest(Execution execution, String action) {
+ public void prepSDNCAdapterRequest(DelegateExecution execution, String action) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
String uuid = execution.getVariable('testReqId') // for junits
// parse the incoming DELETE_VF_MODULE request
// and formulate the outgoing VnfAdapterDeleteV1 request
- public void prepVNFAdapterRequest(Execution execution) {
+ public void prepVNFAdapterRequest(DelegateExecution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
def requestId = UUID.randomUUID().toString()
def origRequestId = execution.getVariable('requestId')
// parse the incoming DELETE_VF_MODULE request
// and formulate the outgoing UpdateAAIVfModuleRequest request
- public void prepUpdateAAIVfModule(Execution execution) {
+ public void prepUpdateAAIVfModule(DelegateExecution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
def vnfId = execution.getVariable("vnfId")
def vfModuleId = execution.getVariable("vfModuleId")
// parse the incoming DELETE_VF_MODULE request
// and formulate the outgoing DeleteAAIVfModuleRequest request
- public void prepDeleteAAIVfModule(Execution execution) {
+ public void prepDeleteAAIVfModule(DelegateExecution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
def vnfId = execution.getVariable("vnfId")
// generates a WorkflowException if
// -
- public void handleDoDeleteVfModuleFailure(Execution execution) {
+ public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
utils.log("ERROR", "AAI error occurred deleting the Generic Vnf: "
+ execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), isDebugEnabled)
execution.setVariable("WorkflowException", exception)
}
- public void sdncValidateResponse(Execution execution, String response){
+ public void sdncValidateResponse(DelegateExecution execution, String response){
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
execution.setVariable("prefix",Prefix)
}
}
- public void postProcessVNFAdapterRequest(Execution execution) {
+ public void postProcessVNFAdapterRequest(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
'execution=' + execution.getId() +
')'
logDebug(" *** COMPLETED postProcessVnfAdapterResponse Process*** ", isDebugLogEnabled)
}
- public void deleteNetworkPoliciesFromAAI(Execution execution) {
+ public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
'execution=' + execution.getId() +
')'
*
* @param execution The flow's execution instance.
*/
- public void prepUpdateAAIGenericVnf(Execution execution) {
+ public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
'execution=' + execution.getId() +
')'
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
}
}
+
+ /**
+ * Using the vnfId and vfModuleId provided in the inputs,
+ * query AAI to get the corresponding VF Module info.
+ * A 200 response is expected with the VF Module info in the response body,
+ * Will determine VF Module's orchestration status if one exists
+ *
+ * @param execution The flow's execution instance.
+ */
+ public void queryAAIVfModuleForStatus(DelegateExecution execution) {
+ def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
+ def method = getClass().getSimpleName() + '.queryAAIVfModuleForStatus(' +
+ 'execution=' + execution.getId() +
+ ')'
+ logDebug('Entered ' + method, isDebugLogEnabled)
+
+ execution.setVariable(Prefix + 'orchestrationStatus', '')
+
+ try {
+ def vnfId = execution.getVariable('vnfId')
+ def vfModuleId = execution.getVariable('vfModuleId')
+
+ AaiUtil aaiUriUtil = new AaiUtil(this)
+ String aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
+ logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
+
+ String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") +
+ "/vf-modules/vf-module/" + UriUtils.encode(vfModuleId, "UTF-8")
+ utils.logAudit("AAI endPoint: " + endPoint)
+
+ try {
+ RESTConfig config = new RESTConfig(endPoint);
+ def responseData = ''
+ def aaiRequestId = UUID.randomUUID().toString()
+ RESTClient client = new RESTClient(config).
+ addHeader('X-TransactionId', aaiRequestId).
+ addHeader('X-FromAppId', 'MSO').
+ addHeader('Content-Type', 'application/xml').
+ addHeader('Accept','application/xml');
+ logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
+ APIResponse response = client.httpGet()
+ utils.logAudit("createVfModule - invoking httpGet() to AAI")
+
+ responseData = response.getResponseBodyAsString()
+ if (responseData != null) {
+ logDebug("Received generic VNF data: " + responseData, isDebugLogEnabled)
+
+ }
+
+ utils.logAudit("deleteVfModule - queryAAIVfModule Response: " + responseData)
+ utils.logAudit("deleteVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
+
+ execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponseCode', response.getStatusCode())
+ execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponse', responseData)
+ logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
+ logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
+ // Retrieve VF Module info and its orchestration status; if not found, do nothing
+ if (response.getStatusCode() == 200) {
+ // Parse the VNF record from A&AI to find base module info
+ logDebug('Parsing the VNF data to find orchestration status', isDebugLogEnabled)
+ if (responseData != null) {
+ def vfModuleText = utils.getNodeXml(responseData, "vf-module")
+ //def xmlVfModule= new XmlSlurper().parseText(vfModuleText)
+ def orchestrationStatus = utils.getNodeText1(vfModuleText, "orchestration-status")
+ execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
+ logDebug("Received orchestration status from A&AI: " + orchestrationStatus, isDebugLogEnabled)
+
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace()
+ logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
+ }
+ logDebug('Exited ' + method, isDebugLogEnabled)
+ } catch (BpmnError e) {
+ throw e;
+ } catch (Exception e) {
+ logError('Caught exception in ' + method, e)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModuleForStatus(): ' + e.getMessage())
+ }
+ }
+