Modify emsdriver Code
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / vfc / nfvo / emsdriver / taskscheduler / CollectManager.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.taskscheduler;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
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.quartz.Job;
27
28
29 public class CollectManager  extends DriverThread{
30
31         private ConfigurationInterface configurationInterface;
32         public void dispose() {
33                 if(configurationInterface != null){
34                         List<EMSInfo> emsInfos = configurationInterface.getAllEMSInfo();
35                         while(isRun() && emsInfos.size() == 0){
36                                 
37                                 emsInfos = configurationInterface.getAllEMSInfo();
38                                 if(emsInfos.size() == 0){
39                                         try {
40                                                 Thread.sleep(1000);
41                                         } catch (InterruptedException e) {
42                                         }
43                                 }
44                                 
45                         }
46                         
47                         List<CollectVo> collectVos = new ArrayList<CollectVo>();
48                         for(EMSInfo emsInfo : emsInfos){
49                                 //cm
50                                 CollectVo CollectVoCm = emsInfo.getCollectVoByType(Constant.COLLECT_TYPE_CM);
51                                 if(CollectVoCm != null){
52                                         CollectVoCm.setEmsName(emsInfo.getName());
53                                         collectVos.add(CollectVoCm);
54                                 }
55                                 
56                                 //pm
57                                 CollectVo CollectVoPm = emsInfo.getCollectVoByType(Constant.COLLECT_TYPE_PM);
58                                 if(CollectVoPm != null){
59                                         CollectVoPm.setEmsName(emsInfo.getName());
60                                         collectVos.add(CollectVoPm);
61                                 }
62                                 
63                         }
64                         if(collectVos.size() > 0){
65                                 this.addCollectJob(collectVos);
66                                 log.info("1 addCollectJob is OK ");
67                         }else{
68                                 log.error("collectVos size is 0");
69                         }
70                         
71                 }else{
72                         log.error("configurationInterface = null,check spring.xml");
73                 }
74         }
75         
76         private void addCollectJob(List<CollectVo> collectVos) {
77                 for(CollectVo collectVo : collectVos){
78                         try {
79                                 String jobName = collectVo.getEmsName()+"_"+collectVo.getType()+collectVo.getIP();
80                                 Job job = new CollectOderJob();
81                                 String jobClass = job.getClass().getName();
82                                 String time = collectVo.getCrontab();
83                                 if(time != null && !"".equals(time)){
84                                         QuartzManager.addJob(jobName, jobClass, time,collectVo);
85                                 }else{
86                                         log.error("type =["+collectVo.getType()+"]ip=["+collectVo.getIP()+"] crontab is null,check EMSInfo.xml");
87                                 }
88                         
89                         } catch (Exception e) {
90                                 log.error("addJob is error",e);
91                         }
92                 }
93         }
94
95         /**
96          * @return the configurationInterface
97          */
98         public ConfigurationInterface getConfigurationInterface() {
99                 return configurationInterface;
100         }
101
102         /**
103          * @param configurationInterface the configurationInterface to set
104          */
105         public void setConfigurationInterface(
106                         ConfigurationInterface configurationInterface) {
107                 this.configurationInterface = configurationInterface;
108         }
109
110         
111
112 }