import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
import org.onap.logging.filter.base.ONAPComponents
import org.onap.so.beans.nsmf.DeAllocateNssi
import org.onap.so.beans.nsmf.EsrInfo
+import org.onap.so.beans.nsmf.NetworkType
import org.onap.so.beans.nsmf.ServiceInfo
+import org.onap.so.beans.nsmf.oof.SubnetType
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.JsonObject
+import com.google.gson.Gson
+
/**
* Internal AN NSSMF to handle NSSI Deallocation
private static final String ROLE_SLICE_PROFILE = "slice-profile-instance"
private static final String ROLE_NSSI = "nssi"
- private static final String AN_NF = "AN-NF"
- private static final String TN_FH = "TN-FH"
- private static final String TN_MH = "TN-MH"
+ private static final String AN_NF = "AN_NF"
+ private static final String TN_FH = "TN_FH"
+ private static final String TN_MH = "TN_MH"
@Override
public void preProcessRequest(DelegateExecution execution) {
logger.debug("${Prefix} - Start preProcessRequest")
String sliceParams = execution.getVariable("sliceParams")
- String sNssaiList = jsonUtil.getJsonValue(sliceParams, "snssaiList")
+ def sNssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "snssaiList"))
String anSliceProfileId = jsonUtil.getJsonValue(sliceParams, "sliceProfileId")
String nsiId = jsonUtil.getJsonValue(sliceParams, "nsiId")
String globalSubscriberId = execution.getVariable("globalSubscriberId")
String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
String anNssiId = execution.getVariable("serviceInstanceID")
- if(isBlank(sNssaiList) || isBlank(anSliceProfileId) || isBlank(nsiId)) {
+ if((sNssaiList.empty) || isBlank(anSliceProfileId) || isBlank(nsiId)) {
String msg = "Input fields cannot be null : Mandatory attributes : [snssaiList, sliceProfileId, nsiId]"
logger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
execution.setVariable("anNfSliceProfileId", getInstanceIdByWorkloadContext(execution.getVariable("relatedSPs"), AN_NF))
Map<String,ServiceInstance> relatedNssis = new HashMap<>()
- execution.setVariable("relatedNssis", getRelatedInstancesByRole(execution, ROLE_NSSI, anNssiId))
+ relatedNssis = getRelatedInstancesByRole(execution, ROLE_NSSI, anNssiId)
+ if(relatedNssis.size() == 1) {
+ execution.setVariable("IsRANNfAlonePresent", true)
+ }
+ execution.setVariable("relatedNssis", relatedNssis)
}
String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
String serviceInstanceId = execution.getVariable("nsiId")
String anNssiId = execution.getVariable("anNssiId")
- String oofRequest = oofUtils.buildTerminateNxiRequest(requestId,anNssiId, ROLE_NSSI,messageType,serviceInstanceId)
- OofRequest oofPayload = new OofRequest()
- oofPayload.setApiPath("/api/oof/terminate/nxi/v1")
- oofPayload.setRequestDetails(oofRequest)
- execution.setVariable("oofAnNssiPayload", oofPayload)
+ String oofRequest = oofUtils.buildTerminateNxiRequest(requestId,anNssiId, "NSSI",messageType,serviceInstanceId)
+ execution.setVariable("oofAnNssiPayload", oofRequest)
logger.debug("Finish prepareOOFTerminationRequest")
}
String anNfNssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"),AN_NF)
execution.setVariable("anNfNssiId", anNfNssiId)
- String oofRequest = oofUtils.buildTerminateNxiRequest(requestId,anNfNssiId, ROLE_NSSI,messageType,serviceInstanceId)
- OofRequest oofPayload = new OofRequest()
- oofPayload.setApiPath("/api/oof/terminate/nxi/v1")
- oofPayload.setRequestDetails(oofRequest)
- execution.setVariable("oofAnNfNssiPayload", oofPayload)
+ String oofRequest = oofUtils.buildTerminateNxiRequest(requestId,anNfNssiId, "NSSI",messageType,serviceInstanceId)
+ execution.setVariable("oofAnNfNssiPayload", oofRequest)
logger.debug("Finish prepareOOFAnNfNssiTerminationRequest")
}
boolean terminateAnNfNSSI = callOofAdapter(execution,execution.getVariable("oofAnNfNssiPayload"))
execution.setVariable("terminateAnNfNSSI", terminateAnNfNSSI)
if(!terminateAnNfNSSI) {
- execution.setVariable("modifyAction",true)
+ execution.setVariable("modifyAction","deallocate")
}
}
void prepareSdnrRequest(DelegateExecution execution) {
String anNfNssiId = execution.getVariable("anNfNssiId")
- String sNssai = execution.getVariable("sNssaiList")
+ String sNssai = execution.getVariable("sNssaiList").get(0)
+ String sliceProfileId = execution.getVariable("anNfSliceProfileId")
String reqId = execution.getVariable("msoRequestId")
String messageType = "SDNRTerminateResponse"
StringBuilder callbackURL = new StringBuilder(UrnPropertiesReader.getVariable("mso.workflow.message.endpoint", execution))
JsonObject input = new JsonObject()
input.addProperty("RANNFNSSIId", anNfNssiId)
input.addProperty("callbackURL", callbackURL.toString())
- input.addProperty("s-NSSAI", sNssai)
+ input.addProperty("sNSSAI", sNssai)
+ input.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId") as String)
+ input.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType") as String)
+ input.addProperty("sliceProfileId",sliceProfileId)
+ input.add("additionalproperties", new JsonObject())
JsonObject Payload = new JsonObject()
- Payload.addProperty("version", "1.0")
- Payload.addProperty("rpc-name", "TerminateRANSlice")
- Payload.addProperty("correlation-id", reqId)
- Payload.addProperty("type", "request")
JsonObject wrapinput = new JsonObject()
- wrapinput.addProperty("Action", "deallocate")
+ wrapinput.addProperty("action", "deallocate")
JsonObject CommonHeader = new JsonObject()
- CommonHeader.addProperty("TimeStamp", new Date(System.currentTimeMillis()).format("yyyy-MM-ddTHH:mm:ss.sss", TimeZone.getDefault()))
- CommonHeader.addProperty("APIver", "1.0")
- CommonHeader.addProperty("RequestID", reqId)
- CommonHeader.addProperty("SubRequestID", "1")
+ CommonHeader.addProperty("timestamp", new Date(System.currentTimeMillis()).format("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", TimeZone.getDefault()))
+ CommonHeader.addProperty("api-ver", "1.0")
+ CommonHeader.addProperty("originator-id", "testing")
+ CommonHeader.addProperty("request-id", reqId)
+ CommonHeader.addProperty("sub-request-id", "1")
+ CommonHeader.add("flags", new JsonObject())
JsonObject body = new JsonObject()
- body.add("input", wrapinput)
JsonObject sdnrRequest = new JsonObject()
Payload.add("input", input)
- wrapinput.add("Payload", Payload)
- wrapinput.add("CommonHeader", CommonHeader)
+ wrapinput.addProperty("payload", Payload.toString())
+ wrapinput.add("common-header", CommonHeader)
body.add("input", wrapinput)
sdnrRequest.add("body", body)
+ sdnrRequest.addProperty("version", "1.0")
+ sdnrRequest.addProperty("rpc-name", "terminateRANSliceInstance")
+ sdnrRequest.addProperty("correlation-id", reqId)
+ sdnrRequest.addProperty("type", "request")
String json = sdnrRequest.toString()
- execution.setVariable("sdnrRequest", sdnrRequest)
+ execution.setVariable("sdnrRequest", json)
execution.setVariable("SDNR_messageType", messageType)
execution.setVariable("SDNR_timeout", "PT10M")
* @param oofRequest - Request payload to be sent to adapter
* @return
*/
- boolean callOofAdapter(DelegateExecution execution, OofRequest oofRequest) {
+ boolean callOofAdapter(DelegateExecution execution, Object oofRequest) {
logger.debug("Start callOofAdapter")
String requestId = execution.getVariable("msoRequestId")
String oofAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution)
URL requestUrl = new URL(oofAdapterEndpoint)
- logger.debug("Calling OOF adapter : ${requestUrl} with payload : ${oofRequest}")
+ OofRequest oofPayload = new OofRequest()
+ oofPayload.setApiPath("/api/oof/terminate/nxi/v1")
+ oofPayload.setRequestDetails(oofRequest)
+ String requestJson = objectMapper.writeValueAsString(oofPayload)
+ logger.debug("Calling OOF adapter : ${requestUrl} with payload : ${requestJson}")
HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL)
- Response httpResponse = httpClient.post(oofRequest)
+ Response httpResponse = httpClient.post(requestJson)
int responseCode = httpResponse.getStatus()
logger.debug("OOF sync response code is: " + responseCode)
- if(responseCode != 200){
+ if(responseCode < 200 || responseCode >= 300){
logger.debug("OOF request failed with reason : " + httpResponse)
exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
}else {
String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
- globalSubscriberId, subscriptionServiceType, anNfNssiId)
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(anNfNssiId))
if (!client.exists(uri)) {
logger.debug("AN NF Service Instance was not found in aai : ${anNfNssiId}")
}else {
String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
- globalSubscriberId, subscriptionServiceType, anNfNssiId)
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(anNfNssiId))
if (!client.exists(uri)) {
logger.debug("AN NF Service Instance was not found in aai : ${anNfNssiId}")
}else {
Map<String,Object> sliceParams = objectMapper.readValue(execution.getVariable("sliceParams"), Map.class)
sliceParams.put("modifyAction", "deallocate")
- execution.setVariable("modificationsliceParams", sliceParams)
+ execution.setVariable("modificationsliceParams", objectMapper.writeValueAsString(sliceParams))
- String serviceId = execution.getVariable("serviceInstanceId")
+ String serviceId = execution.getVariable("serviceInstanceID")
String nsiId = execution.getVariable("nsiId")
logger.debug("Generated new job for Service Instance serviceId:" + serviceId + " operationId:" + modificationJobId)
ResourceOperationStatus initStatus = new ResourceOperationStatus()
- initStatus.setServiceId(serviceId)
+ initStatus.setServiceId(nsiId)
initStatus.setOperationId(modificationJobId)
- initStatus.setResourceTemplateUUID(nsiId)
+ initStatus.setResourceTemplateUUID(serviceId)
initStatus.setOperType("Modify-Deallocate")
requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
String responseId = "1"
String globalSubscriberId = execution.getVariable("globalSubscriberId")
String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
+ String anNssiId = execution.getVariable("anNssiId")
- EsrInfo esrInfo = new EsrInfo()
- esrInfo.setNetworkType(networkType)
- esrInfo.setVendor("ONAP")
-
- ServiceInfo serviceInfo = new ServiceInfo()
- serviceInfo.setNssiId(instanceId)
- serviceInfo.setNsiId(execution.getVariable("nsiId"))
- serviceInfo.setGlobalSubscriberId(globalSubscriberId)
- serviceInfo.setSubscriptionServiceType(subscriptionServiceType)
-
- execution.setVariable("${networkType}_esrInfo", esrInfo)
+ JsonObject esrInfo = new JsonObject()
+ esrInfo.addProperty("networkType", networkType)
+ esrInfo.addProperty("vendor", "ONAP_internal")
+
+ JsonObject serviceInfo = new JsonObject()
+ if (networkType.equals(SubnetType.AN.getSubnetType())) {
+ serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
+ } else {
+ serviceInfo.addProperty("nsiId", anNssiId)
+ }
+ serviceInfo.addProperty("nssiId", instanceId)
+ serviceInfo.addProperty("globalSubscriberId", globalSubscriberId)
+ serviceInfo.addProperty("subscriptionServiceType", subscriptionServiceType)
+
+ execution.setVariable("${networkType}_esrInfo", esrInfo.toString())
execution.setVariable("${networkType}_responseId", responseId)
- execution.setVariable("${networkType}_serviceInfo", serviceInfo)
+ execution.setVariable("${networkType}_serviceInfo", serviceInfo.toString())
}
void validateJobStatus(DelegateExecution execution,String responseDescriptor) {
logger.debug("validateJobStatus ${responseDescriptor}")
- String status = jsonUtil.getJsonValue(responseDescriptor, "responseDescriptor.status")
- String statusDescription = jsonUtil.getJsonValue(responseDescriptor, "responseDescriptor.statusDescription")
+ String status = jsonUtil.getJsonValue(responseDescriptor, "status")
+ String statusDescription = jsonUtil.getJsonValue(responseDescriptor, "statusDescription")
if("finished".equalsIgnoreCase(status)) {
execution.setVariable("isSuccess", true)
}else {
}
void prepareUpdateJobStatus(DelegateExecution execution,String status,String progress,String statusDescription) {
- String serviceId = execution.getVariable("anNssiId")
+ String nssiId = execution.getVariable("anNssiId")
String jobId = execution.getVariable("jobId")
String nsiId = execution.getVariable("nsiId")
ResourceOperationStatus roStatus = new ResourceOperationStatus()
- roStatus.setServiceId(serviceId)
+ roStatus.setServiceId(nsiId)
roStatus.setOperationId(jobId)
- roStatus.setResourceTemplateUUID(nsiId)
+ //roStatus.setResourceTemplateUUID(nsiId)
+ roStatus.setResourceInstanceID(nssiId)
roStatus.setOperType("DeAllocate")
roStatus.setProgress(progress)
roStatus.setStatus(status)
roStatus.setStatusDescription(statusDescription)
- requestDBUtil.prepareUpdateResourceOperationStatus(execution, status)
+ requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
}
void terminateTNFHNssi(DelegateExecution execution) {
String nssmfRequest = buildDeallocateNssiRequest(execution, TN_FH)
String nssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"), TN_FH)
execution.setVariable("tnFHNSSIId", nssiId)
- String urlString = "/api/rest/provMns/v1/NSS/nssi/" + nssiId
+ String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles/" + nssiId
String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
if (nssmfResponse != null) {
String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
String nssmfRequest = buildDeallocateNssiRequest(execution, TN_MH)
String nssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"), TN_MH)
execution.setVariable("tnMHNSSIId", nssiId)
- String urlString = "/api/rest/provMns/v1/NSS/nssi/" + nssiId
+ String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles/" + nssiId
String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
if (nssmfResponse != null) {
String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
void deleteANNSSI(DelegateExecution execution) {
logger.debug("${Prefix} delete AN NSSI")
- String nssiId = execution.getVariable("serviceInstanceID")
+ String nssiId = execution.getVariable("anNssiId")
deleteServiceInstanceInAAI(execution, nssiId)
}
Map<String,ServiceInstance> relatedInstances = new HashMap<>()
AAIResourcesClient client = getAAIClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
- globalSubscriberId, subscriptionServiceType, instanceId)
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(instanceId))
if (!client.exists(uri)) {
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai : ${instanceId}")
}
String relatioshipurl = relationship.getRelatedLink()
String serviceInstanceId =
relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1, relatioshipurl.length())
- uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
- globalSubscriberId, subscriptionServiceType, serviceInstanceId)
+ uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId))
if (!client.exists(uri)) {
exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
"Service Instance was not found in aai: ${serviceInstanceId} related to ${instanceId}")
Map<String, ServiceInstance> relatedNssis = execution.getVariable("relatedNssis")
String anNssiId = execution.getVariable("anNssiId")
- List<String> sNssaiList = execution.getVariable("sNssaiList")
+ List<String> sNssaiList = execution.getVariable("sNssaiList")
Map<String, ServiceInstance> relatedSPs = execution.getVariable("relatedSPs")
String nssiId = tnNssi.getServiceInstanceId()
deallocateNssi.setNssiId(nssiId)
- deallocateNssi.setScriptName(tnNssi.getServiceInstanceName())
+ deallocateNssi.setScriptName("TN1")
deallocateNssi.setSnssaiList(sNssaiList)
deallocateNssi.setSliceProfileId(relatedSPs.get(serviceFunction).getServiceInstanceId())
- EsrInfo esrInfo = new EsrInfo()
- esrInfo.setVendor("ONAP")
- esrInfo.setNetworkType("TN")
+ JsonObject esrInfo = new JsonObject()
+ esrInfo.addProperty("networkType", "tn")
+ esrInfo.addProperty("vendor", "ONAP_internal")
ServiceInfo serviceInfo = new ServiceInfo()
serviceInfo.setServiceInvariantUuid(tnNssi.getModelInvariantId())
serviceInfo.setServiceUuid(tnNssi.getModelVersionId())
serviceInfo.setGlobalSubscriberId(globalSubscriberId)
serviceInfo.setSubscriptionServiceType(subscriptionServiceType)
+ serviceInfo.setNssiId(nssiId)
+ serviceInfo.setNssiName(tnNssi.getServiceInstanceName())
JsonObject json = new JsonObject()
- json.addProperty("deAllocateNssi", objectMapper.writeValueAsString(deallocateNssi))
- json.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo))
- json.addProperty("serviceInfo", objectMapper.writeValueAsString(serviceInfo))
+ Gson jsonConverter = new Gson()
+ json.add("deAllocateNssi", jsonConverter.toJsonTree(deallocateNssi))
+ json.add("esrInfo", esrInfo)
+ json.add("serviceInfo", jsonConverter.toJsonTree(serviceInfo))
return json.toString()
}
private void deleteServiceInstanceInAAI(DelegateExecution execution,String instanceId) {
try {
- AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), instanceId)
- getAAIClient().delete(serviceInstanceUri)
+ AAIResourcesClient client = getAAIClient()
+ AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(instanceId))
+ client.delete(serviceInstanceUri)
logger.debug("${Prefix} Exited deleteServiceInstance")
}catch(Exception e){
logger.debug("Error occured within deleteServiceInstance method: " + e)