[ConfigFetchFromCbs] Fix bug of cbs that fetch configs getting hung when 83/130883/3 jakarta
authorqingshuting <qingshuting1@huawei.com>
Wed, 14 Sep 2022 02:37:24 +0000 (10:37 +0800)
committerqingshuting <qingshuting1@huawei.com>
Tue, 20 Sep 2022 13:13:42 +0000 (21:13 +0800)
policy engine is empty

Issue-ID: DCAEGEN2-3242
Signed-off-by: qingshuting <qingshuting1@huawei.com>
Change-Id: I21307291c182e3681ba864afc5a6a6f7eb5a8add
(cherry picked from commit 7d549f48c21ff063518e8ff481c3e5a9eb8ca8b0)

Changelog.md
src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java

index 9ff9d6b..15c1a00 100644 (file)
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 
 ## [2.1.7] - 2021/05/11
          - [DCAEGEN2-3150](https://jira.onap.org/browse/DCAEGEN2-3150) - Fix bug in handling FM notification
+         - [DCAEGEN2-3242](https://jira.onap.org/browse/DCAEGEN2-3242) - Fix bug in ConfigFectchFromCbs that fetch will get hung when policy config in pdp engine is empty
 
 ## [2.1.6] - 2022/02/07
          - [DCAEGEN2-3057](https://jira.onap.org/browse/DCAEGEN2-3057) - Fix bug in triggering control loop for PCI collision/confusion - by replacing Config DB with CPS
index afd5092..41f00a9 100644 (file)
@@ -3,6 +3,7 @@
  *  son-handler
  *  ================================================================================
  *   Copyright (C) 2019-2021 Wipro Limited.
+ *   Copyright (C) 2022 Huawei Technologies Co., Ltd.
  *   ==============================================================================
  *     Licensed under the Apache License, Version 2.0 (the "License");
  *     you may not use this file except in compliance with the License.
@@ -93,11 +94,15 @@ public class ConfigFetchFromCbs implements Runnable {
                     Type mapType = new TypeToken<Map<String, Object>>() {
                     }.getType();
                     if (jsonObject.getAsJsonObject("policies") != null) {
-                        JsonObject policyJson = jsonObject.getAsJsonObject("policies").getAsJsonArray("items").get(0)
+                        if(jsonObject.getAsJsonObject("policies").getAsJsonArray("items").size() == 0) {
+                            log.error("No policy in policy drool pdp engine, nothing to update.");
+                        } else {
+                            JsonObject policyJson = jsonObject.getAsJsonObject("policies").getAsJsonArray("items").get(0)
                                 .getAsJsonObject().getAsJsonObject("config");
-                        Map<String, Object> policy = new Gson().fromJson(policyJson, mapType);
-                        configPolicy.setConfig(policy);
-                        log.info("Config policy {}", configPolicy);
+                            Map<String, Object> policy = new Gson().fromJson(policyJson, mapType);
+                            configPolicy.setConfig(policy);
+                            log.info("Config policy {}", configPolicy);
+                        }
                     }
                 }, throwable -> log.warn("Ooops", throwable));
     }