2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Telecom Italia
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
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.CloudRegion
26 import org.onap.aai.domain.yang.GenericVnf
27 import org.onap.aai.domain.yang.ModelVer
28 import org.onap.aai.domain.yang.ServiceInstance
29 import org.onap.aai.domain.yang.ServiceSubscription
30 import org.onap.aai.domain.yang.SliceProfile
31 import org.onap.aai.domain.yang.Tenant
32 import org.onap.aai.domain.yang.VfModule
33 import org.onap.aaiclient.client.aai.AAIObjectType
34 import org.onap.aaiclient.client.aai.AAIResourcesClient
35 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
36 import org.onap.aaiclient.client.aai.entities.Relationships
37 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
38 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
39 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
40 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
41 import org.onap.logging.filter.base.ONAPComponents
42 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
43 import org.onap.so.bpmn.common.scripts.ExceptionUtil
44 import org.onap.so.bpmn.common.scripts.RequestDBUtil
45 import org.onap.so.bpmn.core.UrnPropertiesReader
46 import org.onap.so.bpmn.core.json.JsonUtils
47 import org.onap.so.client.HttpClient
48 import org.onap.so.db.request.beans.OperationStatus
49 import org.onap.so.requestsdb.RequestsDbConstant
50 import org.onap.so.serviceinstancebeans.CloudConfiguration
51 import org.onap.so.serviceinstancebeans.LineOfBusiness
52 import org.onap.so.serviceinstancebeans.ModelInfo
53 import org.onap.so.serviceinstancebeans.ModelType
54 import org.onap.so.serviceinstancebeans.OwningEntity
55 import org.onap.so.serviceinstancebeans.Project
56 import org.onap.so.serviceinstancebeans.RequestDetails
57 import org.onap.so.serviceinstancebeans.RequestInfo
58 import org.onap.so.serviceinstancebeans.RequestParameters
59 import org.onap.so.serviceinstancebeans.Resources
60 import org.onap.so.serviceinstancebeans.Service
61 import org.onap.so.serviceinstancebeans.SubscriberInfo
62 import org.onap.so.serviceinstancebeans.VfModules
63 import org.onap.so.serviceinstancebeans.Vnfs
64 import org.slf4j.Logger
65 import org.slf4j.LoggerFactory
67 import javax.ws.rs.core.Response
70 class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
72 private final String PREFIX ="DoCommonCoreNSSI"
74 private static final Logger LOGGER = LoggerFactory.getLogger( DoCommonCoreNSSI.class)
76 private JsonUtils jsonUtil = new JsonUtils()
77 private ExceptionUtil exceptionUtil = new ExceptionUtil()
78 private RequestDBUtil requestDBUtil = new RequestDBUtil()
81 void preProcessRequest(DelegateExecution execution) {
82 LOGGER.trace("${getPrefix()} Start preProcessRequest")
84 def currentNSSI = execution.getVariable("currentNSSI")
86 String msg = "currentNSSI is null"
88 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
91 LOGGER.trace("***** ${getPrefix()} Exit preProcessRequest")
96 * Queries Network Service Instance in AAI
99 void getNetworkServiceInstance(DelegateExecution execution) {
100 LOGGER.trace("${getPrefix()} Start getNetworkServiceInstance")
102 AAIResourcesClient client = getAAIClient()
104 def currentNSSI = execution.getVariable("currentNSSI")
106 String nssiId = currentNSSI['nssiId']
108 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
109 Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
111 if (nssiOpt.isPresent()) {
112 ServiceInstance nssi = nssiOpt.get()
113 currentNSSI['nssi'] = nssi
115 ServiceInstance networkServiceInstance = handleNetworkInstance(execution, nssiId, nssiUri, client)
116 currentNSSI['networkServiceInstance'] = networkServiceInstance
119 String msg = String.format("NSSI %s not found in AAI", nssiId)
121 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
124 LOGGER.trace("${getPrefix()} Exit getNetworkServiceInstance")
129 * Handles Network Service
133 * @return Network Service Instance
135 private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) {
136 ServiceInstance networkServiceInstance = null
138 def currentNSSI = execution.getVariable("currentNSSI")
140 AAIResultWrapper wrapper = client.get(nssiUri)
141 Optional<Relationships> relationships = wrapper.getRelationships()
143 if (relationships.isPresent()) {
144 for (AAIResourceUri networkServiceInstanceUri : relationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
145 Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri)
146 if (networkServiceInstanceOpt.isPresent()) {
147 networkServiceInstance = networkServiceInstanceOpt.get()
149 if (networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
150 currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri
155 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
157 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
162 String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
164 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
167 if(networkServiceInstance == null) {
168 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
170 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
173 return networkServiceInstance
178 * Queries constitute VNF from Network Service Instance
181 void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
182 LOGGER.trace("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
184 def currentNSSI = execution.getVariable("currentNSSI")
186 AAIResourcesClient client = getAAIClient()
188 AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
189 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
190 Optional<Relationships> relationships = wrapper.getRelationships()
191 if (relationships.isPresent()) {
192 for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedUris(Types.GENERIC_VNF)) {
193 currentNSSI['constituteVnfUri'] = constituteVnfUri
194 Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri)
195 if(constituteVnfOpt.isPresent()) {
196 GenericVnf constituteVnf = constituteVnfOpt.get()
197 currentNSSI['constituteVnf'] = constituteVnf
200 String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
202 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
205 break // Should be only one constitute VNF
209 String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
211 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
214 LOGGER.trace("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
220 * Retrieves NSSI associated profiles from AAI
223 void getNSSIAssociatedProfiles(DelegateExecution execution) {
224 LOGGER.trace("${getPrefix()} Start getNSSIAssociatedProfiles")
226 def currentNSSI = execution.getVariable("currentNSSI")
228 ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
230 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
232 if(associatedProfiles.isEmpty()) {
233 String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId())
235 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
238 currentNSSI['associatedProfiles'] = associatedProfiles
241 LOGGER.trace("${getPrefix()} Exit getNSSIAssociatedProfiles")
246 * Calculates a final list of S-NSSAI
249 void calculateSNSSAI(DelegateExecution execution) {
250 LOGGER.trace("${getPrefix()} Start calculateSNSSAI")
252 def currentNSSI = execution.getVariable("currentNSSI")
254 List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles']
256 String currentSNSSAI = currentNSSI['S-NSSAI']
258 List<String> snssais = new ArrayList<>()
260 String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" )
262 boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar)
264 if(isCreateSliceProfileInstance) { // Slice Profile Instance has to be created
265 for (SliceProfile associatedProfile : associatedProfiles) {
266 snssais.add(associatedProfile.getSNssai())
269 snssais.add(currentSNSSAI)
271 else { // Slice profile instance has to be deleted
272 for (SliceProfile associatedProfile : associatedProfiles) {
273 if (!associatedProfile.getSNssai().equals(currentSNSSAI)) { // not current S-NSSAI
274 snssais.add(associatedProfile.getSNssai())
276 currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
281 currentNSSI['S-NSSAIs'] = snssais
283 LOGGER.trace("${getPrefix()} Exit calculateSNSSAI")
288 * Invoke PUT Service Instance API
291 void invokePUTServiceInstance(DelegateExecution execution) {
292 LOGGER.trace("${getPrefix()} Start invokePUTServiceInstance")
294 def currentNSSI = execution.getVariable("currentNSSI")
297 //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}"
298 def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ???
300 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
302 GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
304 String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
306 String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
307 String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
310 String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey)
311 String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey)
313 String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode")
314 if(errorCode == null || errorCode.isEmpty()) { // No error
315 authHeader = responseAuthHeader
318 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage"))
321 def requestDetails = ""
322 String prepareRequestDetailsResponse = prepareRequestDetails(execution)
323 errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
324 if(errorCode == null || errorCode.isEmpty()) { // No error
325 requestDetails = prepareRequestDetailsResponse
328 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage"))
331 String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails)
332 String putServiceInstanceResponse = ""
334 if(errorCode == null || errorCode.isEmpty()) { // No error
335 putServiceInstanceResponse = callPUTServiceInstanceResponse // check the response ???
338 LOGGER.error(jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
339 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
343 String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
345 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
348 LOGGER.trace("${getPrefix()} Exit invokePUTServiceInstance")
352 String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) {
353 String errorCode = ""
354 String errorMessage = ""
358 HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL)
359 httpClient.addAdditionalHeader("Authorization", authHeader)
360 httpClient.addAdditionalHeader("Accept", "application/json")
362 Response httpResponse = httpClient.put(requestDetailsStr) // check http code ???
365 if (httpResponse.hasEntity()) {
366 response = httpResponse.readEntity(String.class)
370 errorMessage = "No response received."
373 " \"errorCode\": \"${errorCode}\",\n" +
374 " \"errorMessage\": \"${errorMessage}\"\n" +
379 String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
383 " \"errorCode\": \"7000\",\n" +
384 " \"errorMessage\": \"${msg}\"\n" +
397 * @param requestDetails
400 ModelInfo prepareModelInfo(DelegateExecution execution) {
402 def currentNSSI = execution.getVariable("currentNSSI")
403 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
405 ModelInfo modelInfo = new ModelInfo()
407 modelInfo.setModelType(ModelType.service)
408 modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
410 AAIResourcesClient client = getAAIClient()
412 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(networkServiceInstance.getModelInvariantId()).modelVer(networkServiceInstance.getModelVersionId()))
413 Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl)
415 if (modelVerOpt.isPresent()) {
416 modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId())
417 modelInfo.setModelName(modelVerOpt.get().getModelName())
418 modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
426 * Prepares subscriber info
428 * @return SubscriberInfo
430 SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) {
431 def currentNSSI = execution.getVariable("currentNSSI")
433 String globalSubscriberId = currentNSSI['globalSubscriberId']
435 String subscriberName = currentNSSI['subscriberName']
437 SubscriberInfo subscriberInfo = new SubscriberInfo()
438 subscriberInfo.setGlobalSubscriberId(globalSubscriberId)
439 subscriberInfo.setSubscriberName(subscriberName)
442 AAIResourcesClient client = getAAIClient()
444 Customer customer = null
446 AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri']
447 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
448 Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships()
449 if(serviceSubscriptionRelationshipsOps.isPresent()) {
450 List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedUris(Types.SERVICE_SUBSCRIPTION)
451 if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) {
452 AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation
453 Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri)
455 if(serviceSubscriptionOpt.isPresent()) {
456 currentNSSI['serviceSubscription'] = serviceSubscriptionOpt.get()
459 wrapper = client.get(serviceSubscriptionUri)
460 Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships()
461 if(customerRelationshipsOps.isPresent()) {
462 List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedUris(Types.CUSTOMER)
463 if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) {
464 Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation
465 if(customerOpt.isPresent()) {
466 customer = customerOpt.get()
467 subscriberInfo.setSubscriberName(customer.getSubscriberName())
475 return subscriberInfo
480 * Prepares Request Info
482 * @return RequestInfo
484 RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) {
485 def currentNSSI = execution.getVariable("currentNSSI")
487 String serviceId = currentNSSI['serviceId']
489 RequestInfo requestInfo = new RequestInfo()
491 requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName())
492 requestInfo.setSource("VID")
493 requestInfo.setProductFamilyId(serviceId)
494 requestInfo.setRequestorId("NBI")
501 * Prepares Model Info
502 * @param networkServiceInstance
506 ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
508 ModelInfo serviceModelInfo = new ModelInfo()
509 serviceModelInfo.setModelType(ModelType.service)
510 serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
512 serviceModelInfo.setModelVersionId(modelInfo.getModelVersionId())
513 serviceModelInfo.setModelName(modelInfo.getModelName())
514 serviceModelInfo.setModelVersion(modelInfo.getModelVersion())
516 return serviceModelInfo
521 * Prepares Cloud configuration
523 * @return CloudConfiguration
525 CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) {
526 def currentNSSI = execution.getVariable("currentNSSI")
528 CloudConfiguration cloudConfiguration = new CloudConfiguration()
530 AAIResourcesClient client = getAAIClient()
532 AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri']
533 AAIResultWrapper wrapper = client.get(constituteVnfUri)
534 Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships()
536 if(cloudRegionRelationshipsOps.isPresent()) {
537 List<AAIResourceUri> cloudRegionRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedUris(Types.CLOUD_REGION)
538 if (!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) {
539 AAIResourceUri cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0)
540 currentNSSI['cloudRegionRelatedAAIUri'] = cloudRegionRelatedAAIUri
542 Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0))
543 CloudRegion cloudRegion = null
544 if (cloudRegionrOpt.isPresent()) {
545 cloudRegion = cloudRegionrOpt.get()
546 cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
547 for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
548 cloudConfiguration.setTenantId(tenant.getTenantId())
549 break // only one is required
552 cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
557 return cloudConfiguration
562 * Prepares a list of VF Modules
564 * @param constituteVnf
565 * @return List<VfModules>
567 List<VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) {
569 AAIResourcesClient client = getAAIClient()
571 List<VfModules> vfModuless = new ArrayList<>()
572 for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
573 VfModules vfmodules = new VfModules()
575 ModelInfo vfModuleModelInfo = new ModelInfo()
576 vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
577 vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
579 AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
581 Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
583 if (vfModuleModelVerOpt.isPresent()) {
584 vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
585 vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
586 vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
588 vfmodules.setModelInfo(vfModuleModelInfo)
590 vfmodules.setInstanceName(vfModule.getVfModuleName())
592 vfModuless.add(vfmodules)
600 * prepares VNF Model Info
602 * @param constituteVnf
605 ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) {
606 ModelInfo vnfModelInfo = new ModelInfo()
608 AAIResourcesClient client = getAAIClient()
610 vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId())
611 vnfModelInfo.setModelCustomizationId(constituteVnf.getModelCustomizationId())
612 vnfModelInfo.setModelInstanceName(constituteVnf.getVnfName())
614 AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(constituteVnf.getModelInvariantId()).modelVer(constituteVnf.getModelVersionId()))
616 Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl)
618 if (vnfModelVerOpt.isPresent()) {
619 vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId())
620 vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName())
621 vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
628 List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) {
629 def currentNSSI = execution.getVariable("currentNSSI")
631 List<Map<String, Object>> instanceParams = new ArrayList<>()
632 Map<String, Object> instanceParamsMap = new HashMap<>()
635 List<String> snssais = (List<String>) currentNSSI['S-NSSAIs']
637 ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
639 String orchStatus = nssi.getOrchestrationStatus()
642 List<Map<String, String>> snssaiList = new ArrayList<>()
644 for(String snssai:snssais) {
645 Map<String, String> snssaisMap = new HashMap<>()
646 snssaisMap.put("snssai", snssai)
647 snssaisMap.put("status", orchStatus)
648 snssaiList.add(snssaisMap)
651 // Map<String, List<Map<String, String>>> supportedNssaiDetails = new HashMap<>()
652 // supportedNssaiDetails.put("sNssai", supportedNssaiDetails)
654 ObjectMapper mapper = new ObjectMapper()
656 String supportedNssaiDetailsStr = mapper.writeValueAsString(snssaiList)
659 instanceParamsMap.put("k8s-rb-profile-name", "default") // ???
660 instanceParamsMap.put("config-type", "day2") // ???
661 instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr)
662 instanceParams.add(instanceParamsMap)
664 return instanceParams
672 Resources prepareResources(DelegateExecution execution) {
673 def currentNSSI = execution.getVariable("currentNSSI")
675 Resources resources = new Resources()
678 List<Vnfs> vnfs = new ArrayList<>()
680 Vnfs vnf = new Vnfs()
683 LineOfBusiness lob = new LineOfBusiness()
684 lob.setLineOfBusinessName("VNF")
685 vnf.setLineOfBusiness(lob)
688 GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
689 vnf.setProductFamilyId(constituteVnf.getServiceId())
691 // Cloud configuration
692 vnf.setCloudConfiguration(prepareCloudConfiguration(execution))
695 vnf.setVfModules(prepareVfModules(execution, constituteVnf))
698 vnf.setModelInfo(prepareVNFModelInfo(execution, constituteVnf))
701 vnf.setInstanceName(constituteVnf.getVnfName())
704 vnf.setInstanceParams(prepareInstanceParams(execution))
709 resources.setVnfs(vnfs)
719 Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
720 Service service = new Service()
723 service.setModelInfo(prepareServiceModelInfo(networkServiceInstance, modelInfo))
725 service.setInstanceName(networkServiceInstance.getServiceInstanceName())
728 service.setResources(prepareResources(execution))
736 * Prepares request parameters
738 * @return RequestParameters
740 RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
741 def currentNSSI = execution.getVariable("currentNSSI")
743 RequestParameters requestParameters = new RequestParameters()
745 ServiceSubscription serviceSubscription = (ServiceSubscription)currentNSSI['serviceSubscription']
747 if(serviceSubscription != null) {
748 requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType())
752 List<Map<String, Object>> userParams = new ArrayList<>()
754 Map<String, Object> userParam = new HashMap<>()
755 userParam.put("Homing_Solution", "none")
756 userParams.add(userParam)
759 Map<String, Object> serviceMap = new HashMap<>()
760 serviceMap.put("service", prepareService(execution, networkServiceInstance, modelInfo))
761 userParams.add(serviceMap)
762 requestParameters.setUserParams(userParams)
764 return requestParameters
769 * Prepare Owning Entity
771 * @return OwningEntity
773 OwningEntity prepareOwningEntity(DelegateExecution execution) {
774 def currentNSSI = execution.getVariable("currentNSSI")
776 AAIResourcesClient client = getAAIClient()
778 AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
780 OwningEntity owningEntity = new OwningEntity()
781 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
782 Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships()
783 if (owningEntityRelationshipsOps.isPresent()) {
784 List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedUris(Types.OWNING_ENTITY)
786 if (!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) {
787 Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation
788 if (owningEntityOpt.isPresent()) {
789 owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId())
790 owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName())
805 Project prepareProject(DelegateExecution execution) {
806 def currentNSSI = execution.getVariable("currentNSSI")
808 AAIResourcesClient client = getAAIClient()
810 Project project = new Project()
812 AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri']
814 if (cloudRegionRelatedAAIUri != null) {
815 AAIResultWrapper wrapper = client.get(cloudRegionRelatedAAIUri)
816 Optional<Relationships> cloudRegionOps = wrapper.getRelationships()
817 if (cloudRegionOps.isPresent()) {
818 List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedUris(Types.PROJECT)
819 if (!(projectAAIUris == null || projectAAIUris.isEmpty())) {
820 Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0))
821 if (projectOpt.isPresent()) {
822 project.setProjectName(projectOpt.get().getProjectName())
833 * Prepares RequestDetails object
837 String prepareRequestDetails(DelegateExecution execution) {
838 String errorCode = ""
839 String errorMessage = ""
842 RequestDetails requestDetails = new RequestDetails()
844 def currentNSSI = execution.getVariable("currentNSSI")
846 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
850 ModelInfo modelInfo = prepareModelInfo(execution)
851 requestDetails.setModelInfo(modelInfo)
854 requestDetails.setSubscriberInfo(prepareSubscriberInfo(execution))
857 requestDetails.setRequestInfo(prepareRequestInfo(execution, networkServiceInstance))
859 // Request Parameters
860 requestDetails.setRequestParameters(prepareRequestParameters(execution, networkServiceInstance, modelInfo))
862 // Cloud configuration
863 requestDetails.setCloudConfiguration(prepareCloudConfiguration(execution))
866 requestDetails.setOwningEntity(prepareOwningEntity(execution))
869 requestDetails.setProject(prepareProject(execution))
871 ObjectMapper mapper = new ObjectMapper()
873 response = mapper.writeValueAsString(requestDetails)
876 String msg = "Exception in ${getPrefix()}.prepareRequestDetails. " + any.getCause()
880 " \"errorCode\": \"7000\",\n" +
881 " \"errorMessage\": \"${msg}\"\n" +
890 String getAuthHeader(DelegateExecution execution, String basicAuthValue, String msokey) {
892 String errorCode = ""
893 String errorMessage = ""
895 LOGGER.debug("Obtained BasicAuth username and password for OOF: " + basicAuthValue)
897 response = utils.getBasicAuth(basicAuthValue, msokey)
898 } catch (Exception ex) {
899 LOGGER.error("Unable to encode username and password string: ", ex)
902 errorMessage = "Internal Error - Unable to encode username and password string"
905 " \"errorCode\": \"${errorCode}\",\n" +
906 " \"errorMessage\": \"${errorMessage}\"\n" +
914 String encryptBasicAuth(String basicAuth, String msoKey) {
915 return utils.encrypt(basicAuth, msoKey)
920 * Removes Slice Profile association with NSSI
923 void removeSPAssociationWithNSSI(DelegateExecution execution) {
924 LOGGER.trace("${getPrefix()} Start removeSPAssociationWithNSSI")
926 AAIResourcesClient client = getAAIClient()
928 def currentNSSI = execution.getVariable("currentNSSI")
930 ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
932 String nssiId = currentNSSI['nssiId']
933 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
935 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
937 String currentSNSSAI = currentNSSI['S-NSSAI']
939 associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) })
942 getAAIClient().update(nssiUri, nssi)
944 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage())
947 LOGGER.trace("${getPrefix()} Exit removeSPAssociationWithNSSI")
952 * Deletes Slice Profile Instance
955 void deleteSliceProfileInstance(DelegateExecution execution) {
956 LOGGER.trace("${getPrefix()} Start deleteSliceProfileInstance")
958 AAIResourcesClient client = getAAIClient()
960 def currentNSSI = execution.getVariable("currentNSSI")
962 SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI['sliceProfileS-NSSAI']
964 String globalSubscriberId = currentNSSI['globalSubscriberId']
965 String serviceType = currentNSSI['serviceType']
966 String nssiId = currentNSSI['nssiId']
968 // global-customer-id, service-type, service-instance-id, profile-id
969 AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(nssiId).sliceProfile(sliceProfileContainsSNSSAI.getProfileId()))
972 getAAIClient().delete(sliceProfileUri)
974 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
977 LOGGER.trace("${getPrefix()} Exit deleteSliceProfileInstance")
982 * Updates operation status
985 void updateServiceOperationStatus(DelegateExecution execution) {
986 LOGGER.trace("${getPrefix()} Start updateServiceOperationStatus")
988 def currentNSSI = execution.getVariable("currentNSSI")
990 OperationStatus operationStatus = new OperationStatus()
991 operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String)
992 operationStatus.setOperationId(currentNSSI['operationId'] as String)
993 operationStatus.setOperation(currentNSSI['operationType'] as String)
994 operationStatus.setResult(RequestsDbConstant.Status.FINISHED)
996 requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus)
998 LOGGER.trace("${getPrefix()} Exit updateServiceOperationStatus")
1003 * Returns AAI client
1004 * @return AAI client
1006 AAIResourcesClient getAAIClient() {
1007 return new AAIResourcesClient()
1011 String getPrefix() {