Subversion Repositories SmartDukaan

Rev

Rev 5563 | Rev 5679 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5563 Rev 5674
Line 1... Line 1...
1
package in.shop2020.alert.handler;
1
package in.shop2020.alert.handler;
2
 
2
 
3
import java.util.ArrayList;
-
 
4
import java.util.List;
-
 
5
 
-
 
6
import in.shop2020.alert.AlertMapper;
3
import in.shop2020.alert.AlertMapper;
7
import in.shop2020.alert.AlertServiceException;
4
import in.shop2020.alert.AlertServiceException;
8
import in.shop2020.alert.AlertType;
-
 
9
import in.shop2020.alert.AlertedEntity;
5
import in.shop2020.alert.AlertedEntity;
10
import in.shop2020.alert.EntityMonitoringStatus;
6
import in.shop2020.alert.EntityMonitoringStatus;
11
import in.shop2020.alert.EntityProcessedState;
7
import in.shop2020.alert.EntityProcessedState;
12
import in.shop2020.alert.EntityType;
8
import in.shop2020.alert.EntityType;
13
import in.shop2020.alert.MonitoredEntity;
9
import in.shop2020.alert.MonitoredEntity;
14
import in.shop2020.alert.SearchFilter;
10
import in.shop2020.alert.SearchFilter;
15
import in.shop2020.alert.persistence.EntityMapper;
11
import in.shop2020.alert.persistence.EntityMapper;
16
import in.shop2020.alert.util.Converter;
12
import in.shop2020.alert.util.Converter;
17
 
13
 
-
 
14
import java.util.ArrayList;
-
 
15
import java.util.List;
-
 
16
 
18
import org.apache.commons.logging.Log;
17
import org.apache.commons.logging.Log;
19
import org.apache.commons.logging.LogFactory;
18
import org.apache.commons.logging.LogFactory;
-
 
19
import org.apache.log4j.Logger;
20
import org.apache.thrift.TException;
20
import org.apache.thrift.TException;
21
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.stereotype.Service;
22
import org.springframework.stereotype.Service;
23
 
23
 
24
@Service
24
@Service
Line 26... Line 26...
26
 
26
 
27
	@Autowired
27
	@Autowired
28
	private EntityMapper entityMapper;
28
	private EntityMapper entityMapper;
29
	
29
	
30
	private static final Log log = LogFactory.getLog(EntityHandler.class);
30
	private static final Log log = LogFactory.getLog(EntityHandler.class);
-
 
31
	private static final Logger alertLogger= Logger.getLogger("AppLogging");
31
 
32
 
32
	public List<MonitoredEntity> getEntities(SearchFilter searchFilter) {
33
	public List<MonitoredEntity> getEntities(SearchFilter searchFilter) {
33
		List<in.shop2020.alert.domain.MonitoredEntity> entities = 
34
		List<in.shop2020.alert.domain.MonitoredEntity> entities = 
34
			entityMapper.getEntities(Converter.toDomainSearchFilter
35
			entityMapper.getEntities(Converter.toDomainSearchFilter
35
					(searchFilter));
36
					(searchFilter));
Line 65... Line 66...
65
			alertedEntity.setEntityProperties(entity.getEntityProperties());
66
			alertedEntity.setEntityProperties(entity.getEntityProperties());
66
			if(entity.getEntityProcessedState().getValue() == EntityProcessedState.WARNING_SENT.getValue()) {
67
			if(entity.getEntityProcessedState().getValue() == EntityProcessedState.WARNING_SENT.getValue()) {
67
				alertedEntity.setLastAlertedTime(entity.getWarnExpiryTime());
68
				alertedEntity.setLastAlertedTime(entity.getWarnExpiryTime());
68
				alertedEntity.setEntityProcessedState(EntityProcessedState.WARNING_SENT);
69
				alertedEntity.setEntityProcessedState(EntityProcessedState.WARNING_SENT);
69
				entityMapper.insertAlertedEntity(alertedEntity);
70
				entityMapper.insertAlertedEntity(alertedEntity);
-
 
71
 
-
 
72
				AlertMapper alertMap;
-
 
73
		    	String 	delayedEventDescription = "UNKNOWN";
-
 
74
	    		alertMap = getAlertMapper(entity.getEntityType(), entity.getEventType());
-
 
75
	    		if(alertMap!=null) {
-
 
76
	    			delayedEventDescription = alertMap.getEventdesciption();
-
 
77
	    		}
-
 
78
	    		alertLogger.warn(entity.getWarnExpiryTime() + "\tEntityType=" + 
-
 
79
						entity.getEntityType() + " ; "+"\tEventType=" + delayedEventDescription + " ; " +
-
 
80
						"AlertSeverity=WARN ; " + "ExpiredTime=" + entity.getWarnExpiryTime());
70
			}
81
			}
71
			else {
82
			else {
72
				alertedEntity.setLastAlertedTime(entity.getCriticalExpiryTime());
83
				alertedEntity.setLastAlertedTime(entity.getCriticalExpiryTime());
73
				alertedEntity.setEntityProcessedState(EntityProcessedState.CRITICAL_SENT);
84
				alertedEntity.setEntityProcessedState(EntityProcessedState.CRITICAL_SENT);
74
				entityMapper.insertAlertedEntity(alertedEntity);
85
				entityMapper.insertAlertedEntity(alertedEntity);
-
 
86
 
-
 
87
				AlertMapper alertMap;
-
 
88
		    	String 	delayedEventDescription = "UNKNOWN";
-
 
89
	    		alertMap = getAlertMapper(entity.getEntityType(), entity.getEventType());
-
 
90
	    		if(alertMap!=null) {
-
 
91
	    			delayedEventDescription = alertMap.getEventdesciption();
-
 
92
	    		}
-
 
93
	    		alertLogger.error(entity.getCriticalExpiryTime() + "\tEntityType=" + 
-
 
94
						entity.getEntityType() + " ; "+"\tEventType=" + delayedEventDescription + " ; " +
-
 
95
						"AlertSeverity=CRITICAL ; " + "ExpiredTime=" + entity.getCriticalExpiryTime());
75
			}
96
			}
76
		}
97
		}
