Fix bugs in Allocate flow
[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         logger.debug("setEnableSdncConfig: enableSdnc=" + enableSdnc)
381
382         execution.setVariable("enableSdnc", enableSdnc)
383     }
384
385     String setExecVarFromJsonIfExists(DelegateExecution execution,
386                                       String jsonStr, String jsonKey, String varName) {
387         return setExecVarFromJsonStr(execution, jsonStr, jsonKey, varName, false)
388     }
389
390     String setExecVarFromJsonStr(DelegateExecution execution,
391                                  String jsonStr, String jsonKey, String varName,
392                                  boolean exceptionOnErr) {
393         String msg = ""
394         String valueStr = jsonUtil.getJsonValue(jsonStr, jsonKey)
395         if (isBlank(valueStr)) {
396             if (exceptionOnErr) {
397                 msg = "cannot find " + jsonKey + " in " + jsonStr
398                 logger.debug(msg)
399                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
400             }
401         } else {
402             execution.setVariable(varName, valueStr)
403         }
404
405         return valueStr
406     }
407
408     ServiceInstance getServiceInstanceFromAai(String serviceInstanceId) {
409         if (isBlank(serviceInstanceId)) {
410             logger.error("ERROR: getServiceInstanceFromAai: serviceInstanceId is blank")
411             return null
412         }
413
414         ServiceInstance nssi = null
415         AAIResourcesClient client = new AAIResourcesClient()
416         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE
417                 .getFragment(serviceInstanceId))
418         Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, uri)
419
420         if (nssiOpt.isPresent()) {
421             nssi = nssiOpt.get()
422             return nssi
423         } else {
424             String msg = String.format("ERROR: getServiceInstanceFromAai: NSSI %s not found in AAI", serviceInstanceId)
425             logger.error(msg)
426         }
427
428         return nssi;
429     }
430
431     String getModelUuidFromServiceInstance(String serviceInstanceId) {
432         ServiceInstance si = getServiceInstanceFromAai(serviceInstanceId)
433         if (si == null) {
434             String msg = String.format("ERROR: getModelUuidFromServiceInstance: getServiceInstanceFromAai() failed. " +
435                     "serviceInstanceId=%s", serviceInstanceId)
436             logger.error(msg)
437             return null
438         }
439
440         return si.getModelVersionId()
441     }
442
443     AAIResourceUri buildNetworkPolicyUri(String networkPolicyId) {
444         AAIResourceUri networkPolicyUri =
445                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
446
447         return networkPolicyUri
448     }
449
450     AAIResourceUri buildAllottedResourceUri(DelegateExecution execution, String serviceInstanceId,
451                                             String allottedResourceId) {
452
453         AAIResourceUri allottedResourceUri =
454                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
455                         .customer(execution.getVariable("globalSubscriberId"))
456                         .serviceSubscription(execution.getVariable("subscriptionServiceType"))
457                         .serviceInstance(serviceInstanceId)
458                         .allottedResource(allottedResourceId))
459
460         return allottedResourceUri
461     }
462
463     AAIPluralResourceUri buildAllottedResourcesUri(DelegateExecution execution, String serviceInstanceId) {
464
465         AAIPluralResourceUri arsUri =
466                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
467                         .customer(execution.getVariable("globalSubscriberId"))
468                         .serviceSubscription(execution.getVariable("subscriptionServiceType"))
469                         .serviceInstance(serviceInstanceId)
470                         .allottedResources())
471
472         return arsUri
473     }
474
475     AllottedResources getAllottedResourcesFromAai(DelegateExecution execution, String serviceInstanceId, boolean exceptionOnErr) {
476         AllottedResources res
477         try {
478             AAIResourcesClient client = new AAIResourcesClient()
479
480             AAIPluralResourceUri arsUri = buildAllottedResourcesUri(execution, serviceInstanceId)
481
482             //AAIResultWrapper wrapperAllotted = client.get(arsUri, NotFoundException.class)
483             //Optional<AllottedResources> allAllotted = wrapperAllotted.asBean(AllottedResources.class)
484             //AllottedResources allottedResources = allAllotted.get()
485
486             Optional<AllottedResources> arsOpt = client.get(AllottedResources.class, arsUri)
487             if (arsOpt.isPresent()) {
488                 res = arsOpt.get()
489                 return res
490             } else {
491                 String msg = String.format("ERROR: getAllottedResourcesFromAai: ars not found. nssiId=%s", serviceInstanceId)
492                 logger.error(msg)
493                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
494             }
495         } catch (BpmnError e) {
496             if (exceptionOnErr) {
497                 throw e;
498             }
499         } catch (Exception ex) {
500             if (exceptionOnErr) {
501                 String msg = String.format("ERROR: getAllottedResourcesFromAai: %s", ex.getMessage())
502                 logger.error(msg)
503                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
504             }
505         }
506
507         return res
508     }
509
510     String getPolicyIdFromAr(DelegateExecution execution, String serviceInstanceId,
511                              String arId, boolean exceptionOnErr) {
512         String res
513         try {
514             AAIResourcesClient client = new AAIResourcesClient()
515
516             AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId)
517             List<AAIResourceUri> policyUriList = getRelationshipUriListInAai(execution, arUri,
518                     AAIFluentTypeBuilder.Types.NETWORK_POLICY, exceptionOnErr)
519             for (AAIResourceUri policyUri : policyUriList) {
520                 Optional<NetworkPolicy> policyOpt = client.get(NetworkPolicy.class, policyUri)
521                 if (policyOpt.isPresent()) {
522                     NetworkPolicy policy = policyOpt.get()
523                     return policy.getNetworkPolicyId()
524                 } else {
525                     String msg = String.format("ERROR: getPolicyIdFromAr: arUri=%s", policyUri)
526                     logger.error(msg)
527                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
528                 }
529             }
530         } catch (BpmnError e) {
531             if (exceptionOnErr) {
532                 throw e;
533             }
534         } catch (Exception ex) {
535             if (exceptionOnErr) {
536                 String msg = String.format("ERROR: getPolicyIdFromAr: %s", ex.getMessage())
537                 logger.error(msg)
538                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
539             }
540         }
541
542         return res
543     }
544
545
546     List<AAIResourceUri> getRelationshipUriListInAai(DelegateExecution execution,
547                                                      AAIResourceUri uri,
548                                                      Object info,
549                                                      boolean exceptionOnErr) {
550         AAIResourcesClient client = new AAIResourcesClient()
551         AAIResultWrapper wrapper = client.get(uri);
552         Optional<Relationships> relationships = wrapper.getRelationships()
553         if (relationships.isPresent()) {
554             return relationships.get().getRelatedUris(info)
555         } else {
556             if (exceptionOnErr) {
557                 String msg = "ERROR: getRelationshipUriListInAai: No relationship found"
558                 logger.error(msg)
559                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
560             }
561         }
562
563         return null
564     }
565
566     List<String> getLogicalLinkNamesFromAr(DelegateExecution execution, String serviceInstanceId,
567                                            String arId, boolean exceptionOnErr) {
568         List<String> res = new ArrayList<>()
569         try {
570             AAIResourcesClient client = new AAIResourcesClient()
571
572             AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId)
573             List<AAIResourceUri> logicalLinkUriList = getRelationshipUriListInAai(execution, arUri,
574                     AAIFluentTypeBuilder.Types.LOGICAL_LINK, exceptionOnErr)
575             for (AAIResourceUri logicalLinkUri : logicalLinkUriList) {
576                 Optional<LogicalLink> logicalLinkOpt = client.get(LogicalLink.class, logicalLinkUri)
577                 if (logicalLinkOpt.isPresent()) {
578                     LogicalLink logicalLink = logicalLinkOpt.get()
579                     res.add(logicalLink.getLinkName())
580                 } else {
581                     String msg = String.format("ERROR: getLogicalLinkNamesFromAr: logicalLinkUri=%s", logicalLinkUri)
582                     logger.error(msg)
583                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
584                 }
585             }
586         } catch (BpmnError e) {
587             if (exceptionOnErr) {
588                 throw e;
589             }
590         } catch (Exception ex) {
591             if (exceptionOnErr) {
592                 String msg = String.format("ERROR: getLogicalLinkNamesFromAr: %s", ex.getMessage())
593                 logger.error(msg)
594                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
595             }
596         }
597
598         return res
599     }
600 }