6c12a656f443634ed8d9bab459bc2ce6b241307d
[so.git] /
1 package org.onap.so.bpmn.infrastructure.scripts
2
3 import com.fasterxml.jackson.databind.ObjectMapper
4 import org.camunda.bpm.engine.delegate.BpmnError
5 import org.camunda.bpm.engine.delegate.DelegateExecution
6 import org.onap.aai.domain.yang.CloudRegion
7 import org.onap.aai.domain.yang.Customer
8 import org.onap.aai.domain.yang.GenericVnf
9 import org.onap.aai.domain.yang.ModelVer
10 import org.onap.aai.domain.yang.ServiceInstance
11 import org.onap.aai.domain.yang.ServiceSubscription
12 import org.onap.aai.domain.yang.SliceProfile
13 import org.onap.aai.domain.yang.Tenant
14 import org.onap.aai.domain.yang.VfModule
15 import org.onap.aaiclient.client.aai.AAIObjectType
16 import org.onap.aaiclient.client.aai.AAIResourcesClient
17 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
18 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
19 import org.onap.aaiclient.client.aai.entities.Relationships
20 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
21 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
22 import org.onap.logging.filter.base.ONAPComponents
23 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
24 import org.onap.so.bpmn.common.scripts.ExceptionUtil
25 import org.onap.so.bpmn.common.scripts.MsoUtils
26 import org.onap.so.bpmn.common.scripts.RequestDBUtil
27 import org.onap.so.bpmn.core.UrnPropertiesReader
28 import org.onap.so.bpmn.core.json.JsonUtils
29 import org.onap.so.client.HttpClient
30 import org.onap.so.db.request.beans.OperationStatus
31 import org.onap.so.requestsdb.RequestsDbConstant
32 import org.onap.so.serviceinstancebeans.CloudConfiguration
33 import org.onap.so.serviceinstancebeans.ModelInfo
34 import org.onap.so.serviceinstancebeans.ModelType
35 import org.onap.so.serviceinstancebeans.OwningEntity
36 import org.onap.so.serviceinstancebeans.Project
37 import org.onap.so.serviceinstancebeans.RequestDetails
38 import org.onap.so.serviceinstancebeans.RequestInfo
39 import org.onap.so.serviceinstancebeans.RequestParameters
40 import org.onap.so.serviceinstancebeans.Resources
41 import org.onap.so.serviceinstancebeans.Service
42 import org.onap.so.serviceinstancebeans.SubscriberInfo
43 import org.onap.so.serviceinstancebeans.VfModules
44 import org.onap.so.serviceinstancebeans.Vnfs
45 import org.slf4j.Logger
46 import org.slf4j.LoggerFactory
47
48 import javax.ws.rs.core.Response
49
50 class DoModifyCoreNSSI extends AbstractServiceTaskProcessor {
51
52     private final String PREFIX ="DoModifyCoreNSSI"
53
54     private ExceptionUtil exceptionUtil = new ExceptionUtil()
55     private RequestDBUtil requestDBUtil = new RequestDBUtil()
56     private MsoUtils utils = new MsoUtils()
57     private JsonUtils jsonUtil = new JsonUtils()
58
59     private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class)
60
61     @Override
62     void preProcessRequest(DelegateExecution execution) {
63         LOGGER.trace("${PREFIX} Start preProcessRequest")
64
65         def currentNSSI = execution.getVariable("currentNSSI")
66         if (!currentNSSI) {
67             String msg = "currentNSSI is null"
68             LOGGER.error(msg)
69             exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
70         }
71
72         LOGGER.trace("***** ${PREFIX} Exit preProcessRequest")
73     }
74
75
76     /**
77      * Queries Network Service Instance in AAI
78      * @param execution
79      */
80     void getNetworkServiceInstance(DelegateExecution execution) {
81         LOGGER.trace("${PREFIX} Start getNetworkServiceInstance")
82
83         AAIResourcesClient client = getAAIClient()
84
85         def currentNSSI = execution.getVariable("currentNSSI")
86
87         String globalSubscriberId = currentNSSI['globalSubscriberId']
88         String serviceType = currentNSSI['serviceType']
89         String nssiId = currentNSSI['nssiServiceInstanceId']
90
91         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) //AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nssiId)
92         Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
93
94         if (nssiOpt.isPresent()) {
95             ServiceInstance nssi = nssiOpt.get()
96             execution.setVariable("nssi", nssi)
97
98             execution.setVariable("nssiUri", nssiUrl)
99
100             // Network Service Instance
101             AAIResultWrapper wrapper = client.get(nssiUri);
102             Optional<Relationships> relationships = wrapper.getRelationships()
103             if (relationships.isPresent()) {
104                 for(AAIResourceUri networkServiceInstanceUri: relationships.get().getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)){ // ???
105                     Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri)
106                     if(networkServiceInstanceOpt.isPresent()) {
107                         ServiceInstance networkServiceInstance = networkServiceInstanceOpt.get()
108
109                         if(networkServiceInstance.getServiceRole().equals("Network Service")) { // Network Service
110                             execution.setVariable("networkServiceInstance", networkServiceInstance)
111
112                             execution.setVariable("networkServiceInstanceUri", networkServiceInstanceUri)
113                             break // Should be only one Network Service Instance
114                         }
115                     }
116                     else {
117                         String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
118                         LOGGER.error(msg)
119                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
120                     }
121
122                 }
123             }
124             else {
125                 String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
126                 LOGGER.error(msg)
127                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
128             }
129         }
130         else {
131             String msg = String.format("NSSI %s not found in AAI", nssiId)
132             LOGGER.error(msg)
133             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
134         }
135
136
137         LOGGER.trace("***** ${PREFIX} Exit getNetworkServiceInstance")
138     }
139
140
141     /**
142      * Queries constitute VNF from Network Service Instance
143      * @param execution
144      */
145     void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
146         LOGGER.trace("${PREFIX} Start getConstituteVNFFromNetworkServiceInst")
147
148         AAIResourcesClient client = getAAIClient()
149
150         AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)execution.getVariable("networkServiceInstanceUri")
151         AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
152         Optional<Relationships> relationships = wrapper.getRelationships()
153         if (relationships.isPresent()) {
154             for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF)) {  // ???
155                 execution.setVariable("constituteVnfUri", constituteVnfUri)
156                 Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri)
157                 if(constituteVnfOpt.isPresent()) {
158                     GenericVnf constituteVnf = constituteVnfOpt.get()
159                     execution.setVariable("constituteVnf", constituteVnf)
160                 }
161                 else {
162                     String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)execution.getVariable("networkServiceInstance")).getServiceInstanceId())
163                     LOGGER.error(msg)
164                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
165                 }
166
167                 execution.setVariable("networkServiceInstanceUri", networkServiceInstanceUri)
168                 break  // Should be only one constitute VNF
169             }
170         }
171         else {
172             String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)execution.getVariable("networkServiceInstance")).getServiceInstanceId())
173             LOGGER.error(msg)
174             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
175         }
176
177         LOGGER.trace("${PREFIX} Exit getConstituteVNFFromNetworkServiceInst")
178
179     }
180
181
182     /**
183      * Retrieves NSSI associated profiles from AAI
184      * @param execution
185      */
186     void getNSSIAssociatedProfiles(DelegateExecution execution) {
187         LOGGER.trace("${PREFIX} Start getNSSIAssociatedProfiles")
188
189         AAIResourcesClient client = getAAIClient()
190
191         ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi")
192
193         List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
194
195         if(associatedProfiles.isEmpty()) {
196             String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId())
197             LOGGER.error(msg)
198             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
199         }
200         else {
201             execution.setVariable("associatedProfiles", associatedProfiles)
202         }
203
204         LOGGER.trace("${PREFIX} Exit getNSSIAssociatedProfiles")
205     }
206
207
208     /**
209      * Calculates a final list of S-NSSAI
210      * @param execution
211      */
212     void calculateSNSSAI(DelegateExecution execution) {
213         LOGGER.trace("${PREFIX} Start calculateSNSSAI")
214
215         List<SliceProfile> associatedProfiles = (List<SliceProfile>)execution.getVariable("associatedProfiles")
216
217         def currentNSSI = execution.getVariable("currentNSSI")
218
219         String currentSNSSAI = currentNSSI['S-NSSAI']
220
221         List<String> snssais = new ArrayList<>()
222
223         if((Boolean)execution.getVariable("isCreateSliceProfileInstance" ).equals(Boolean.TRUE)) { // Slice Profile Instance has to be created
224             for (SliceProfile associatedProfile : associatedProfiles) {
225                 snssais.add(associatedProfile.getSNssai())
226             }
227
228             snssais.add(currentSNSSAI)
229         }
230         else { // Slice profile instance has to be deleted
231             for (SliceProfile associatedProfile : associatedProfiles) {
232                 if (!associatedProfile.getSNssai().equals(currentNSSI)) { // not current S-NSSAI
233                     snssais.add(associatedProfile.getSNssai())
234                 }
235             }
236         }
237
238         execution.setVariable("S-NSSAIs", snssais)
239
240         LOGGER.trace("${PREFIX} Exit calculateSNSSAI")
241     }
242
243
244     /**
245      * Invoke PUT Service Instance API
246      * @param execution
247      */
248     void invokePUTServiceInstance(DelegateExecution execution) {
249         LOGGER.trace("${PREFIX} Start invokePUTServiceInstance")
250
251         try {
252             //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}"
253             def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ???
254
255             ServiceInstance networkServiceInstance = (ServiceInstance)execution.getVariable("networkServiceInstance")
256
257             GenericVnf constituteVnf = (GenericVnf)execution.getVariable("constituteVnf")
258
259             String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) // ???
260
261             String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
262             String basicAuth =  UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
263             String basicAuthValue = utils.encrypt(basicAuth, msoKey)
264             String encodeString = utils.getBasicAuth(basicAuthValue, msoKey)
265
266             HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL)
267             httpClient.addAdditionalHeader("Authorization", encodeString)
268             httpClient.addAdditionalHeader("Accept", "application/json")
269
270             RequestDetails requestDetails = prepareRequestDetails(execution)
271             ObjectMapper mapper = new ObjectMapper()
272             String requestDetailsStr = mapper.writeValueAsString(requestDetails)
273
274             Response httpResponse = httpClient.put(requestDetailsStr) // check http code ???
275         } catch (any) {
276             String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
277             LOGGER.error(msg)
278             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
279         }
280
281         LOGGER.trace("${PREFIX} Exit invokePUTServiceInstance")
282     }
283
284
285     /**
286      * Prepare model info
287      * @param execution
288      * @param requestDetails
289      * @return
290      */
291     private ModelInfo prepareModelInfo(DelegateExecution execution) {
292         ModelInfo modelInfo = new ModelInfo()
293
294         modelInfo.setModelType(ModelType.service)
295         modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
296
297         AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId()) // model of Network Service Instance ???
298         Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl)
299
300         if (modelVerOpt.isPresent()) {
301             modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId())
302             modelInfo.setModelName(modelVerOpt.get().getModelName())
303             modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
304         }
305
306
307         return modelInfo
308     }
309
310
311     /**
312      * Prepares RequestDetails object
313      * @param execution
314      * @return
315      */
316     private RequestDetails prepareRequestDetails(DelegateExecution execution) {
317         RequestDetails requestDetails = new RequestDetails()
318
319         def currentNSSI = execution.getVariable("currentNSSI")
320
321         String globalSubscriberId = currentNSSI['globalSubscriberId']
322
323         ServiceInstance networkServiceInstance = (ServiceInstance)execution.getVariable("networkServiceInstance")
324
325
326         AAIResourcesClient client = getAAIClient()
327
328         // Model Info
329         requestDetails.setModelInfo(prepareModelInfo(execution))
330
331         // Subscriber Info
332         SubscriberInfo subscriberInfo = new SubscriberInfo()
333         subscriberInfo.setGlobalSubscriberId(globalSubscriberId)
334
335         Customer customer = null
336         ServiceSubscription serviceSubscription = null
337
338         AAIResourceUri networkServiceInstanceUri = execution.getVariable("networkServiceInstanceUri")
339         AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
340         Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships()
341         if(serviceSubscriptionRelationshipsOps.isPresent()) {
342             List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION)
343             if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) {
344                 AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation
345                 Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri)
346                 if(serviceSubscriptionOpt.isPresent()) {
347                     serviceSubscription = serviceSubscriptionOpt.get()
348                 }
349
350                 wrapper = client.get(serviceSubscriptionUri)
351                 Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships()
352                 if(customerRelationshipsOps.isPresent()) {
353                     List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CUSTOMER)
354                     if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) {
355                         Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation
356                         if(customerOpt.isPresent()) {
357                             customer = customerOpt.get()
358                             subscriberInfo.setSubscriberName(customer.getSubscriberName())
359                         }
360                     }
361                 }
362             }
363
364         }
365         requestDetails.setSubscriberInfo(subscriberInfo)
366
367         // Request Info
368         RequestInfo requestInfo = new RequestInfo()
369         requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName())
370
371         /* No found data to provide ???
372         requestInfo.setSource()
373         requestInfo.setSuppressRollback()
374         requestInfo.setRequestorId()
375         requestInfo.setProductFamilyId()
376         */
377
378         requestDetails.setRequestInfo(requestInfo)
379
380
381         // Request Parameters
382         RequestParameters requestParameters = new RequestParameters()
383
384         // No found data to provide ??? requestParameters.setaLaCarte()
385         requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType())
386
387         // User params
388         List<Map<String, Object>> userParams = new ArrayList<>()
389         // Service
390         Service service = new Service()
391         // Model Info
392         ModelInfo serviceModelInfo = new ModelInfo()
393         serviceModelInfo.setModelType(ModelType.service)
394         serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
395
396         serviceModelInfo.setModelVersionId(modelInfo.get().getModelVersionId())
397         serviceModelInfo.setModelName(modelInfo.get().getModelName())
398         serviceModelInfo.setModelVersion(modelInfo.get().getModelVersion())
399
400         service.setModelInfo(serviceModelInfo)
401
402         // Resources
403         Resources resources = new Resources()
404
405         CloudRegion cloudRegion = null
406         AAIResourceUri cloudRegionRelatedAAIUri = null
407         // VNFs
408         List<Vnfs> vnfs = new ArrayList<>()
409         // VNF
410         Vnfs vnf = new Vnfs()
411
412         // Cloud configuration
413         CloudConfiguration cloudConfiguration = new CloudConfiguration()
414
415         AAIResourceUri constituteVnfUri = (AAIResourceUri)execution.getVariable("constituteVnfUri")
416         wrapper = client.get(constituteVnfUri)
417         Optional<Relationships> constituteVnfOps = wrapper.getRelationships()
418         if(constituteVnfOps.isPresent()) {
419             List<AAIResourceUri> cloudRegionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION)
420             if(!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) {
421                 cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0)
422                 Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0))
423                 if(cloudRegionrOpt.isPresent()) {
424                     cloudRegion = cloudRegionrOpt.get()
425                     cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
426                     for(Tenant tenant:cloudRegion.getTenants()) {
427                         cloudConfiguration.setTenantId(tenant.getTenantId())
428                         break // only one is required
429                     }
430
431                     cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
432                 }
433             }
434         }
435
436         vnf.setCloudConfiguration(cloudConfiguration)
437
438         // VF Modules
439         GenericVnf constituteVnf = execution.getVariable("constituteVnf")
440         List<VfModules> vfModuless = new ArrayList<>()
441         for(VfModule vfModule:constituteVnf.getVfModules()) {
442             VfModules vfmodules = new VfModules()
443
444             ModelInfo vfModuleModelInfo = new ModelInfo()
445             vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
446
447             AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId()) // ???
448             Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
449
450             if (vfModuleModelVerOpt.isPresent()) {
451                 vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
452                 vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
453                 vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
454
455                 // No model customization ID
456             }
457             vfmodules.setModelInfo(vfModuleModelInfo)
458
459             vfmodules.setInstanceName(vfModule.getVfModuleName()) // ???
460
461             vfModuless.add(vfmodules)
462         }
463         vnf.setVfModules(vfModuless)
464
465         // Model Info
466         ModelInfo vnfModelInfo = new ModelInfo()
467         vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId())
468         AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, constituteVnf.getModelInvariantId()) // ???
469         Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl)
470
471         if (vnfModelVerOpt.isPresent()) {
472             vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId())
473             vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName())
474             vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
475
476             // No model customization ID
477             // No model instance name
478         }
479
480         vnf.setModelInfo(vnfModelInfo)
481
482         // Instance name
483         vnf.setInstanceName(constituteVnf.getVnfInstanceId())
484
485         // Instance params
486         List<Map<String, Object>> instanceParams = new ArrayList<>()
487         Map<String, Object> supporrtedNSSAIMap = new HashMap<>()
488
489         // Supported S-NSSAI
490         List<String> snssais = ( List<String>)execution.getVariable("S-NSSAIs")
491         supporrtedNSSAIMap.put("supporrtedNSSAI", snssais) // remaining S-NSSAIs ??? there is no status for each s-nssai
492         instanceParams.add(supporrtedNSSAIMap)
493
494         // No other instance params, e.g. config-type
495
496         vnf.setInstanceParams(instanceParams)
497
498         // No platform data
499
500         vnfs.add(vnf)
501         resources.setVnfs(vnfs)
502
503         service.setResources(resources)
504
505         Map<String, Object> serviceMap = new HashMap<>()
506         serviceMap.put("service", service)
507         userParams.add(serviceMap)
508         requestParameters.setUserParams(userParams)
509
510         // No other user params
511
512         requestDetails.setRequestParameters(requestParameters)
513
514         // No other request params
515
516         // Cloud configuration
517         requestDetails.setCloudConfiguration(cloudConfiguration)
518
519         // Owning entity
520         OwningEntity owningEntity = new OwningEntity()
521         wrapper = client.get(networkServiceInstanceUri)
522         Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships()
523         if(owningEntityRelationshipsOps.isPresent()) {
524             List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)
525
526             if(!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) {
527                 Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation
528                 if(owningEntityOpt.isPresent()) {
529                     owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId())
530                     owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName())
531                     requestDetails.setOwningEntity(owningEntity)
532                 }
533             }
534         }
535
536         // Project
537         Project project = new Project()
538         if(cloudRegionRelatedAAIUri != null) {
539             wrapper = client.get(cloudRegionRelatedAAIUri)
540             Optional<Relationships> cloudRegionOps = wrapper.getRelationships()
541             if(cloudRegionOps.isPresent()) {
542                 List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedAAIUris(AAIObjectType.PROJECT)
543                 if (!(projectAAIUris == null || projectAAIUris.isEmpty())) {
544                     Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0))
545                     if(projectOpt.isPresent()) {
546                         project.setProjectName(projectOpt.get().getProjectName())
547                     }
548                 }
549             }
550         }
551         requestDetails.setProject(project)
552
553         return requestDetails
554     }
555
556
557     /**
558      * Creates Slice Profile Instance
559      * @param execution
560      */
561     void createSliceProfileInstance(DelegateExecution execution) {
562         LOGGER.trace("${PREFIX} Start createSliceProfileInstance")
563
564         String sliceProfileID = execution.getVariable("sliceProfileID")
565         Map<String, Object> sliceProfileMap = execution.getVariable("sliceProfileCn")
566         Map<String, Object> serviceProfileMap = execution.getVariable("serviceProfile")
567
568         SliceProfile sliceProfile = new SliceProfile()
569         sliceProfile.setServiceAreaDimension("")
570         sliceProfile.setPayloadSize(0)
571         sliceProfile.setJitter(0)
572         sliceProfile.setSurvivalTime(0)
573         sliceProfile.setExpDataRate(0)
574         sliceProfile.setTrafficDensity(0)
575         sliceProfile.setConnDensity(0)
576         sliceProfile.setSNssai(sliceProfileMap.get("sNSSAI").toString())
577         sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString()))
578         sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString()))
579         sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
580         sliceProfile.setResourceSharingLevel(sliceProfileMap.get("activityFactor").toString())
581         sliceProfile.setUeMobilityLevel(serviceProfileMap.get("uEMobilityLevel").toString())
582         sliceProfile.setCoverageAreaTAList(serviceProfileMap.get("coverageAreaTAList").toString())
583         sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
584         sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString()))
585         sliceProfile.setProfileId(sliceProfileID)
586         sliceProfile.setE2ELatency(0)
587
588         try {
589             AAIResourcesClient client = getAAIClient()
590             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, sliceProfileID)
591             client.create(uri, sliceProfile)
592
593             execution.setVariable("createdSliceProfile", sliceProfile)
594         } catch (Exception ex) {
595             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile create call:" + ex.getMessage())
596         }
597
598         LOGGER.trace("${PREFIX} Exit createSliceProfileInstance")
599     }
600
601
602     /**
603      * Creates Slice Profile association with NSSI
604      * @param execution
605      */
606     void associateSliceProfileInstanceWithNSSI(DelegateExecution execution) {
607         LOGGER.trace("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
608
609         String sliceProfileID = execution.getVariable("sliceProfileID")
610
611         def currentNSSI = execution.getVariable("currentNSSI")
612
613         String nssiId = currentNSSI['nssiServiceInstanceId']
614
615         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
616         AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, sliceProfileID)
617
618         try {
619             SliceProfile createdSliceProfile = (SliceProfile)execution.getVariable("createdSliceProfile")
620             ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi")
621             List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
622             associatedProfiles.add(createdSliceProfile)
623
624             getAAIClient().update(nssiUri, nssi)
625
626             getAAIClient().connect(sliceProfileUri, nsiUri, AAIEdgeLabel.BELONGS_TO)
627         }catch(Exception e){
628             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI disconnect call: " + e.getMessage())
629         }
630
631         LOGGER.trace("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")
632     }
633
634
635     /**
636     * Removes Slice Profile association with NSSI
637     * @param execution
638     */
639     void removeSPAssociationWithNSSI(DelegateExecution execution) {
640         LOGGER.trace("${PREFIX} Start removeSPAssociationWithNSSI")
641
642         AAIResourcesClient client = getAAIClient()
643
644         def currentNSSI = execution.getVariable("currentNSSI")
645
646         ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi")
647
648         String nssiId = currentNSSI['nssiServiceInstanceId']
649         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
650
651         List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
652
653         String currentSNSSAI = currentNSSI['S-NSSAI']
654
655         associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) })
656
657         try {
658             getAAIClient().update(nssiUri, nssi)
659         }catch(Exception e){
660             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage())
661         }
662
663         LOGGER.trace("${PREFIX} Exit removeSPAssociationWithNSSI")
664     }
665
666
667     /**
668      * Deletes Slice Profile Instance
669      * @param execution
670      */
671     void deleteSliceProfileInstance(DelegateExecution execution) {
672         LOGGER.trace("${PREFIX} Start deleteSliceProfileInstance")
673
674         AAIResourcesClient client = getAAIClient()
675
676         def currentNSSI = execution.getVariable("currentNSSI")
677
678         ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi")
679
680         List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
681
682         String currentSNSSAI = currentNSSI['S-NSSAI']
683
684         AAIResourceUri sliceProfileUri = null
685
686         for(SliceProfile associatedProfile:associatedProfiles) {
687             if(!associatedProfile.getSNssai().equals(currentNSSI)) { // not current S-NSSAI
688                 sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, associatedProfile.getProfileId())
689                 break
690             }
691         }
692
693         try {
694             getAAIClient().delete(sliceProfileUri)
695         }catch(Exception e){
696             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
697         }
698
699         LOGGER.trace("${PREFIX} Exit deleteSliceProfileInstance")
700     }
701
702
703     /**
704      * Updates operation status
705      * @param execution
706      */
707     void updateServiceOperationStatus(DelegateExecution execution) {
708         LOGGER.trace("${PREFIX} Start updateServiceOperationStatus")
709
710         def currentNSSI = execution.getVariable("currentNSSI")
711
712         OperationStatus operationStatus = new OperationStatus()
713         operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String)
714         operationStatus.setOperationId(currentNSSI['operationId'] as String)
715         operationStatus.setOperation(currentNSSI['operationType'] as String)
716         operationStatus.setResult(RequestsDbConstant.Status.FINISHED)
717
718         requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus)
719
720         LOGGER.trace("${PREFIX} Exit updateServiceOperationStatus")
721     }
722
723
724     /**
725      * Returns AAI client
726      * @return AAI client
727      */
728     AAIResourcesClient getAAIClient() {
729         return new AAIResourcesClient()
730     }
731
732 }