Merge "Add ml-prediction-ms with basic build infrastruct."
[dcaegen2/services.git] / components / slice-analysis-ms / src / main / java / org / onap / slice / analysis / ms / service / ConfigThread.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *   Copyright (C) 2022 Huawei Technologies Co., Ltd.
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  *******************************************************************************/
21
22 package org.onap.slice.analysis.ms.service;
23
24 import org.onap.slice.analysis.ms.models.ConfigPolicy;
25 import org.onap.slice.analysis.ms.service.ccvpn.CCVPNPmDatastore;
26 import org.onap.slice.analysis.ms.utils.BeanUtil;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * This thread is used to convert ccvpn runtime configurations from policy to our local memory CCVPNPmDatastore
32  */
33 public class ConfigThread extends Thread{
34
35     CCVPNPmDatastore ccvpnPmDatastore = BeanUtil.getBean(CCVPNPmDatastore.class);
36     private static Logger log = LoggerFactory.getLogger(ConfigThread.class);
37
38     public ConfigThread () {
39         super();
40     }
41
42     public void run() {
43         log.info("Config Thread is starting...");
44         boolean done = false;
45         while(!done) {
46             try {
47                 Thread.sleep(1000);
48                 ConfigPolicy configPolicy = ConfigPolicy.getInstance();
49                 if(configPolicy != null && configPolicy.getConfig() != null) {
50                     String cllId = null;
51                     Boolean clBwAssuranceStatus = null;
52                     int originalBw = 0;
53                     if(configPolicy.getConfig().containsKey("cllId")){
54                         cllId = String.valueOf(configPolicy.getConfig().get("cllId"));
55                     }
56                     if(configPolicy.getConfig().containsKey("closedLoopStatus")){
57                         clBwAssuranceStatus = String.valueOf(configPolicy.getConfig().get("closedLoopStatus")).equalsIgnoreCase("true");
58                     }
59                     if(configPolicy.getConfig().containsKey("originalBw")){
60                         originalBw = Integer.parseInt(String.valueOf(configPolicy.getConfig().get("originalBw")));
61                     }
62                     if(cllId!=null && clBwAssuranceStatus!=null){
63                         ccvpnPmDatastore.updateConfigFromPolicy(cllId, clBwAssuranceStatus, originalBw);
64                     }
65                 } else {
66                     log.error("Config policy is empty, nothing to update.");
67                 }
68
69             } catch (Exception e) {
70                 log.error("Exception in Config Thread ", e);
71                 done = true;
72             }
73         }
74     }
75 }