Merge "Enable DeleteChildService functionality" into recursive-orch
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / TnNssmfUtils.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.AllottedResources
26 import org.onap.aai.domain.yang.LogicalLink
27 import org.onap.aai.domain.yang.NetworkPolicy
28 import org.onap.aai.domain.yang.Relationship
29 import org.onap.aai.domain.yang.ServiceInstance
30 import org.onap.aaiclient.client.aai.AAIResourcesClient
31 import org.onap.aaiclient.client.aai.AAIVersion
32 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
33 import org.onap.aaiclient.client.aai.entities.Relationships
34 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
35 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
36 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
37 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
38 import org.onap.so.bpmn.common.scripts.ExceptionUtil
39 import org.onap.so.bpmn.common.scripts.MsoUtils
40 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
41 import org.onap.so.bpmn.core.RollbackData
42 import org.onap.so.bpmn.core.UrnPropertiesReader
43 import org.onap.so.bpmn.core.WorkflowException
44 import org.onap.so.bpmn.core.json.JsonUtils
45 import org.onap.so.db.request.beans.ResourceOperationStatus
46 import org.slf4j.Logger
47 import org.slf4j.LoggerFactory
48
49 import static org.apache.commons.lang3.StringUtils.isBlank
50
51 class TnNssmfUtils {
52     static final String AAI_VERSION = AAIVersion.LATEST
53     private static final Logger logger = LoggerFactory.getLogger(TnNssmfUtils.class);
54
55
56     ExceptionUtil exceptionUtil = new ExceptionUtil()
57     JsonUtils jsonUtil = new JsonUtils()
58     MsoUtils msoUtils = new MsoUtils()
59     SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
60
61     TnNssmfUtils() {
62     }
63
64
65     void setSdncCallbackUrl(DelegateExecution execution, boolean exceptionOnErr) {
66         setSdncCallbackUrl(execution, "sdncCallbackUrl", exceptionOnErr)
67     }
68
69     void setSdncCallbackUrl(DelegateExecution execution, String variableName, boolean exceptionOnErr) {
70         String sdncCallbackUrl = UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback', execution)
71
72         if (isBlank(sdncCallbackUrl) && exceptionOnErr) {
73             String msg = "mso.workflow.sdncadapter.callback is null"
74             logger.debug(msg)
75             exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
76         } else {
77             execution.setVariable(variableName, sdncCallbackUrl)
78         }
79     }
80
81     String buildSDNCRequest(DelegateExecution execution, String svcInstId, String svcAction) {
82         String reqAction
83         switch (svcAction) {
84             case "create":
85                 reqAction = "AllocateTransportSliceInstance"
86                 break
87             case "delete":
88                 reqAction = "DeleteTransportSliceInstance"
89                 break
90             case "activate":
91                 reqAction = "ActivateTransportSliceInstance"
92                 break
93             case "deactivate":
94                 reqAction = "DeactivateTransportSliceInstance"
95                 break
96             case "update":
97                 reqAction = "ModifyTransportSliceInstance"
98                 break
99             default:
100                 reqAction = svcAction
101         }
102
103         buildSDNCRequest(execution, svcInstId, svcAction, reqAction)
104     }
105
106     String buildSDNCRequest(DelegateExecution execution, String svcInstId, String svcAction, String reqAction) {
107
108         String uuid = execution.getVariable('testReqId') // for junits
109         if (uuid == null) {
110             uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
111         }
112
113         def callbackURL = execution.getVariable("sdncCallbackUrl")
114         def requestId = execution.getVariable("msoRequestId")
115         def serviceId = execution.getVariable("sliceServiceInstanceId")
116         def subServiceType = execution.getVariable("subscriptionServiceType")
117         def vnfType = execution.getVariable("serviceType")
118         def vnfName = execution.getVariable("sliceServiceInstanceName")
119         def tenantId = execution.getVariable("sliceServiceInstanceId")
120         def source = execution.getVariable("sliceServiceInstanceId")
121         def vnfId = execution.getVariable("sliceServiceInstanceId")
122         def cloudSiteId = execution.getVariable("sliceServiceInstanceId")
123         def serviceModelInfo = execution.getVariable("serviceModelInfo")
124         def vnfModelInfo = execution.getVariable("serviceModelInfo")
125         def globalSubscriberId = execution.getVariable("globalSubscriberId")
126
127         String vnfNameString = """<vnf-name>${MsoUtils.xmlEscape(vnfName)}</vnf-name>"""
128         String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
129         String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
130
131         String sdncVNFParamsXml = ""
132
133         if (execution.getVariable("vnfParamsExistFlag") == true) {
134             sdncVNFParamsXml = buildSDNCParamsXml(execution)
135         } else {
136             sdncVNFParamsXml = buildDefaultVnfInputParams(vnfId)
137         }
138
139         String sdncRequest =
140                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
141                                                     xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
142                                                     xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
143          <sdncadapter:RequestHeader>
144             <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
145             <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
146             <sdncadapter:SvcAction>${MsoUtils.xmlEscape(svcAction)}</sdncadapter:SvcAction>
147             <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
148             <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
149             <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
150          </sdncadapter:RequestHeader>
151     <sdncadapterworkflow:SDNCRequestData>
152         <request-information>
153             <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
154             <request-action>${MsoUtils.xmlEscape(reqAction)}</request-action>
155             <source>${MsoUtils.xmlEscape(source)}</source>
156             <notification-url/>
157             <order-number/>
158             <order-version/>
159         </request-information>
160         <service-information>
161             <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
162             <subscription-service-type>${MsoUtils.xmlEscape(subServiceType)}</subscription-service-type>
163             ${serviceEcompModelInformation}
164             <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
165             <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
166         </service-information>
167         <vnf-information>
168             <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
169             <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
170             ${vnfEcompModelInformation}
171         </vnf-information>
172         <vnf-request-input>
173             ${vnfNameString}
174             <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
175             <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
176             ${sdncVNFParamsXml}
177         </vnf-request-input>
178     </sdncadapterworkflow:SDNCRequestData>
179     </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
180
181         logger.debug("sdncRequest:  " + sdncRequest)
182         return sdncRequest
183     }
184
185
186     String buildDefaultVnfInputParams(String vnfName) {
187         String res =
188                 """<vnf-input-parameters>
189                       <param>
190                           <name>${MsoUtils.xmlEscape(vnfName)}</name>
191                       </param>
192                    </vnf-input-parameters>"""
193
194         return res
195     }
196
197     String buildSDNCParamsXml(DelegateExecution execution) {
198         String params = ""
199         StringBuilder sb = new StringBuilder()
200         Map<String, String> paramsMap = execution.getVariable("TNNSSMF_vnfParamsMap")
201
202         for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
203             String paramsXml
204             String key = entry.getKey();
205             String value = entry.getValue()
206             paramsXml = """<${key}>$value</$key>"""
207             params = sb.append(paramsXml)
208         }
209         return params
210     }
211
212     void validateSDNCResponse(DelegateExecution execution, String response, String method) {
213         validateSDNCResponse(execution, response, method, true)
214     }
215
216     void validateSDNCResponse(DelegateExecution execution, String response, String method, boolean exceptionOnErr) {
217         logger.debug("STARTED ValidateSDNCResponse Process")
218
219         String msg
220
221         String prefix = execution.getVariable("prefix")
222         if (isBlank(prefix)) {
223             if (exceptionOnErr) {
224                 msg = "validateSDNCResponse: prefix is null"
225                 logger.error(msg)
226                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
227             }
228             return
229         }
230
231         WorkflowException workflowException = execution.getVariable("WorkflowException")
232         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
233
234         logger.debug("TnNssmfUtils.validateSDNCResponse: SDNCResponse: " + response)
235         logger.debug("TnNssmfUtils.validateSDNCResponse: workflowException: " + workflowException)
236
237         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
238
239         String sdncResponse = response
240         if (execution.getVariable(prefix + 'sdncResponseSuccess') == true) {
241             logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse)
242             RollbackData rollbackData = execution.getVariable("rollbackData")
243             if (rollbackData == null) {
244                 rollbackData = new RollbackData()
245             }
246
247             if (method.equals("allocate")) {
248                 rollbackData.put("VNFMODULE", "rollbackSDNCRequestAllocate", "true")
249             } else if (method.equals("deallocate")) {
250                 rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeallocate", "true")
251             } else if (method.equals("activate")) {
252                 rollbackData.put("VNFMODULE", "rollbackSDNCRequestActivate", "true")
253             } else if (method.equals("deactivate")) {
254                 rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeactivate", "true")
255             } else if (method.equals("modify")) {
256                 rollbackData.put("VNFMODULE", "rollbackSDNCRequestModify", "true")
257             }
258             execution.setVariable("rollbackData", rollbackData)
259         } else {
260             if (exceptionOnErr) {
261                 msg = "TnNssmfUtils.validateSDNCResponse: bad Response from SDNC Adapter for " + method + " SDNC Call."
262                 logger.error(msg)
263                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
264             }
265         }
266
267         logger.debug("COMPLETED ValidateSDNCResponse Process")
268     }
269
270     String getExecutionInputParams(DelegateExecution execution) {
271         String res = "\n msoRequestId=" + execution.getVariable("msoRequestId") +
272                 "\n modelInvariantUuid=" + execution.getVariable("modelInvariantUuid") +
273                 "\n modelUuid=" + execution.getVariable("modelUuid") +
274                 "\n serviceInstanceID=" + execution.getVariable("serviceInstanceID") +
275                 "\n operationType=" + execution.getVariable("operationType") +
276                 "\n globalSubscriberId=" + execution.getVariable("globalSubscriberId") +
277                 "\n dummyServiceId=" + execution.getVariable("dummyServiceId") +
278                 "\n nsiId=" + execution.getVariable("nsiId") +
279                 "\n networkType=" + execution.getVariable("networkType") +
280                 "\n subscriptionServiceType=" + execution.getVariable("subscriptionServiceType") +
281                 "\n jobId=" + execution.getVariable("jobId") +
282                 "\n sliceParams=" + execution.getVariable("sliceParams") +
283                 "\n servicename=" + execution.getVariable("servicename")
284
285         return res
286     }
287
288     String getFirstSnssaiFromSliceProfile(String sliceProfileStr) {
289         String snssaiListStr = jsonUtil.getJsonValue(sliceProfileStr, "snssaiList")
290         String snssai = jsonUtil.StringArrayToList(snssaiListStr).get(0)
291
292         return snssai
293     }
294
295     String getFirstPlmnIdFromSliceProfile(String sliceProfileStr) {
296         String plmnListStr = jsonUtil.getJsonValue(sliceProfileStr, "pLMNIdList")
297         String res = jsonUtil.StringArrayToList(plmnListStr).get(0)
298
299         return res
300     }
301
302     void createRelationShipInAAI(DelegateExecution execution, AAIResourceUri uri, Relationship relationship) {
303         logger.debug("createRelationShipInAAI Start")
304         String msg
305         AAIResourcesClient client = new AAIResourcesClient()
306         try {
307             if (!client.exists(uri)) {
308                 logger.info("ERROR: createRelationShipInAAI: not exist: uri={}", uri)
309                 return
310             }
311             AAIResourceUri from = ((AAIResourceUri) (uri.clone())).relationshipAPI()
312             client.create(from, relationship)
313
314         } catch (BpmnError e) {
315             throw e
316         } catch (Exception ex) {
317             msg = "Exception in createRelationShipInAAI. " + ex.getMessage()
318             logger.info(msg)
319             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
320         }
321         logger.debug("createRelationShipInAAI Exit")
322     }
323
324     void attachLogicalLinkToAllottedResource(DelegateExecution execution, String aaiVersion, AAIResourceUri arUri,
325                                              String logicalLinkId) {
326
327         String toLink = "aai/${aaiVersion}/network/logical-links/logical-link/${logicalLinkId}"
328
329         Relationship relationship = new Relationship()
330         relationship.setRelatedLink(toLink)
331         relationship.setRelatedTo("logical-link")
332         relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
333
334         createRelationShipInAAI(execution, arUri, relationship)
335     }
336
337     void attachNetworkPolicyToAllottedResource(DelegateExecution execution, String aaiVersion,
338                                                AAIResourceUri aaiResourceUri, String networkPolicyId) {
339
340         String toLink = "aai/${aaiVersion}/network/network-policies/network-policy/${networkPolicyId}"
341
342         Relationship relationship = new Relationship()
343         relationship.setRelatedLink(toLink)
344         relationship.setRelatedTo("network-policy")
345         relationship.setRelationshipLabel("org.onap.relationships.inventory.Uses")
346
347         createRelationShipInAAI(execution, aaiResourceUri, relationship)
348
349     }
350
351     ResourceOperationStatus buildRoStatus(String nsstId,
352                                           String nssiId,
353                                           String jobId,
354                                           String nsiId,
355                                           String action,
356                                           String status,
357                                           String progress,
358                                           String statusDescription) {
359         ResourceOperationStatus roStatus = new ResourceOperationStatus()
360         roStatus.setResourceTemplateUUID(nsstId)
361         roStatus.setResourceInstanceID(nssiId)
362         roStatus.setServiceId(nsiId)
363         roStatus.setOperationId(jobId)
364         roStatus.setOperType(action)
365         roStatus.setProgress(progress)
366         roStatus.setStatus(status)
367         roStatus.setStatusDescription(statusDescription)
368
369         return roStatus
370     }
371
372
373     void setEnableSdncConfig(DelegateExecution execution) {
374         String enableSdnc = UrnPropertiesReader.getVariable(
375                 "mso.workflow.TnNssmf.enableSDNCNetworkConfig")
376         if (isBlank(enableSdnc)) {
377             logger.debug("mso.workflow.TnNssmf.enableSDNCNetworkConfig is undefined, so use default value (true)")
378             enableSdnc = "true"
379         }
380         enableSdnc = "false"
381         logger.debug("setEnableSdncConfig: enableSdnc=" + enableSdnc)
382
383         execution.setVariable("enableSdnc", enableSdnc)
384     }
385
386     String setExecVarFromJsonIfExists(DelegateExecution execution,
387                                       String jsonStr, String jsonKey, String varName) {
388         return setExecVarFromJsonStr(execution, jsonStr, jsonKey, varName, false)
389     }
390
391     String setExecVarFromJsonStr(DelegateExecution execution,
392                                  String jsonStr, String jsonKey, String varName,
393                                  boolean exceptionOnErr) {
394         String msg = ""
395         String valueStr = jsonUtil.getJsonValue(jsonStr, jsonKey)
396         if (isBlank(valueStr)) {
397             if (exceptionOnErr) {
398                 msg = "cannot find " + jsonKey + " in " + jsonStr
399                 logger.debug(msg)
400                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
401             }
402         } else {
403             execution.setVariable(varName, valueStr)
404         }
405
406         return valueStr
407     }
408
409     ServiceInstance getServiceInstanceFromAai(String serviceInstanceId) {
410         if (isBlank(serviceInstanceId)) {
411             logger.error("ERROR: getServiceInstanceFromAai: serviceInstanceId is blank")
412             return null
413         }
414
415         ServiceInstance nssi = null
416         AAIResourcesClient client = new AAIResourcesClient()
417         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE
418                 .getFragment(serviceInstanceId))
419         Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, uri)
420
421         if (nssiOpt.isPresent()) {
422             nssi = nssiOpt.get()
423             return nssi
424         } else {
425             String msg = String.format("ERROR: getServiceInstanceFromAai: NSSI %s not found in AAI", serviceInstanceId)
426             logger.error(msg)
427         }
428
429         return nssi;
430     }
431
432     String getModelUuidFromServiceInstance(String serviceInstanceId) {
433         ServiceInstance si = getServiceInstanceFromAai(serviceInstanceId)
434         if (si == null) {
435             String msg = String.format("ERROR: getModelUuidFromServiceInstance: getServiceInstanceFromAai() failed. " +
436                     "serviceInstanceId=%s", serviceInstanceId)
437             logger.error(msg)
438             return null
439         }
440
441         return si.getModelVersionId()
442     }
443
444     AAIResourceUri buildNetworkPolicyUri(String networkPolicyId) {
445         AAIResourceUri networkPolicyUri =
446                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
447
448         return networkPolicyUri
449     }
450
451     AAIResourceUri buildAllottedResourceUri(DelegateExecution execution, String serviceInstanceId,
452                                             String allottedResourceId) {
453
454         AAIResourceUri allottedResourceUri =
455                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
456                         .customer(execution.getVariable("globalSubscriberId"))
457                         .serviceSubscription(execution.getVariable("subscriptionServiceType"))
458                         .serviceInstance(serviceInstanceId)
459                         .allottedResource(allottedResourceId))
460
461         return allottedResourceUri
462     }
463
464     AAIPluralResourceUri buildAllottedResourcesUri(DelegateExecution execution, String serviceInstanceId) {
465
466         AAIPluralResourceUri arsUri =
467                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
468                         .customer(execution.getVariable("globalSubscriberId"))
469                         .serviceSubscription(execution.getVariable("subscriptionServiceType"))
470                         .serviceInstance(serviceInstanceId)
471                         .allottedResources())
472
473         return arsUri
474     }
475
476     AllottedResources getAllottedResourcesFromAai(DelegateExecution execution, String serviceInstanceId, boolean exceptionOnErr) {
477         AllottedResources res
478         try {
479             AAIResourcesClient client = new AAIResourcesClient()
480
481             AAIPluralResourceUri arsUri = buildAllottedResourcesUri(execution, serviceInstanceId)
482
483             //AAIResultWrapper wrapperAllotted = client.get(arsUri, NotFoundException.class)
484             //Optional<AllottedResources> allAllotted = wrapperAllotted.asBean(AllottedResources.class)
485             //AllottedResources allottedResources = allAllotted.get()
486
487             Optional<AllottedResources> arsOpt = client.get(AllottedResources.class, arsUri)
488             if (arsOpt.isPresent()) {
489                 res = arsOpt.get()
490                 return res
491             } else {
492                 String msg = String.format("ERROR: getAllottedResourcesFromAai: ars not found. nssiId=%s", serviceInstanceId)
493                 logger.error(msg)
494                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
495             }
496         } catch (BpmnError e) {
497             if (exceptionOnErr) {
498                 throw e;
499             }
500         } catch (Exception ex) {
501             if (exceptionOnErr) {
502                 String msg = String.format("ERROR: getAllottedResourcesFromAai: %s", ex.getMessage())
503                 logger.error(msg)
504                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
505             }
506         }
507
508         return res
509     }
510
511     String getPolicyIdFromAr(DelegateExecution execution, String serviceInstanceId,
512                              String arId, boolean exceptionOnErr) {
513         String res
514         try {
515             AAIResourcesClient client = new AAIResourcesClient()
516
517             AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId)
518             List<AAIResourceUri> policyUriList = getRelationshipUriListInAai(execution, arUri,
519                     AAIFluentTypeBuilder.Types.NETWORK_POLICY, exceptionOnErr)
520             for (AAIResourceUri policyUri : policyUriList) {
521                 Optional<NetworkPolicy> policyOpt = client.get(NetworkPolicy.class, policyUri)
522                 if (policyOpt.isPresent()) {
523                     NetworkPolicy policy = policyOpt.get()
524                     return policy.getNetworkPolicyId()
525                 } else {
526                     String msg = String.format("ERROR: getPolicyIdFromAr: arUri=%s", policyUri)
527                     logger.error(msg)
528                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
529                 }
530             }
531         } catch (BpmnError e) {
532             if (exceptionOnErr) {
533                 throw e;
534             }
535         } catch (Exception ex) {
536             if (exceptionOnErr) {
537                 String msg = String.format("ERROR: getPolicyIdFromAr: %s", ex.getMessage())
538                 logger.error(msg)
539                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
540             }
541         }
542
543         return res
544     }
545
546
547     List<AAIResourceUri> getRelationshipUriListInAai(DelegateExecution execution,
548                                                      AAIResourceUri uri,
549                                                      Object info,
550                                                      boolean exceptionOnErr) {
551         AAIResourcesClient client = new AAIResourcesClient()
552         AAIResultWrapper wrapper = client.get(uri);
553         Optional<Relationships> relationships = wrapper.getRelationships()
554         if (relationships.isPresent()) {
555             return relationships.get().getRelatedUris(info)
556         } else {
557             if (exceptionOnErr) {
558                 String msg = "ERROR: getRelationshipUriListInAai: No relationship found"
559                 logger.error(msg)
560                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
561             }
562         }
563
564         return null
565     }
566
567     List<String> getLogicalLinkNamesFromAr(DelegateExecution execution, String serviceInstanceId,
568                                            String arId, boolean exceptionOnErr) {
569         List<String> res = new ArrayList<>()
570         try {
571             AAIResourcesClient client = new AAIResourcesClient()
572
573             AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId)
574             List<AAIResourceUri> logicalLinkUriList = getRelationshipUriListInAai(execution, arUri,
575                     AAIFluentTypeBuilder.Types.LOGICAL_LINK, exceptionOnErr)
576             for (AAIResourceUri logicalLinkUri : logicalLinkUriList) {
577                 Optional<LogicalLink> logicalLinkOpt = client.get(LogicalLink.class, logicalLinkUri)
578                 if (logicalLinkOpt.isPresent()) {
579                     LogicalLink logicalLink = logicalLinkOpt.get()
580                     res.add(logicalLink.getLinkName())
581                 } else {
582                     String msg = String.format("ERROR: getLogicalLinkNamesFromAr: logicalLinkUri=%s", logicalLinkUri)
583                     logger.error(msg)
584                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
585                 }
586             }
587         } catch (BpmnError e) {
588             if (exceptionOnErr) {
589                 throw e;
590             }
591         } catch (Exception ex) {
592             if (exceptionOnErr) {
593                 String msg = String.format("ERROR: getLogicalLinkNamesFromAr: %s", ex.getMessage())
594                 logger.error(msg)
595                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
596             }
597         }
598
599         return res
600     }
601 }