* ============LICENSE_END=========================================================
*/
-package com.att.bpm.scripts
-
-import groovy.util.Node
-import groovy.util.XmlParser;
-import groovy.xml.QName
-
-import java.io.Serializable;
+package org.openecomp.mso.bpmn.common.scripts
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.runtime.Execution
-import org.springframework.web.util.UriUtils
-
-import org.openecomp.mso.rest.APIResponse
-import org.openecomp.mso.rest.RESTClient
-import org.openecomp.mso.rest.RESTConfig
-import org.openecomp.mso.bpmn.core.RollbackData
import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.rest.APIResponse
+import org.springframework.web.util.UriUtils
public class UpdateAAIGenericVnf extends AbstractServiceTaskProcessor {
execution.setVariable('UAAIGenVnf_vnfId', null)
execution.setVariable('UAAIGenVnf_personaModelId', null)
execution.setVariable('UAAIGenVnf_personaModelVersion', null)
+ execution.setVariable("UAAIGenVnf_ipv4OamAddress", null)
+ execution.setVariable('UAAIGenVnf_managementV6Address', null)
execution.setVariable('UAAIGenVnf_getGenericVnfResponseCode' ,null)
execution.setVariable('UAAIGenVnf_getGenericVnfResponse', '')
execution.setVariable('UAAIGenVnf_updateGenericVnfResponseCode', null)
try {
def xml = execution.getVariable('UpdateAAIGenericVnfRequest')
logDebug('Received request xml:\n' + xml, isDebugLogEnabled)
+ utils.logAudit("UpdateAAIGenericVnf Request XML: " + xml)
initProcessVariables(execution)
def vnfId = getRequiredNodeText(execution, xml,'vnf-id')
execution.setVariable('UAAIGenVnf_vnfId', vnfId)
- def personaModelId = getRequiredNodeText(execution, xml,'persona-model-id')
- execution.setVariable('UAAIGenVnf_personaModelId', personaModelId)
+ def personaModelId = getNodeTextForce(xml,'persona-model-id')
+ if (personaModelId != null && !personaModelId.isEmpty()) {
+ execution.setVariable('UAAIGenVnf_personaModelId', personaModelId)
+ }
- def personaModelVersion = getRequiredNodeText(execution, xml,'persona-model-version')
- execution.setVariable('UAAIGenVnf_personaModelVersion', personaModelVersion)
+ def personaModelVersion = getNodeTextForce(xml,'persona-model-version')
+ if (personaModelVersion != null && !personaModelVersion.isEmpty()) {
+ execution.setVariable('UAAIGenVnf_personaModelVersion', personaModelVersion)
+ }
+
+ def ipv4OamAddress = getNodeTextForce(xml, 'ipv4-oam-address')
+ if (ipv4OamAddress != null && !ipv4OamAddress.isEmpty()) {
+ execution.setVariable('UAAIGenVnf_ipv4OamAddress', ipv4OamAddress)
+ }
+
+ def managementV6Address = getNodeTextForce(xml, 'management-v6-address')
+ if (managementV6Address != null && !managementV6Address.isEmpty()) {
+ execution.setVariable('UAAIGenVnf_managementV6Address', managementV6Address)
+ }
logDebug('Exited ' + method, isDebugLogEnabled)
} catch (BpmnError e) {
AaiUtil aaiUriUtil = new AaiUtil(this)
def 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")
-
- String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
+ String endPoint = execution.getVariable('URN_aai_endpoint') + aai_uri + '/' + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
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');
- if (basicAuthCred != null && !"".equals(basicAuthCred)) {
- client.addAuthorizationHeader(basicAuthCred)
- }
-
logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
- APIResponse response = client.httpGet()
-
- responseData = response.getResponseBodyAsString()
+ utils.logAudit("Sending GET to AAI endpoint: " + endPoint)
+
+ APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
+ def responseData = response.getResponseBodyAsString()
execution.setVariable('UAAIGenVnf_getGenericVnfResponseCode', response.getStatusCode())
execution.setVariable('UAAIGenVnf_getGenericVnfResponse', responseData)
+ utils.logAudit("UpdateAAIGenericVnf Response data: " + responseData)
logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
} catch (Exception ex) {
def genericVnf = execution.getVariable('UAAIGenVnf_getGenericVnfResponse')
def origRequest = execution.getVariable('UpdateAAIGenericVnfRequest')
+ utils.logAudit("UpdateGenericVnf Request: " + origRequest)
// Confirm resource-version is in retrieved Generic VNF
def Node genericVnfNode = xmlParser.parseText(genericVnf)
if (utils.getChildNode(genericVnfNode, 'resource-version') == null) {
}
// Handle persona-model-id/persona-model-version
+
def String newPersonaModelId = execution.getVariable('UAAIGenVnf_personaModelId')
def String newPersonaModelVersion = execution.getVariable('UAAIGenVnf_personaModelVersion')
+ if (newPersonaModelId != null || newPersonaModelVersion != null) {
- // Confirm "new" persona-model-id is same as "current" persona-model-id
- def Node currPersonaModelIdNode = utils.getChildNode(genericVnfNode, 'persona-model-id')
- def String currPersonaModelId = ''
- if (currPersonaModelIdNode != null) {
- currPersonaModelId = currPersonaModelIdNode.text()
+ // Confirm "new" persona-model-id is same as "current" persona-model-id
+ def Node currPersonaModelIdNode = utils.getChildNode(genericVnfNode, 'persona-model-id')
+ def String currPersonaModelId = ''
+ if (currPersonaModelIdNode != null) {
+ currPersonaModelId = currPersonaModelIdNode.text()
+ }
+ if (!newPersonaModelId.equals(currPersonaModelId)) {
+ def msg = 'Can\'t update Generic VNF ' + vnfId + ' since there is \'persona-model-id\' mismatch between the current and new values'
+ logError(msg)
+ throw new Exception(msg)
+ }
+
+ // Construct payload
+ updateGenericVnfNode(origRequest, genericVnfNode, 'persona-model-version')
}
- if (!newPersonaModelId.equals(currPersonaModelId)) {
- def msg = 'Can\'t update Generic VNF ' + vnfId + ' since there is \'persona-model-id\' mismatch between the current and new values'
- logError(msg)
- throw new Exception(msg)
+
+ // Handle ipv4-oam-address
+ def String ipv4OamAddress = execution.getVariable('UAAIGenVnf_ipv4OamAddress')
+ if (ipv4OamAddress != null) {
+ // Construct payload
+ updateGenericVnfNode(origRequest, genericVnfNode, 'ipv4-oam-address')
}
- // Construct payload
- updateGenericVnfNode(origRequest, genericVnfNode, 'persona-model-version')
+ // Handle management-v6-address
+ def String managementV6Address = execution.getVariable('UAAIGenVnf_managementV6Address')
+ if (managementV6Address != null) {
+ // Construct payload
+ updateGenericVnfNode(origRequest, genericVnfNode, 'management-v6-address')
+ }
+
def payload = utils.nodeToString(genericVnfNode)
// Construct endpoint
logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
String endPoint = execution.getVariable('URN_aai_endpoint') + aai_uri + '/' + UriUtils.encode(vnfId, "UTF-8")
- String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
-
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');
- if (basicAuthCred != null && !"".equals(basicAuthCred)) {
- client.addAuthorizationHeader(basicAuthCred)
- }
-
logDebug('sending PUT to AAI endpoint \'' + endPoint + '\'' + 'with payload \n' + payload, isDebugLogEnabled)
- APIResponse response = client.httpPut(payload)
-
- responseData = response.getResponseBodyAsString()
+ utils.logAudit("Sending PUT to AAI endpoint: " + endPoint)
+
+ APIResponse response = aaiUriUtil.executeAAIPutCall(execution, endPoint, payload)
+ def responseData = response.getResponseBodyAsString()
execution.setVariable('UAAIGenVnf_updateGenericVnfResponseCode', response.getStatusCode())
execution.setVariable('UAAIGenVnf_updateGenericVnfResponse', responseData)
+ utils.logAudit("UpdateAAIGenericVnf Response Data: " + responseData)
logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
} catch (Exception ex) {
execution.getVariable('UAAIGenVnf_getGenericVnfResponse'))
execution.setVariable('WorkflowException', exception)
+ utils.logAudit("Workflow Exception occurred when handling Quering AAI: " + exception.getErrorMessage())
logDebug('Exited ' + method, isDebugLogEnabled)
}
logError('Error occurred attempting to update Generic VNF in AAI, Response Code ' +
execution.getVariable('UAAIGenVnf_updateGenericVnfResponseCode') + ', Error Response ' +
execution.getVariable('UAAIGenVnf_updateGenericVnfResponse'))
+
String processKey = getProcessKey(execution);
WorkflowException exception = new WorkflowException(processKey, 5000,
execution.getVariable('UAAIGenVnf_updateGenericVnfResponse'))
execution.setVariable('WorkflowException', exception)
+ utils.logAudit("Workflow Exception occurred when Updating GenericVnf: " + exception.getErrorMessage())
logDebug('Exited ' + method, isDebugLogEnabled)
}
}