From ebb211290263b95f69f55f373d3f98938d22a45f Mon Sep 17 00:00:00 2001 From: qingshuting Date: Fri, 26 Aug 2022 17:14:19 +0800 Subject: [SLICEANALYSIS] Fix bug of SDK fetch getting hung when policy config in pdp engine is empty Issue-ID: DCAEGEN2-3242 Signed-off-by: qingshuting Change-Id: I5dbc0db9fbb23f33b4651e917b9eee0ca257d4da --- components/slice-analysis-ms/ChangeLog.md | 1 + .../analysis/ms/controller/ConfigFetchFromCbs.java | 38 ++++++++++++---------- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'components/slice-analysis-ms') diff --git a/components/slice-analysis-ms/ChangeLog.md b/components/slice-analysis-ms/ChangeLog.md index f3a6910b..bae8280d 100644 --- a/components/slice-analysis-ms/ChangeLog.md +++ b/components/slice-analysis-ms/ChangeLog.md @@ -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 diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java index fbb47e32..2bdb0506 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java @@ -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>() { + }.getType(); - Type mapType = new TypeToken>() { - }.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 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; -- cgit 1.2.3-korg