* ============LICENSE_END=========================================================
*/
-package com.att.bpm.scripts
-import java.io.Serializable;
-
+package org.openecomp.mso.bpmn.common.scripts
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 CreateAAIVfModule extends AbstractServiceTaskProcessor{
execution.setVariable("CAAIVfMod_serviceId",null)
execution.setVariable("CAAIVfMod_personaId",null)
execution.setVariable("CAAIVfMod_personaVer",null)
+ execution.setVariable("CAAIVfMod_modelCustomizationId",null)
execution.setVariable("CAAIVfMod_vnfPersonaId",null)
execution.setVariable("CAAIVfMod_vnfPersonaVer",null)
execution.setVariable("CAAIVfMod_isBaseVfModule", false)
// and VF Module data in the flow Execution
public void preProcessRequest(Execution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
- def xml = execution.getVariable("CreateAAIVfModuleRequest")
- utils.log("DEBUG", "input request xml:" + xml, isDebugEnabled)
initProcessVariables(execution)
- def vnfId = ""
- if (utils.nodeExists(xml, "vnf-id")) {
- vnfId = utils.getNodeText(xml,"vnf-id")
- }
- if (vnfId.isEmpty()) {
+ def vnfId = execution.getVariable("vnfId")
+ if (vnfId == null || vnfId.isEmpty()) {
execution.setVariable("CAAIVfMod_newGenericVnf", true)
+ execution.setVariable("CAAIVfMod_vnfId","")
}
- execution.setVariable("CAAIVfMod_vnfId",vnfId)
-
- def vnfName = ""
- if (utils.nodeExists(xml, "vnf-name")) {
- vnfName = utils.getNodeText(xml,"vnf-name")
+ else {
+ execution.setVariable("CAAIVfMod_vnfId",vnfId)
}
+
+ def vnfName = execution.getVariable("vnfName")
execution.setVariable("CAAIVfMod_vnfName", vnfName)
- if (utils.nodeExists(xml, "vnf-type")) {
- execution.setVariable("CAAIVfMod_vnfType",utils.getNodeText(xml,"vnf-type"))
+ String vnfType = execution.getVariable("vnfType")
+ if (vnfType != null && !vnfType.isEmpty()) {
+ execution.setVariable("CAAIVfMod_vnfType", vnfType)
} else {
execution.setVariable("CAAIVfMod_vnfType","")
}
- execution.setVariable("CAAIVfMod_serviceId",utils.getNodeText(xml,"service-id"))
+ execution.setVariable("CAAIVfMod_serviceId", execution.getVariable("serviceId"))
+
+ String personaModelId = execution.getVariable("personaModelId")
- if (utils.nodeExists(xml, "persona-model-id")) {
- execution.setVariable("CAAIVfMod_personaId",utils.getNodeText(xml,"persona-model-id"))
+ if (personaModelId != null && !personaModelId.isEmpty()) {
+ execution.setVariable("CAAIVfMod_personaId",personaModelId)
} else {
execution.setVariable("CAAIVfMod_personaId","")
}
+
+ String personaModelVersion = execution.getVariable("personaModelVersion")
- if (utils.nodeExists(xml, "persona-model-version")) {
- execution.setVariable("CAAIVfMod_personaVer",utils.getNodeText(xml,"persona-model-version"))
+ if (personaModelVersion != null && !personaModelVersion.isEmpty()) {
+ execution.setVariable("CAAIVfMod_personaVer", personaModelVersion)
} else {
execution.setVariable("CAAIVfMod_personaVer","")
}
- if (utils.nodeExists(xml, "vnf-persona-model-id")) {
- execution.setVariable("CAAIVfMod_vnfPersonaId",utils.getNodeText(xml,"vnf-persona-model-id"))
+
+ String modelCustomizationId = execution.getVariable("modelCustomizationId")
+
+ if (modelCustomizationId != null && !modelCustomizationId.isEmpty()) {
+ execution.setVariable("CAAIVfMod_modelCustomizationId",modelCustomizationId)
+ } else {
+ execution.setVariable("CAAIVfMod_modelCustomizationId","")
+ }
+
+ String vnfPersonaModelId = execution.getVariable("vnfPersonaModelId")
+
+ if (vnfPersonaModelId != null && !vnfPersonaModelId.isEmpty()) {
+ execution.setVariable("CAAIVfMod_vnfPersonaId",vnfPersonaModelId)
} else {
execution.setVariable("CAAIVfMod_vnfPersonaId","")
}
+
+ String vnfPersonaModelVersion = execution.getVariable("vnfPersonaModelVersion")
- if (utils.nodeExists(xml, "vnf-persona-model-version")) {
- execution.setVariable("CAAIVfMod_vnfPersonaVer",utils.getNodeText(xml,"vnf-persona-model-version"))
+ if (vnfPersonaModelVersion != null && !vnfPersonaModelVersion.isEmpty()) {
+ execution.setVariable("CAAIVfMod_vnfPersonaVer",vnfPersonaModelVersion)
} else {
execution.setVariable("CAAIVfMod_vnfPersonaVer","")
}
//isBaseVfModule
Boolean isBaseVfModule = false
- if (utils.nodeExists(xml, "is-base-vf-module")) {
- String isBaseVfModuleString = utils.getNodeText(xml, "is-base-vf-module")
- if (isBaseVfModuleString.equals("true")) {
- isBaseVfModule = true
- }
+ String isBaseVfModuleString = execution.getVariable("isBaseVfModule")
+ if (isBaseVfModuleString != null && isBaseVfModuleString.equals("true")) {
+ isBaseVfModule = true
}
execution.setVariable("CAAIVfMod_isBaseVfModule", isBaseVfModule)
logDebug("VID Request received", isDebugEnabled)
}
- execution.setVariable("CAAIVfMod_moduleName",utils.getNodeText(xml,"vf-module-name"))
- execution.setVariable("CAAIVfMod_moduleModelName",utils.getNodeText(xml,"vf-module-model-name"))
+ execution.setVariable("CAAIVfMod_moduleName",execution.getVariable("vfModuleName"))
+ execution.setVariable("CAAIVfMod_moduleModelName",execution.getVariable("vfModuleModelName"))
AaiUtil aaiUriUtil = new AaiUtil(this)
def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
String aaiNamespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
logDebug('AAI namespace is: ' + aaiNamespace, isDebugEnabled)
- execution.setVariable("CAAIVfMod_aaiNamespace","${aaiNamespace}")
-
+ execution.setVariable("CAAIVfMod_aaiNamespace","${aaiNamespace}")
- if (vnfId.isEmpty()) {
+ if (vnfId == null || vnfId.isEmpty()) {
// TBD - assert that the vnfName is not empty
execution.setVariable("CAAIVfMod_genericVnfGetEndpoint",
"${aai_uri}/?vnf-name=" +
- UriUtils.encode(vnfName,"UTF-8"))
+ UriUtils.encode(vnfName,"UTF-8") + "&depth=1")
} else {
execution.setVariable("CAAIVfMod_genericVnfGetEndpoint",
- "${aai_uri}/" + UriUtils.encode(vnfId,"UTF-8"))
+ "${aai_uri}/" + UriUtils.encode(vnfId,"UTF-8") + "?depth=1")
}
-
+ utils.logAudit("CreateAAIVfModule VNF PUT Endpoint: ${aai_uri}/")
execution.setVariable("CAAIVfMod_genericVnfPutEndpoint","${aai_uri}/")
}
public void queryAAIForGenericVnf(Execution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
def endPoint = execution.getVariable("URN_aai_endpoint") + execution.getVariable("CAAIVfMod_genericVnfGetEndpoint")
- def aaiRequestId = UUID.randomUUID().toString()
-
- RESTConfig config = new RESTConfig(endPoint);
- utils.log("DEBUG","queryAAIForGenericVnf() endpoint-" + endPoint, isDebugEnabled)
- def responseData = ""
-
- String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
try {
- 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)
- }
+ utils.log("DEBUG","queryAAIForGenericVnf() endpoint-" + endPoint, isDebugEnabled)
utils.log("DEBUG", "invoking GET call to AAI endpoint :"+System.lineSeparator()+endPoint,isDebugEnabled)
- APIResponse response = client.httpGet()
-
- responseData = response.getResponseBodyAsString()
- execution.setVariable("CAAIVfMod_queryGenericVnfResponseCode", response.getStatusCode())
+ utils.logAudit("CreateAAIVfModule sending GET call to AAI Endpoint: " + endPoint)
+
+ AaiUtil aaiUtil = new AaiUtil(this)
+ APIResponse response = aaiUtil.executeAAIGetCall(execution, endPoint)
+ def responseData = response.getResponseBodyAsString()
+ def statusCode = response.getStatusCode()
+ execution.setVariable("CAAIVfMod_queryGenericVnfResponseCode", statusCode)
execution.setVariable("CAAIVfMod_queryGenericVnfResponse", responseData)
- utils.log("DEBUG", "Response code:" + response.getStatusCode(), isDebugEnabled)
+
+ utils.logAudit("CreateAAIVfModule Response Code: " + statusCode)
+ utils.logAudit("CreateAAIVfModule Response data: " + responseData)
+ utils.log("DEBUG", "Response code:" + statusCode, isDebugEnabled)
utils.log("DEBUG", "Response:" + System.lineSeparator()+responseData,isDebugEnabled)
} catch (Exception ex) {
ex.printStackTrace()
// note: to get here, the vnf-id in the original CREATE_VF_MODULE request was absent or ""
public void createGenericVnf(Execution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
- def aaiRequestId = UUID.randomUUID().toString()
// TBD - is this how we want to generate the Id for the new Generic VNF?
def newVnfId = UUID.randomUUID().toString()
def endPoint = execution.getVariable("URN_aai_endpoint") +
execution.getVariable("CAAIVfMod_genericVnfPutEndpoint") + newVnfId
// update the flow execution with the new Vnf Id
execution.setVariable("CAAIVfMod_vnfId",newVnfId)
-
- String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
-
+
// AaiUriUtil aaiUriUtil = new AaiUriUtil(this)
// def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
// logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)
</generic-vnf>""" as String
execution.setVariable("CAAIVfMod_createGenericVnfPayload", payload)
- RESTConfig config = new RESTConfig(endPoint);
- utils.log("DEBUG","createGenericVnf() endpoint-" + endPoint, isDebugEnabled)
- def responseData = ""
try {
- 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)
- }
+ utils.log("DEBUG","createGenericVnf() endpoint-" + endPoint, isDebugEnabled)
utils.log("DEBUG", "invoking PUT call to AAI with payload:"+System.lineSeparator()+payload,isDebugEnabled)
- APIResponse response = client.httpPut(payload)
-
- responseData = response.getResponseBodyAsString()
- execution.setVariable("CAAIVfMod_createGenericVnfResponseCode", response.getStatusCode())
+ utils.logAudit("Sending PUT call to AAI with Endpoint /n" + endPoint + " with payload /n" + payload)
+
+ AaiUtil aaiUtil = new AaiUtil(this);
+ APIResponse response = aaiUtil.executeAAIPutCall(execution, endPoint, payload);
+ def responseData = response.getResponseBodyAsString()
+ def responseStatusCode = response.getStatusCode()
+ execution.setVariable("CAAIVfMod_createGenericVnfResponseCode", responseStatusCode)
execution.setVariable("CAAIVfMod_createGenericVnfResponse", responseData)
- utils.log("DEBUG", "Response code:" + response.getStatusCode(), isDebugEnabled)
+
+ utils.logAudit("Response Code: " + responseStatusCode)
+ utils.logAudit("Response Data: " + responseData)
+ utils.log("DEBUG", "Response code:" + responseStatusCode, isDebugEnabled)
utils.log("DEBUG", "Response:" + System.lineSeparator()+responseData,isDebugEnabled)
} catch (Exception ex) {
ex.printStackTrace()
// need to append the existing Vnf Id or the one generated in createGenericVnf() to the url
endPoint = endPoint + UriUtils.encode(execution.getVariable("CAAIVfMod_vnfId"), "UTF-8") +
"/vf-modules/vf-module/" + newModuleId;
- def aaiRequestId = UUID.randomUUID().toString()
-
- String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
// if we get to this point, we may be about to create the Vf Module,
// add rollback information about the Generic VNF for this base/add-on module
<vf-module-name>${execution.getVariable("CAAIVfMod_moduleName")}</vf-module-name>
<persona-model-id>${execution.getVariable("CAAIVfMod_personaId")}</persona-model-id>
<persona-model-version>${execution.getVariable("CAAIVfMod_personaVer")}</persona-model-version>
+ <persona-model-customization-id>${execution.getVariable("CAAIVfMod_modelCustomizationId")}</persona-model-customization-id>
<is-base-vf-module>${isBaseModule}</is-base-vf-module>
<orchestration-status>pending-create</orchestration-status>
</vf-module>""" as String
execution.setVariable("CAAIVfMod_createVfModulePayload", payload)
- RESTConfig config = new RESTConfig(endPoint);
- utils.log("DEBUG","createVfModule() endpoint-" + endPoint, isDebugEnabled)
- def responseData = ""
try {
- 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)
- }
+ utils.log("DEBUG","createVfModule() endpoint-" + endPoint, isDebugEnabled)
utils.log("DEBUG", "invoking PUT call to AAI with payload:"+System.lineSeparator()+payload,isDebugEnabled)
- APIResponse response = client.httpPut(payload)
-
- responseData = response.getResponseBodyAsString()
- execution.setVariable("CAAIVfMod_createVfModuleResponseCode", response.getStatusCode())
+ utils.logAudit("CreateAAIVfModule sending PUT call to AAI with endpoint /n" + endPoint + " with payload /n " + payload)
+
+ AaiUtil aaiUtil = new AaiUtil(this)
+ APIResponse response = aaiUtil.executeAAIPutCall(execution, endPoint, payload)
+ def responseData = response.getResponseBodyAsString()
+ def statusCode = response.getStatusCode()
+ execution.setVariable("CAAIVfMod_createVfModuleResponseCode", statusCode)
execution.setVariable("CAAIVfMod_createVfModuleResponse", responseData)
- utils.log("DEBUG", "Response code:" + response.getStatusCode(), isDebugEnabled)
+
+ utils.log("DEBUG", "Response code:" + statusCode, isDebugEnabled)
utils.log("DEBUG", "Response:" + System.lineSeparator()+responseData,isDebugEnabled)
-
+ utils.logAudit("Response Code: " + statusCode)
+ utils.logAudit("Response data: " + responseData)
// the base or add-on VF Module was successfully created,
// add the module name to the rollback data and the response
- if (isOneOf(response.getStatusCode(), 200, 201)) {
+ if (isOneOf(statusCode, 200, 201)) {
rollbackData.put("VFMODULE", "vfModuleId", newModuleId)
rollbackData.put("VFMODULE", "vfModuleName", execution.getVariable("CAAIVfMod_moduleName"))
execution.setVariable("RollbackData", rollbackData)
execution.setVariable("CreateAAIVfModuleResponse", responseOut)
utils.log("DEBUG", "CreateAAIVfModuleResponse:" + System.lineSeparator()+responseOut,isDebugEnabled)
+ utils.logAudit("CreateAAIVfModule Response /n " + responseOut)
}
} catch (Exception ex) {
ex.printStackTrace()
String processKey = getProcessKey(execution);
WorkflowException exception = new WorkflowException(processKey, errorCode, errorResponse)
execution.setVariable("WorkflowException", exception)
+ utils.logAudit("Workflow exception occurred in CreateAAIVfModule: " + errorResponse)
}
/**
AaiUtil aaiUriUtil = new AaiUtil(this)
def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
+ utils.logAudit("CreateAAIVfModule rollback AAI URI: " + aai_uri)
if (rollbackData != null) {
if (rollbackData.hasType("VFMODULE")) {