[SLICEANALYSIS] Fix bug of SDK fetch getting hung when policy config in 68/130968/4 jakarta
authorqingshuting <qingshuting1@huawei.com>
Fri, 16 Sep 2022 03:46:41 +0000 (11:46 +0800)
committerqingshuting <qingshuting1@huawei.com>
Wed, 21 Sep 2022 01:46:59 +0000 (09:46 +0800)
pdp engine is empty

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

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

index 5521e8f..bdce865 100644 (file)
@@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
-
 ## [1.1.3] - 2022/05/11
          - [DCAEGEN2-3156](https://jira.onap.org/browse/DCAEGEN2-3156) - Fix bug in fetching PM data from DES
 
+         - [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.2] - 2022/05/01
 
          - [DCAEGEN2-3145](https://jira.onap.org/browse/DCAEGEN2-3145) - Filter RAN related service instances in AAI
index 57a831e..b80ac79 100644 (file)
@@ -1,22 +1,23 @@
 /*******************************************************************************
  *  ============LICENSE_START=======================================================
- *  son-handler
+ *  slice-analysis-ms
  *  ================================================================================
  *   Copyright (C) 2019-2020 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.
  *     You may obtain a copy of the License at
- *  
- *          http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
  *     Unless required by applicable law or agreed to in writing, software
  *     distributed under the License is distributed on an "AS IS" BASIS,
  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *     See the License for the specific language governing permissions and
  *     limitations under the License.
  *     ============LICENSE_END=========================================================
- *  
+ *
  *******************************************************************************/
 
 package org.onap.slice.analysis.ms;
@@ -26,26 +27,26 @@ import org.onap.slice.analysis.ms.service.PmThread;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** 
+/**
  * This class starts the pm thread and consumer thread
  */
 public class MainThread {
 
-       private static Logger log = LoggerFactory.getLogger(MainThread.class);
-       
-       private MainThread() {
-               
-       }
-       
-       /**
-        * main thread initialization.
-        */
-       public static void initiateThreads() {
-               log.debug("initializing Pm thread & Consumer thread");
-               Thread pmThread = new Thread(new PmThread());
-               pmThread.start();
-               Thread consumerThread = new Thread(new ConsumerThread());
-               consumerThread.start();
-       }
+    private static Logger log = LoggerFactory.getLogger(MainThread.class);
+
+    private MainThread() {
+
+    }
+
+    /**
+     * main thread initialization.
+    */
+    public static void initiateThreads() {
+        log.debug("initializing Pm thread & Consumer thread");
+        Thread pmThread = new Thread(new PmThread());
+        pmThread.start();
+        Thread consumerThread = new Thread(new ConsumerThread());
+        consumerThread.start();
+    }
 
 }
index fbb47e3..ea93424 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.
@@ -33,7 +34,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFact
 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests;
 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest;
 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext;
 import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
 import org.onap.slice.analysis.ms.models.ConfigPolicy;
 import org.onap.slice.analysis.ms.models.Configuration;
@@ -97,12 +97,17 @@ 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));
     }