Search in sources :

Example 11 with LaserRuntimeException

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);
    }
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 12 with LaserRuntimeException

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);
    }
}
Also used : Alarm(cern.laser.business.data.Alarm) FaultState(cern.laser.source.alarmsysteminterface.FaultState) Timestamp(java.sql.Timestamp) Source(cern.laser.business.data.Source) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Example 13 with LaserRuntimeException

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);
}
Also used : Alarm(cern.laser.business.data.Alarm) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Example 14 with LaserRuntimeException

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;
}
Also used : Alarm(cern.laser.business.data.Alarm) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Example 15 with LaserRuntimeException

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);
}
Also used : Alarm(cern.laser.business.data.Alarm) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Aggregations

LaserRuntimeException (cern.laser.business.LaserRuntimeException)15 Alarm (cern.laser.business.data.Alarm)8 Iterator (java.util.Iterator)6 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)5 LaserCreateException (cern.laser.business.LaserCreateException)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 JMSException (javax.jms.JMSException)3 Topic (javax.jms.Topic)3 NamingException (javax.naming.NamingException)3 AdminUser (cern.laser.business.data.AdminUser)2 AlarmImpl (cern.laser.business.data.AlarmImpl)2 Source (cern.laser.business.data.Source)2 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)2 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)2 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)2 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)2 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)2 ObjectMessage (javax.jms.ObjectMessage)2 TextMessage (javax.jms.TextMessage)2