77
		entityMapper.removeMonitoredEntity(entityType, key);
98
		entityMapper.removeMonitoredEntity(entityType, key);
78
	}
99
	}
79
 
100
 
80
	public void updateMonitoredObject(MonitoredEntity monitoredEntity) {
101
	public void updateMonitoredObject(MonitoredEntity monitoredEntity) 
-
 
102
		throws AlertServiceException{
81
		in.shop2020.alert.domain.MonitoredEntity entity = entityMapper.getEntity(monitoredEntity.getEntityType(), monitoredEntity.getEntityIdentifier());
103
		in.shop2020.alert.domain.MonitoredEntity entity = entityMapper.getEntity(monitoredEntity.getEntityType(), 
-
 
104
				monitoredEntity.getEntityIdentifier());
-
 
105
		if(entity!=null) {
82
		if(entity.getEntityProcessedState().getValue() > EntityProcessedState.UNEXPIRED.getValue()) {
106
			if(entity.getEntityProcessedState().getValue() > EntityProcessedState.UNEXPIRED.getValue()) {
83
			in.shop2020.alert.domain.AlertedEntity alertedEntity = new in.shop2020.alert.domain.AlertedEntity();
107
				in.shop2020.alert.domain.AlertedEntity alertedEntity = new in.shop2020.alert.domain.AlertedEntity();
84
			alertedEntity.setEntityType(entity.getEntityType());
108
				alertedEntity.setEntityType(entity.getEntityType());
85
			alertedEntity.setEventType(entity.getEventType());
109
				alertedEntity.setEventType(entity.getEventType());
86
			alertedEntity.setEntityIdentifier(entity.getEntityIdentifier());
110
				alertedEntity.setEntityIdentifier(entity.getEntityIdentifier());
87
			alertedEntity.setEntityProperties(entity.getEntityProperties());
111
				alertedEntity.setEntityProperties(entity.getEntityProperties());
88
			if(entity.getEntityProcessedState().getValue() == EntityProcessedState.WARNING_SENT.getValue()) {
112
				if(entity.getEntityProcessedState().getValue() == EntityProcessedState.WARNING_SENT.getValue()) {
89
				alertedEntity.setLastAlertedTime(entity.getWarnExpiryTime());
113
					alertedEntity.setLastAlertedTime(entity.getWarnExpiryTime());
90
				alertedEntity.setEntityProcessedState(EntityProcessedState.WARNING_SENT);
114
					alertedEntity.setEntityProcessedState(EntityProcessedState.WARNING_SENT);
91
				entityMapper.insertAlertedEntity(alertedEntity);
115
					entityMapper.insertAlertedEntity(alertedEntity);
-
 
116
	
-
 
117
					AlertMapper alertMap;
-
 
118
			    	String 	delayedEventDescription = "UNKNOWN";
-
 
119
		    		alertMap = getAlertMapper(entity.getEntityType(), entity.getEventType());
-
 
120
		    		if(alertMap!=null) {
-
 
121
		    			delayedEventDescription = alertMap.getEventdesciption();
-
 
122
		    		}
-
 
123
		    		alertLogger.warn(entity.getWarnExpiryTime() + "\tEntityType=" + 
-
 
124
							entity.getEntityType() + " ; "+"\tEventType=" + delayedEventDescription + " ; " +
-
 
125
							"AlertSeverity=WARN ; " + "ExpiredTime=" + entity.getWarnExpiryTime());
92
			}
126
				}
93
			else {
127
				else {
94
				alertedEntity.setLastAlertedTime(entity.getCriticalExpiryTime());
128
					alertedEntity.setLastAlertedTime(entity.getCriticalExpiryTime());
95
				alertedEntity.setEntityProcessedState(EntityProcessedState.CRITICAL_SENT);
129
					alertedEntity.setEntityProcessedState(EntityProcessedState.CRITICAL_SENT);
96
				entityMapper.insertAlertedEntity(alertedEntity);
130
					entityMapper.insertAlertedEntity(alertedEntity);
-
 
131
					
-
 
132
					AlertMapper alertMap;
-
 
133
			    	String 	delayedEventDescription = "UNKNOWN";
-
 
134
		    		alertMap = getAlertMapper(entity.getEntityType(), entity.getEventType());
-
 
135
		    		if(alertMap!=null) {
-
 
136
		    			delayedEventDescription = alertMap.getEventdesciption();
-
 
137
		    		}
-
 
138
		    		alertLogger.error(entity.getCriticalExpiryTime() + "\tEntityType=" + 
-
 
139
							entity.getEntityType() + " ; "+"\tEventType=" + delayedEventDescription + " ; " +
-
 
140
							"AlertSeverity=CRITICAL ; " + "ExpiredTime=" + entity.getCriticalExpiryTime());
-
 
141
				}
97
			}
142
			}
-
 
143
				monitoredEntity.setId(entity.getId());
-
 
144
				entityMapper.updateEntity(Converter.toDbEntity(monitoredEntity));
-
 
145
		} else {
-
 
146
			scheduleAlert(monitoredEntity);
98
		}
147
		}
99
			monitoredEntity.setId(entity.getId());
-
 
100
			entityMapper.updateEntity(Converter.toDbEntity(monitoredEntity));
-
 
101
	}
148
	}
