[SLICEANALYSIS] Fix bug of SDK fetch getting hung when policy config in 51/130451/3
authorqingshuting <qingshuting1@huawei.com>
Fri, 26 Aug 2022 09:14:19 +0000 (17:14 +0800)
committerqingshuting <qingshuting1@huawei.com>
Tue, 30 Aug 2022 08:30:49 +0000 (16:30 +0800)
pdp engine is empty

Issue-ID: DCAEGEN2-3242
Signed-off-by: qingshuting <qingshuting1@huawei.com>
Change-Id: I5dbc0db9fbb23f33b4651e917b9eee0ca257d4da

components/slice-analysis-ms/ChangeLog.md
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java

index f3a6910..bae8280 100644 (file)
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 ## [1.1.4] - 2022/07/28
          - [DCAEGEN2-3120](https://jira.onap.org/browse/DCAEGEN2-3120) - Enhance sliceanalysis MS to use DCAE SDK dmaap-client lib
          - [DCAEGEN2-3157](https://jira.onap.org/browse/DCAEGEN2-3157) - CodeCoverage improvement for dcaegen2-services-slice-analysis-ms
+         - [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
 
 ## [1.1.3] - 2022/05/11
          - [DCAEGEN2-3156](https://jira.onap.org/browse/DCAEGEN2-3156) - Fix bug in fetching PM data from DES
index fbb47e3..2bdb050 100644 (file)
@@ -3,6 +3,7 @@
  *  slice-analysis-ms
  *  ================================================================================
  *   Copyright (C) 2020-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.
@@ -82,33 +83,36 @@ public class ConfigFetchFromCbs implements Runnable {
         // Create the client and use it to get the configuration
         final CbsRequest request = CbsRequests.getAll(diagnosticContext);
         return CbsClientFactory.createCbsClient(cbsClientConfiguration)
-                .flatMapMany(cbsClient -> cbsClient.updates(request, initialDelay, period)).subscribe(jsonObject -> {
-                    log.info("configuration and policy from CBS {}", jsonObject);
-                    JsonObject config = jsonObject.getAsJsonObject("config");
-                    Duration newPeriod = Duration.ofSeconds(config.get("cbsPollingInterval").getAsInt());
-                    if (!newPeriod.equals(period)) {
-                        interval = newPeriod;
-                        synchronized (this) {
-                            this.notifyAll();
-                        }
-
+            .flatMapMany(cbsClient -> cbsClient.updates(request, initialDelay, period)).subscribe(jsonObject -> {
+                log.info("configuration and policy from CBS {}", jsonObject);
+                JsonObject config = jsonObject.getAsJsonObject("config");
+                Duration newPeriod = Duration.ofSeconds(config.get("cbsPollingInterval").getAsInt());
+                if (!newPeriod.equals(period)) {
+                    interval = newPeriod;
+                    synchronized (this) {
+                        this.notifyAll();
                     }
-                    Configuration.getInstance().updateConfigurationFromJsonObject(config);
+                }
+                Configuration.getInstance().updateConfigurationFromJsonObject(config);
+
+                Type mapType = new TypeToken<Map<String, Object>>() {
+                }.getType();
 
-                    Type mapType = new TypeToken<Map<String, Object>>() {
-                    }.getType();
-                    if (jsonObject.getAsJsonObject("policies") != null) {
+                if (jsonObject.getAsJsonObject("policies") != null) {
+                    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");
+                            .getAsJsonObject().getAsJsonObject("config");
                         Map<String, Object> policy = new Gson().fromJson(policyJson, mapType);
                         configPolicy.setConfig(policy);
                         log.info("Config policy {}", configPolicy);
                     }
-                }, throwable -> log.warn("Ooops", throwable));
+                }
+            }, throwable -> log.warn("Ooops", throwable));
     }
 
 
-
     @Override
     public void run() {
         Boolean done = false;