2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.onap.aai.domain.yang.Relationship
25 import org.onap.aai.domain.yang.ServiceInstance
26 import org.onap.aaiclient.client.aai.AAIObjectName
27 import org.onap.aaiclient.client.aai.AAIResourcesClient
28 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
29 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
30 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.slf4j.Logger
33 import org.slf4j.LoggerFactory
35 import javax.ws.rs.NotFoundException
38 private static final Logger LOGGER = LoggerFactory.getLogger(AAISliceUtil.class);
39 ExceptionUtil exceptionUtil = new ExceptionUtil()
41 * Get NSSI Id from AAI
46 List<String> getNSSIIdList(DelegateExecution execution, String nsiId){
47 List<String> nssiIdList = []
51 String errorMsg = "query nssi from aai failed."
52 AAIResultWrapper wrapper = queryAAI(execution, AAIFluentTypeBuilder.Types.SERVICE_INSTANCE, nsiId, errorMsg)
53 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
56 List<Relationship> relationshipList = si.get().getRelationshipList()?.getRelationship()
57 for (Relationship relationship : relationshipList)
59 String relatedTo = relationship.getRelatedTo()
60 if (relatedTo == "service-instance")
62 String relatedLink = relationship.getRelatedLink()?:""
63 String instanceId = relatedLink ? relatedLink.substring(relatedLink.lastIndexOf("/") + 1,relatedLink.length()) : ""
64 AAIResultWrapper wrapper1 = queryAAI(execution, AAIFluentTypeBuilder.Types.SERVICE_INSTANCE, instanceId, errorMsg)
65 Optional<ServiceInstance> serviceInstance = wrapper1.asBean(ServiceInstance.class)
67 if (serviceInstance.isPresent()) {
68 ServiceInstance instance = serviceInstance.get()
69 if ("nssi".equalsIgnoreCase(instance.getServiceRole())) {
70 nssiId = instance.getServiceInstanceId()
71 nssiIdList.add(nssiId)
82 String msg = "Exception in getNSIFromAAI " + ex.getMessage()
84 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
91 * get nssi service from AAI
95 List<ServiceInstance> getNSSIListFromAAI(DelegateExecution execution, List<String> nssiIdList)
97 LOGGER.trace("***** Start getNSSIListFromAAI *****")
98 List<ServiceInstance> nssiInstanceList = []
99 String errorMsg = "query nssi list from aai failed"
100 for(String nssiId : nssiIdList){
101 AAIResultWrapper wrapper = queryAAI(execution, AAIFluentTypeBuilder.Types.SERVICE_INSTANCE, nssiId, errorMsg)
102 Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
104 nssiInstanceList.add(si.get())
107 LOGGER.trace(" ***** Exit getNSSIListFromAAI *****")
108 return nssiInstanceList
115 * @param aaiObjectName
117 * @return AAIResultWrapper
119 private AAIResultWrapper queryAAI(DelegateExecution execution, AAIObjectName aaiObjectName, String instanceId, String errorMsg)
121 LOGGER.trace(" ***** Start queryAAI *****")
122 String globalSubscriberId = execution.getVariable("globalSubscriberId")
123 String serviceType = execution.getVariable("serviceType")
125 org.onap.aaiclient.client.generated.fluentbuilders.ServiceInstance serviceInstanceType = AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(instanceId)
127 if (aaiObjectName == AAIFluentTypeBuilder.Types.ALLOTTED_RESOURCE) {
128 type = serviceInstanceType.allottedResources()
129 } else if (aaiObjectName == AAIFluentTypeBuilder.Types.SLICE_PROFILES) {
130 type = serviceInstanceType.sliceProfiles()
132 type = serviceInstanceType
134 def uri = AAIUriFactory.createResourceUri(type)
135 if (!getAAIClient().exists(uri)) {
136 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMsg)
138 AAIResultWrapper wrapper = getAAIClient().get(uri, NotFoundException.class)
139 LOGGER.trace(" ***** Exit queryAAI *****")
143 AAIResourcesClient getAAIClient(){
144 return new AAIResourcesClient()