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.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.json.JSONArray
27 import org.json.JSONObject
28 import org.onap.aai.domain.yang.v19.*
29 import org.onap.aaiclient.client.aai.AAIResourcesClient
30 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
31 import org.onap.aaiclient.client.aai.entities.Relationships
32 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
33 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
35 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
36 import org.onap.logging.filter.base.ONAPComponents
37 import org.onap.so.bpmn.common.scripts.*
38 import org.onap.so.bpmn.core.UrnPropertiesReader
39 import org.onap.so.bpmn.core.json.JsonUtils
40 import org.onap.so.client.HttpClient
41 import org.onap.so.db.request.beans.ResourceOperationStatus
42 import org.onap.so.serviceinstancebeans.*
43 import org.slf4j.Logger
44 import org.slf4j.LoggerFactory
46 import javax.ws.rs.NotFoundException
47 import javax.ws.rs.core.Response
49 import static org.apache.commons.lang3.StringUtils.isBlank
51 class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
53 private final String PREFIX ="DoCommonCoreNSSI"
55 private static final String SLICE_PROFILE_TEMPLATE = "{\"sliceProfileId\": \"%s\"}"
57 private static final Logger LOGGER = LoggerFactory.getLogger( DoCommonCoreNSSI.class)
59 private JsonUtils jsonUtil = new JsonUtils()
60 private ExceptionUtil exceptionUtil = new ExceptionUtil()
61 private RequestDBUtil requestDBUtil = new RequestDBUtil()
64 void preProcessRequest(DelegateExecution execution) {
65 LOGGER.debug("${getPrefix()} Start preProcessRequest")
67 def currentNSSI = execution.getVariable("currentNSSI")
73 String nssiId = execution.getVariable("serviceInstanceID")
74 if (isBlank(nssiId)) {
75 String msg = "NSSI service instance id is null"
77 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
80 currentNSSI['nssiId'] = nssiId
84 String nsiId = execution.getVariable("nsiId")
86 String msg = "nsiId is null"
88 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
91 currentNSSI['nsiId'] = nsiId
96 String sliceProfile = execution.getVariable("sliceParams")
98 /* if(jsonUtil.jsonValueExists(execution.getVariable("sliceParams"), "sliceProfile")) {
99 sliceProfile = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfile")
101 else { // In case of Deallocate flow or Modify flow with deletion of Slice Profile Instance
102 if(jsonUtil.jsonValueExists(execution.getVariable("sliceParams"), "sliceProfileId")) {
103 sliceProfile = String.format(SLICE_PROFILE_TEMPLATE, jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfileId"))
106 String msg = "Either Slice Profile or Slice Profile Id should be provided"
107 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111 LOGGER.debug("sliceProfile=" + sliceProfile)
112 currentNSSI['sliceProfile'] = sliceProfile
115 String strList = jsonUtil.getJsonValue(sliceProfile, "snssaiList")
117 if(strList != null) {
118 def snssaiList = jsonUtil.StringArrayToList(strList)
120 String sNssai = snssaiList.get(0)
121 currentNSSI['S-NSSAI'] = sNssai
124 LOGGER.debug("S-NSSAI=" + currentNSSI['S-NSSAI'])
127 String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId")
128 currentNSSI['sliceProfileId'] = sliceProfileId
130 execution.setVariable("currentNSSI", currentNSSI)
132 LOGGER.debug("***** ${getPrefix()} Exit preProcessRequest")
137 * Queries Network Service Instance in AAI
140 void getNetworkServiceInstance(DelegateExecution execution) {
141 LOGGER.debug("${getPrefix()} Start getNetworkServiceInstance")
143 AAIResourcesClient client = getAAIClient()
145 def currentNSSI = execution.getVariable("currentNSSI")
147 String nssiId = currentNSSI['nssiId']
149 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
150 Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
152 if (nssiOpt.isPresent()) {
153 ServiceInstance nssi = nssiOpt.get()
154 currentNSSI['nssi'] = nssi
156 ServiceInstance networkServiceInstance = handleNetworkInstance(execution, nssiId, nssiUri, client)
157 currentNSSI['networkServiceInstance'] = networkServiceInstance
160 String msg = String.format("NSSI %s not found in AAI", nssiId)
162 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
165 LOGGER.debug("${getPrefix()} Exit getNetworkServiceInstance")
170 * Handles Network Service
174 * @return Network Service Instance
176 private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) {
177 LOGGER.debug("${getPrefix()} Start handleNetworkInstance")
179 ServiceInstance networkServiceInstance = null
181 def currentNSSI = execution.getVariable("currentNSSI")
183 AAIResultWrapper wrapper = client.get(nssiUri)
184 Optional<Relationships> relationships = wrapper.getRelationships()
186 if (relationships.isPresent()) {
187 for (AAIResourceUri networkServiceInstanceUri : relationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
188 Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri)
189 if (networkServiceInstanceOpt.isPresent()) {
190 networkServiceInstance = networkServiceInstanceOpt.get()
192 if (networkServiceInstance.getServiceRole() == null /* WorkAround */ || networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
193 currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri
198 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
200 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
204 if (currentNSSI['networkServiceInstanceUri'] == null) {
205 String msg = String.format("Network Service Instance URI is null")
207 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
211 String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
213 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
216 if(networkServiceInstance == null) {
217 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
219 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
222 LOGGER.debug("${getPrefix()} Exit handleNetworkInstance")
224 return networkServiceInstance
229 * Queries constitute VNF from Network Service Instance
232 void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
233 LOGGER.debug("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
235 def currentNSSI = execution.getVariable("currentNSSI")
237 AAIResourcesClient client = getAAIClient()
239 AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
240 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
241 Optional<Relationships> relationships = wrapper.getRelationships()
243 if (relationships.isPresent()) {
244 for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedUris(Types.GENERIC_VNF)) {
245 currentNSSI['constituteVnfUri'] = constituteVnfUri
246 Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri)
247 if(constituteVnfOpt.isPresent()) {
248 GenericVnf constituteVnf = constituteVnfOpt.get()
249 currentNSSI['constituteVnf'] = constituteVnf
252 String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
254 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
257 break // Should be only one constitute VNF
261 String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
263 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
266 LOGGER.debug("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
272 * Invoke PUT Service Instance API
275 void invokePUTServiceInstance(DelegateExecution execution) {
276 LOGGER.debug("${getPrefix()} Start invokePUTServiceInstance")
278 def currentNSSI = execution.getVariable("currentNSSI")
281 //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}"
282 def nsmfЕndPoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ???
284 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
286 GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
288 // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5
289 String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
291 String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
293 String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
295 def authHeader = utils.getBasicAuth(basicAuth, msoKey) // ""
296 /* String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey)
298 String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey)
300 String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode")
301 if(errorCode == null || errorCode.isEmpty()) { // No error
302 authHeader = responseAuthHeader
305 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage"))
308 def requestDetails = ""
310 String prepareRequestDetailsResponse = prepareRequestDetails(execution)
311 LOGGER.debug("invokePUTServiceInstance: prepareRequestDetailsResponse=" + prepareRequestDetailsResponse)
313 String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
314 LOGGER.debug("invokePUTServiceInstance: errorCode=" + errorCode)
315 if(errorCode == null || errorCode.isEmpty()) { // No error
316 requestDetails = prepareRequestDetailsResponse
319 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage"))
322 String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails)
324 String macroOperationId = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestId")
325 String requestSelfLink = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestSelfLink")
327 execution.setVariable("macroOperationId", macroOperationId)
328 execution.setVariable("requestSelfLink", requestSelfLink)
329 currentNSSI['requestSelfLink'] = requestSelfLink
332 String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
334 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
337 LOGGER.debug("${getPrefix()} Exit invokePUTServiceInstance")
341 String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) {
342 LOGGER.debug("${getPrefix()} Start callPUTServiceInstance")
344 String errorCode = ""
345 String errorMessage = ""
348 LOGGER.debug("callPUTServiceInstance: url = " + url)
349 LOGGER.debug("callPUTServiceInstance: authHeader = " + authHeader)
352 HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
353 httpClient.addAdditionalHeader("Authorization", authHeader)
354 httpClient.addAdditionalHeader("Accept", "application/json")
356 Response httpResponse = httpClient.put(requestDetailsStr)
358 int soResponseCode = httpResponse.getStatus()
359 if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) {
360 response = httpResponse.readEntity(String.class)
362 LOGGER.debug("callPUTServiceInstance: response = " + response)
366 errorMessage = "Response code is " + soResponseCode
369 " \"errorCode\": \"${errorCode}\",\n" +
370 " \"errorMessage\": \"${errorMessage}\"\n" +
375 String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
379 " \"errorCode\": \"7000\",\n" +
380 " \"errorMessage\": \"${msg}\"\n" +
385 LOGGER.debug("${getPrefix()} Exit callPUTServiceInstance")
395 * @param requestDetails
398 ModelInfo prepareModelInfo(DelegateExecution execution) {
399 LOGGER.debug("${getPrefix()} Start prepareModelInfo")
401 def currentNSSI = execution.getVariable("currentNSSI")
402 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
404 ModelInfo modelInfo = new ModelInfo()
406 modelInfo.setModelType(ModelType.service)
407 modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
409 AAIResourcesClient client = getAAIClient()
411 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(networkServiceInstance.getModelInvariantId()).modelVer(networkServiceInstance.getModelVersionId()))
412 Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl)
414 if (modelVerOpt.isPresent()) {
415 modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId())
416 modelInfo.setModelName(modelVerOpt.get().getModelName())
417 modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
420 LOGGER.debug("${getPrefix()} Exit prepareModelInfo")
427 * Prepares subscriber info
429 * @return SubscriberInfo
431 SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) {
432 LOGGER.debug("${getPrefix()} Start prepareSubscriberInfo")
434 def currentNSSI = execution.getVariable("currentNSSI")
436 String globalSubscriberId = execution.getVariable("globalSubscriberId")
438 String subscriberName = execution.getVariable("subscriberName")
440 SubscriberInfo subscriberInfo = new SubscriberInfo()
441 subscriberInfo.setGlobalSubscriberId(globalSubscriberId)
442 subscriberInfo.setSubscriberName(subscriberName)
445 AAIResourcesClient client = getAAIClient()
447 Customer customer = null
449 AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri']
450 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
451 Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships()
452 if(serviceSubscriptionRelationshipsOps.isPresent()) {
453 List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedUris(Types.SERVICE_SUBSCRIPTION)
454 if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) {
455 AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation
456 Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri)
458 if(serviceSubscriptionOpt.isPresent()) {
459 currentNSSI['serviceSubscription'] = serviceSubscriptionOpt.get()
462 wrapper = client.get(serviceSubscriptionUri)
463 Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships()
464 if(customerRelationshipsOps.isPresent()) {
465 List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedUris(Types.CUSTOMER)
466 if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) {
467 Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation
468 if(customerOpt.isPresent()) {
469 customer = customerOpt.get()
470 subscriberInfo.setSubscriberName(customer.getSubscriberName())
478 LOGGER.debug("${getPrefix()} Exit prepareSubscriberInfo")
480 return subscriberInfo
485 * Prepares Request Info
487 * @return RequestInfo
489 RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) {
490 LOGGER.debug("${getPrefix()} Start prepareRequestInfo")
492 def currentNSSI = execution.getVariable("currentNSSI")
494 String productFamilyId = execution.getVariable("productFamilyId")
496 RequestInfo requestInfo = new RequestInfo()
498 requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName())
499 requestInfo.setSource("VID")
500 requestInfo.setProductFamilyId(productFamilyId)
501 requestInfo.setRequestorId("NBI")
503 LOGGER.debug("${getPrefix()} Exit prepareRequestInfo")
510 * Prepares Model Info
511 * @param networkServiceInstance
515 ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
516 LOGGER.debug("${getPrefix()} Start prepareServiceModelInfo")
518 ModelInfo serviceModelInfo = new ModelInfo()
519 serviceModelInfo.setModelType(ModelType.service)
520 serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
522 serviceModelInfo.setModelVersionId(modelInfo.getModelVersionId())
523 serviceModelInfo.setModelName(modelInfo.getModelName())
524 serviceModelInfo.setModelVersion(modelInfo.getModelVersion())
526 LOGGER.debug("${getPrefix()} Exit prepareServiceModelInfo")
528 return serviceModelInfo
533 * Prepares Cloud configuration
535 * @return CloudConfiguration
537 CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) {
538 LOGGER.debug("${getPrefix()} Start prepareCloudConfiguration")
540 def currentNSSI = execution.getVariable("currentNSSI")
542 CloudConfiguration cloudConfiguration = new CloudConfiguration()
544 AAIResourcesClient client = getAAIClient()
546 AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri']
548 AAIResultWrapper wrapper = client.get(constituteVnfUri)
549 Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships()
551 if(cloudRegionRelationshipsOps.isPresent()) {
552 List<AAIResourceUri> cloudRegionRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedUris(Types.CLOUD_REGION)
553 if (!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) {
554 AAIResourceUri cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0)
555 currentNSSI['cloudRegionRelatedAAIUri'] = cloudRegionRelatedAAIUri
557 Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0))
558 CloudRegion cloudRegion = null
559 if (cloudRegionrOpt.isPresent()) {
560 cloudRegion = cloudRegionrOpt.get()
561 cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
563 if(cloudRegion.getTenants() != null && cloudRegion.getTenants().getTenant() != null) {
564 for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
565 cloudConfiguration.setTenantId(tenant.getTenantId())
566 cloudConfiguration.setTenantName(tenant.getTenantName())
567 break // only one is required
571 List<AAIResourceUri> tenantRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedUris(Types.TENANT)
572 if (!(tenantRelatedAAIUris == null || tenantRelatedAAIUris.isEmpty())) {
573 Optional<Tenant> tenantOpt = client.get(Tenant.class, tenantRelatedAAIUris.get(0))
575 if (tenantOpt.isPresent()) {
576 tenant = tenantOpt.get()
578 LOGGER.debug("prepareCloudConfiguration: tenantId=" + tenant.getTenantId())
579 LOGGER.debug("prepareCloudConfiguration: tenantName=" + tenant.getTenantName())
581 cloudConfiguration.setTenantId(tenant.getTenantId())
582 cloudConfiguration.setTenantName(tenant.getTenantName())
587 cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
592 LOGGER.debug("${getPrefix()} Exit prepareCloudConfiguration")
594 return cloudConfiguration
599 * Prepares a list of VF Modules
601 * @param constituteVnf
602 * @return List<VfModules>
604 List<org.onap.so.serviceinstancebeans.VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) {
605 LOGGER.debug("${getPrefix()} Start prepareVfModules")
607 AAIResourcesClient client = getAAIClient()
609 def currentNSSI = execution.getVariable("currentNSSI")
611 List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
613 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
615 String networkServiceModelInvariantUuid = networkServiceInstance.getModelInvariantId()
617 String serviceVnfs="";
620 CatalogDbUtils catalogDbUtils = getCatalogDbUtilsFactory().create()
622 String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution, networkServiceModelInvariantUuid)
623 LOGGER.debug("***** JSON IS: "+json)
625 serviceVnfs = jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs") ?: ""
627 ObjectMapper mapper = new ObjectMapper()
629 List<Object> vnfList = mapper.readValue(serviceVnfs, List.class)
630 LOGGER.debug("vnfList: "+vnfList)
632 Map vnfMap = vnfList.get(0)
633 ModelInfo vnfModelInfo = vnfMap.get("modelInfo")
634 vnfModelInfo.setModelCustomizationId(vnfModelInfo.getModelCustomizationUuid())
635 vnfModelInfo.setModelVersionId(vnfModelInfo.getModelId())
636 LOGGER.debug("vnfModelInfo "+vnfModelInfo)
639 List<Map<String, Object>> vfModuleList = vnfMap.get("vfModules")
640 LOGGER.debug("vfModuleList "+vfModuleList)
643 List<ModelInfo> vfModelInfoList = new ArrayList<>()
645 //Traverse VFModules List and add in vfModelInfoList
646 for (vfModule in vfModuleList) {
647 ModelInfo vfModelInfo = vfModule.get("modelInfo")
648 vfModelInfo.setModelCustomizationId(vfModelInfo.getModelCustomizationUuid())
649 vfModelInfo.setModelVersionId(vfModelInfo.getModelId())
650 LOGGER.debug("vfModelInfo "+vfModelInfo)
651 vfModelInfoList.add(vfModelInfo)
654 for (ModelInfo vfModuleModelInfo : vfModelInfoList) {
655 org.onap.so.serviceinstancebeans.VfModules vfModules = new org.onap.so.serviceinstancebeans.VfModules()
656 vfModules.setModelInfo(vfModuleModelInfo)
657 vfModules.setInstanceName(vfModuleModelInfo.getModelName())
659 List<Map<String, Object>> vfModuleInstanceParams = new ArrayList<>()
660 vfModules.setInstanceParams(vfModuleInstanceParams)
661 vfModuless.add(vfModules)
664 } catch (Exception ex){
665 msg = "Exception in prepareVfModules " + ex.getMessage()
667 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
671 List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
672 if(constituteVnf.getVfModules() != null && constituteVnf.getVfModules().getVfModule() != null) {
673 for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
674 org.onap.so.serviceinstancebeans.VfModules vfmodules = new org.onap.so.serviceinstancebeans.VfModules()
676 ModelInfo vfModuleModelInfo = new ModelInfo()
677 vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
678 vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
680 AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
682 Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
684 if (vfModuleModelVerOpt.isPresent()) {
685 vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
686 vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
687 vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
689 vfmodules.setModelInfo(vfModuleModelInfo)
691 vfmodules.setInstanceName(vfModule.getVfModuleName())
693 vfModuless.add(vfmodules)
697 LOGGER.debug("${getPrefix()} Exit prepareVfModules")
704 * prepares VNF Model Info
706 * @param constituteVnf
709 ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) {
710 LOGGER.debug("${getPrefix()} Start prepareVNFModelInfo")
712 ModelInfo vnfModelInfo = new ModelInfo()
714 AAIResourcesClient client = getAAIClient()
716 vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId())
717 vnfModelInfo.setModelCustomizationId(constituteVnf.getModelCustomizationId())
718 vnfModelInfo.setModelInstanceName(constituteVnf.getVnfName())
720 AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(constituteVnf.getModelInvariantId()).modelVer(constituteVnf.getModelVersionId()))
722 Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl)
724 if (vnfModelVerOpt.isPresent()) {
725 vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId())
726 vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName())
727 vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
730 LOGGER.debug("${getPrefix()} Exit prepareVNFModelInfo")
736 List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) {
737 LOGGER.debug("${getPrefix()} Start prepareInstanceParams")
739 def currentNSSI = execution.getVariable("currentNSSI")
741 List<Map<String, Object>> instanceParams = new ArrayList<>()
742 Map<String, Object> instanceParamsMap = new HashMap<>()
745 def snssaisList = currentNSSI['S-NSSAIs']
746 List<String> snssais = new ArrayList<>()
747 if(snssaisList != null) {
748 snssais = new ArrayList<String>((List<String>)snssaisList)
751 LOGGER.debug("prepareInstanceParams: snssais size = " + snssais.size())
753 ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
755 String orchStatus = nssi.getOrchestrationStatus()
758 List<Map<String, String>> snssaiList = new ArrayList<>()
760 for(String snssai:snssais) {
761 LOGGER.debug("prepareInstanceParams: snssai = " + snssai)
762 Map<String, String> snssaisMap = new HashMap<>()
763 snssaisMap.put("snssai", snssai)
764 snssaisMap.put("status", orchStatus)
765 snssaiList.add(snssaisMap)
768 // Map<String, List<Map<String, String>>> supportedNssaiDetails = new HashMap<>()
769 // supportedNssaiDetails.put("sNssai", supportedNssaiDetails)
771 ObjectMapper mapper = new ObjectMapper()
773 Map<String, Object> nSsai= new LinkedHashMap<>()
774 nSsai.put("sNssai", snssaiList)
776 // String supportedsNssaiJson = mapper.writeValueAsString(snssaiList)
777 String supportedsNssaiJson = mapper.writeValueAsString(nSsai)
779 instanceParamsMap.put("k8s-rb-profile-name", "default") // ???
780 instanceParamsMap.put("config-type", "day2") // ???
781 instanceParamsMap.put("supportedsNssai", supportedsNssaiJson)
782 instanceParams.add(instanceParamsMap)
784 LOGGER.debug("${getPrefix()} Exit prepareInstanceParams")
786 return instanceParams
794 Resources prepareResources(DelegateExecution execution) {
795 LOGGER.debug("${getPrefix()} Start prepareResources")
797 def currentNSSI = execution.getVariable("currentNSSI")
799 Resources resources = new Resources()
802 List<Vnfs> vnfs = new ArrayList<>()
804 Vnfs vnf = new Vnfs()
807 org.onap.so.serviceinstancebeans.LineOfBusiness lob = new org.onap.so.serviceinstancebeans.LineOfBusiness()
808 lob.setLineOfBusinessName("VNF")
809 vnf.setLineOfBusiness(lob)
812 GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
813 vnf.setProductFamilyId(constituteVnf.getServiceId())
815 // Cloud configuration
816 vnf.setCloudConfiguration(prepareCloudConfiguration(execution))
819 vnf.setVfModules(prepareVfModules(execution, constituteVnf))
822 vnf.setModelInfo(prepareVNFModelInfo(execution, constituteVnf))
825 vnf.setInstanceName(constituteVnf.getVnfName())
828 vnf.setInstanceParams(prepareInstanceParams(execution))
833 resources.setVnfs(vnfs)
835 LOGGER.debug("${getPrefix()} Exit prepareResources")
845 org.onap.so.serviceinstancebeans.Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
846 LOGGER.debug("${getPrefix()} Start prepareService")
848 org.onap.so.serviceinstancebeans.Service service = new org.onap.so.serviceinstancebeans.Service()
851 service.setModelInfo(prepareServiceModelInfo(networkServiceInstance, modelInfo))
853 service.setInstanceName(networkServiceInstance.getServiceInstanceName())
856 service.setResources(prepareResources(execution))
858 LOGGER.debug("${getPrefix()} Exit prepareService")
866 * Prepares request parameters
868 * @return RequestParameters
870 RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
871 LOGGER.debug("${getPrefix()} Start prepareRequestParameters")
873 def currentNSSI = execution.getVariable("currentNSSI")
875 RequestParameters requestParameters = new RequestParameters()
877 ServiceSubscription serviceSubscription = (ServiceSubscription)currentNSSI['serviceSubscription']
879 if(serviceSubscription != null) {
880 requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType())
884 List<Map<String, Object>> userParams = new ArrayList<>()
886 Map<String, Object> userParam = new HashMap<>()
887 userParam.put("Homing_Solution", "none")
888 userParams.add(userParam)
891 Map<String, Object> serviceMap = new HashMap<>()
892 serviceMap.put("service", prepareService(execution, networkServiceInstance, modelInfo))
893 userParams.add(serviceMap)
894 requestParameters.setUserParams(userParams)
896 requestParameters.setaLaCarte(false)
898 LOGGER.debug("${getPrefix()} Exit prepareRequestParameters")
900 return requestParameters
905 * Prepare Owning Entity
907 * @return OwningEntity
909 org.onap.so.serviceinstancebeans.OwningEntity prepareOwningEntity(DelegateExecution execution) {
910 LOGGER.debug("${getPrefix()} Start prepareOwningEntity")
912 def currentNSSI = execution.getVariable("currentNSSI")
914 AAIResourcesClient client = getAAIClient()
916 AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
918 org.onap.so.serviceinstancebeans.OwningEntity owningEntity = new org.onap.so.serviceinstancebeans.OwningEntity()
919 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
920 Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships()
921 if (owningEntityRelationshipsOps.isPresent()) {
922 List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedUris(Types.OWNING_ENTITY)
924 if (!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) {
925 Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.v19.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation
926 if (owningEntityOpt.isPresent()) {
927 owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId())
928 owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName())
934 LOGGER.debug("${getPrefix()} Exit prepareOwningEntity")
945 org.onap.so.serviceinstancebeans.Project prepareProject(DelegateExecution execution) {
946 LOGGER.debug("${getPrefix()} Start prepareProject")
948 def currentNSSI = execution.getVariable("currentNSSI")
950 AAIResourcesClient client = getAAIClient()
952 org.onap.so.serviceinstancebeans.Project project = new org.onap.so.serviceinstancebeans.Project()
954 AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri']
956 if (cloudRegionRelatedAAIUri != null) {
957 AAIResultWrapper wrapper = client.get(cloudRegionRelatedAAIUri)
958 Optional<Relationships> cloudRegionOps = wrapper.getRelationships()
959 if (cloudRegionOps.isPresent()) {
960 List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedUris(Types.PROJECT)
961 if (!(projectAAIUris == null || projectAAIUris.isEmpty())) {
962 Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.v19.Project.class, projectAAIUris.get(0))
963 if (projectOpt.isPresent()) {
964 project.setProjectName(projectOpt.get().getProjectName())
970 LOGGER.debug("${getPrefix()} Exit prepareProject")
977 * Prepares RequestDetails object
981 String prepareRequestDetails(DelegateExecution execution) {
982 LOGGER.debug("${getPrefix()} Start prepareRequestDetails")
984 String errorCode = ""
985 String errorMessage = ""
988 RequestDetails requestDetails = new RequestDetails()
990 def currentNSSI = execution.getVariable("currentNSSI")
992 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
996 ModelInfo modelInfo = prepareModelInfo(execution)
997 requestDetails.setModelInfo(modelInfo)
1000 requestDetails.setSubscriberInfo(prepareSubscriberInfo(execution))
1003 requestDetails.setRequestInfo(prepareRequestInfo(execution, networkServiceInstance))
1005 // Request Parameters
1006 requestDetails.setRequestParameters(prepareRequestParameters(execution, networkServiceInstance, modelInfo))
1008 // Cloud configuration
1009 requestDetails.setCloudConfiguration(prepareCloudConfiguration(execution))
1012 requestDetails.setOwningEntity(prepareOwningEntity(execution))
1015 requestDetails.setProject(prepareProject(execution))
1017 Map<String, Object> requestDetailsMap = new LinkedHashMap<>()
1018 requestDetailsMap.put("requestDetails", requestDetails)
1020 ObjectMapper mapper = new ObjectMapper()
1022 response = mapper.writeValueAsString(requestDetailsMap)
1025 String msg = "Exception in ${getPrefix()}.prepareRequestDetails. " + any.getCause()
1029 " \"errorCode\": \"7000\",\n" +
1030 " \"errorMessage\": \"${msg}\"\n" +
1035 LOGGER.debug("${getPrefix()} Exit prepareRequestDetails")
1041 String getAuthHeader(DelegateExecution execution, String basicAuthValue, String msokey) {
1042 String response = ""
1043 String errorCode = ""
1044 String errorMessage = ""
1046 LOGGER.debug("Obtained BasicAuth username and password for OOF: " + basicAuthValue)
1048 response = utils.getBasicAuth(basicAuthValue, msokey)
1049 } catch (Exception ex) {
1050 LOGGER.error("Unable to encode username and password string: ", ex)
1053 errorMessage = "Internal Error - Unable to encode username and password string"
1056 " \"errorCode\": \"${errorCode}\",\n" +
1057 " \"errorMessage\": \"${errorMessage}\"\n" +
1065 String encryptBasicAuth(String basicAuth, String msoKey) {
1066 return utils.encrypt(basicAuth, msoKey)
1071 * Retrieves NSSI associated profiles from AAI
1074 void getNSSIAssociatedProfiles(DelegateExecution execution) {
1075 LOGGER.debug("${getPrefix()} Start getNSSIAssociatedProfiles")
1077 List<SliceProfile> associatedProfiles = new ArrayList<>()
1079 AAIResourcesClient client = getAAIClient()
1081 def currentNSSI = execution.getVariable("currentNSSI")
1083 ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
1085 String nssiId = currentNSSI['nssiId']
1087 String givenSliceProfileId = currentNSSI['sliceProfileId']
1090 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
1091 AAIResultWrapper nssiWrapper = client.get(nssiUri)
1092 Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
1094 if (nssiRelationships.isPresent()) {
1095 // Allotted Resource
1096 for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
1097 AAIResultWrapper arWrapper = client.get(allottedResourceUri)
1098 Optional<Relationships> arRelationships = arWrapper.getRelationships()
1100 if(arRelationships.isPresent()) {
1101 // Slice Profile Instance
1102 for (AAIResourceUri sliceProfileInstanceUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
1103 Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
1105 if (sliceProfileInstanceOpt.isPresent()) {
1106 ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
1107 if(sliceProfileInstance.getServiceRole().equals("slice-profile-instance")) { // Service instance as a Slice Profile Instance
1109 String globalSubscriberId = execution.getVariable("globalSubscriberId")
1110 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
1112 org.onap.aaiclient.client.generated.fluentbuilders.SliceProfiles sliceProfilesType =
1113 AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstance.getServiceInstanceId()).sliceProfiles()
1115 def sliceProfilesUri = AAIUriFactory.createResourceUri(sliceProfilesType)
1116 LOGGER.debug("client.exists(sliceProfilesUri = " + client.exists(sliceProfilesUri))
1117 if (!client.exists(sliceProfilesUri)) {
1118 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Slice Profiles URI doesn't exist")
1121 AAIResultWrapper sliceProfilesWrapper = client.get(sliceProfilesUri)
1122 Optional<SliceProfiles> sliceProfilesOpt = sliceProfilesWrapper.asBean(SliceProfiles.class)
1123 if(sliceProfilesOpt.isPresent()) {
1124 SliceProfiles sliceProfiles = sliceProfilesOpt.get()
1126 LOGGER.debug("getNSSIAssociatedProfiles: sliceProfiles.getSliceProfile().size() = " + sliceProfiles.getSliceProfile().size())
1127 LOGGER.debug("getNSSIAssociatedProfiles: givenSliceProfileId = " + givenSliceProfileId)
1128 for(SliceProfile sliceProfile: sliceProfiles.getSliceProfile()) {
1129 LOGGER.debug("getNSSIAssociatedProfiles: sliceProfile.getProfileId() = " + sliceProfile.getProfileId())
1130 if(sliceProfile.getProfileId().equals(givenSliceProfileId)) { // Slice profile id equals to received slice profile id
1131 currentNSSI['sliceProfileInstanceUri'] = sliceProfileInstanceUri
1136 associatedProfiles.addAll(sliceProfiles.getSliceProfile()) // Adds all slice profiles
1142 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No Slice Profile Instance found")
1147 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for Allotted Resource")
1153 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for nssi id = " + nssiId)
1156 checkAssociatedProfiles(execution, associatedProfiles, nssi)
1158 currentNSSI['associatedProfiles'] = associatedProfiles
1160 LOGGER.debug("${getPrefix()} Exit getNSSIAssociatedProfiles")
1164 void checkAssociatedProfiles(DelegateExecution execution, List<SliceProfile> associatedProfiles, ServiceInstance nssi) {}
1168 * Removes Slice Profile association with NSSI
1171 void removeSPAssociationWithNSSI(DelegateExecution execution) {
1172 LOGGER.debug("${getPrefix()} Start removeSPAssociationWithNSSI")
1174 AAIResourcesClient client = getAAIClient()
1176 def currentNSSI = execution.getVariable("currentNSSI")
1178 String nssiId = currentNSSI['nssiId']
1179 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
1181 String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
1183 boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
1185 AAIResourceUri sliceProfileInstanceUri = null
1186 if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
1187 def spURI = currentNSSI['sliceProfileInstanceUri']
1189 sliceProfileInstanceUri = (AAIResourceUri)spURI
1192 String msg = "Slice Profile association with NSSI was already removed"
1197 // Removes SLice Profile Instance association with NSSI
1198 if(sliceProfileInstanceUri != null) { // NSSI should not be terminated
1200 client.disconnect(nssiUri, sliceProfileInstanceUri)
1202 catch (Exception e) {
1203 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance association with NSSI dosconnect call: " + e.getMessage())
1208 LOGGER.debug("${getPrefix()} Exit removeSPAssociationWithNSSI")
1213 * Deletes Slice Profile Instance
1216 void deleteSliceProfileInstance(DelegateExecution execution) {
1217 LOGGER.debug("${getPrefix()} Start deleteSliceProfileInstance")
1219 AAIResourcesClient client = getAAIClient()
1221 def currentNSSI = execution.getVariable("currentNSSI")
1223 String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
1225 boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
1227 AAIResourceUri sliceProfileInstanceUri = null
1228 if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
1229 def spURI = currentNSSI['sliceProfileInstanceUri']
1231 sliceProfileInstanceUri = (AAIResourceUri)spURI
1234 String msg = "Slice Profile instance was already deleted"
1239 if(sliceProfileInstanceUri != null) {
1241 client.delete(sliceProfileInstanceUri)
1242 } catch (Exception e) {
1243 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
1247 LOGGER.debug("${getPrefix()} Exit deleteSliceProfileInstance")
1252 * Prepares update resource operation status
1255 void prepareUpdateResourceOperationStatus(DelegateExecution execution) {
1256 LOGGER.debug("${getPrefix()} Start updateServiceOperationStatus")
1258 def currentNSSI = execution.getVariable("currentNSSI")
1260 //Prepare Update Status for PUT failure and success
1261 String isTimeOutVar = execution.getVariable("isTimeOut")
1262 if(!isBlank(isTimeOutVar) && isTimeOutVar.equals("YES")) {
1263 LOGGER.error("TIMEOUT - SO PUT Failure")
1264 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "SO PUT Failure")
1266 execution.setVariable("progress", "100")
1267 execution.setVariable("status", "finished")
1268 execution.setVariable("operationContent", "${getAction()} Core NSSI successful.")
1271 setResourceOperationStatus(execution, "finished", "100", "Core NSSI ${getAction()} successful")
1273 LOGGER.debug("${getPrefix()} Exit updateServiceOperationStatus")
1278 * Prepares ResourceOperation status
1280 * @param operationType
1282 void setResourceOperationStatus(DelegateExecution execution, String status, String progress, String statusDesc) {
1283 LOGGER.debug("${getPrefix()} Start setResourceOperationStatus")
1285 def currentNSSI = execution.getVariable("currentNSSI")
1287 String serviceId = currentNSSI['nsiId']
1288 String jobId = execution.getVariable("jobId")
1289 String nsiId = currentNSSI['nsiId']
1290 String operationType = execution.getVariable("operationType")
1291 String resourceInstanceId = currentNSSI['nssiId']
1293 ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
1294 String modelUuid = nssi.getModelVersionId()
1296 ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
1297 resourceOperationStatus.setServiceId(serviceId)
1298 resourceOperationStatus.setOperationId(jobId)
1299 resourceOperationStatus.setResourceTemplateUUID(modelUuid)
1300 resourceOperationStatus.setOperType(operationType)
1301 resourceOperationStatus.setResourceInstanceID(resourceInstanceId)
1302 resourceOperationStatus.setStatus(status)
1303 resourceOperationStatus.setProgress(progress)
1304 resourceOperationStatus.setStatusDescription(statusDesc)
1305 requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
1307 LOGGER.debug("${getPrefix()} Exit setResourceOperationStatus")
1312 * Prepares failed operation status update
1315 void prepareFailedOperationStatusUpdate(DelegateExecution execution) {
1316 LOGGER.debug("${getPrefix()} Start prepareFailedOperationStatusUpdate")
1318 setResourceOperationStatus(execution, "failed", "0", "Core NSSI ${getAction()} Failed")
1320 LOGGER.debug("${getPrefix()} Exit prepareFailedOperationStatusUpdate")
1325 * Gets progress status of ServiceInstance PUT operation
1328 public void getPUTServiceInstanceProgress(DelegateExecution execution) {
1329 LOGGER.debug("${getPrefix()} Start getPUTServiceInstanceProgress")
1331 def currentNSSI = execution.getVariable("currentNSSI")
1333 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
1335 String url = currentNSSI['requestSelfLink']
1337 String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
1339 String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
1342 String basicAuthValue = utils.getBasicAuth(basicAuth, msoKey)
1344 getProgress(execution, url, basicAuthValue, "putStatus")
1346 LOGGER.debug("${getPrefix()} Exit getPUTServiceInstanceProgress")
1350 void getProgress(DelegateExecution execution, String url, String authHeader, String statusVariableName) {
1351 LOGGER.debug("${getPrefix()} Start getProgress")
1353 LOGGER.debug("getProgress: url = " + url)
1354 LOGGER.debug("getProgress: authHeader = " + authHeader)
1359 HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
1360 httpClient.addAdditionalHeader("Authorization", authHeader)
1361 httpClient.addAdditionalHeader("Accept", "application/json")
1363 Response response = httpClient.get()
1364 int responseCode = response.getStatus()
1365 // execution.setVariable("GetServiceOrderResponseCode", responseCode)
1366 LOGGER.debug("Get ServiceOrder response code is: " + responseCode)
1368 String soResponse = ""
1369 if(response.hasEntity()) {
1370 soResponse = response.readEntity(String.class)
1371 // execution.setVariable("GetServiceOrderResponse", extApiResponse)
1372 LOGGER.debug("Create response body is: " + soResponse)
1375 //Process Response //200 OK 201 CREATED 202 ACCEPTED
1376 if (responseCode >= 200 && responseCode < 204) {
1377 LOGGER.debug("Get Create ServiceOrder Received a Good Response")
1378 String requestState = jsonUtil.getJsonValue(soResponse, "request.requestStatus.requestState")
1381 JSONArray items = responseObj.getJSONArray("orderItem")
1382 JSONObject item = items.get(0)
1383 JSONObject service = item.get("service")
1384 String networkServiceId = service.get("id")
1385 if (networkServiceId == null || networkServiceId.equals("null")) {
1386 prepareFailedOperationStatusUpdate(execution)
1390 execution.setVariable("networkServiceId", networkServiceId)
1391 String serviceOrderState = item.get("state")
1392 execution.setVariable("ServiceOrderState", serviceOrderState) */
1394 // Get serviceOrder State and process progress
1395 if("ACKNOWLEDGED".equalsIgnoreCase(requestState)) {
1396 execution.setVariable(statusVariableName, "processing")
1398 else if("IN_PROGRESS".equalsIgnoreCase(requestState)) {
1399 execution.setVariable(statusVariableName, "processing")
1401 else if("COMPLETE".equalsIgnoreCase(requestState)) {
1402 execution.setVariable(statusVariableName, "completed")
1404 else if("FAILED".equalsIgnoreCase(requestState)) {
1405 msg = "ServiceOrder failed"
1406 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1408 else if("REJECTED".equalsIgnoreCase(requestState)) {
1409 prepareFailedOperationStatusUpdate(execution)
1412 msg = "ServiceOrder failed"
1413 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1417 msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode
1418 prepareFailedOperationStatusUpdate(execution)
1421 }catch(Exception e){
1422 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage())
1425 LOGGER.debug("${getPrefix()} Exit getProgress")
1434 void timeDelay(DelegateExecution execution) {
1435 LOGGER.debug("${getPrefix()} Start timeDelay")
1438 LOGGER.debug("${getPrefix()} timeDelay going to sleep for 5 sec")
1442 LOGGER.debug("${getPrefix()} ::: timeDelay wakeup after 5 sec")
1443 } catch(InterruptedException e) {
1444 LOGGER.error("${getPrefix()} ::: timeDelay exception" + e)
1447 LOGGER.debug("${getPrefix()} Exit timeDelay")
1451 void postProcessRequest(DelegateExecution execution) {
1452 LOGGER.debug("${getPrefix()} Start postProcessRequest")
1454 execution.removeVariable("currentNSSI")
1456 LOGGER.debug("***** ${getPrefix()} Exit postProcessRequest")
1462 * Returns AAI client
1463 * @return AAI client
1465 AAIResourcesClient getAAIClient() {
1466 return new AAIResourcesClient()
1470 ExternalAPIUtilFactory getExternalAPIUtilFactory() {
1471 return new ExternalAPIUtilFactory()
1476 * Returns Catalog DB Util Factory
1477 * @return ew CatalogDbUtilsFactory()
1479 CatalogDbUtilsFactory getCatalogDbUtilsFactory() {
1480 return new CatalogDbUtilsFactory()
1484 private String getPrefix() {
1488 String getAction() {