2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Wipro Limited. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License")
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import static org.apache.commons.lang3.StringUtils.isBlank
25 import javax.ws.rs.NotFoundException
26 import javax.ws.rs.core.Response
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.aai.domain.yang.*
31 import org.onap.aaiclient.client.aai.AAIObjectType
32 import org.onap.aaiclient.client.aai.AAIResourcesClient
33 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
34 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
35 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
36 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
37 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
38 import org.onap.logging.filter.base.ONAPComponents
39 import org.onap.so.beans.nsmf.DeAllocateNssi
40 import org.onap.so.beans.nsmf.EsrInfo
41 import org.onap.so.beans.nsmf.NetworkType
42 import org.onap.so.beans.nsmf.ServiceInfo
43 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
44 import org.onap.so.bpmn.common.scripts.ExceptionUtil
45 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
46 import org.onap.so.bpmn.common.scripts.OofUtils
47 import org.onap.so.bpmn.common.scripts.RequestDBUtil
48 import org.onap.so.bpmn.core.UrnPropertiesReader
49 import org.onap.so.bpmn.core.json.JsonUtils
50 import org.onap.so.client.HttpClient
51 import org.onap.so.client.HttpClientFactory
52 import org.onap.so.client.oof.adapter.beans.payload.OofRequest
53 import org.onap.so.db.request.beans.ResourceOperationStatus
54 import org.slf4j.Logger
55 import org.slf4j.LoggerFactory
57 import com.fasterxml.jackson.databind.ObjectMapper
58 import com.google.gson.JsonObject
59 import com.google.gson.Gson
63 * Internal AN NSSMF to handle NSSI Deallocation
65 class DoDeAllocateAccessNSSI extends AbstractServiceTaskProcessor {
67 String Prefix="DoDeAllocateAccessNSSI"
68 ExceptionUtil exceptionUtil = new ExceptionUtil()
69 RequestDBUtil requestDBUtil = new RequestDBUtil()
70 JsonUtils jsonUtil = new JsonUtils()
71 OofUtils oofUtils = new OofUtils()
72 ObjectMapper objectMapper = new ObjectMapper()
73 private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
75 private static final Logger logger = LoggerFactory.getLogger(DoDeAllocateAccessNSSI.class)
76 private static final String ROLE_SLICE_PROFILE = "slice-profile-instance"
77 private static final String ROLE_NSSI = "nssi"
79 private static final String AN_NF = "AN_NF"
80 private static final String TN_FH = "TN_FH"
81 private static final String TN_MH = "TN_MH"
84 public void preProcessRequest(DelegateExecution execution) {
85 logger.debug("${Prefix} - Start preProcessRequest")
87 String sliceParams = execution.getVariable("sliceParams")
88 def sNssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "snssaiList"))
89 String anSliceProfileId = jsonUtil.getJsonValue(sliceParams, "sliceProfileId")
90 String nsiId = jsonUtil.getJsonValue(sliceParams, "nsiId")
91 String globalSubscriberId = execution.getVariable("globalSubscriberId")
92 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
93 String anNssiId = execution.getVariable("serviceInstanceID")
95 if((sNssaiList.empty) || isBlank(anSliceProfileId) || isBlank(nsiId)) {
96 String msg = "Input fields cannot be null : Mandatory attributes : [snssaiList, sliceProfileId, nsiId]"
98 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
101 if( isBlank(anNssiId) || isBlank(globalSubscriberId) || isBlank(subscriptionServiceType)) {
102 String msg = "Missing Input fields from main process : [serviceInstanceID, globalSubscriberId, subscriptionServiceType]"
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 execution.setVariable("sNssaiList", sNssaiList)
108 execution.setVariable("anSliceProfileId", anSliceProfileId)
109 execution.setVariable("nsiId", nsiId)
110 execution.setVariable("anNssiId", anNssiId)
112 logger.debug("${Prefix} - Preprocessing completed with sliceProfileId : ${anSliceProfileId} , nsiId : ${nsiId} , nssiId : ${anNssiId}")
116 * Method to fetch AN NSSI Constituents and Slice Profile constituents
119 void getRelatedInstances(DelegateExecution execution) {
120 logger.debug("${Prefix} - Get Related Instances")
121 String anSliceProfileId = execution.getVariable("anSliceProfileId")
122 String anNssiId = execution.getVariable("anNssiId")
124 Map<String,ServiceInstance> relatedSPs = new HashMap<>()
125 execution.setVariable("relatedSPs", getRelatedInstancesByRole(execution, ROLE_SLICE_PROFILE, anSliceProfileId))
126 execution.setVariable("anNfSliceProfileId", getInstanceIdByWorkloadContext(execution.getVariable("relatedSPs"), AN_NF))
128 Map<String,ServiceInstance> relatedNssis = new HashMap<>()
129 execution.setVariable("relatedNssis", getRelatedInstancesByRole(execution, ROLE_NSSI, anNssiId))
136 void prepareOOFAnNssiTerminationRequest(DelegateExecution execution) {
137 logger.debug("Start prepareOOFTerminationRequest")
138 String requestId = execution.getVariable("msoRequestId")
139 String messageType = "AN_NSSITermination"
140 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
141 String serviceInstanceId = execution.getVariable("nsiId")
142 String anNssiId = execution.getVariable("anNssiId")
143 String oofRequest = oofUtils.buildTerminateNxiRequest(requestId,anNssiId, "NSSI",messageType,serviceInstanceId)
144 execution.setVariable("oofAnNssiPayload", oofRequest)
145 logger.debug("Finish prepareOOFTerminationRequest")
149 void performOofAnNSSITerminationCall(DelegateExecution execution) {
150 boolean terminateAnNSSI = callOofAdapter(execution,execution.getVariable("oofAnNssiPayload"))
151 execution.setVariable("terminateAnNSSI", terminateAnNSSI)
157 void prepareOOFAnNfNssiTerminationRequest(DelegateExecution execution) {
158 logger.debug("Start prepareOOFAnNfNssiTerminationRequest")
159 String requestId = execution.getVariable("msoRequestId")
160 String messageType = "AN_NF_NSSITermination"
161 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
162 String serviceInstanceId = execution.getVariable("anNssiId")
164 String anNfNssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"),AN_NF)
165 execution.setVariable("anNfNssiId", anNfNssiId)
167 String oofRequest = oofUtils.buildTerminateNxiRequest(requestId,anNfNssiId, "NSSI",messageType,serviceInstanceId)
168 execution.setVariable("oofAnNfNssiPayload", oofRequest)
169 logger.debug("Finish prepareOOFAnNfNssiTerminationRequest")
173 void performOofAnNfNSSITerminationCall(DelegateExecution execution) {
174 boolean terminateAnNfNSSI = callOofAdapter(execution,execution.getVariable("oofAnNfNssiPayload"))
175 execution.setVariable("terminateAnNfNSSI", terminateAnNfNSSI)
176 if(!terminateAnNfNSSI) {
177 execution.setVariable("modifyAction","deallocate")
181 void prepareSdnrRequest(DelegateExecution execution) {
183 String anNfNssiId = execution.getVariable("anNfNssiId")
184 String sNssai = execution.getVariable("sNssaiList").get(0)
185 String sliceProfileId = execution.getVariable("anNfSliceProfileId")
186 String reqId = execution.getVariable("msoRequestId")
187 String messageType = "SDNRTerminateResponse"
188 StringBuilder callbackURL = new StringBuilder(UrnPropertiesReader.getVariable("mso.workflow.message.endpoint", execution))
189 callbackURL.append("/").append(messageType).append("/").append(reqId)
191 JsonObject input = new JsonObject()
192 input.addProperty("RANNFNSSIId", anNfNssiId)
193 input.addProperty("callbackURL", callbackURL.toString())
194 input.addProperty("sNSSAI", sNssai)
195 input.addProperty("sliceProfileId",sliceProfileId)
196 input.add("additionalproperties", new JsonObject())
198 JsonObject Payload = new JsonObject()
200 JsonObject wrapinput = new JsonObject()
201 wrapinput.addProperty("action", "deallocate")
203 JsonObject CommonHeader = new JsonObject()
204 CommonHeader.addProperty("timestamp", new Date(System.currentTimeMillis()).format("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", TimeZone.getDefault()))
205 CommonHeader.addProperty("api-ver", "1.0")
206 CommonHeader.addProperty("originator-id", "testing")
207 CommonHeader.addProperty("request-id", reqId)
208 CommonHeader.addProperty("sub-request-id", "1")
209 CommonHeader.add("flags", new JsonObject())
211 JsonObject body = new JsonObject()
213 JsonObject sdnrRequest = new JsonObject()
214 Payload.add("input", input)
215 wrapinput.addProperty("payload", Payload.toString())
216 wrapinput.add("common-header", CommonHeader)
217 body.add("input", wrapinput)
218 sdnrRequest.add("body", body)
219 sdnrRequest.addProperty("version", "1.0")
220 sdnrRequest.addProperty("rpc-name", "terminateRANSliceInstance")
221 sdnrRequest.addProperty("correlation-id", reqId)
222 sdnrRequest.addProperty("type", "request")
224 String json = sdnrRequest.toString()
225 execution.setVariable("sdnrRequest", json)
226 execution.setVariable("SDNR_messageType", messageType)
227 execution.setVariable("SDNR_timeout", "PT10M")
231 void processSdnrResponse(DelegateExecution execution) {
232 logger.debug("${Prefix} processing SdnrResponse")
233 Map<String, Object> resMap = objectMapper.readValue(execution.getVariable("SDNR_Response"),Map.class)
234 String status = resMap.get("status")
235 String reason = resMap.get("reason")
236 if("success".equalsIgnoreCase(status)) {
237 execution.setVariable("isAnNfTerminated", true)
239 execution.setVariable("isAnNfTerminated", false)
240 logger.debug("AN NF Termination failed with reason ${reason}")
242 logger.debug("${Prefix} processed SdnrResponse")
247 * @param oofRequest - Request payload to be sent to adapter
250 boolean callOofAdapter(DelegateExecution execution, Object oofRequest) {
251 logger.debug("Start callOofAdapter")
252 String requestId = execution.getVariable("msoRequestId")
253 String oofAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution)
254 URL requestUrl = new URL(oofAdapterEndpoint)
255 OofRequest oofPayload = new OofRequest()
256 oofPayload.setApiPath("/api/oof/terminate/nxi/v1")
257 oofPayload.setRequestDetails(oofRequest)
258 String requestJson = objectMapper.writeValueAsString(oofPayload)
259 logger.debug("Calling OOF adapter : ${requestUrl} with payload : ${requestJson}")
260 HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL)
261 Response httpResponse = httpClient.post(requestJson)
262 int responseCode = httpResponse.getStatus()
263 logger.debug("OOF sync response code is: " + responseCode)
264 if(responseCode < 200 || responseCode >= 300){
265 logger.debug("OOF request failed with reason : " + httpResponse)
266 exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
268 Map<String,Object> response = objectMapper.readValue(httpResponse.getEntity(),Map.class)
269 boolean terminateResponse = response.get("terminateResponse")
270 if(!terminateResponse) {
271 logger.debug("Terminate response is false because " + response.get("reason"))
273 return terminateResponse
277 void deallocateAnNfNssi(DelegateExecution execution) {
278 logger.debug("${Prefix} - call deallocateAnNfNssi ")
279 String anNfNssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"), AN_NF)
280 String globalSubscriberId = execution.getVariable("globalSubscriberId")
281 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
283 AAIResourcesClient client = new AAIResourcesClient()
284 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(anNfNssiId))
285 if (!client.exists(uri)) {
286 logger.debug("AN NF Service Instance was not found in aai : ${anNfNssiId}")
293 * Removes relationship between AN NSSI and AN_NF NSSI
296 void dissociateAnNfNssi(DelegateExecution execution) {
297 logger.debug("${Prefix} - call dissociateAnNfNssi ")
298 String anNfNssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"), AN_NF)
299 String globalSubscriberId = execution.getVariable("globalSubscriberId")
300 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
302 AAIResourcesClient client = new AAIResourcesClient()
303 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(anNfNssiId))
304 if (!client.exists(uri)) {
305 logger.debug("AN NF Service Instance was not found in aai : ${anNfNssiId}")
312 * Method to prepare request for AN NSSI modification
313 * Call Modify AN NSSI in case OOF sends Terminate NSSI=False
316 void preparejobForANNSSIModification(DelegateExecution execution) {
318 String modificationJobId = UUID.randomUUID().toString()
319 execution.setVariable("modificationJobId", modificationJobId)
321 Map<String,Object> sliceParams = objectMapper.readValue(execution.getVariable("sliceParams"), Map.class)
322 sliceParams.put("modifyAction", "deallocate")
323 execution.setVariable("modificationsliceParams", objectMapper.writeValueAsString(sliceParams))
325 String serviceId = execution.getVariable("serviceInstanceID")
326 String nsiId = execution.getVariable("nsiId")
327 logger.debug("Generated new job for Service Instance serviceId:" + serviceId + " operationId:" + modificationJobId)
329 ResourceOperationStatus initStatus = new ResourceOperationStatus()
330 initStatus.setServiceId(serviceId)
331 initStatus.setOperationId(modificationJobId)
332 initStatus.setResourceTemplateUUID(nsiId)
333 initStatus.setOperType("Modify-Deallocate")
334 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
336 logger.debug(Prefix + "prepareInitOperationStatus Exit")
339 void prepareQueryJobStatus(DelegateExecution execution,String jobId,String networkType,String instanceId) {
341 String responseId = "1"
342 String globalSubscriberId = execution.getVariable("globalSubscriberId")
343 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
345 JsonObject esrInfo = new JsonObject()
346 esrInfo.addProperty("networkType", networkType)
347 esrInfo.addProperty("vendor", "ONAP_internal")
349 JsonObject serviceInfo = new JsonObject()
350 serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
351 serviceInfo.addProperty("nssiId", instanceId)
352 serviceInfo.addProperty("globalSubscriberId", globalSubscriberId)
353 serviceInfo.addProperty("subscriptionServiceType", subscriptionServiceType)
355 execution.setVariable("${networkType}_esrInfo", esrInfo.toString())
356 execution.setVariable("${networkType}_responseId", responseId)
357 execution.setVariable("${networkType}_serviceInfo", serviceInfo.toString())
361 void validateJobStatus(DelegateExecution execution,String responseDescriptor) {
362 logger.debug("validateJobStatus ${responseDescriptor}")
363 String status = jsonUtil.getJsonValue(responseDescriptor, "status")
364 String statusDescription = jsonUtil.getJsonValue(responseDescriptor, "statusDescription")
365 if("finished".equalsIgnoreCase(status)) {
366 execution.setVariable("isSuccess", true)
368 execution.setVariable("isSuccess", false)
372 void prepareUpdateJobStatus(DelegateExecution execution,String status,String progress,String statusDescription) {
373 String nssiId = execution.getVariable("anNssiId")
374 String jobId = execution.getVariable("jobId")
375 String nsiId = execution.getVariable("nsiId")
377 ResourceOperationStatus roStatus = new ResourceOperationStatus()
378 roStatus.setServiceId(nsiId)
379 roStatus.setOperationId(jobId)
380 //roStatus.setResourceTemplateUUID(nsiId)
381 roStatus.setResourceInstanceID(nssiId)
382 roStatus.setOperType("DeAllocate")
383 roStatus.setProgress(progress)
384 roStatus.setStatus(status)
385 roStatus.setStatusDescription(statusDescription)
386 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
389 void terminateTNFHNssi(DelegateExecution execution) {
390 logger.debug("Start terminateTNFHNssi in ${Prefix}")
391 String nssmfRequest = buildDeallocateNssiRequest(execution, TN_FH)
392 String nssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"), TN_FH)
393 execution.setVariable("tnFHNSSIId", nssiId)
394 String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles/" + nssiId
395 String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
396 if (nssmfResponse != null) {
397 String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
398 execution.setVariable("TN_FH_jobId",jobId)
400 logger.error("received error message from NSSMF : "+ nssmfResponse)
401 exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
403 logger.debug("Exit terminateTNFHNssi in ${Prefix}")
406 void terminateTNMHNssi(DelegateExecution execution) {
407 logger.debug("Start terminateTNMHNssi in ${Prefix}")
408 String nssmfRequest = buildDeallocateNssiRequest(execution, TN_MH)
409 String nssiId = getInstanceIdByWorkloadContext(execution.getVariable("relatedNssis"), TN_MH)
410 execution.setVariable("tnMHNSSIId", nssiId)
411 String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles/" + nssiId
412 String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
413 if (nssmfResponse != null) {
414 String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
415 execution.setVariable("TN_MH_jobId",jobId)
417 logger.error("received error message from NSSMF : "+ nssmfResponse)
418 exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
420 logger.debug("Exit terminateTNMHNssi in ${Prefix}")
423 void deleteRanNfSliceProfileInAAI(DelegateExecution execution) {
424 logger.debug("${Prefix} delete Ran NF SliceProfile In AAI")
425 String spId = execution.getVariable("anNfSliceProfileId")
426 deleteServiceInstanceInAAI(execution, spId)
429 void deleteTNSliceProfileInAAI(DelegateExecution execution) {
430 logger.debug("${Prefix} delete TN FH SliceProfile In AAI")
431 String fhSP = getInstanceIdByWorkloadContext(execution.getVariable("relatedSPs"), TN_FH)
432 deleteServiceInstanceInAAI(execution, fhSP)
433 logger.debug("${Prefix} delete TN MH SliceProfile In AAI")
434 String mhSP = getInstanceIdByWorkloadContext(execution.getVariable("relatedSPs"), TN_MH)
435 deleteServiceInstanceInAAI(execution, mhSP)
438 void deleteANNSSI(DelegateExecution execution) {
439 logger.debug("${Prefix} delete AN NSSI")
440 String nssiId = execution.getVariable("anNssiId")
441 deleteServiceInstanceInAAI(execution, nssiId)
445 * Fetches a collection of service instances with the specific role and maps it based on workload context
446 * (AN-NF,TN-FH,TN-MH)
448 * @param role - nssi/slice profile instance
449 * @param instanceId - id to which the related list to be found
452 private Map<String,ServiceInstance> getRelatedInstancesByRole(DelegateExecution execution,String role,String instanceId) {
453 logger.debug("${Prefix} - Fetching related ${role} from AAI")
454 String globalSubscriberId = execution.getVariable("globalSubscriberId")
455 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
457 if( isBlank(role) || isBlank(instanceId)) {
458 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Role and instanceId are mandatory")
461 Map<String,ServiceInstance> relatedInstances = new HashMap<>()
463 AAIResourcesClient client = getAAIClient()
464 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(instanceId))
465 if (!client.exists(uri)) {
466 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai : ${instanceId}")
468 AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
469 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
471 List<Relationship> relationshipList = si.get().getRelationshipList().getRelationship()
472 for (Relationship relationship : relationshipList) {
473 String relatedTo = relationship.getRelatedTo()
474 if (relatedTo.toLowerCase() == "service-instance") {
475 String relatioshipurl = relationship.getRelatedLink()
476 String serviceInstanceId =
477 relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1, relatioshipurl.length())
478 uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId))
479 if (!client.exists(uri)) {
480 exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
481 "Service Instance was not found in aai: ${serviceInstanceId} related to ${instanceId}")
483 AAIResultWrapper wrapper01 = client.get(uri, NotFoundException.class)
484 Optional<ServiceInstance> serviceInstance = wrapper01.asBean(ServiceInstance.class)
485 if (serviceInstance.isPresent()) {
486 ServiceInstance instance = serviceInstance.get()
487 if (role.equalsIgnoreCase(instance.getServiceRole())) {
488 relatedInstances.put(instance.getWorkloadContext(),instance)
494 logger.debug("Found ${relatedInstances.size()} ${role} related to ${instanceId} ")
495 return relatedInstances
498 private String getInstanceIdByWorkloadContext(Map<String,ServiceInstance> instances,String workloadContext ) {
499 String instanceId = instances.get(workloadContext).getServiceInstanceId()
500 if(instanceId == null) {
501 throw new BpmnError( 2500, "${workloadContext} NSSI ID is not found.")
507 * Method to handle deallocation of RAN NSSI constituents(TN_FH/TN_MH)
509 * @param serviceFunction - TN_FH/TN_MH
512 private String buildDeallocateNssiRequest(DelegateExecution execution,String serviceFunction) {
513 String globalSubscriberId = execution.getVariable("globalSubscriberId")
514 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
515 Map<String, ServiceInstance> relatedNssis = execution.getVariable("relatedNssis")
517 String anNssiId = execution.getVariable("anNssiId")
518 List<String> sNssaiList = execution.getVariable("sNssaiList")
520 Map<String, ServiceInstance> relatedSPs = execution.getVariable("relatedSPs")
522 DeAllocateNssi deallocateNssi = new DeAllocateNssi()
523 deallocateNssi.setNsiId(execution.getVariable("nsiId"))
524 ServiceInstance tnNssi = relatedNssis.get(serviceFunction)
525 String nssiId = tnNssi.getServiceInstanceId()
527 deallocateNssi.setNssiId(nssiId)
528 deallocateNssi.setScriptName("TN1")
529 deallocateNssi.setSnssaiList(sNssaiList)
530 deallocateNssi.setSliceProfileId(relatedSPs.get(serviceFunction).getServiceInstanceId())
532 JsonObject esrInfo = new JsonObject()
533 esrInfo.addProperty("networkType", "tn")
534 esrInfo.addProperty("vendor", "ONAP_internal")
536 ServiceInfo serviceInfo = new ServiceInfo()
537 serviceInfo.setServiceInvariantUuid(tnNssi.getModelInvariantId())
538 serviceInfo.setServiceUuid(tnNssi.getModelVersionId())
539 serviceInfo.setGlobalSubscriberId(globalSubscriberId)
540 serviceInfo.setSubscriptionServiceType(subscriptionServiceType)
541 serviceInfo.setNssiId(nssiId)
542 serviceInfo.setNssiName(tnNssi.getServiceInstanceName())
544 JsonObject json = new JsonObject()
545 Gson jsonConverter = new Gson()
546 json.add("deAllocateNssi", jsonConverter.toJsonTree(deallocateNssi))
547 json.add("esrInfo", esrInfo)
548 json.add("serviceInfo", jsonConverter.toJsonTree(serviceInfo))
549 return json.toString()
553 private void deleteServiceInstanceInAAI(DelegateExecution execution,String instanceId) {
555 AAIResourcesClient client = getAAIClient()
556 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(instanceId))
557 client.delete(serviceInstanceUri)
558 logger.debug("${Prefix} Exited deleteServiceInstance")
560 logger.debug("Error occured within deleteServiceInstance method: " + e)