*/
package org.onap.so.bpmn.infrastructure.scripts
-
import static org.apache.commons.lang3.StringUtils.isBlank
import javax.ws.rs.NotFoundException
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.so.beans.nsmf.ActDeActNssi
import org.onap.so.beans.nsmf.EsrInfo
import org.onap.so.beans.nsmf.ServiceInfo
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.JsonObject
+import groovy.json.JsonSlurper
+import com.google.gson.Gson
/**
* Internal AN NSSMF to handle NSSI Activation/Deactivation
RequestDBUtil requestDBUtil = new RequestDBUtil()
JsonUtils jsonUtil = new JsonUtils()
ObjectMapper objectMapper = new ObjectMapper()
+ AnNssmfUtils anNssmfUtils = new AnNssmfUtils()
private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
private static final Logger logger = LoggerFactory.getLogger(DoActivateAccessNSSI.class)
private static final String KEY_SLICE_PROFILE = "SliceProfile"
private static final String KEY_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"
private static final String ACTIVATE = "activateInstance"
private static final String DEACTIVATE = "deactivateInstance"
- private static final String VENDOR_ONAP = "ONAP"
+ private static final String VENDOR_ONAP = "ONAP_internal"
+
+ enum orchStatusMap {
+ activateInstance("activated"),
+ deactivateInstance("deactivated")
+
+ private String value;
+
+ private orchStatusMap(String value) {
+ this.value = value;
+ }
+ }
- Map<String,String> orchStatusMap = new HashMap<>()
@Override
public void preProcessRequest(DelegateExecution execution) {
logger.debug("${Prefix} - Start preProcessRequest")
String sliceParams = execution.getVariable("sliceParams")
- String sNssaiList = jsonUtil.getJsonValue(sliceParams, "snssaiList")
+ List<String> sNssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "snssaiList"))
String anSliceProfileId = jsonUtil.getJsonValue(sliceParams, "sliceProfileId")
String nsiId = execution.getVariable("nsiId")
String globalSubscriberId = execution.getVariable("globalSubscriberId")
String anNssiId = execution.getVariable("serviceInstanceID")
String operationType = execution.getVariable("operationType")
- 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("nsiId", nsiId)
execution.setVariable("anNssiId", anNssiId)
- orchStatusMap.put(ACTIVATE, "activated")
- orchStatusMap.put(DEACTIVATE, "deactivated")
-
logger.debug("${Prefix} - Preprocessing completed with sliceProfileId : ${anSliceProfileId} , nsiId : ${nsiId} , nssiId : ${anNssiId}")
}
execution.setVariable("relatedSPs", getRelatedInstancesByRole(execution, ROLE_SLICE_PROFILE,KEY_SLICE_PROFILE, anSliceProfileId))
Map<String,ServiceInstance> relatedNssis = new HashMap<>()
- execution.setVariable("relatedNssis", getRelatedInstancesByRole(execution, ROLE_NSSI,KEY_NSSI, anNssiId))
+ relatedNssis = getRelatedInstancesByRole(execution, ROLE_NSSI,KEY_NSSI, anNssiId)
+ execution.setVariable("relatedNssis", relatedNssis)
+ if(relatedNssis.size() == 1) {
+ execution.setVariable("IsRANNfAlonePresent", true)
+ }
logger.trace("${Prefix} - Exit Get Related instances")
}
ServiceInstance sliceProfileInstance = execution.getVariable(KEY_SLICE_PROFILE)
String orchStatus = sliceProfileInstance.getOrchestrationStatus()
String operationType = execution.getVariable("operationType")
- if(orchStatusMap.get(operationType).equalsIgnoreCase(orchStatus)) {
- execution.setVariable("shouldChangeSPStatus", true)
- }else {
+ if(orchStatusMap.valueOf(operationType).toString().equalsIgnoreCase(orchStatus)) {
execution.setVariable("shouldChangeSPStatus", false)
- }
+ }else {
+ execution.setVariable("shouldChangeSPStatus", true)
+
+ }
logger.debug("${Prefix} - SPOrchStatus : ${orchStatus}")
}
String orchStatus = sliceProfileInstance.getOrchestrationStatus()
String operationType = execution.getVariable("operationType")
- if(orchStatusMap.get(operationType).equalsIgnoreCase(orchStatus)) {
- execution.setVariable("shouldChangeAN_NF_SPStatus", true)
- }else {
+ if(orchStatusMap.valueOf(operationType).toString().equalsIgnoreCase(orchStatus)) {
execution.setVariable("shouldChangeAN_NF_SPStatus", false)
+ }else {
+ execution.setVariable("shouldChangeAN_NF_SPStatus", true)
}
logger.debug("${Prefix} - getAnNfSPOrchStatus AN_NF SP ID:${anNfSPId} : ${orchStatus}")
}
String action = operationType.equalsIgnoreCase(ACTIVATE) ? "activate":"deactivate"
String anNfNssiId = execution.getVariable("anNfNssiId")
- String sNssai = execution.getVariable("sNssaiList")
+ List<String> sNssai = execution.getVariable("sNssaiList")
String reqId = execution.getVariable("msoRequestId")
String messageType = "SDNRActivateResponse"
StringBuilder callbackURL = new StringBuilder(UrnPropertiesReader.getVariable("mso.workflow.message.endpoint", execution))
callbackURL.append("/").append(messageType).append("/").append(reqId)
JsonObject input = new JsonObject()
+ String sliceProfileId = execution.getVariable("anNfSPId")
+ input.addProperty("sliceProfileId",sliceProfileId)
input.addProperty("RANNFNSSIId", anNfNssiId)
input.addProperty("callbackURL", callbackURL.toString())
- input.addProperty("s-NSSAI", sNssai)
-
- JsonObject Payload = new JsonObject()
- Payload.addProperty("version", "1.0")
- Payload.addProperty("rpc-name", "activateRANSlice")
- Payload.addProperty("correlation-id", reqId)
- Payload.addProperty("type", "request")
+ input.addProperty("sNSSAI", sNssai.toString())
JsonObject wrapinput = new JsonObject()
- wrapinput.addProperty("Action", action)
+ wrapinput.addProperty("action", action)
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("request-id", reqId)
+ CommonHeader.addProperty("sub-request-id", "1")
JsonObject body = new JsonObject()
body.add("input", wrapinput)
JsonObject sdnrRequest = new JsonObject()
- Payload.add("input", input)
- wrapinput.add("Payload", Payload)
- wrapinput.add("CommonHeader", CommonHeader)
+ JsonObject payload = new JsonObject()
+ payload.add("input", input)
+ 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", "activateRANSliceInstance")
+ 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")
- logger.debug("${Prefix} - prepareSdnrActivationRequest : SDNR Request : ${json}")
+ logger.debug("${Prefix} - Exit prepareSdnrActivationRequest ")
}
void processSdnrResponse(DelegateExecution execution) {
String orchStatus = sliceProfileInstance.getOrchestrationStatus()
String operationType = execution.getVariable("operationType")
- if(orchStatusMap.get(operationType).equalsIgnoreCase(orchStatus)) {
- execution.setVariable("shouldChangeTN_FH_SPStatus", true)
- }else {
+ if(orchStatusMap.valueOf(operationType).toString().equalsIgnoreCase(orchStatus)) {
execution.setVariable("shouldChangeTN_FH_SPStatus", false)
+ }else {
+ execution.setVariable("shouldChangeTN_FH_SPStatus", true)
}
logger.debug("${Prefix} Exit getTnFhSPOrchStatus TN_FH SP ID:${tnFhSPId} : ${orchStatus}")
String urlOpType = operationType.equalsIgnoreCase(ACTIVATE) ? "activation":"deactivation"
List<String> sNssaiList = execution.getVariable("sNssaiList")
- String snssai = sNssaiList != null ? sNssaiList.get(0) : ""
-
- String urlString = "/api/rest/provMns/v1/NSS/" + snssai + urlOpType
+ String snssai = sNssaiList.get(0)
+ String urlString = "/api/rest/provMns/v1/NSS/" + snssai + "/" + urlOpType
String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
if (nssmfResponse != null) {
String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
String orchStatus = sliceProfileInstance.getOrchestrationStatus()
String operationType = execution.getVariable("operationType")
- if(orchStatusMap.get(operationType).equalsIgnoreCase(orchStatus)) {
- execution.setVariable("shouldChangeTN_MH_SPStatus", true)
- }else {
+ if(orchStatusMap.valueOf(operationType).toString().equalsIgnoreCase(orchStatus)) {
execution.setVariable("shouldChangeTN_MH_SPStatus", false)
+ }else {
+ execution.setVariable("shouldChangeTN_MH_SPStatus", true)
}
logger.debug("${Prefix} Exit getTnMhSPOrchStatus TN_MH SP ID:${tnFhSPId} : ${orchStatus}")
}
String urlOpType = operationType.equalsIgnoreCase(ACTIVATE) ? "activation":"deactivation"
List<String> sNssaiList = execution.getVariable("sNssaiList")
- String snssai = sNssaiList != null ? sNssaiList.get(0) : ""
+ String snssai = sNssaiList.get(0)
- String urlString = "/api/rest/provMns/v1/NSS/" + snssai + urlOpType
+ String urlString = "/api/rest/provMns/v1/NSS/" + snssai + "/" + urlOpType
String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
if (nssmfResponse != null) {
String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
String anSliceProfileId = execution.getVariable("anSliceProfileId")
updateOrchStatus(execution, anNssiId)
updateOrchStatus(execution, anSliceProfileId)
- logger.debug("${Prefix} Start updateANStatus")
+ logger.debug("${Prefix} Exit updateANStatus")
}
void prepareQueryJobStatus(DelegateExecution execution,String jobId,String networkType,String instanceId) {
String globalSubscriberId = execution.getVariable("globalSubscriberId")
String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
- EsrInfo esrInfo = new EsrInfo()
- esrInfo.setNetworkType(networkType)
- esrInfo.setVendor(VENDOR_ONAP)
+ JsonObject esrInfo = new JsonObject()
+ esrInfo.addProperty("networkType", networkType)
+ esrInfo.addProperty("vendor", VENDOR_ONAP)
- ServiceInfo serviceInfo = new ServiceInfo()
- serviceInfo.setNssiId(instanceId)
- serviceInfo.setNsiId(execution.getVariable("nsiId"))
- serviceInfo.setGlobalSubscriberId(globalSubscriberId)
- serviceInfo.setSubscriptionServiceType(subscriptionServiceType)
+ JsonObject serviceInfo = new JsonObject()
+ serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
+ serviceInfo.addProperty("nssiId", instanceId)
+ serviceInfo.addProperty("globalSubscriberId", globalSubscriberId)
+ serviceInfo.addProperty("subscriptionServiceType", subscriptionServiceType)
- execution.setVariable("${networkType}_esrInfo", esrInfo)
+ 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")
- if("finished".equalsIgnoreCase(status)) {
+ String jobResponse = execution.getVariable("tn_responseDescriptor")
+ logger.debug("Job status response "+jobResponse)
+ String status = jsonUtil.getJsonValue(jobResponse, "status")
+ String statusDescription = jsonUtil.getJsonValue(jobResponse, "statusDescription")
+ if("finished".equalsIgnoreCase(status)) {
execution.setVariable("isSuccess", true)
}else {
execution.setVariable("isSuccess", false)
try {
AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
- globalSubscriberId, subscriptionServiceType, serviceId)
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceId))
if (!client.exists(uri)) {
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
}
void prepareUpdateJobStatus(DelegateExecution execution,String status,String progress,String statusDescription) {
logger.debug("${Prefix} Start prepareUpdateJobStatus : ${statusDescription}")
- String serviceId = execution.getVariable("anNssiId")
+ String nssiId = execution.getVariable("anNssiId")
String jobId = execution.getVariable("jobId")
String nsiId = execution.getVariable("nsiId")
+ //String modelUuid = execution.getVariable("modelUuid")
+ String modelUuid = anNssmfUtils.getModelUuid(execution, nssiId)
String operationType = execution.getVariable("operationType")
ResourceOperationStatus roStatus = new ResourceOperationStatus()
- roStatus.setServiceId(serviceId)
+ roStatus.setServiceId(nsiId)
roStatus.setOperationId(jobId)
- roStatus.setResourceTemplateUUID(nsiId)
+ roStatus.setResourceTemplateUUID(modelUuid)
+ roStatus.setResourceInstanceID(nssiId)
roStatus.setOperType(operationType)
roStatus.setProgress(progress)
roStatus.setStatus(status)
roStatus.setStatusDescription(statusDescription)
- requestDBUtil.prepareUpdateResourceOperationStatus(execution, status)
+ requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
+ logger.debug("${Prefix} Exit prepareUpdateJobStatus : ${statusDescription}")
}
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}")
String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
Map<String, ServiceInstance> relatedNssis = execution.getVariable("relatedNssis")
- String anNssiId = execution.getVariable("anNssiId")
+ String nsiId = execution.getVariable("nsiId")
List<String> sNssaiList = execution.getVariable("sNssaiList")
ServiceInstance tnNssi = relatedNssis.get(serviceFunction)
ActDeActNssi actDeactNssi = new ActDeActNssi()
actDeactNssi.setNssiId(nssiId)
- actDeactNssi.setNsiId(anNssiId)
+ actDeactNssi.setNsiId(nsiId)
actDeactNssi.setSliceProfileId(relatedSPs.get(serviceFunction).getServiceInstanceId())
actDeactNssi.setSnssaiList(sNssaiList)
- EsrInfo esrInfo = new EsrInfo()
- esrInfo.setVendor(VENDOR_ONAP)
- esrInfo.setNetworkType("TN")
+ JsonObject esrInfo = new JsonObject()
+ esrInfo.addProperty("networkType", "tn")
+ esrInfo.addProperty("vendor", VENDOR_ONAP)
ServiceInfo serviceInfo = new ServiceInfo()
serviceInfo.setServiceInvariantUuid(tnNssi.getModelInvariantId())
serviceInfo.setServiceUuid(tnNssi.getModelVersionId())
serviceInfo.setGlobalSubscriberId(globalSubscriberId)
serviceInfo.setSubscriptionServiceType(subscriptionServiceType)
+ serviceInfo.setNssiId(nssiId)
JsonObject json = new JsonObject()
- json.addProperty("actDeActNssi", objectMapper.writeValueAsString(actDeactNssi))
- json.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo))
- json.addProperty("serviceInfo", objectMapper.writeValueAsString(serviceInfo))
+ Gson jsonConverter = new Gson()
+ json.add("actDeActNssi", jsonConverter.toJsonTree(actDeactNssi))
+ json.add("esrInfo", esrInfo)
+ json.add("serviceInfo", jsonConverter.toJsonTree(serviceInfo))
return json.toString()
}