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
126 String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId")
127 currentNSSI['sliceProfileId'] = sliceProfileId
129 execution.setVariable("currentNSSI", currentNSSI)
131 LOGGER.debug("***** ${getPrefix()} Exit preProcessRequest")
136 * Queries Network Service Instance in AAI
139 void getNetworkServiceInstance(DelegateExecution execution) {
140 LOGGER.debug("${getPrefix()} Start getNetworkServiceInstance")
142 AAIResourcesClient client = getAAIClient()
144 def currentNSSI = execution.getVariable("currentNSSI")
146 String nssiId = currentNSSI['nssiId']
148 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
149 Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
151 if (nssiOpt.isPresent()) {
152 ServiceInstance nssi = nssiOpt.get()
153 currentNSSI['nssi'] = nssi
155 ServiceInstance networkServiceInstance = handleNetworkInstance(execution, nssiId, nssiUri, client)
156 currentNSSI['networkServiceInstance'] = networkServiceInstance
159 String msg = String.format("NSSI %s not found in AAI", nssiId)
161 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
164 LOGGER.debug("${getPrefix()} Exit getNetworkServiceInstance")
169 * Handles Network Service
173 * @return Network Service Instance
175 private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) {
176 LOGGER.debug("${getPrefix()} Start handleNetworkInstance")
178 ServiceInstance networkServiceInstance = null
180 def currentNSSI = execution.getVariable("currentNSSI")
182 AAIResultWrapper wrapper = client.get(nssiUri)
183 Optional<Relationships> relationships = wrapper.getRelationships()
185 if (relationships.isPresent()) {
186 for (AAIResourceUri networkServiceInstanceUri : relationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
187 Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri)
188 if (networkServiceInstanceOpt.isPresent()) {
189 networkServiceInstance = networkServiceInstanceOpt.get()
191 if (networkServiceInstance.getServiceRole() == null /* WorkAround */ || networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
192 currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri
197 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
199 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
203 if (currentNSSI['networkServiceInstanceUri'] == null) {
204 String msg = String.format("Network Service Instance URI is null")
206 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
210 String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
212 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
215 if(networkServiceInstance == null) {
216 String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
218 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
221 LOGGER.debug("${getPrefix()} Exit handleNetworkInstance")
223 return networkServiceInstance
228 * Queries constitute VNF from Network Service Instance
231 void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
232 LOGGER.debug("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
234 def currentNSSI = execution.getVariable("currentNSSI")
236 AAIResourcesClient client = getAAIClient()
238 AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
239 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
240 Optional<Relationships> relationships = wrapper.getRelationships()
242 if (relationships.isPresent()) {
243 for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedUris(Types.GENERIC_VNF)) {
244 currentNSSI['constituteVnfUri'] = constituteVnfUri
245 Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri)
246 if(constituteVnfOpt.isPresent()) {
247 GenericVnf constituteVnf = constituteVnfOpt.get()
248 currentNSSI['constituteVnf'] = constituteVnf
251 String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
253 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
256 break // Should be only one constitute VNF
260 String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
262 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
265 LOGGER.debug("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
271 * Invoke PUT Service Instance API
274 void invokePUTServiceInstance(DelegateExecution execution) {
275 LOGGER.debug("${getPrefix()} Start invokePUTServiceInstance")
277 def currentNSSI = execution.getVariable("currentNSSI")
280 //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}"
281 def nsmfЕndPoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ???
283 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
285 GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
287 // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5
288 String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
290 String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
292 String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
294 def authHeader = utils.getBasicAuth(basicAuth, msoKey) // ""
295 /* String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey)
297 String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey)
299 String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode")
300 if(errorCode == null || errorCode.isEmpty()) { // No error
301 authHeader = responseAuthHeader
304 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage"))
307 def requestDetails = ""
309 String prepareRequestDetailsResponse = prepareRequestDetails(execution)
310 LOGGER.debug("invokePUTServiceInstance: prepareRequestDetailsResponse=" + prepareRequestDetailsResponse)
312 String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
313 LOGGER.debug("invokePUTServiceInstance: errorCode=" + errorCode)
314 if(errorCode == null || errorCode.isEmpty()) { // No error
315 requestDetails = prepareRequestDetailsResponse
318 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage"))
321 String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails)
323 String macroOperationId = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestId")
324 String requestSelfLink = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestSelfLink")
326 execution.setVariable("macroOperationId", macroOperationId)
327 execution.setVariable("requestSelfLink", requestSelfLink)
328 currentNSSI['requestSelfLink'] = requestSelfLink
331 String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
333 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
336 LOGGER.debug("${getPrefix()} Exit invokePUTServiceInstance")
340 String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) {
341 LOGGER.debug("${getPrefix()} Start callPUTServiceInstance")
343 String errorCode = ""
344 String errorMessage = ""
347 LOGGER.debug("callPUTServiceInstance: url = " + url)
348 LOGGER.debug("callPUTServiceInstance: authHeader = " + authHeader)
351 HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
352 httpClient.addAdditionalHeader("Authorization", authHeader)
353 httpClient.addAdditionalHeader("Accept", "application/json")
355 Response httpResponse = httpClient.put(requestDetailsStr)
357 int soResponseCode = httpResponse.getStatus()
358 if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) {
359 response = httpResponse.readEntity(String.class)
361 LOGGER.debug("callPUTServiceInstance: response = " + response)
365 errorMessage = "Response code is " + soResponseCode
368 " \"errorCode\": \"${errorCode}\",\n" +
369 " \"errorMessage\": \"${errorMessage}\"\n" +
374 String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
378 " \"errorCode\": \"7000\",\n" +
379 " \"errorMessage\": \"${msg}\"\n" +
386 LOGGER.debug("${getPrefix()} Exit callPUTServiceInstance")
393 * @param requestDetails
396 ModelInfo prepareModelInfo(DelegateExecution execution) {
397 LOGGER.debug("${getPrefix()} Start prepareModelInfo")
399 def currentNSSI = execution.getVariable("currentNSSI")
400 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
402 ModelInfo modelInfo = new ModelInfo()
404 modelInfo.setModelType(ModelType.service)
405 modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
407 AAIResourcesClient client = getAAIClient()
409 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(networkServiceInstance.getModelInvariantId()).modelVer(networkServiceInstance.getModelVersionId()))
410 Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl)
412 if (modelVerOpt.isPresent()) {
413 modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId())
414 modelInfo.setModelName(modelVerOpt.get().getModelName())
415 modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
418 LOGGER.debug("${getPrefix()} Exit prepareModelInfo")
425 * Prepares subscriber info
427 * @return SubscriberInfo
429 SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) {
430 LOGGER.debug("${getPrefix()} Start prepareSubscriberInfo")
432 def currentNSSI = execution.getVariable("currentNSSI")
434 String globalSubscriberId = execution.getVariable("globalSubscriberId")
436 String subscriberName = execution.getVariable("subscriberName")
438 SubscriberInfo subscriberInfo = new SubscriberInfo()
439 subscriberInfo.setGlobalSubscriberId(globalSubscriberId)
440 subscriberInfo.setSubscriberName(subscriberName)
443 AAIResourcesClient client = getAAIClient()
445 Customer customer = null
447 AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri']
448 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
449 Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships()
450 if(serviceSubscriptionRelationshipsOps.isPresent()) {
451 List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedUris(Types.SERVICE_SUBSCRIPTION)
452 if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) {
453 AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation
454 Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri)
456 if(serviceSubscriptionOpt.isPresent()) {
457 currentNSSI['serviceSubscription'] = serviceSubscriptionOpt.get()
460 wrapper = client.get(serviceSubscriptionUri)
461 Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships()
462 if(customerRelationshipsOps.isPresent()) {
463 List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedUris(Types.CUSTOMER)
464 if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) {
465 Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation
466 if(customerOpt.isPresent()) {
467 customer = customerOpt.get()
468 subscriberInfo.setSubscriberName(customer.getSubscriberName())
476 LOGGER.debug("${getPrefix()} Exit prepareSubscriberInfo")
478 return subscriberInfo
483 * Prepares Request Info
485 * @return RequestInfo
487 RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) {
488 LOGGER.debug("${getPrefix()} Start prepareRequestInfo")
490 def currentNSSI = execution.getVariable("currentNSSI")
492 String productFamilyId = execution.getVariable("productFamilyId")
494 RequestInfo requestInfo = new RequestInfo()
496 requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName())
497 requestInfo.setSource("VID")
498 requestInfo.setProductFamilyId(productFamilyId)
499 requestInfo.setRequestorId("NBI")
501 LOGGER.debug("${getPrefix()} Exit prepareRequestInfo")
508 * Prepares Model Info
509 * @param networkServiceInstance
513 ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
514 LOGGER.debug("${getPrefix()} Start prepareServiceModelInfo")
516 ModelInfo serviceModelInfo = new ModelInfo()
517 serviceModelInfo.setModelType(ModelType.service)
518 serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
520 serviceModelInfo.setModelVersionId(modelInfo.getModelVersionId())
521 serviceModelInfo.setModelName(modelInfo.getModelName())
522 serviceModelInfo.setModelVersion(modelInfo.getModelVersion())
524 LOGGER.debug("${getPrefix()} Exit prepareServiceModelInfo")
526 return serviceModelInfo
531 * Prepares Cloud configuration
533 * @return CloudConfiguration
535 CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) {
536 LOGGER.debug("${getPrefix()} Start prepareCloudConfiguration")
538 def currentNSSI = execution.getVariable("currentNSSI")
540 CloudConfiguration cloudConfiguration = new CloudConfiguration()
542 AAIResourcesClient client = getAAIClient()
544 AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri']
546 AAIResultWrapper wrapper = client.get(constituteVnfUri)
547 Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships()
549 if(cloudRegionRelationshipsOps.isPresent()) {
550 List<AAIResourceUri> cloudRegionRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedUris(Types.CLOUD_REGION)
551 if (!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) {
552 AAIResourceUri cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0)
553 currentNSSI['cloudRegionRelatedAAIUri'] = cloudRegionRelatedAAIUri
555 Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0))
556 CloudRegion cloudRegion = null
557 if (cloudRegionrOpt.isPresent()) {
558 cloudRegion = cloudRegionrOpt.get()
559 cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
561 if(cloudRegion.getTenants() != null && cloudRegion.getTenants().getTenant() != null) {
562 for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
563 cloudConfiguration.setTenantId(tenant.getTenantId())
564 cloudConfiguration.setTenantName(tenant.getTenantName())
565 break // only one is required
569 List<AAIResourceUri> tenantRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedUris(Types.TENANT)
570 if (!(tenantRelatedAAIUris == null || tenantRelatedAAIUris.isEmpty())) {
571 Optional<Tenant> tenantOpt = client.get(Tenant.class, tenantRelatedAAIUris.get(0))
573 if (tenantOpt.isPresent()) {
574 tenant = tenantOpt.get()
576 LOGGER.debug("prepareCloudConfiguration: tenantId=" + tenant.getTenantId())
577 LOGGER.debug("prepareCloudConfiguration: tenantName=" + tenant.getTenantName())
579 cloudConfiguration.setTenantId(tenant.getTenantId())
580 cloudConfiguration.setTenantName(tenant.getTenantName())
585 cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
590 LOGGER.debug("${getPrefix()} Exit prepareCloudConfiguration")
592 return cloudConfiguration
597 * Prepares a list of VF Modules
599 * @param constituteVnf
600 * @return List<VfModules>
602 List<org.onap.so.serviceinstancebeans.VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) {
603 LOGGER.debug("${getPrefix()} Start prepareVfModules")
605 AAIResourcesClient client = getAAIClient()
607 def currentNSSI = execution.getVariable("currentNSSI")
609 List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
611 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
613 String networkServiceModelInvariantUuid = networkServiceInstance.getModelInvariantId()
615 String serviceVnfs="";
618 CatalogDbUtils catalogDbUtils = getCatalogDbUtilsFactory().create()
620 String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution, networkServiceModelInvariantUuid)
621 LOGGER.debug("***** JSON IS: "+json)
623 serviceVnfs = jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs") ?: ""
625 ObjectMapper mapper = new ObjectMapper()
627 List<Object> vnfList = mapper.readValue(serviceVnfs, List.class)
628 LOGGER.debug("vnfList: "+vnfList)
630 Map vnfMap = vnfList.get(0)
631 ModelInfo vnfModelInfo = vnfMap.get("modelInfo")
632 vnfModelInfo.setModelCustomizationId(vnfModelInfo.getModelCustomizationUuid())
633 vnfModelInfo.setModelVersionId(vnfModelInfo.getModelId())
634 LOGGER.debug("vnfModelInfo "+vnfModelInfo)
637 List<Map<String, Object>> vfModuleList = vnfMap.get("vfModules")
638 LOGGER.debug("vfModuleList "+vfModuleList)
641 List<ModelInfo> vfModelInfoList = new ArrayList<>()
643 //Traverse VFModules List and add in vfModelInfoList
644 for (vfModule in vfModuleList) {
645 ModelInfo vfModelInfo = vfModule.get("modelInfo")
646 vfModelInfo.setModelCustomizationId(vfModelInfo.getModelCustomizationUuid())
647 vfModelInfo.setModelVersionId(vfModelInfo.getModelId())
648 LOGGER.debug("vfModelInfo "+vfModelInfo)
649 vfModelInfoList.add(vfModelInfo)
652 for (ModelInfo vfModuleModelInfo : vfModelInfoList) {
653 org.onap.so.serviceinstancebeans.VfModules vfModules = new org.onap.so.serviceinstancebeans.VfModules()
654 vfModules.setModelInfo(vfModuleModelInfo)
655 vfModules.setInstanceName(vfModuleModelInfo.getModelName())
657 List<Map<String, Object>> vfModuleInstanceParams = new ArrayList<>()
658 vfModules.setInstanceParams(vfModuleInstanceParams)
659 vfModuless.add(vfModules)
662 } catch (Exception ex){
663 msg = "Exception in prepareVfModules " + ex.getMessage()
665 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
669 List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
670 if(constituteVnf.getVfModules() != null && constituteVnf.getVfModules().getVfModule() != null) {
671 for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
672 org.onap.so.serviceinstancebeans.VfModules vfmodules = new org.onap.so.serviceinstancebeans.VfModules()
674 ModelInfo vfModuleModelInfo = new ModelInfo()
675 vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
676 vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
678 AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
680 Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
682 if (vfModuleModelVerOpt.isPresent()) {
683 vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
684 vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
685 vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
687 vfmodules.setModelInfo(vfModuleModelInfo)
689 vfmodules.setInstanceName(vfModule.getVfModuleName())
691 vfModuless.add(vfmodules)
695 LOGGER.debug("${getPrefix()} Exit prepareVfModules")
702 * prepares VNF Model Info
704 * @param constituteVnf
707 ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) {
708 LOGGER.debug("${getPrefix()} Start prepareVNFModelInfo")
710 ModelInfo vnfModelInfo = new ModelInfo()
712 AAIResourcesClient client = getAAIClient()
714 vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId())
715 vnfModelInfo.setModelCustomizationId(constituteVnf.getModelCustomizationId())
716 vnfModelInfo.setModelInstanceName(constituteVnf.getVnfName())
718 AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(constituteVnf.getModelInvariantId()).modelVer(constituteVnf.getModelVersionId()))
720 Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl)
722 if (vnfModelVerOpt.isPresent()) {
723 vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId())
724 vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName())
725 vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
728 LOGGER.debug("${getPrefix()} Exit prepareVNFModelInfo")
734 List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) {
735 LOGGER.debug("${getPrefix()} Start prepareInstanceParams")
737 def currentNSSI = execution.getVariable("currentNSSI")
739 List<Map<String, Object>> instanceParams = new ArrayList<>()
740 Map<String, Object> instanceParamsMap = new HashMap<>()
743 List<String> snssais = (List<String>) currentNSSI['S-NSSAIs']
745 ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
747 String orchStatus = nssi.getOrchestrationStatus()
750 List<Map<String, String>> snssaiList = new ArrayList<>()
752 for(String snssai:snssais) {
753 Map<String, String> snssaisMap = new HashMap<>()
754 snssaisMap.put("snssai", snssai)
755 snssaisMap.put("status", orchStatus)
756 snssaiList.add(snssaisMap)
759 // Map<String, List<Map<String, String>>> supportedNssaiDetails = new HashMap<>()
760 // supportedNssaiDetails.put("sNssai", supportedNssaiDetails)
762 ObjectMapper mapper = new ObjectMapper()
764 String supportedNssaiDetailsStr = mapper.writeValueAsString(snssaiList)
767 instanceParamsMap.put("k8s-rb-profile-name", "default") // ???
768 instanceParamsMap.put("config-type", "day2") // ???
769 instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr)
770 instanceParams.add(instanceParamsMap)
772 LOGGER.debug("${getPrefix()} Exit prepareInstanceParams")
774 return instanceParams
782 Resources prepareResources(DelegateExecution execution) {
783 LOGGER.debug("${getPrefix()} Start prepareResources")
785 def currentNSSI = execution.getVariable("currentNSSI")
787 Resources resources = new Resources()
790 List<Vnfs> vnfs = new ArrayList<>()
792 Vnfs vnf = new Vnfs()
795 org.onap.so.serviceinstancebeans.LineOfBusiness lob = new org.onap.so.serviceinstancebeans.LineOfBusiness()
796 lob.setLineOfBusinessName("VNF")
797 vnf.setLineOfBusiness(lob)
800 GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
801 vnf.setProductFamilyId(constituteVnf.getServiceId())
803 // Cloud configuration
804 vnf.setCloudConfiguration(prepareCloudConfiguration(execution))
807 vnf.setVfModules(prepareVfModules(execution, constituteVnf))
810 vnf.setModelInfo(prepareVNFModelInfo(execution, constituteVnf))
813 vnf.setInstanceName(constituteVnf.getVnfName())
816 vnf.setInstanceParams(prepareInstanceParams(execution))
821 resources.setVnfs(vnfs)
823 LOGGER.debug("${getPrefix()} Exit prepareResources")
833 org.onap.so.serviceinstancebeans.Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
834 LOGGER.debug("${getPrefix()} Start prepareService")
836 org.onap.so.serviceinstancebeans.Service service = new org.onap.so.serviceinstancebeans.Service()
839 service.setModelInfo(prepareServiceModelInfo(networkServiceInstance, modelInfo))
841 service.setInstanceName(networkServiceInstance.getServiceInstanceName())
844 service.setResources(prepareResources(execution))
846 LOGGER.debug("${getPrefix()} Exit prepareService")
854 * Prepares request parameters
856 * @return RequestParameters
858 RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
859 LOGGER.debug("${getPrefix()} Start prepareRequestParameters")
861 def currentNSSI = execution.getVariable("currentNSSI")
863 RequestParameters requestParameters = new RequestParameters()
865 ServiceSubscription serviceSubscription = (ServiceSubscription)currentNSSI['serviceSubscription']
867 if(serviceSubscription != null) {
868 requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType())
872 List<Map<String, Object>> userParams = new ArrayList<>()
874 Map<String, Object> userParam = new HashMap<>()
875 userParam.put("Homing_Solution", "none")
876 userParams.add(userParam)
879 Map<String, Object> serviceMap = new HashMap<>()
880 serviceMap.put("service", prepareService(execution, networkServiceInstance, modelInfo))
881 userParams.add(serviceMap)
882 requestParameters.setUserParams(userParams)
884 requestParameters.setaLaCarte(false)
886 LOGGER.debug("${getPrefix()} Exit prepareRequestParameters")
888 return requestParameters
893 * Prepare Owning Entity
895 * @return OwningEntity
897 org.onap.so.serviceinstancebeans.OwningEntity prepareOwningEntity(DelegateExecution execution) {
898 LOGGER.debug("${getPrefix()} Start prepareOwningEntity")
900 def currentNSSI = execution.getVariable("currentNSSI")
902 AAIResourcesClient client = getAAIClient()
904 AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
906 org.onap.so.serviceinstancebeans.OwningEntity owningEntity = new org.onap.so.serviceinstancebeans.OwningEntity()
907 AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
908 Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships()
909 if (owningEntityRelationshipsOps.isPresent()) {
910 List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedUris(Types.OWNING_ENTITY)
912 if (!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) {
913 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
914 if (owningEntityOpt.isPresent()) {
915 owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId())
916 owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName())
922 LOGGER.debug("${getPrefix()} Exit prepareOwningEntity")
933 org.onap.so.serviceinstancebeans.Project prepareProject(DelegateExecution execution) {
934 LOGGER.debug("${getPrefix()} Start prepareProject")
936 def currentNSSI = execution.getVariable("currentNSSI")
938 AAIResourcesClient client = getAAIClient()
940 org.onap.so.serviceinstancebeans.Project project = new org.onap.so.serviceinstancebeans.Project()
942 AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri']
944 if (cloudRegionRelatedAAIUri != null) {
945 AAIResultWrapper wrapper = client.get(cloudRegionRelatedAAIUri)
946 Optional<Relationships> cloudRegionOps = wrapper.getRelationships()
947 if (cloudRegionOps.isPresent()) {
948 List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedUris(Types.PROJECT)
949 if (!(projectAAIUris == null || projectAAIUris.isEmpty())) {
950 Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.v19.Project.class, projectAAIUris.get(0))
951 if (projectOpt.isPresent()) {
952 project.setProjectName(projectOpt.get().getProjectName())
958 LOGGER.debug("${getPrefix()} Exit prepareProject")
965 * Prepares RequestDetails object
969 String prepareRequestDetails(DelegateExecution execution) {
970 LOGGER.debug("${getPrefix()} Start prepareRequestDetails")
972 String errorCode = ""
973 String errorMessage = ""
976 RequestDetails requestDetails = new RequestDetails()
978 def currentNSSI = execution.getVariable("currentNSSI")
980 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
984 ModelInfo modelInfo = prepareModelInfo(execution)
985 requestDetails.setModelInfo(modelInfo)
988 requestDetails.setSubscriberInfo(prepareSubscriberInfo(execution))
991 requestDetails.setRequestInfo(prepareRequestInfo(execution, networkServiceInstance))
993 // Request Parameters
994 requestDetails.setRequestParameters(prepareRequestParameters(execution, networkServiceInstance, modelInfo))
996 // Cloud configuration
997 requestDetails.setCloudConfiguration(prepareCloudConfiguration(execution))
1000 requestDetails.setOwningEntity(prepareOwningEntity(execution))
1003 requestDetails.setProject(prepareProject(execution))
1005 Map<String, Object> requestDetailsMap = new LinkedHashMap<>()
1006 requestDetailsMap.put("requestDetails", requestDetails)
1008 ObjectMapper mapper = new ObjectMapper()
1010 response = mapper.writeValueAsString(requestDetailsMap)
1013 String msg = "Exception in ${getPrefix()}.prepareRequestDetails. " + any.getCause()
1017 " \"errorCode\": \"7000\",\n" +
1018 " \"errorMessage\": \"${msg}\"\n" +
1023 LOGGER.debug("${getPrefix()} Exit prepareRequestDetails")
1029 String getAuthHeader(DelegateExecution execution, String basicAuthValue, String msokey) {
1030 String response = ""
1031 String errorCode = ""
1032 String errorMessage = ""
1034 LOGGER.debug("Obtained BasicAuth username and password for OOF: " + basicAuthValue)
1036 response = utils.getBasicAuth(basicAuthValue, msokey)
1037 } catch (Exception ex) {
1038 LOGGER.error("Unable to encode username and password string: ", ex)
1041 errorMessage = "Internal Error - Unable to encode username and password string"
1044 " \"errorCode\": \"${errorCode}\",\n" +
1045 " \"errorMessage\": \"${errorMessage}\"\n" +
1053 String encryptBasicAuth(String basicAuth, String msoKey) {
1054 return utils.encrypt(basicAuth, msoKey)
1059 * Retrieves NSSI associated profiles from AAI
1062 void getNSSIAssociatedProfiles(DelegateExecution execution) {
1063 LOGGER.debug("${getPrefix()} Start getNSSIAssociatedProfiles")
1065 List<SliceProfile> associatedProfiles = new ArrayList<>()
1067 AAIResourcesClient client = getAAIClient()
1069 def currentNSSI = execution.getVariable("currentNSSI")
1071 ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
1073 String nssiId = currentNSSI['nssiId']
1075 String givenSliceProfileId = currentNSSI['sliceProfileId']
1078 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
1079 AAIResultWrapper nssiWrapper = client.get(nssiUri)
1080 Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
1082 if (nssiRelationships.isPresent()) {
1083 // Allotted Resource
1084 for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
1085 AAIResultWrapper arWrapper = client.get(allottedResourceUri)
1086 Optional<Relationships> arRelationships = arWrapper.getRelationships()
1088 if(arRelationships.isPresent()) {
1089 // Slice Profile Instance
1090 for (AAIResourceUri sliceProfileInstanceUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
1091 Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
1093 if (sliceProfileInstanceOpt.isPresent()) {
1094 ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
1095 if(sliceProfileInstance.getServiceRole().equals("slice-profile-instance")) { // Service instance as a Slice Profile Instance
1097 String globalSubscriberId = execution.getVariable("globalSubscriberId")
1098 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
1100 org.onap.aaiclient.client.generated.fluentbuilders.SliceProfiles sliceProfilesType =
1101 AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstance.getServiceInstanceId()).sliceProfiles()
1103 def sliceProfilesUri = AAIUriFactory.createResourceUri(sliceProfilesType)
1104 LOGGER.debug("client.exists(sliceProfilesUri = " + client.exists(sliceProfilesUri))
1105 if (!client.exists(sliceProfilesUri)) {
1106 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Slice Profiles URI doesn't exist")
1109 AAIResultWrapper sliceProfilesWrapper = client.get(sliceProfilesUri)
1110 Optional<SliceProfiles> sliceProfilesOpt = sliceProfilesWrapper.asBean(SliceProfiles.class)
1111 if(sliceProfilesOpt.isPresent()) {
1112 SliceProfiles sliceProfiles = sliceProfilesOpt.get()
1114 LOGGER.debug("getNSSIAssociatedProfiles: sliceProfiles.getSliceProfile().size() = " + sliceProfiles.getSliceProfile().size())
1115 LOGGER.debug("getNSSIAssociatedProfiles: givenSliceProfileId = " + givenSliceProfileId)
1116 for(SliceProfile sliceProfile: sliceProfiles.getSliceProfile()) {
1117 LOGGER.debug("getNSSIAssociatedProfiles: sliceProfile.getProfileId() = " + sliceProfile.getProfileId())
1118 if(sliceProfile.getProfileId().equals(givenSliceProfileId)) { // Slice profile id equals to received slice profile id
1119 currentNSSI['sliceProfileInstanceUri'] = sliceProfileInstanceUri
1124 associatedProfiles.addAll(sliceProfiles.getSliceProfile()) // Adds all slice profiles
1130 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No Slice Profile Instance found")
1135 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for Allotted Resource")
1141 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for nssi id = " + nssiId)
1144 checkAssociatedProfiles(execution, associatedProfiles, nssi)
1146 currentNSSI['associatedProfiles'] = associatedProfiles
1148 LOGGER.debug("${getPrefix()} Exit getNSSIAssociatedProfiles")
1152 void checkAssociatedProfiles(DelegateExecution execution, List<SliceProfile> associatedProfiles, ServiceInstance nssi) {}
1156 * Removes Slice Profile association with NSSI
1159 void removeSPAssociationWithNSSI(DelegateExecution execution) {
1160 LOGGER.debug("${getPrefix()} Start removeSPAssociationWithNSSI")
1162 AAIResourcesClient client = getAAIClient()
1164 def currentNSSI = execution.getVariable("currentNSSI")
1166 String nssiId = currentNSSI['nssiId']
1167 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
1169 String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
1171 boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
1173 AAIResourceUri sliceProfileInstanceUri = null
1174 if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
1175 def spURI = currentNSSI['sliceProfileInstanceUri']
1177 sliceProfileInstanceUri = (AAIResourceUri)spURI
1180 String msg = "Slice Profile URI not found"
1182 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1186 // Removes SLice Profile Instance association with NSSI
1187 if(sliceProfileInstanceUri != null) { // NSSI should not be terminated
1189 client.disconnect(nssiUri, sliceProfileInstanceUri)
1191 catch (Exception e) {
1192 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance association with NSSI dosconnect call: " + e.getMessage())
1197 LOGGER.debug("${getPrefix()} Exit removeSPAssociationWithNSSI")
1202 * Deletes Slice Profile Instance
1205 void deleteSliceProfileInstance(DelegateExecution execution) {
1206 LOGGER.debug("${getPrefix()} Start deleteSliceProfileInstance")
1208 AAIResourcesClient client = getAAIClient()
1210 def currentNSSI = execution.getVariable("currentNSSI")
1212 String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
1214 boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
1216 AAIResourceUri sliceProfileInstanceUri = null
1217 if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
1218 def spURI = currentNSSI['sliceProfileInstanceUri']
1220 sliceProfileInstanceUri = (AAIResourceUri)spURI
1223 String msg = "Slice Profile URI not found"
1225 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1229 if(sliceProfileInstanceUri != null) { // NSSI should not be terminated
1231 client.delete(sliceProfileInstanceUri)
1232 } catch (Exception e) {
1233 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
1237 LOGGER.debug("${getPrefix()} Exit deleteSliceProfileInstance")
1242 * Prepares update resource operation status
1245 void prepareUpdateResourceOperationStatus(DelegateExecution execution) {
1246 LOGGER.debug("${getPrefix()} Start updateServiceOperationStatus")
1248 def currentNSSI = execution.getVariable("currentNSSI")
1250 //Prepare Update Status for PUT failure and success
1251 String isTimeOutVar = execution.getVariable("isTimeOut")
1252 if(!isBlank(isTimeOutVar) && isTimeOutVar.equals("YES")) {
1253 LOGGER.error("TIMEOUT - SO PUT Failure")
1254 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "SO PUT Failure")
1256 execution.setVariable("progress", "100")
1257 execution.setVariable("status", "finished")
1258 execution.setVariable("operationContent", "${getAction()} Core NSSI successful.")
1261 setResourceOperationStatus(execution, "finished", "100", "Core NSSI ${getAction()} successful")
1263 LOGGER.debug("${getPrefix()} Exit updateServiceOperationStatus")
1268 * Prepares ResourceOperation status
1270 * @param operationType
1272 void setResourceOperationStatus(DelegateExecution execution, String status, String progress, String statusDesc) {
1273 LOGGER.debug("${getPrefix()} Start setResourceOperationStatus")
1275 def currentNSSI = execution.getVariable("currentNSSI")
1277 String serviceId = currentNSSI['nsiId']
1278 String jobId = execution.getVariable("jobId")
1279 String nsiId = currentNSSI['nsiId']
1280 String operationType = execution.getVariable("operationType")
1281 String resourceInstanceId = currentNSSI['nssiId']
1283 ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
1284 String modelUuid = nssi.getModelVersionId()
1286 ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
1287 resourceOperationStatus.setServiceId(serviceId)
1288 resourceOperationStatus.setOperationId(jobId)
1289 resourceOperationStatus.setResourceTemplateUUID(modelUuid)
1290 resourceOperationStatus.setOperType(operationType)
1291 resourceOperationStatus.setResourceInstanceID(resourceInstanceId)
1292 resourceOperationStatus.setStatus(status)
1293 resourceOperationStatus.setProgress(progress)
1294 resourceOperationStatus.setStatusDescription(statusDesc)
1295 requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
1297 LOGGER.debug("${getPrefix()} Exit setResourceOperationStatus")
1302 * Prepares failed operation status update
1305 void prepareFailedOperationStatusUpdate(DelegateExecution execution) {
1306 LOGGER.debug("${getPrefix()} Start prepareFailedOperationStatusUpdate")
1308 setResourceOperationStatus(execution, "failed", "0", "Core NSSI ${getAction()} Failed")
1310 LOGGER.debug("${getPrefix()} Exit prepareFailedOperationStatusUpdate")
1315 * Gets progress status of ServiceInstance PUT operation
1318 public void getPUTServiceInstanceProgress(DelegateExecution execution) {
1319 LOGGER.debug("${getPrefix()} Start getPUTServiceInstanceProgress")
1321 def currentNSSI = execution.getVariable("currentNSSI")
1323 ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
1325 String url = currentNSSI['requestSelfLink']
1327 String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
1329 String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
1332 String basicAuthValue = utils.getBasicAuth(basicAuth, msoKey)
1334 getProgress(execution, url, basicAuthValue, "putStatus")
1336 LOGGER.debug("${getPrefix()} Exit getPUTServiceInstanceProgress")
1340 void getProgress(DelegateExecution execution, String url, String authHeader, String statusVariableName) {
1341 LOGGER.debug("${getPrefix()} Start getProgress")
1343 LOGGER.debug("getProgress: url = " + url)
1344 LOGGER.debug("getProgress: authHeader = " + authHeader)
1349 HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
1350 httpClient.addAdditionalHeader("Authorization", authHeader)
1351 httpClient.addAdditionalHeader("Accept", "application/json")
1353 Response response = httpClient.get()
1354 int responseCode = response.getStatus()
1355 // execution.setVariable("GetServiceOrderResponseCode", responseCode)
1356 LOGGER.debug("Get ServiceOrder response code is: " + responseCode)
1358 String soResponse = ""
1359 if(response.hasEntity()) {
1360 soResponse = response.readEntity(String.class)
1361 // execution.setVariable("GetServiceOrderResponse", extApiResponse)
1362 LOGGER.debug("Create response body is: " + soResponse)
1365 //Process Response //200 OK 201 CREATED 202 ACCEPTED
1366 if (responseCode >= 200 && responseCode < 204) {
1367 LOGGER.debug("Get Create ServiceOrder Received a Good Response")
1368 String requestState = jsonUtil.getJsonValue(soResponse, "request.requestStatus.requestState")
1371 JSONArray items = responseObj.getJSONArray("orderItem")
1372 JSONObject item = items.get(0)
1373 JSONObject service = item.get("service")
1374 String networkServiceId = service.get("id")
1375 if (networkServiceId == null || networkServiceId.equals("null")) {
1376 prepareFailedOperationStatusUpdate(execution)
1380 execution.setVariable("networkServiceId", networkServiceId)
1381 String serviceOrderState = item.get("state")
1382 execution.setVariable("ServiceOrderState", serviceOrderState) */
1384 // Get serviceOrder State and process progress
1385 if("ACKNOWLEDGED".equalsIgnoreCase(requestState)) {
1386 execution.setVariable(statusVariableName, "processing")
1388 else if("IN_PROGRESS".equalsIgnoreCase(requestState)) {
1389 execution.setVariable(statusVariableName, "processing")
1391 else if("COMPLETE".equalsIgnoreCase(requestState)) {
1392 execution.setVariable(statusVariableName, "completed")
1394 else if("FAILED".equalsIgnoreCase(requestState)) {
1395 msg = "ServiceOrder failed"
1396 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1398 else if("REJECTED".equalsIgnoreCase(requestState)) {
1399 prepareFailedOperationStatusUpdate(execution)
1402 msg = "ServiceOrder failed"
1403 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1407 msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode
1408 prepareFailedOperationStatusUpdate(execution)
1411 }catch(Exception e){
1412 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage())
1415 LOGGER.debug("${getPrefix()} Exit getProgress")
1424 void timeDelay(DelegateExecution execution) {
1425 LOGGER.debug("${getPrefix()} Start timeDelay")
1428 LOGGER.debug("${getPrefix()} timeDelay going to sleep for 5 sec")
1432 LOGGER.debug("${getPrefix()} ::: timeDelay wakeup after 5 sec")
1433 } catch(InterruptedException e) {
1434 LOGGER.error("${getPrefix()} ::: timeDelay exception" + e)
1437 LOGGER.debug("${getPrefix()} Exit timeDelay")
1441 void postProcessRequest(DelegateExecution execution) {
1442 LOGGER.debug("${getPrefix()} Start postProcessRequest")
1444 execution.removeVariable("currentNSSI")
1446 LOGGER.debug("***** ${getPrefix()} Exit postProcessRequest")
1452 * Returns AAI client
1453 * @return AAI client
1455 AAIResourcesClient getAAIClient() {
1456 return new AAIResourcesClient()
1460 ExternalAPIUtilFactory getExternalAPIUtilFactory() {
1461 return new ExternalAPIUtilFactory()
1466 * Returns Catalog DB Util Factory
1467 * @return ew CatalogDbUtilsFactory()
1469 CatalogDbUtilsFactory getCatalogDbUtilsFactory() {
1470 return new CatalogDbUtilsFactory()
1474 private String getPrefix() {
1478 String getAction() {