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