Modify emsdriver Code
[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 import java.util.ArrayList;
18 import java.util.List;
19
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
26 public class AlarmManager  extends DriverThread{
27
28         private ConfigurationInterface configurationInterface;
29         
30         @Override
31         public void dispose() {
32                 log.debug("AlarmManager is start");
33                 //get alarm config
34                 List<EMSInfo> emsInfos = configurationInterface.getAllEMSInfo();
35                 while(isRun() && emsInfos.size() == 0){
36                         emsInfos = configurationInterface.getAllEMSInfo();
37                         if(emsInfos.size() == 0){
38                                 try {
39                                         Thread.sleep(1000);
40                                         log.debug("config is not load");
41                                 } catch (InterruptedException e) {
42                                 }
43                         }
44                 }
45                 List<CollectVo> collectVos = new ArrayList<CollectVo>();
46                 for(EMSInfo emsInfo : emsInfos){
47                         //alarm
48                         CollectVo CollectVo = emsInfo.getCollectVoByType(Constant.COLLECT_TYPE_ALARM);
49                         if(CollectVo != null){
50                                 CollectVo.setEmsName(emsInfo.getName());
51                                 collectVos.add(CollectVo);
52                         }else{
53                                 log.error("emsInfo.getCollectVoByType(EMS_RESOUCE) result CollectVo = null emsInfo ="+emsInfo);
54                         }
55                 }
56                 
57                 for(CollectVo collectVo : collectVos){
58                         AlarmTaskThread alarm = new AlarmTaskThread(collectVo);
59                         alarm.setName(collectVo.getIP()+collectVo.getPort());
60                         alarm.start();
61                         log.info("AlarmTaskThread is start");
62                 }
63                 
64         }
65
66         /**
67          * @return the configurationInterface
68          */
69         public ConfigurationInterface getConfigurationInterface() {
70                 return configurationInterface;
71         }
72
73         /**
74          * @param configurationInterface the configurationInterface to set
75          */
76         public void setConfigurationInterface(
77                         ConfigurationInterface configurationInterface) {
78                 this.configurationInterface = configurationInterface;
79         }
80         
81         
82
83 }