use of cern.laser.business.LaserRuntimeException in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method removeAlarmInternal.
private void removeAlarmInternal(String userId, AlarmDefinition alarmDefinition) throws LaserDefinitionException {
if (alarmDefinition == null) {
throw new LaserDefinitionNotValidException("alarm is null");
}
Alarm alarm = alarmDAO.getAlarm(alarmDefinition.getAlarmId());
if (alarm == null) {
throw new LaserDefinitionNotFoundException("alarm " + alarmDefinition.getAlarmId() + " does not exist");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
if (!admin_user.administersSource(alarm.getSource())) {
throw new LaserDefinitionNotAllowedException("not in source administrators");
}
try {
LOGGER.info("user " + admin_user.getName() + " removing alarm : " + alarmDefinition.getAlarmId());
alarmDAO.deleteAlarm(alarm);
LOGGER.info("alarm removed");
} catch (Exception e) {
throw new LaserRuntimeException("unable to remove alarm " + alarmDefinition.getAlarmId() + " : " + e.getMessage(), e);
}
}
use of cern.laser.business.LaserRuntimeException in project ACS by ACS-Community.
the class AlarmSourceMonitorImpl method check.
public void check() {
try {
LOGGER.debug("checking sources...");
Source[] sources = sourceDAO.findAllSources();
Source laser_source = sourceDAO.findByLaserSource();
for (int i = 0; i < sources.length; i++) {
Source source = sources[i];
if (!source.equals(laser_source)) {
if (source.isEnabled().booleanValue()) {
if (source.getStatus().getLastContact() == null) {
source.getStatus().setLastContact(new Timestamp(System.currentTimeMillis()));
}
if (((System.currentTimeMillis() - source.getStatus().getLastContact().getTime()) > source.getConnectionTimeout().longValue())) {
if (source.isConnected().booleanValue()) {
// generate surveillance alarm
Alarm surveillance_alarm = alarmCache.getCopy(source.getSurveillanceAlarmId());
FaultState surveillance_fs = AlarmSystemInterfaceFactory.createFaultState(surveillance_alarm.getTriplet().getFaultFamily(), surveillance_alarm.getTriplet().getFaultMember(), surveillance_alarm.getTriplet().getFaultCode().intValue());
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
surveillance_fs.setDescriptor(FaultState.ACTIVE);
surveillance_fs.setUserTimestamp(timestamp);
LOGGER.warn("generating surveillance alarm :\n" + surveillance_fs);
alarmMessageProcessor.processChange(surveillance_fs, surveillance_alarm.getSource().getName(), InetAddress.getLocalHost().getHostName(), timestamp);
// set not connected
source.getStatus().setConnected(Boolean.FALSE);
}
} else {
if (!source.isConnected().booleanValue()) {
// terminate surveillance alarm
Alarm surveillance_alarm = alarmCache.getCopy(source.getSurveillanceAlarmId());
FaultState surveillance_fs = AlarmSystemInterfaceFactory.createFaultState(surveillance_alarm.getTriplet().getFaultFamily(), surveillance_alarm.getTriplet().getFaultMember(), surveillance_alarm.getTriplet().getFaultCode().intValue());
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
surveillance_fs.setDescriptor(FaultState.TERMINATE);
surveillance_fs.setUserTimestamp(timestamp);
LOGGER.warn("generating surveillance alarm :\n" + surveillance_fs);
alarmMessageProcessor.processChange(surveillance_fs, surveillance_alarm.getSource().getName(), InetAddress.getLocalHost().getHostName(), timestamp);
// set connected
source.getStatus().setConnected(Boolean.TRUE);
}
}
}
}
}
LOGGER.debug("sources checked");
} catch (Exception e) {
throw new LaserRuntimeException("unable to check sources", e);
}
}
use of cern.laser.business.LaserRuntimeException in project ACS by ACS-Community.
the class CoreServiceImpl method search.
/**
* @param categoryIds
* @param sql
* @param clientId
*/
public void search(Integer[] categoryIds, String sql, String clientId) {
String destination = getSearchRootTopic() + "." + clientId;
String category_constraints = buildCategorySQLFilter(categoryIds);
String select_sql = "select alarm_id from alarm_definition where " + sql + " and alarm_id in " + "(select alarm_id from alarm_category where " + category_constraints + ")";
if (LOGGER.isDebugEnabled())
LOGGER.debug("search sql : " + select_sql);
Collection search_result = alarmDAO.search(select_sql);
if (LOGGER.isDebugEnabled())
LOGGER.debug("found " + search_result.size() + " alarms");
Collection found_alarms = new ArrayList(search_result.size());
try {
for (Iterator iter = search_result.iterator(); iter.hasNext(); ) {
Alarm alarm = alarmCache.getReference((String) iter.next());
found_alarms.add(alarm);
}
} catch (AlarmCacheException e) {
throw new LaserRuntimeException("unable to search alarms", e);
}
alarmPublisher.sendSearch(found_alarms, destination);
}
use of cern.laser.business.LaserRuntimeException in project ACS by ACS-Community.
the class CoreServiceImpl method getAlarmsByCategory.
/*
* (non-Javadoc)
*
* @see cern.laser.business.ejb.CoreServiceSessionEJB#getAlarmsByCategory(java.lang.Integer)
*/
public Collection getAlarmsByCategory(Integer categoryId) {
Collection result = null;
// Category category = categoryDAO.getCategory(categoryId);
// if (category != null) {
String[] alarms = categoryDAO.getAlarms(categoryId);
result = new ArrayList(alarms.length);
for (int i = 0; i < alarms.length; i++) {
Alarm alarm;
try {
alarm = alarmCache.getReference(alarms[i]);
} catch (AlarmCacheException e) {
LOGGER.error("unable to get alarm " + alarms[i] + " from cache", e);
throw new LaserRuntimeException("unable to get alarm " + alarms[i] + " from cache", e);
}
result.add(alarm);
}
return result;
}
use of cern.laser.business.LaserRuntimeException in project ACS by ACS-Community.
the class CoreServiceImpl method archiveSearch.
/**
* @param categoryIds
* @param sql
* @param clientId
*/
public void archiveSearch(Integer[] categoryIds, String sql, String clientId) {
String destination = getSearchRootTopic() + "." + clientId;
String category_constraints = buildCategorySQLFilter(categoryIds);
String select_sql = "select alarm_id from alarm_definition where " + sql + " and alarm_id in " + "(select alarm_id from alarm_category where " + category_constraints + ")";
if (LOGGER.isDebugEnabled())
LOGGER.debug("search sql " + select_sql);
Collection search_result = alarmDAO.archiveSearch(select_sql);
Collection found_alarms = new ArrayList(search_result.size());
try {
for (Iterator iter = search_result.iterator(); iter.hasNext(); ) {
Alarm alarm = alarmCache.getReference((String) iter.next());
found_alarms.add(alarm);
}
} catch (AlarmCacheException e) {
throw new LaserRuntimeException("unable to search alarms", e);
}
alarmPublisher.sendSearch(found_alarms, destination);
}
Aggregations