Code Smells in emsdriver conf
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / vfc / nfvo / emsdriver / collector / alarm / AlarmManager.java
1 /*
2  * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.vfc.nfvo.emsdriver.collector.alarm;
17
18 import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
19 import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
20 import org.onap.vfc.nfvo.emsdriver.commons.model.EMSInfo;
21 import org.onap.vfc.nfvo.emsdriver.commons.utils.DriverThread;
22 import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface;
23 import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationManager;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 public class AlarmManager extends DriverThread {
29
30     private ConfigurationInterface configurationInterface;
31
32     @Override
33     public void dispose() {
34         log.debug("AlarmManager is start");
35         //get alarm CONFIG_PROPERTIES_LOCATION
36         List<EMSInfo> emsInfos = configurationInterface.getAllEMSInfo();
37         while (isRun() && emsInfos.isEmpty()) {
38             emsInfos = configurationInterface.getAllEMSInfo();
39             if (emsInfos.isEmpty()) {
40                 try {
41                     Thread.sleep(1000);
42                     log.debug("The configuration properties from " + ConfigurationManager.CONFIG_PROPERTIES_LOCATION + " is not load");
43                 } catch (Exception e) {
44                         log.error("Exception",e);
45                 }
46             }
47         }
48         List<CollectVo> collectVos = new ArrayList<>();
49         for (EMSInfo emsInfo : emsInfos) {
50             //alarm
51             CollectVo collectVo = emsInfo.getCollectVoByType(Constant.COLLECT_TYPE_ALARM);
52             if (collectVo != null) {
53                 collectVo.setEmsName(emsInfo.getName());
54                 collectVos.add(collectVo);
55             } else {
56                 log.error("emsInfo.getCollectVoByType(EMS_RESOUCE) result CollectVo = null emsInfo =" + emsInfo);
57             }
58         }
59
60         for (CollectVo collectVo : collectVos) {
61             AlarmTaskThread alarm = new AlarmTaskThread(collectVo);
62             alarm.setName(collectVo.getIP() + collectVo.getPort());
63             alarm.start();
64             log.info("AlarmTaskThread is start");
65         }
66
67     }
68
69     /**
70      * @return the configurationInterface
71      */
72     public ConfigurationInterface getConfigurationInterface() {
73         return configurationInterface;
74     }
75
76     /**
77      * @param configurationInterface the configurationInterface to set
78      */
79     public void setConfigurationInterface(
80             ConfigurationInterface configurationInterface) {
81         this.configurationInterface = configurationInterface;
82     }
83
84
85 }