| 5519 |
amar.kumar |
1 |
package in.shop2020.alert.handler;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.alert.AlertMapper;
|
|
|
4 |
import in.shop2020.alert.AlertService.Iface;
|
|
|
5 |
import in.shop2020.alert.AlertServiceException;
|
|
|
6 |
import in.shop2020.alert.AlertType;
|
|
|
7 |
import in.shop2020.alert.AlertedEntity;
|
|
|
8 |
import in.shop2020.alert.EntityType;
|
|
|
9 |
import in.shop2020.alert.MonitoredEntity;
|
|
|
10 |
import in.shop2020.alert.SearchFilter;
|
|
|
11 |
import in.shop2020.alert.handler.EntityHandler;
|
|
|
12 |
|
|
|
13 |
import java.util.List;
|
|
|
14 |
|
|
|
15 |
import org.apache.thrift.TException;
|
|
|
16 |
import org.slf4j.Logger;
|
|
|
17 |
import org.slf4j.LoggerFactory;
|
|
|
18 |
import org.springframework.context.ApplicationContext;
|
|
|
19 |
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
|
20 |
|
|
|
21 |
public class AlertServiceHandler implements Iface {
|
|
|
22 |
|
|
|
23 |
private static Logger logger = LoggerFactory.getLogger(AlertServiceHandler.class);
|
|
|
24 |
|
|
|
25 |
private EntityHandler entityHandler;
|
|
|
26 |
private ApplicationContext context;
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
public AlertServiceHandler() {
|
|
|
30 |
logger.info("Creating context");
|
|
|
31 |
context = new ClassPathXmlApplicationContext("context.xml");
|
|
|
32 |
entityHandler = context.getBean(EntityHandler.class);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
@Override
|
|
|
36 |
public void scheduleAlert(MonitoredEntity monitoredEntity)
|
|
|
37 |
throws AlertServiceException, TException {
|
|
|
38 |
entityHandler.scheduleAlert(monitoredEntity);
|
|
|
39 |
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
@Override
|
|
|
43 |
public void updateMonitoredObject(MonitoredEntity monitoredEntity)
|
|
|
44 |
throws AlertServiceException, TException {
|
|
|
45 |
entityHandler.updateMonitoredObject(monitoredEntity);
|
|
|
46 |
|
|
|
47 |
}
|
|
|
48 |
@Override
|
|
|
49 |
public void endMonitoringEntity(EntityType entityType, String key)
|
|
|
50 |
throws AlertServiceException, TException {
|
|
|
51 |
entityHandler.endMonitoring(entityType, key);
|
|
|
52 |
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
@Override
|
|
|
56 |
public List<MonitoredEntity> getEntities(SearchFilter searchFilter)
|
|
|
57 |
throws AlertServiceException, TException {
|
|
|
58 |
return entityHandler.getEntities(searchFilter);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
@Override
|
|
|
62 |
public List<AlertedEntity> getAlertedEntities(SearchFilter searchFilter)
|
|
|
63 |
throws AlertServiceException, TException {
|
|
|
64 |
return entityHandler.getAlertedEntities(searchFilter);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
public void registerEventType(AlertMapper alertMap)
|
|
|
69 |
throws AlertServiceException, TException {
|
|
|
70 |
entityHandler.registerEventType(alertMap);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
@Override
|
|
|
74 |
public AlertMapper getAlertMapper(EntityType entityType, int eventType)
|
|
|
75 |
throws AlertServiceException, TException {
|
|
|
76 |
return entityHandler.getAlertMapper(entityType, eventType);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
@Override
|
|
|
80 |
public void activateEntityMonitoring(EntityType entityType, String userIds)
|
|
|
81 |
throws AlertServiceException, TException {
|
|
|
82 |
entityHandler.activateEntityMonitoring(entityType, userIds);
|
|
|
83 |
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
@Override
|
|
|
87 |
public void deActivateEntityMonitoring(EntityType entityType)
|
|
|
88 |
throws AlertServiceException, TException {
|
|
|
89 |
entityHandler.deActivateEntityMonitoring(entityType);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@Override
|
|
|
93 |
public boolean isAlive() throws TException {
|
|
|
94 |
try {
|
|
|
95 |
return true;
|
|
|
96 |
} catch (Exception e) {
|
|
|
97 |
logger.error("Alert Service not running", e);
|
|
|
98 |
return false;
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
@Override
|
|
|
103 |
public void closeSession() throws TException {
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public void setDataSourceUrl(String dbHost) {
|
|
|
107 |
org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource)context.getBean("dataSource");
|
|
|
108 |
ds.setUrl(dbHost);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
public String getDataSourceUrl() {
|
|
|
112 |
org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource)context.getBean("dataSource");
|
|
|
113 |
return ds.getUrl();
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
}
|