2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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.common.scripts
23 import org.json.JSONObject;
24 import org.json.JSONArray;
26 import org.onap.so.bpmn.core.UrnPropertiesReader;
27 import org.springframework.web.util.UriUtils;
29 import org.onap.so.bpmn.core.json.JsonUtils
32 import groovy.json.JsonBuilder
33 import groovy.json.JsonSlurper
34 import groovy.util.slurpersupport.GPathResult
35 import groovy.xml.QName;
37 import org.camunda.bpm.engine.delegate.DelegateExecution
39 import org.onap.so.logger.MsoLogger;
40 import org.onap.so.rest.APIResponse;
41 import org.onap.so.rest.RESTClient
42 import org.onap.so.rest.RESTConfig
43 import org.onap.so.logger.MessageEnum
48 * Utilities for accessing Catalog DB Adapter to retrieve Networks, VNF/VFModules, AllottedResources and complete ServiceResources information
52 class CatalogDbUtils {
53 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CatalogDbUtils.class);
56 MsoUtils utils = new MsoUtils()
57 JsonUtils jsonUtils = new JsonUtils()
58 static private String defaultDbAdapterVersion = "v2"
60 public JSONArray getAllNetworksByServiceModelUuid(DelegateExecution execution, String serviceModelUuid) {
61 JSONArray networksList = null
62 String endPoint = "/serviceNetworks?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
64 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
66 if (catalogDbResponse != null) {
67 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", "v1")
72 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
79 public JSONArray getAllNetworksByServiceModelUuid(DelegateExecution execution, String serviceModelUuid, String catalogUtilsVersion) {
80 JSONArray networksList = null
81 String endPoint = "/serviceNetworks?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
83 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
85 if (catalogDbResponse != null) {
86 if (!catalogUtilsVersion.equals("v1")) {
87 JSONObject responseJson = new JSONObject(catalogDbResponse)
88 networksList = responseJson.getJSONArray("serviceNetworks")
91 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", catalogUtilsVersion)
97 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
104 public JSONArray getAllNetworksByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid) {
105 JSONArray networksList = null
106 String endPoint = "/serviceNetworks?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
108 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
110 if (catalogDbResponse != null) {
111 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", "v1")
115 catch (Exception e) {
116 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
123 public JSONArray getAllNetworksByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid, String catalogUtilsVersion) {
124 JSONArray networksList = null
125 String endPoint = "/serviceNetworks?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
127 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
129 if (catalogDbResponse != null) {
130 if (!catalogUtilsVersion.equals("v1")) {
131 JSONObject responseJson = new JSONObject(catalogDbResponse)
132 networksList = responseJson.getJSONArray("serviceNetworks")
135 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", catalogUtilsVersion)
140 catch (Exception e) {
141 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
148 public JSONArray getAllNetworksByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion) {
149 JSONArray networksList = null
150 String endPoint = "/serviceNetworks?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
152 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
154 if (catalogDbResponse != null) {
155 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", "v1")
159 catch (Exception e) {
160 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
167 public JSONArray getAllNetworksByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion, String catalogUtilsVersion) {
168 JSONArray networksList = null
169 String endPoint = "/serviceNetworks?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
171 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
173 if (catalogDbResponse != null) {
174 if (!catalogUtilsVersion.equals("v1")) {
175 JSONObject responseJson = new JSONObject(catalogDbResponse)
176 networksList = responseJson.getJSONArray("serviceNetworks")
179 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", catalogUtilsVersion)
184 catch (Exception e) {
185 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
192 public JSONArray getAllNetworksByNetworkModelCustomizationUuid(DelegateExecution execution, String networkModelCustomizationUuid) {
193 JSONArray networksList = null
194 String endPoint = "/serviceNetworks?networkModelCustomizationUuid=" + UriUtils.encode(networkModelCustomizationUuid, "UTF-8")
196 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
198 if (catalogDbResponse != null) {
199 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", "v1")
203 catch (Exception e) {
204 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
211 public JSONArray getAllNetworksByNetworkModelCustomizationUuid(DelegateExecution execution, String networkModelCustomizationUuid, String catalogUtilsVersion) {
212 JSONArray networksList = null
213 String endPoint = "/serviceNetworks?networkModelCustomizationUuid=" + UriUtils.encode(networkModelCustomizationUuid, "UTF-8")
215 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
217 if (catalogDbResponse != null) {
218 if (!catalogUtilsVersion.equals("v1")) {
219 JSONObject responseJson = new JSONObject(catalogDbResponse)
220 networksList = responseJson.getJSONArray("serviceNetworks")
223 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", catalogUtilsVersion)
228 catch (Exception e) {
229 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
236 public JSONArray getAllNetworksByNetworkType(DelegateExecution execution, String networkType) {
237 JSONArray networksList = null
238 String endPoint = "/serviceNetworks?networkType=" + UriUtils.encode(networkType, "UTF-8")
240 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
242 if (catalogDbResponse != null) {
243 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", "v1")
247 catch (Exception e) {
248 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
255 public JSONArray getAllNetworksByNetworkType(DelegateExecution execution, String networkType, String catalogUtilsVersion) {
256 JSONArray networksList = null
257 String endPoint = "/serviceNetworks?networkType=" + UriUtils.encode(networkType, "UTF-8")
259 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
261 if (catalogDbResponse != null) {
262 if (!catalogUtilsVersion.equals("v1")) {
263 JSONObject responseJson = new JSONObject(catalogDbResponse)
264 networksList = responseJson.getJSONArray("serviceNetworks")
267 networksList = parseNetworksJson(catalogDbResponse, "serviceNetworks", catalogUtilsVersion)
272 catch (Exception e) {
273 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
281 public JSONArray getAllVnfsByServiceModelUuid(DelegateExecution execution, String serviceModelUuid) {
282 JSONArray vnfsList = null
283 String endPoint = "/serviceVnfs?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
285 msoLogger.debug("ENDPOINT: " + endPoint)
286 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
288 if (catalogDbResponse != null) {
289 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", "v1")
293 catch (Exception e) {
294 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
301 public JSONArray getAllVnfsByServiceModelUuid(DelegateExecution execution, String serviceModelUuid, String catalogUtilsVersion) {
302 JSONArray vnfsList = null
303 String endPoint = "/serviceVnfs?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
305 msoLogger.debug("ENDPOINT: " + endPoint)
306 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
308 if (catalogDbResponse != null) {
309 if (!catalogUtilsVersion.equals("v1")) {
310 JSONObject responseJson = new JSONObject(catalogDbResponse)
311 vnfsList = responseJson.getJSONArray("serviceVnfs")
314 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", catalogUtilsVersion)
319 catch (Exception e) {
320 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
327 public JSONArray getAllVnfsByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid) {
328 JSONArray vnfsList = null
329 String endPoint ="/serviceVnfs?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
331 msoLogger.debug("ENDPOINT: " + endPoint)
332 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
334 if (catalogDbResponse != null) {
335 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", "v1")
339 catch (Exception e) {
340 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
347 public JSONArray getAllVnfsByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid, String catalogUtilsVersion) {
348 JSONArray vnfsList = null
349 String endPoint = "/serviceVnfs?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
351 msoLogger.debug("ENDPOINT: " + endPoint)
352 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
354 if (catalogDbResponse != null) {
355 if (!catalogUtilsVersion.equals("v1")) {
356 JSONObject responseJson = new JSONObject(catalogDbResponse)
357 vnfsList = responseJson.getJSONArray("serviceVnfs")
360 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", catalogUtilsVersion)
365 catch (Exception e) {
366 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
373 public JSONArray getAllVnfsByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion) {
374 JSONArray vnfsList = null
375 String endPoint = "/serviceVnfs?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
377 msoLogger.debug("ENDPOINT: " + endPoint)
378 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
380 if (catalogDbResponse != null) {
381 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", "v1")
385 catch (Exception e) {
386 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
393 public JSONArray getAllVnfsByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion, String catalogUtilsVersion) {
394 JSONArray vnfsList = null
395 String endPoint = "/serviceVnfs?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
397 msoLogger.debug("ENDPOINT: " + endPoint)
398 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
400 if (catalogDbResponse != null) {
401 if (!catalogUtilsVersion.equals("v1")) {
402 JSONObject responseJson = new JSONObject(catalogDbResponse)
403 vnfsList = responseJson.getJSONArray("serviceVnfs")
406 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", catalogUtilsVersion)
411 catch (Exception e) {
412 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
419 public JSONArray getAllVnfsByVnfModelCustomizationUuid(DelegateExecution execution, String vnfModelCustomizationUuid) {
420 JSONArray vnfsList = null
421 String endPoint = "/serviceVnfs?vnfModelCustomizationUuid=" + UriUtils.encode(vnfModelCustomizationUuid, "UTF-8")
423 msoLogger.debug("ENDPOINT: " + endPoint)
424 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
426 if (catalogDbResponse != null) {
427 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", "v1")
431 catch (Exception e) {
432 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
440 * This method gets a all vnfs for a particular
441 * service from the catalog database using the
442 * service model's model name.
444 * @param catalogDbEndpoint
445 * @param serviceModelModelName
449 public JSONArray getAllVnfsByServiceModelModelName(DelegateExecution execution, String serviceModelModelName) {
450 JSONArray vnfsList = null
451 String endPoint = "/serviceVnfs?serviceModelName=" + UriUtils.encode(serviceModelModelName, "UTF-8")
453 msoLogger.debug("ENDPOINT: " + endPoint)
454 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
456 if (catalogDbResponse != null) {
457 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", defaultDbAdapterVersion)
459 }catch (Exception e) {
460 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
466 public JSONArray getAllVnfsByVnfModelCustomizationUuid(DelegateExecution execution, String vnfModelCustomizationUuid, String catalogUtilsVersion) {
467 JSONArray vnfsList = null
468 String endPoint = "/serviceVnfs?vnfModelCustomizationUuid=" + UriUtils.encode(vnfModelCustomizationUuid, "UTF-8")
470 msoLogger.debug("ENDPOINT: " + endPoint)
471 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
473 if (catalogDbResponse != null) {
474 if (!catalogUtilsVersion.equals("v1")) {
475 JSONObject responseJson = new JSONObject(catalogDbResponse)
476 vnfsList = responseJson.getJSONArray("serviceVnfs")
479 vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", catalogUtilsVersion)
484 catch (Exception e) {
485 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
493 * This method gets a single vf module from
494 * the catalog database using the vf module's
495 * model name. It returns that vf module as
498 * @param catalogDbEndpoint
499 * @param vfModuleModelName
502 public JSONObject getVfModuleByVfModuleModelName(DelegateExecution execution, String vfModuleModelName) {
503 JSONObject vfModule = null
504 String endPoint = "/vfModules?vfModuleModelName=" + UriUtils.encode(vfModuleModelName, "UTF-8")
506 msoLogger.debug("Get VfModule By VfModule ModelName Endpoint is: " + endPoint)
507 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
509 if (catalogDbResponse != null) {
510 vfModule = parseVfModuleJson(catalogDbResponse, "vfModules", "v1")
514 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
522 * This method gets a single vf module from
523 * the catalog database using the vf module's
524 * model name. It returns that vf module as
527 * @param catalogDbEndpoint
528 * @param vfModuleModelName
529 * @param catalogUtilsVersion
532 public JSONObject getVfModuleByVfModuleModelName(DelegateExecution execution, String vfModuleModelName, String catalogUtilsVersion) {
533 JSONObject vfModule = null
534 String endPoint = "/vfModules?vfModuleModelName=" + UriUtils.encode(vfModuleModelName, "UTF-8")
536 msoLogger.debug("Get VfModule By VfModule ModelName Endpoint is: " + endPoint)
537 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
539 if (catalogDbResponse != null) {
540 vfModule = parseVfModuleJson(catalogDbResponse, "vfModules", "v1")
544 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
552 public JSONArray getAllottedResourcesByServiceModelUuid(DelegateExecution execution, String serviceModelUuid) {
553 JSONArray vnfsList = null
554 String endPoint = "/ServiceAllottedResources?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
556 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
558 if (catalogDbResponse != null) {
559 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", "v1")
563 catch (Exception e) {
564 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
571 public JSONArray getAllottedResourcesByServiceModelUuid(DelegateExecution execution, String serviceModelUuid, String catalogUtilsVersion) {
572 JSONArray vnfsList = null
573 String endPoint = "/ServiceAllottedResources?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
575 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
577 if (catalogDbResponse != null) {
578 if (!catalogUtilsVersion.equals("v1")) {
579 JSONObject responseJson = new JSONObject(catalogDbResponse)
580 vnfsList = responseJson.getJSONArray("serviceAllottedResources")
583 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", catalogUtilsVersion)
588 catch (Exception e) {
589 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
596 public JSONArray getAllottedResourcesByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid) {
597 JSONArray vnfsList = null
598 String endPoint = "/serviceAllottedResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
600 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
602 if (catalogDbResponse != null) {
603 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", "v1")
607 catch (Exception e) {
608 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
615 public JSONArray getAllottedResourcesByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid, String catalogUtilsVersion) {
616 JSONArray vnfsList = null
617 String endPoint = "/serviceAllottedResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
619 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
621 if (catalogDbResponse != null) {
622 if (!catalogUtilsVersion.equals("v1")) {
623 JSONObject responseJson = new JSONObject(catalogDbResponse)
624 vnfsList = responseJson.getJSONArray()
627 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", catalogUtilsVersion)
632 catch (Exception e) {
633 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.getStackTrace());
640 public JSONArray getAllottedResourcesByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion) {
641 JSONArray vnfsList = null
642 String endPoint = "/serviceAllottedResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
644 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
646 if (catalogDbResponse != null) {
647 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", "v1")
651 catch (Exception e) {
652 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
659 public JSONArray getAllottedResourcesByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion, String catalogUtilsVersion) {
660 JSONArray vnfsList = null
661 String endPoint = "/serviceAllottedResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
663 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
665 if (catalogDbResponse != null) {
666 if (!catalogUtilsVersion.equals("v1")) {
667 JSONObject responseJson = new JSONObject(catalogDbResponse)
668 vnfsList = responseJson.getJSONArray("serviceAllottedResources")
671 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", catalogUtilsVersion)
676 catch (Exception e) {
677 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
685 public JSONArray getAllottedResourcesByArModelCustomizationUuid(DelegateExecution execution, String arModelCustomizationUuid) {
686 JSONArray vnfsList = null
687 String endPoint = "/serviceAllottedResources?serviceModelCustomizationUuid=" + UriUtils.encode(arModelCustomizationUuid, "UTF-8")
689 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
691 if (catalogDbResponse != null) {
692 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", "v1")
696 catch (Exception e) {
697 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
704 public JSONArray getAllottedResourcesByArModelCustomizationUuid(DelegateExecution execution, String arModelCustomizationUuid, String catalogUtilsVersion) {
705 JSONArray vnfsList = null
706 String endPoint = "/serviceAllottedResources?serviceModelCustomizationUuid=" + UriUtils.encode(arModelCustomizationUuid, "UTF-8")
708 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
710 if (catalogDbResponse != null) {
711 if (!catalogUtilsVersion.equals("v1")) {
712 JSONObject responseJson = new JSONObject(catalogDbResponse)
713 vnfsList = responseJson.getJSONArray("serviceAllottedResources")
716 vnfsList = parseAllottedResourcesJson(catalogDbResponse, "serviceAllottedResources", catalogUtilsVersion)
721 catch (Exception e) {
722 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
729 public JSONObject getServiceResourcesByServiceModelUuid(DelegateExecution execution, String serviceModelUuid) {
730 JSONObject resources = null
731 String endPoint = "/serviceResources?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
733 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
735 if (catalogDbResponse != null) {
737 resources = parseServiceResourcesJson(catalogDbResponse, "v1")
741 catch (Exception e) {
742 utils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
749 public JSONObject getServiceResourcesByServiceModelUuid(DelegateExecution execution, String serviceModelUuid, String catalogUtilsVersion) {
750 JSONObject resources = null
751 String endPoint = "/serviceResources?serviceModelUuid=" + UriUtils.encode(serviceModelUuid, "UTF-8")
753 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
755 if (catalogDbResponse != null) {
756 if (!catalogUtilsVersion.equals("v1")) {
757 resources = new JSONObject(catalogDbResponse)
760 resources = parseServiceResourcesJson(catalogDbResponse, catalogUtilsVersion)
764 catch (Exception e) {
765 utils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
772 public JSONObject getServiceResourcesByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid) {
773 JSONObject resources = null
774 String endPoint = "/serviceResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
776 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
778 if (catalogDbResponse != null) {
780 resources = parseServiceResourcesJson(catalogDbResponse, "v1")
784 catch (Exception e) {
785 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
792 public String getServiceResourcesByServiceModelInvariantUuidString(DelegateExecution execution, String serviceModelInvariantUuid) {
793 String resources = null
794 String endPoint = "/serviceResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
796 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
798 if (catalogDbResponse != null) {
800 resources = catalogDbResponse
804 catch (Exception e) {
805 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
812 public JSONObject getServiceResourcesByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid, String catalogUtilsVersion) {
813 JSONObject resources = null
814 String endPoint = "/serviceResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
816 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
818 if (catalogDbResponse != null) {
819 if (!catalogUtilsVersion.equals("v1")) {
820 resources = new JSONObject(catalogDbResponse)
823 resources = parseServiceResourcesJson(catalogDbResponse, catalogUtilsVersion)
828 catch (Exception e) {
829 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
837 public JSONObject getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion) {
838 JSONObject resources = null
839 String endPoint = "/serviceResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
841 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
843 if (catalogDbResponse != null) {
845 resources = parseServiceResourcesJson(catalogDbResponse)
849 catch (Exception e) {
850 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
857 public JSONObject getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(DelegateExecution execution, String serviceModelInvariantUuid, String serviceModelVersion, String catalogUtilsVersion) {
858 JSONObject resources = null
859 String endPoint = "/serviceResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") + "&serviceModelVersion=" + UriUtils.encode(serviceModelVersion, "UTF-8")
861 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
863 if (catalogDbResponse != null) {
864 if (!catalogUtilsVersion.equals("v1")) {
865 resources = new JSONObject(catalogDbResponse)
868 resources = parseServiceResourcesJson(catalogDbResponse, catalogUtilsVersion)
873 catch (Exception e) {
874 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
883 private JSONArray parseNetworksJson (String catalogDbResponse, String arrayName, String catalogUtilsVersion) {
884 JSONArray modelInfos = null
886 msoLogger.debug("parseNetworksJson - catalogUtilsVersion is " + catalogUtilsVersion)
888 // Create array of jsons
890 JSONObject responseJson = new JSONObject(catalogDbResponse)
891 JSONArray networks = responseJson.getJSONArray(arrayName)
892 modelInfos = new JSONArray()
894 for (int i = 0; i < networks.length(); i++) {
896 JSONObject network = networks.getJSONObject(i)
897 JSONObject modelJson = new JSONObject()
898 JSONObject modelInfo = buildModelInfo("network", network, catalogUtilsVersion)
899 modelJson.put("modelInfo", modelInfo)
900 String networkType = jsonUtils.getJsonValueForKey(network, "networkType")
901 modelJson.put("networkType", networkType)
903 switch (catalogUtilsVersion) {
907 String toscaNodeType = jsonUtils.getJsonValueForKey(network, "toscaNodeType")
908 modelJson.put("toscaNodeType", toscaNodeType)
909 String networkTechnology = jsonUtils.getJsonValueForKey(network, "networkTechnology")
910 modelJson.put("networkTechnology", networkTechnology)
911 String networkRole = jsonUtils.getJsonValueForKey(network, "networkRole")
912 modelJson.put("networkRole", networkRole)
913 String networkScope = jsonUtils.getJsonValueForKey(network, "networkScope")
914 modelJson.put("networkScope", networkScope)
917 modelInfos.put(modelJson)
920 String modelInfosString = modelInfos.toString()
921 msoLogger.debug("Returning networks JSON: " + modelInfosString)
923 } catch (Exception e) {
924 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
930 private JSONArray parseVnfsJson (String catalogDbResponse, String arrayName, String catalogUtilsVersion) {
931 JSONArray modelInfos = null
933 msoLogger.debug("parseVnfsJson - catalogUtilsVersion is " + catalogUtilsVersion)
936 // Create array of jsons
938 JSONObject responseJson = new JSONObject(catalogDbResponse)
939 JSONArray vnfs = responseJson.getJSONArray(arrayName)
940 modelInfos = new JSONArray()
942 for (int i = 0; i < vnfs.length(); i++) {
943 JSONObject vnf = vnfs.getJSONObject(i)
945 msoLogger.debug(vnf.toString(2))
946 JSONObject modelInfo = buildModelInfo("vnf", vnf, catalogUtilsVersion)
947 JSONObject modelJson = new JSONObject()
948 modelJson.put("modelInfo", modelInfo)
949 switch(catalogUtilsVersion) {
953 String toscaNodeType = jsonUtils.getJsonValueForKey(vnf, "toscaNodeType")
954 modelJson.put("toscaNodeType", toscaNodeType)
955 String nfType = jsonUtils.getJsonValueForKey(vnf, "nfType")
956 modelJson.put("nfType", nfType)
957 String nfRole = jsonUtils.getJsonValueForKey(vnf, "nfRole")
958 modelJson.put("nfRole", nfRole)
959 String nfCode = jsonUtils.getJsonValueForKey(vnf, "nfCode")
960 modelJson.put("nfNamingCode", nfCode)
961 String nfFunction = jsonUtils.getJsonValueForKey(vnf, "nfFunction")
962 modelJson.put("nfFunction", nfFunction)
963 String multiStageDesign = jsonUtils.getJsonValueForKey(vnf, "multiStageDesign")
964 modelJson.put("multiStageDesign", multiStageDesign)
968 JSONArray vfModules = null
970 vfModules = vnf.getJSONArray("vfModules")
971 } catch (Exception e)
973 msoLogger.debug("Cannot find VF MODULE ARRAY: " + i + ", exception is " + e.message)
976 if (vfModules != null) {
977 JSONArray vfModuleInfo = new JSONArray()
978 for (int j = 0; j < vfModules.length(); j++) {
979 JSONObject vfModule = vfModules.getJSONObject(j)
980 JSONObject vfModuleModelInfo = buildModelInfo("vfModule", vfModule, catalogUtilsVersion)
981 JSONObject vfModuleModelJson = new JSONObject()
982 vfModuleModelJson.put("modelInfo", vfModuleModelInfo)
983 String vfModuleType = jsonUtils.getJsonValueForKey(vfModule, "type")
984 vfModuleModelJson.put("vfModuleType", vfModuleType)
985 switch(catalogUtilsVersion) {
987 //TODO this does not work, isBase is not a integer.
988 Integer isBase = jsonUtils.getJsonIntValueForKey(vfModule, "isBase")
989 if (isBase.intValue() == 1) {
990 vfModuleModelJson.put("isBase", "true")
993 vfModuleModelJson.put("isBase", "false")
997 boolean isBase = jsonUtils.getJsonBooleanValueForKey(vfModule, "isBase")
998 vfModuleModelJson.put("isBase", isBase)
1001 String vfModuleLabel = jsonUtils.getJsonValueForKey(vfModule, "label")
1002 vfModuleModelJson.put("vfModuleLabel", vfModuleLabel)
1003 Integer initialCount = jsonUtils.getJsonIntValueForKey(vfModule, "initialCount")
1004 vfModuleModelJson.put("initialCount", initialCount.intValue())
1005 vfModuleInfo.put(vfModuleModelJson)
1007 modelJson.put("vfModules", vfModuleInfo)
1009 modelInfos.put(modelJson)
1012 String modelInfosString = modelInfos.toString()
1013 msoLogger.debug("Returning vnfs JSON: " + modelInfosString)
1015 } catch (Exception e) {
1016 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
1023 * This method parses a Vf Module from the
1026 * @param catalogDbResponse
1028 * @param catalogUtilsVersion
1029 * @return vfModulelJson
1031 private JSONObject parseVfModuleJson (String catalogDbResponse, String arrayName, String catalogUtilsVersion) {
1032 JSONObject vfModulelJson = new JSONObject()
1033 msoLogger.debug("Started Parse Vf Module Json")
1035 JSONObject responseJson = new JSONObject(catalogDbResponse)
1036 JSONArray vfModules = responseJson.getJSONArray(arrayName)
1037 if(vfModules != null){
1038 JSONObject vfModuleInfo = new JSONObject()
1039 for (int i = 0; i < vfModules.length(); i++) {
1040 JSONObject vfModule = vfModules.getJSONObject(i)
1041 JSONObject vfModuleModelInfo = buildModelInfo("vfModule", vfModule, catalogUtilsVersion)
1042 vfModulelJson.put("modelInfo", vfModuleModelInfo)
1043 String vfModuleType = jsonUtils.getJsonValueForKey(vfModule, "type")
1044 vfModulelJson.put("vfModuleType", vfModuleType)
1045 switch(catalogUtilsVersion) {
1047 Integer isBase = jsonUtils.getJsonIntValueForKey(vfModule, "isBase")
1048 if (isBase.intValue() == 1) {
1049 vfModulelJson.put("isBase", "true")
1052 vfModulelJson.put("isBase", "false")
1056 boolean isBase = jsonUtils.getJsonBooleanValueForKey(vfModule, "isBase")
1057 vfModulelJson.put("isBase", isBase)
1060 String vfModuleLabel = jsonUtils.getJsonValueForKey(vfModule, "label")
1061 vfModulelJson.put("vfModuleLabel", vfModuleLabel)
1062 Integer initialCount = jsonUtils.getJsonIntValueForKey(vfModule, "initialCount")
1063 vfModulelJson.put("initialCount", initialCount.intValue())
1066 msoLogger.debug("Completed Parsing Vf Module: " + vfModulelJson.toString())
1067 }catch (Exception e){
1068 msoLogger.debug("Exception while parsing Vf Modules from Catalog DB Response: " + e.message)
1071 return vfModulelJson
1074 private JSONArray parseAllottedResourcesJson (String catalogDbResponse, String arrayName, String catalogUtilsVersion) {
1075 JSONArray modelInfos = null
1077 msoLogger.debug("parseAllottedResourcesJson - catalogUtilsVersion is " + catalogUtilsVersion)
1080 // Create array of jsons
1082 JSONObject responseJson = new JSONObject(catalogDbResponse)
1083 JSONArray allottedResources = responseJson.getJSONArray(arrayName)
1084 modelInfos = new JSONArray()
1086 for (int i = 0; i < allottedResources.length(); i++) {
1087 JSONObject allottedResource = allottedResources.getJSONObject(i)
1088 JSONObject modelInfo = buildModelInfo("allottedResource", allottedResource, catalogUtilsVersion)
1089 JSONObject modelJson = new JSONObject()
1090 modelJson.put("modelInfo", modelInfo)
1091 switch(catalogUtilsVersion) {
1095 String toscaNodeType = jsonUtils.getJsonValueForKey(allottedResource, "toscaNodeType")
1096 modelJson.put("toscaNodeType", toscaNodeType)
1097 String nfType = jsonUtils.getJsonValueForKey(allottedResource, "nfType")
1098 modelJson.put("nfType", nfType)
1099 String nfRole = jsonUtils.getJsonValueForKey(allottedResource, "nfRole")
1100 modelJson.put("nfRole", nfRole)
1101 String nfCode = jsonUtils.getJsonValueForKey(allottedResource, "nfCode")
1102 modelJson.put("nfNamingCode", nfCode)
1103 String nfFunction = jsonUtils.getJsonValueForKey(allottedResource, "nfFunction")
1104 modelJson.put("nfFunction", nfFunction)
1105 String providingServiceModelName = jsonUtils.getJsonValueForKey(allottedResource, "providingServiceModelName")
1106 modelJson.put("providingServiceModelName", providingServiceModelName)
1107 String providingServiceModelUuid = jsonUtils.getJsonValueForKey(allottedResource, "providingServiceModelUuid")
1108 modelJson.put("providingServiceModelUuid", providingServiceModelUuid)
1113 modelInfos.put(modelJson)
1116 String modelInfosString = modelInfos.toString()
1117 msoLogger.debug("Returning allottedResources JSON: " + modelInfosString)
1119 } catch (Exception e) {
1120 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
1126 //TODO this is wrong
1127 private JSONObject parseServiceResourcesJson (String catalogDbResponse) {
1128 JSONObject serviceResources = new JSONObject()
1129 String catalogUtilsVersion = "v1"
1132 // Create array of jsons
1134 JSONObject responseJson = new JSONObject(catalogDbResponse)
1135 JSONObject serviceResourcesRoot = responseJson.getJSONObject("serviceResources")
1136 JSONArray vnfsArray = parseVnfsJson(serviceResourcesRoot.toString(), "vnfResources", catalogUtilsVersion)
1137 serviceResources.put("vnfs", vnfsArray)
1138 JSONArray networksArray = parseNetworksJson(serviceResourcesRoot.toString(), "networkResourceCustomization", catalogUtilsVersion)
1139 serviceResources.put("networks", networksArray)
1140 JSONArray allottedResourcesArray = parseAllottedResourcesJson(serviceResourcesRoot.toString(), "allottedResourceCustomization", catalogUtilsVersion)
1141 serviceResources.put("allottedResources", allottedResourcesArray)
1143 String serviceResourcesString = serviceResources.toString()
1144 msoLogger.debug("Returning serviceResources JSON: " + serviceResourcesString)
1146 } catch (Exception e) {
1147 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
1150 return serviceResources
1153 private JSONObject parseServiceResourcesJson (String catalogDbResponse, String catalogUtilsVersion) {
1154 JSONObject serviceResources = new JSONObject()
1155 JSONObject serviceResourcesObject = new JSONObject()
1156 String serviceResourcesString = ""
1159 // Create array of jsons
1161 JSONObject responseJson = new JSONObject(catalogDbResponse)
1162 JSONObject serviceResourcesRoot = responseJson.getJSONObject("serviceResources")
1163 JSONObject modelInfo = buildModelInfo("", serviceResourcesRoot, catalogUtilsVersion)
1164 serviceResources.put("modelInfo", modelInfo)
1165 JSONArray vnfsArray = parseVnfsJson(serviceResourcesRoot.toString(), "serviceVnfs", catalogUtilsVersion)
1166 serviceResources.put("serviceVnfs", vnfsArray)
1167 JSONArray networksArray = parseNetworksJson(serviceResourcesRoot.toString(), "serviceNetworks", catalogUtilsVersion)
1168 serviceResources.put("serviceNetworks", networksArray)
1169 JSONArray allottedResourcesArray = parseAllottedResourcesJson(serviceResourcesRoot.toString(), "serviceAllottedResources", catalogUtilsVersion)
1170 serviceResources.put("serviceAllottedResources", allottedResourcesArray)
1171 serviceResourcesObject.put("serviceResources", serviceResources)
1173 serviceResourcesString = serviceResourcesObject.toString()
1174 msoLogger.debug("Returning serviceResources JSON: " + serviceResourcesString)
1176 } catch (Exception e) {
1177 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
1180 return serviceResourcesObject
1183 private JSONObject buildModelInfo(String modelType, JSONObject modelFromDb, String catalogUtilsVersion) {
1184 JSONObject modelInfo = null
1186 modelInfo = new JSONObject()
1187 modelInfo.put("modelType", modelType)
1188 String modelInvariantId = jsonUtils.getJsonValueForKey(modelFromDb, "modelInvariantUuid")
1189 modelInfo.put("modelInvariantId", modelInvariantId)
1190 if(modelType.equalsIgnoreCase("allottedResource") || modelType.equalsIgnoreCase("vnf")){
1191 String modelInstanceName = jsonUtils.getJsonValueForKey(modelFromDb, "modelInstanceName")
1192 modelInfo.put("modelInstanceName", modelInstanceName)
1194 if ((!"vfModule".equals(modelType) && !"vnf".equals(modelType)) || !catalogUtilsVersion.equals("v1")) {
1195 String modelVersionId = jsonUtils.getJsonValueForKey(modelFromDb, "modelUuid")
1196 modelInfo.put("modelVersionId", modelVersionId)
1199 String modelVersionId = jsonUtils.getJsonValueForKey(modelFromDb, "asdcUuid")
1200 modelInfo.put("modelVersionId", modelVersionId)
1202 String modelName = jsonUtils.getJsonValueForKey(modelFromDb, "modelName")
1203 modelInfo.put("modelName", modelName)
1204 String modelVersion = jsonUtils.getJsonValueForKey(modelFromDb, "modelVersion")
1205 modelInfo.put("modelVersion", modelVersion)
1206 if (!"vfModule".equals(modelType)) {
1207 String modelCustomizationName = jsonUtils.getJsonValueForKey(modelFromDb, "modelCustomizationName")
1208 modelInfo.put("modelCustomizationName", modelCustomizationName)
1210 String modelCustomizationId = jsonUtils.getJsonValueForKey(modelFromDb, "modelCustomizationUuid")
1211 switch (catalogUtilsVersion) {
1213 modelInfo.put("modelCustomizationId", modelCustomizationId)
1216 modelInfo.put("modelCustomizationUuid", modelCustomizationId)
1219 JSONObject modelJson = new JSONObject()
1220 modelJson.put("modelInfo", modelInfo)
1222 catch (Exception e) {
1223 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception while parsing model information", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
1228 private String getResponseFromCatalogDb (DelegateExecution execution, String endPoint) {
1231 String catalogDbEndpoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint",execution)
1232 String queryEndpoint = catalogDbEndpoint + "/" + defaultDbAdapterVersion + endPoint
1233 RESTConfig config = new RESTConfig(queryEndpoint);
1234 def responseData = ''
1235 def bpmnRequestId = UUID.randomUUID().toString()
1236 RESTClient client = new RESTClient(config).
1237 addHeader('X-TransactionId', bpmnRequestId).
1238 addHeader('X-FromAppId', 'BPMN').
1239 addHeader('Content-Type', 'application/json').
1240 addHeader('Accept','application/json');
1242 String basicAuthCred = execution.getVariable("BasicAuthHeaderValueDB")
1243 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
1244 client.addAuthorizationHeader(basicAuthCred)
1246 client.addAuthorizationHeader(getBasicDBAuthHeader(execution))
1248 msoLogger.debug('sending GET to Catalog DB endpoint: ' + endPoint)
1249 APIResponse response = client.httpGet()
1251 responseData = response.getResponseBodyAsString()
1252 if (responseData != null) {
1253 msoLogger.debug("Received data from Catalog DB: " + responseData)
1256 msoLogger.debug('Response code:' + response.getStatusCode())
1257 msoLogger.debug('Response:' + System.lineSeparator() + responseData)
1258 if (response.getStatusCode() == 200) {
1259 // parse response as needed
1266 catch (Exception e) {
1267 msoLogger.debug("ERROR WHILE QUERYING CATALOG DB: " + e.message)
1274 * get resource recipe by resource model uuid and action
1276 public JSONObject getResourceRecipe(DelegateExecution execution, String resourceModelUuid, String action) {
1277 String endPoint = "/resourceRecipe?resourceModelUuid=" + UriUtils.encode(resourceModelUuid, "UTF-8")+ "&action=" + UriUtils.encode(action, "UTF-8")
1278 JSONObject responseJson = null
1280 msoLogger.debug("ENDPOINT: " + endPoint)
1281 String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
1283 if (catalogDbResponse != null) {
1284 responseJson = new JSONObject(catalogDbResponse)
1287 catch (Exception e) {
1288 utils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
1295 private String getBasicDBAuthHeader(DelegateExecution execution) {
1297 String encodedString = null
1299 String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution)
1300 utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB)
1302 encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution))
1303 execution.setVariable("BasicAuthHeaderValueDB",encodedString)
1304 } catch (IOException ex) {
1305 String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
1306 utils.log("ERROR", dataErrorMessage)
1308 return encodedString