Removing unused imports
[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.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
21 import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
22 import org.onap.vfc.nfvo.emsdriver.commons.model.EMSInfo;
23 import org.onap.vfc.nfvo.emsdriver.commons.utils.DriverThread;
24 import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface;
25 import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationManager;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 public class AlarmManager extends DriverThread {
31         protected static final Logger logger = LoggerFactory.getLogger(AlarmManager.class);
32         private ConfigurationInterface configurationInterface;
33
34         @Override
35         public void dispose() {
36                 logger.debug("AlarmManager is start");
37                 // get alarm CONFIG_PROPERTIES_LOCATION
38                 List<EMSInfo> emsInfos = configurationInterface.getAllEMSInfo();
39                 while (isRun() && emsInfos.isEmpty()) {
40                         emsInfos = configurationInterface.getAllEMSInfo();
41                         if (emsInfos.isEmpty()) {
42                                 try {
43                                         Thread.sleep(1000);
44                                         logger.debug("The configuration properties from "
45                                                         + ConfigurationManager.CONFIG_PROPERTIES_LOCATION
46                                                         + " is not load");
47                                 } catch (Exception e) {
48                                         logger.error("Exception", e);
49                                 }
50                         }
51                 }
52                 List<CollectVo> collectVos = new ArrayList<>();
53                 for (EMSInfo emsInfo : emsInfos) {
54                         // alarm
55                         CollectVo collectVo = emsInfo.getCollectVoByType(Constant.COLLECT_TYPE_ALARM);
56                         if (collectVo != null) {
57                                 collectVo.setEmsName(emsInfo.getName());
58                                 collectVos.add(collectVo);
59                         } else {
60                                 logger.error("emsInfo.getCollectVoByType(EMS_RESOUCE) result CollectVo = null emsInfo ="
61                                                 + emsInfo);
62                         }
63                 }
64
65                 for (CollectVo collectVo : collectVos) {
66                         AlarmTaskThread alarm = new AlarmTaskThread(collectVo);
67                         alarm.setName(collectVo.getIP() + collectVo.getPort());
68                         alarm.start();
69                         logger.info("AlarmTaskThread is start");
70                 }
71
72         }
73
74         /**
75          * @return the configurationInterface
76          */
77         public ConfigurationInterface getConfigurationInterface() {
78                 return configurationInterface;
79         }
80
81         /**
82          * @param configurationInterface  the configurationInterface to set
83          */
84         public void setConfigurationInterface(
85                         ConfigurationInterface configurationInterface) {
86                 this.configurationInterface = configurationInterface;
87         }
88
89 }