102
 
149
 
103
	public void scheduleAlert(MonitoredEntity monitoredEntity) 
150
	public void scheduleAlert(MonitoredEntity monitoredEntity) 
104
		throws AlertServiceException {
151
		throws AlertServiceException {
105
		if(isEntityMonitorable(monitoredEntity.getEntityType())) {
152
		if(isEntityMonitorable(monitoredEntity.getEntityType())) {
Line 122... Line 169...
122
				tEntitiesTobeAlerted.add(Converter.toThriftMonitoredEntity(entity));
169
				tEntitiesTobeAlerted.add(Converter.toThriftMonitoredEntity(entity));
123
			}
170
			}
124
			return tEntitiesTobeAlerted;
171
			return tEntitiesTobeAlerted;
125
		}
172
		}
126
		return null;
173
		return null;
-
 
174
	}
-
 
175
	
-
 
176
	public List<MonitoredEntity> getActiveAlertEntities() {
-
 
177
		List<in.shop2020.alert.domain.MonitoredEntity> activeAlertEntities = 
-
 
178
			entityMapper.getActiveAlertEntities();
-
 
179
		if(activeAlertEntities != null) {
-
 
180
			List<MonitoredEntity> tEntitiesTobeAlerted = new ArrayList<MonitoredEntity>();
-
 
181
			for(in.shop2020.alert.domain.MonitoredEntity entity : activeAlertEntities) {
-
 
182
				tEntitiesTobeAlerted.add(Converter.toThriftMonitoredEntity(entity));
-
 
183
			}
-
 
184
			return tEntitiesTobeAlerted;
-
 
185
		}
-
 
186
		return null;
127
	}
187
	}
128
 
188
 
129
	public void updateEntityProcessedState(long id, EntityProcessedState state) {
189
	public void updateEntityProcessedState(long id, EntityProcessedState state) {
130
		entityMapper.updateEntityProcessedState(id, state);
190
		entityMapper.updateEntityProcessedState(id, state);
131
	}
191
	}