1 package org.onap.so.bpmn.infrastructure.scripts
3 import com.fasterxml.jackson.databind.ObjectMapper
4 import org.camunda.bpm.engine.delegate.DelegateExecution
5 import org.onap.aai.domain.yang.CloudRegion
6 import org.onap.aai.domain.yang.Customer
7 import org.onap.aai.domain.yang.ModelVer
8 import org.onap.aai.domain.yang.OwningEntities
9 import org.onap.aai.domain.yang.ServiceSubscription
10 import org.onap.aai.domain.yang.SliceProfile
11 import org.onap.aai.domain.yang.GenericVnf
12 import org.onap.aai.domain.yang.ServiceInstance
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.AAIResultWrapper
18 import org.onap.aaiclient.client.aai.entities.Relationships
19 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
20 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
21 import org.onap.logging.filter.base.ONAPComponents
22 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
23 import org.onap.so.bpmn.common.scripts.ExceptionUtil
24 import org.onap.so.bpmn.common.scripts.MsoUtils
25 import org.onap.so.bpmn.common.scripts.RequestDBUtil
26 import org.onap.so.bpmn.core.UrnPropertiesReader
27 import org.onap.so.bpmn.core.json.JsonUtils
28 import org.onap.so.client.HttpClient
29 import org.onap.so.client.HttpClientFactory
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
48 import javax.ws.rs.core.Response
50 class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
51 private final String PREFIX ="DoDeallocateCoreNSSI"
53 private ExceptionUtil exceptionUtil = new ExceptionUtil()
54 private RequestDBUtil requestDBUtil = new RequestDBUtil()
55 private MsoUtils utils = new MsoUtils()
56 private JsonUtils jsonUtil = new JsonUtils()
58 private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateCoreNSSI.class)
61 void preProcessRequest(DelegateExecution execution) {
62 LOGGER.trace("${PREFIX} Start preProcessRequest")
64 def currentNSSI = execution.getVariable("currentNSSI")
66 String msg = "currentNSSI is null"
68 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
71 LOGGER.trace("***** ${PREFIX} Exit preProcessRequest")
76 * Queries OOF for NSSI termination
79 void executeTerminateNSSIQuery(DelegateExecution execution) {
81 LOGGER.trace("${PREFIX} Start executeTerminateNSSIQuery")
83 def currentNSSI = execution.getVariable("currentNSSI")
85 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
87 //Prepare auth for OOF
89 String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution)
90 String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
92 String basicAuthValue = utils.encrypt(basicAuth, msokey)
93 if (basicAuthValue != null) {
94 logger.debug( "Obtained BasicAuth username and password for OOF: " + basicAuthValue)
96 authHeader = utils.getBasicAuth(basicAuthValue, msokey)
97 execution.setVariable("BasicAuthHeaderValue", authHeader)
98 } catch (Exception ex) {
99 logger.debug( "Unable to encode username and password string: " + ex)
100 exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to " +
101 "encode username and password string")
104 logger.debug( "Unable to obtain BasicAuth - BasicAuth value null")
105 exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
109 //Prepare send request to OOF
110 String oofRequest = buildOOFRequest(execution)
112 URL url = new URL(urlString+"/api/oof/terminate/nxi/v1")
113 HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.OOF)
114 httpClient.addAdditionalHeader("Authorization", authHeader)
115 httpClient.addAdditionalHeader("Accept", "application/json")
116 httpClient.addAdditionalHeader("Content-Type", "application/json")
118 Response httpResponse = httpClient.post(oofRequest)
120 int responseCode = httpResponse.getStatus()
121 logger.debug("OOF sync response code is: " + responseCode)
123 if(responseCode != 202){ // Accepted
124 exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
127 if(httpResponse.hasEntity()){
128 String OOFResponse = httpResponse.readEntity(Boolean.class)
129 String isTerminateNSSI = jsonUtil.getJsonValue(OOFResponse, "terminateResponse")
131 execution.setVariable("isTerminateNSSI", Boolean.parseBoolean(isTerminateNSSI))
134 LOGGER.trace("${PREFIX} Exit executeTerminateNSSIQuery")
143 private String buildOOFRequest(DelegateExecution execution) {
145 def currentNSSI = execution.getVariable("currentNSSI")
147 String nssiId = currentNSSI['nssiId']
148 String requestId = execution.getVariable("mso-request-id")
150 String request = "{\n" +
151 " \"type\": \"NSSI\",\n" +
152 " \"NxIId\": \"${nssiId}\",\n" +
153 " \"requestInfo\": {\n" +
154 " \"transactionId\": \"${requestId}\",\n" +
155 " \"requestId\": \"${requestId}\",\n" +
156 " \"sourceId\": \"so\",\n" +
166 * Queries Network Service Instance in AAI
169 void getNetworkServiceInstance(DelegateExecution execution) {
170 LOGGER.trace("${PREFIX} Start getNetworkServiceInstance")
172 AAIResourcesClient client = getAAIClient()
174 def currentNSSI = execution.getVariable("currentNSSI")
176 String globalSubscriberId = currentNSSI['globalSubscriberId']
177 String serviceType = currentNSSI['serviceType']
178 String nssiId = currentNSSI['nssiId']
180 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) //AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nssiId)
181 Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
183 if (nssiOpt.isPresent()) {
184 ServiceInstance nssi = nssiOpt.get()
185 currentNSSI['nssi'] = nssi
187 ServiceInstance networkServiceInstance = handleNetworkInstance(execution, nssiId, nssiUri, client)
188 currentNSSI['networkServiceInstance'] = networkServiceInstance
191 String msg = String.format("NSSI %s not found in AAI", nssiId)
193 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
196 LOGGER.trace("${PREFIX} Exit getNetworkServiceInstance")
201 * Handles Network Service
205 * @return Network Service Instance
207 private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) {
208 ServiceInstance networkServiceInstance = null
210 def currentNSSI = execution.getVariable("currentNSSI")
212 AAIResultWrapper wrapper = client.get(nssiUri)
213 Optional<Relationships> relationships = wrapper.getRelationships()
215 if (relationships.isPresent()) {
216 for (AAIResourceUri networkServiceInstanceUri : relationships.get().getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)) {
217 Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri)
218 if (networkServiceInstanceOpt.isPresent()) {
219 networkServiceInstance = networkServiceInstanceOpt.get()
221 if (networkServiceInstance.getServiceRole().equals("Network Service")) { // Network Service role
222 currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri
227 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
229 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
234 String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
236 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
239 if(networkServiceInstance == null) {
240 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
242 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
245 return networkServiceInstance
250 * Invokes deleteServiceOrder external API
253 void deleteServiceOrder(DelegateExecution execution) {
255 LOGGER.trace("${PREFIX} Start deleteServiceOrder")
257 def currentNSSI = execution.getVariable("currentNSSI")
260 //url:/nbi/api/v4/serviceOrder/"
261 def nbiEndpointUrl = UrnPropertiesReader.getVariable("nbi.endpoint.url", execution) // ???
263 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
265 String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId()) // Service Order ID = Network Service Instance ID ???
267 String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
268 String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
269 String basicAuthValue = utils.encrypt(basicAuth, msoKey)
270 String encodeString = utils.getBasicAuth(basicAuthValue, msoKey)
272 HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL)
273 httpClient.addAdditionalHeader("Authorization", encodeString)
274 httpClient.addAdditionalHeader("Accept", "application/json")
275 Response httpResponse = httpClient.delete() // check http code ???
277 String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
279 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
282 LOGGER.trace("${PREFIX} Exit deleteServiceOrder")
287 * Queries constitute VNF from Network Service Instance
290 void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
291 LOGGER.trace("${PREFIX} Start getConstituteVNFFromNetworkServiceInst")
293 def currentNSSI = execution.getVariable("currentNSSI")
295 AAIResourcesClient client = getAAIClient()
297 AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
298 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
299 Optional<Relationships> relationships = wrapper.getRelationships()
300 if (relationships.isPresent()) {
301 for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF)) { // ???
302 execution.setVariable("constituteVnfUri", constituteVnfUri)
303 Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri)
304 if(constituteVnfOpt.isPresent()) {
305 GenericVnf constituteVnf = constituteVnfOpt.get()
306 execution.setVariable("constituteVnf", constituteVnf)
309 String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
311 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
314 break // Should be only one constitute VNF
318 String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
320 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
323 LOGGER.trace("${PREFIX} Exit getConstituteVNFFromNetworkServiceInst")
329 * Retrieves NSSI associated profiles from AAI
332 void getNSSIAssociatedProfiles(DelegateExecution execution) {
333 LOGGER.trace("${PREFIX} Start getNSSIAssociatedProfiles")
335 def currentNSSI = execution.getVariable("currentNSSI")
337 ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
339 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
341 if(associatedProfiles.isEmpty()) {
342 String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId())
344 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
347 execution.setVariable("associatedProfiles", associatedProfiles)
350 LOGGER.trace("${PREFIX} Exit getNSSIAssociatedProfiles")
355 * Calculates a final list of S-NSSAI
358 void calculateSNSSAI(DelegateExecution execution) {
359 LOGGER.trace("${PREFIX} Start calculateSNSSAI")
361 List<SliceProfile> associatedProfiles = (List<SliceProfile>)execution.getVariable("associatedProfiles")
363 def currentNSSI = execution.getVariable("currentNSSI")
365 String currentSNSSAI = currentNSSI['S-NSSAI']
367 List<String> snssais = new ArrayList<>()
369 for(SliceProfile associatedProfile:associatedProfiles) {
370 if(!associatedProfile.getSNssai().equals(currentNSSI)) { // not current S-NSSAI
371 snssais.add(associatedProfile.getSNssai())
375 execution.setVariable("S-NSSAIs", snssais)
377 LOGGER.trace("${PREFIX} Exit calculateSNSSAI")
382 * Invoke PUT Service Instance API
385 void invokePUTServiceInstance(DelegateExecution execution) {
386 LOGGER.trace("${PREFIX} Start invokePUTServiceInstance")
388 def currentNSSI = execution.getVariable("currentNSSI")
391 //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}"
392 def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ???
394 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
396 GenericVnf constituteVnf = (GenericVnf)execution.getVariable("constituteVnf")
398 String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) // ???
400 String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
401 String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
402 String basicAuthValue = utils.encrypt(basicAuth, msoKey)
403 String encodeString = utils.getBasicAuth(basicAuthValue, msoKey)
405 HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL)
406 httpClient.addAdditionalHeader("Authorization", encodeString)
407 httpClient.addAdditionalHeader("Accept", "application/json")
409 RequestDetails requestDetails = prepareRequestDetails(execution)
410 ObjectMapper mapper = new ObjectMapper()
411 String requestDetailsStr = mapper.writeValueAsString(requestDetails)
413 Response httpResponse = httpClient.put(requestDetailsStr) // check http code ???
415 String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
417 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
420 LOGGER.trace("${PREFIX} Exit invokePUTServiceInstance")
427 * @param requestDetails
430 private ModelInfo prepareModelInfo(DelegateExecution execution) {
431 ModelInfo modelInfo = new ModelInfo()
433 modelInfo.setModelType(ModelType.service)
434 modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
436 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId()) // model of Network Service Instance ???
437 Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl)
439 if (modelVerOpt.isPresent()) {
440 modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId())
441 modelInfo.setModelName(modelVerOpt.get().getModelName())
442 modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
451 * Prepares RequestDetails object
455 private RequestDetails prepareRequestDetails(DelegateExecution execution) {
456 RequestDetails requestDetails = new RequestDetails()
458 def currentNSSI = execution.getVariable("currentNSSI")
460 String globalSubscriberId = currentNSSI['globalSubscriberId']
462 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
465 AAIResourcesClient client = getAAIClient()
468 requestDetails.setModelInfo(prepareModelInfo(execution))
471 SubscriberInfo subscriberInfo = new SubscriberInfo()
472 subscriberInfo.setGlobalSubscriberId(globalSubscriberId)
474 Customer customer = null
475 ServiceSubscription serviceSubscription = null
477 AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri']
478 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
479 Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships()
480 if(serviceSubscriptionRelationshipsOps.isPresent()) {
481 List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION)
482 if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) {
483 AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation
484 Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri)
485 if(serviceSubscriptionOpt.isPresent()) {
486 serviceSubscription = serviceSubscriptionOpt.get()
489 wrapper = client.get(serviceSubscriptionUri)
490 Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships()
491 if(customerRelationshipsOps.isPresent()) {
492 List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CUSTOMER)
493 if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) {
494 Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation
495 if(customerOpt.isPresent()) {
496 customer = customerOpt.get()
497 subscriberInfo.setSubscriberName(customer.getSubscriberName())
504 requestDetails.setSubscriberInfo(subscriberInfo)
507 RequestInfo requestInfo = new RequestInfo()
508 requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName())
510 /* No found data to provide ???
511 requestInfo.setSource()
512 requestInfo.setSuppressRollback()
513 requestInfo.setRequestorId()
514 requestInfo.setProductFamilyId()
517 requestDetails.setRequestInfo(requestInfo)
520 // Request Parameters
521 RequestParameters requestParameters = new RequestParameters()
523 // No found data to provide ??? requestParameters.setaLaCarte()
524 requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType())
527 List<Map<String, Object>> userParams = new ArrayList<>()
529 Service service = new Service()
531 ModelInfo serviceModelInfo = new ModelInfo()
532 serviceModelInfo.setModelType(ModelType.service)
533 serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
535 serviceModelInfo.setModelVersionId(modelInfo.get().getModelVersionId())
536 serviceModelInfo.setModelName(modelInfo.get().getModelName())
537 serviceModelInfo.setModelVersion(modelInfo.get().getModelVersion())
539 service.setModelInfo(serviceModelInfo)
542 Resources resources = new Resources()
544 CloudRegion cloudRegion = null
545 AAIResourceUri cloudRegionRelatedAAIUri = null
547 List<Vnfs> vnfs = new ArrayList<>()
549 Vnfs vnf = new Vnfs()
551 // Cloud configuration
552 CloudConfiguration cloudConfiguration = new CloudConfiguration()
554 AAIResourceUri constituteVnfUri = (AAIResourceUri)execution.getVariable("constituteVnfUri")
555 wrapper = client.get(constituteVnfUri)
556 Optional<Relationships> constituteVnfOps = wrapper.getRelationships()
557 if(constituteVnfOps.isPresent()) {
558 List<AAIResourceUri> cloudRegionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION)
559 if(!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) {
560 cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0)
561 Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0))
562 if(cloudRegionrOpt.isPresent()) {
563 cloudRegion = cloudRegionrOpt.get()
564 cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
565 for(Tenant tenant:cloudRegion.getTenants()) {
566 cloudConfiguration.setTenantId(tenant.getTenantId())
567 break // only one is required
570 cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
575 vnf.setCloudConfiguration(cloudConfiguration)
578 GenericVnf constituteVnf = execution.getVariable("constituteVnf")
579 List<VfModules> vfModuless = new ArrayList<>()
580 for(VfModule vfModule:constituteVnf.getVfModules()) {
581 VfModules vfmodules = new VfModules()
583 ModelInfo vfModuleModelInfo = new ModelInfo()
584 vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
586 AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId()) // ???
587 Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
589 if (vfModuleModelVerOpt.isPresent()) {
590 vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
591 vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
592 vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
594 // No model customization ID
596 vfmodules.setModelInfo(vfModuleModelInfo)
598 vfmodules.setInstanceName(vfModule.getVfModuleName()) // ???
600 vfModuless.add(vfmodules)
602 vnf.setVfModules(vfModuless)
605 ModelInfo vnfModelInfo = new ModelInfo()
606 vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId())
607 AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, constituteVnf.getModelInvariantId()) // ???
608 Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl)
610 if (vnfModelVerOpt.isPresent()) {
611 vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId())
612 vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName())
613 vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
615 // No model customization ID
616 // No model instance name
619 vnf.setModelInfo(vnfModelInfo)
622 vnf.setInstanceName(constituteVnf.getVnfInstanceId())
625 List<Map<String, Object>> instanceParams = new ArrayList<>()
626 Map<String, Object> supporrtedNSSAIMap = new HashMap<>()
629 List<String> snssais = ( List<String>)execution.getVariable("S-NSSAIs")
630 supporrtedNSSAIMap.put("supporrtedNSSAI", snssais) // remaining S-NSSAIs ??? there is no status for each s-nssai
631 instanceParams.add(supporrtedNSSAIMap)
633 // No other instance params, e.g. config-type
635 vnf.setInstanceParams(instanceParams)
640 resources.setVnfs(vnfs)
642 service.setResources(resources)
644 Map<String, Object> serviceMap = new HashMap<>()
645 serviceMap.put("service", service)
646 userParams.add(serviceMap)
647 requestParameters.setUserParams(userParams)
649 // No other user params
651 requestDetails.setRequestParameters(requestParameters)
653 // No other request params
655 // Cloud configuration
656 requestDetails.setCloudConfiguration(cloudConfiguration)
659 OwningEntity owningEntity = new OwningEntity()
660 wrapper = client.get(networkServiceInstanceUri)
661 Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships()
662 if(owningEntityRelationshipsOps.isPresent()) {
663 List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)
665 if(!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) {
666 Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation
667 if(owningEntityOpt.isPresent()) {
668 owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId())
669 owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName())
670 requestDetails.setOwningEntity(owningEntity)
676 Project project = new Project()
677 if(cloudRegionRelatedAAIUri != null) {
678 wrapper = client.get(cloudRegionRelatedAAIUri)
679 Optional<Relationships> cloudRegionOps = wrapper.getRelationships()
680 if(cloudRegionOps.isPresent()) {
681 List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedAAIUris(AAIObjectType.PROJECT)
682 if (!(projectAAIUris == null || projectAAIUris.isEmpty())) {
683 Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0))
684 if(projectOpt.isPresent()) {
685 project.setProjectName(projectOpt.get().getProjectName())
690 requestDetails.setProject(project)
692 return requestDetails
697 * Removes NSSI association with NSI
700 void removeNSSIAssociationWithNSI(DelegateExecution execution) {
701 LOGGER.trace("${PREFIX} Start removeNSSIAssociationWithNSI")
703 AAIResourcesClient client = getAAIClient()
705 def currentNSSI = execution.getVariable("currentNSSI")
707 String nssiId = currentNSSI['nssiServiceInstanceId']
708 String nsiId = currentNSSI['nsiId']
710 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
711 AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nsiId)
714 getAAIClient().disconnect(nssiUri, nsiUri)
716 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage())
719 LOGGER.trace("${PREFIX} Exit removeNSSIAssociationWithNSI")
724 * Removes Slice Profile association with NSSI
727 void removeSPAssociationWithNSSI(DelegateExecution execution) {
728 LOGGER.trace("${PREFIX} Start removeSPAssociationWithNSSI")
730 AAIResourcesClient client = getAAIClient()
732 def currentNSSI = execution.getVariable("currentNSSI")
734 ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
736 String nssiId = currentNSSI['nssiServiceInstanceId']
737 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
739 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
741 String currentSNSSAI = currentNSSI['S-NSSAI']
743 associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) })
746 getAAIClient().update(nssiUri, nssi)
748 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage())
751 LOGGER.trace("${PREFIX} Exit removeSPAssociationWithNSSI")
756 * Deletes Slice Profile Instance
759 void deleteSliceProfileInstance(DelegateExecution execution) {
760 LOGGER.trace("${PREFIX} Start deleteSliceProfileInstance")
762 AAIResourcesClient client = getAAIClient()
764 def currentNSSI = execution.getVariable("currentNSSI")
766 ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
768 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
770 String currentSNSSAI = currentNSSI['S-NSSAI']
772 AAIResourceUri sliceProfileUri = null
774 for(SliceProfile associatedProfile:associatedProfiles) {
775 if(!associatedProfile.getSNssai().equals(currentNSSI)) { // not current S-NSSAI
776 sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, associatedProfile.getProfileId())
782 getAAIClient().delete(sliceProfileUri)
784 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
787 LOGGER.trace("${PREFIX} Exit deleteSliceProfileInstance")
792 * Delets NSSI Service Instance
795 void deleteNSSIServiceInstance(DelegateExecution execution) {
796 LOGGER.trace("${PREFIX} Start deleteNSSIServiceInstance")
798 AAIResourcesClient client = getAAIClient()
800 def currentNSSI = execution.getVariable("currentNSSI")
802 String nssiId = currentNSSI['nssiServiceInstanceId']
803 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
806 getAAIClient().delete(nssiUri)
808 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI Service Instance delete call: " + e.getMessage())
811 LOGGER.trace("${PREFIX} Exit deleteNSSIServiceInstance")
816 * Updates operation status
819 void updateServiceOperationStatus(DelegateExecution execution) {
820 LOGGER.trace("${PREFIX} Start updateServiceOperationStatus")
822 def currentNSSI = execution.getVariable("currentNSSI")
824 OperationStatus operationStatus = new OperationStatus()
825 operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String)
826 operationStatus.setOperationId(currentNSSI['operationId'] as String)
827 operationStatus.setOperation(currentNSSI['operationType'] as String)
828 operationStatus.setResult(RequestsDbConstant.Status.FINISHED)
830 requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus)
832 LOGGER.trace("${PREFIX} Exit updateServiceOperationStatus")
840 AAIResourcesClient getAAIClient() {
841 return new AAIResourcesClient()