ad2bb038f5793bb3e2ec6d9c104d741e6a7949d0
[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                         this.addCollectJob(collectVos);
65                         log.info("addCollectJob is OK ");
66                 }else{
67                         log.error("configurationInterface = null,check spring.xml");
68                 }
69         }
70         
71         private void addCollectJob(List<CollectVo> collectVos) {
72                 for(CollectVo collectVo : collectVos){
73                         try {
74                                 String jobName = collectVo.getEmsName()+"_"+collectVo.getType()+collectVo.getIP();
75                                 Job job = new CollectOderJob();
76                                 String jobClass = job.getClass().getName();
77                                 String time = collectVo.getCrontab();
78                                 if(time != null && !"".equals(time)){
79                                         QuartzManager.addJob(jobName, jobClass, time,collectVo);
80                                 }else{
81                                         log.error("type =["+collectVo.getType()+"]ip=["+collectVo.getIP()+"] crontab is null,check EMSInfo.xml");
82                                 }
83                         
84                         } catch (Exception e) {
85                                 log.error("addJob is error",e);
86                         }
87                 }
88         }
89
90         /**
91          * @return the configurationInterface
92          */
93         public ConfigurationInterface getConfigurationInterface() {
94                 return configurationInterface;
95         }
96
97         /**
98          * @param configurationInterface the configurationInterface to set
99          */
100         public void setConfigurationInterface(
101                         ConfigurationInterface configurationInterface) {
102                 this.configurationInterface = configurationInterface;
103         }
104
105         
106
107 }