Search in sources :

Example 1 with Alarm

use of cern.laser.business.data.Alarm in project ACS by ACS-Community.

the class AlarmMessageProcessorImpl method processBackup.

private void processBackup(ASIMessage asiMessage) throws Exception {
    String source_name = asiMessage.getSourceName();
    String source_hostname = asiMessage.getSourceHostname();
    String source_timestamp = asiMessage.getSourceTimestamp();
    logger.log(AcsLogLevel.DEBUG, "processing backup from " + source_name + "@" + source_hostname + " [" + source_timestamp + "]");
    Source source = sourceDAO.findSource(source_name);
    logger.log(AcsLogLevel.DEBUG, "getting active alarms...");
    String[] source_alarm_ids = sourceDAO.getAlarms(source.getSourceId());
    Collection active_alarms = new ArrayList(source_alarm_ids.length);
    for (int i = 0; i < source_alarm_ids.length; i++) {
        Alarm alarm = alarmCache.getReference(source_alarm_ids[i]);
        if (alarm.getStatus().getActive().booleanValue() && (!alarm.getInstant().booleanValue())) {
            active_alarms.add(alarm);
        }
    }
    logger.log(AcsLogLevel.DEBUG, "checking backup...");
    // check if backup alarms match active alarms for the same source
    Set active_identifiers = new HashSet();
    Iterator active_alarms_iterator = active_alarms.iterator();
    while (active_alarms_iterator.hasNext()) {
        active_identifiers.add(((Alarm) active_alarms_iterator.next()).getAlarmId());
    }
    Collection<FaultState> backup_fault_states = ASIMessageHelper.unmarshal(asiMessage);
    logger.log(AcsLogLevel.DEBUG, "processing " + backup_fault_states.size() + " backup alarms");
    Set<String> backup_identifiers = new HashSet<String>();
    for (FaultState fault_state : backup_fault_states) {
        // Before notify the statistics that a alarm is going to be processed
        String alarmID = Triplet.toIdentifier(fault_state.getFamily(), fault_state.getMember(), Integer.valueOf(fault_state.getCode()));
        statisticsEngine.processedFS(alarmID, fault_state.getDescriptor().equals(FaultState.ACTIVE));
        backup_identifiers.add(alarmID);
    }
    logger.log(AcsLogLevel.DEBUG, asiMessage.getSourceName() + " : " + active_identifiers.size() + " active alarms found, received " + backup_identifiers.size());
    if ((backup_identifiers.containsAll(active_identifiers)) && (active_identifiers.containsAll(backup_identifiers))) {
        logger.log(AcsLogLevel.DEBUG, "backup matches active alarms");
    } else {
        logger.log(AcsLogLevel.WARNING, "backup mismatch");
        logger.log(AcsLogLevel.DEBUG, "alarms found :\n" + active_identifiers);
        logger.log(AcsLogLevel.DEBUG, "alarms received :\n" + backup_identifiers);
        Iterator backup_identifiers_iterator = backup_identifiers.iterator();
        while (backup_identifiers_iterator.hasNext()) {
            if (active_identifiers.remove(backup_identifiers_iterator.next())) {
                backup_identifiers_iterator.remove();
            }
        }
        if (!backup_identifiers.isEmpty()) {
            logger.log(AcsLogLevel.WARNING, backup_identifiers.size() + " backup alarms are not active");
            logger.log(AcsLogLevel.DEBUG, "active by backup :\n" + backup_identifiers);
            for (FaultState fault_state : backup_fault_states) {
                if (backup_identifiers.contains(Triplet.toIdentifier(fault_state.getFamily(), fault_state.getMember(), new Integer(fault_state.getCode())))) {
                    fault_state.setDescriptor(FaultState.ACTIVE);
                    fault_state.setActivatedByBackup(true);
                    try {
                        Timestamp timestamp = new Timestamp(IsoDateFormat.parseIsoTimestamp(source_timestamp).getTime());
                        processChange(fault_state, source_name, source_hostname, timestamp);
                    } catch (Exception e) {
                        logger.log(AcsLogLevel.ERROR, "unable to activate alarm by backup", e);
                    }
                }
            }
        }
        if (!active_identifiers.isEmpty()) {
            logger.log(AcsLogLevel.WARNING, active_identifiers.size() + " active alarms are not in backup");
            logger.log(AcsLogLevel.DEBUG, "terminate by backup :\n" + active_identifiers);
            active_alarms_iterator = active_alarms.iterator();
            while (active_alarms_iterator.hasNext()) {
                Alarm alarm = (Alarm) active_alarms_iterator.next();
                if (active_identifiers.contains(alarm.getAlarmId())) {
                    FaultState fault_state = AlarmSystemInterfaceFactory.createFaultState(alarm.getTriplet().getFaultFamily(), alarm.getTriplet().getFaultMember(), alarm.getTriplet().getFaultCode().intValue());
                    fault_state.setUserTimestamp(new Timestamp(System.currentTimeMillis()));
                    fault_state.setUserProperties(alarm.getStatus().getProperties());
                    fault_state.setDescriptor(FaultState.TERMINATE);
                    fault_state.setTerminatedByBackup(true);
                    try {
                        Timestamp timestamp = new Timestamp(IsoDateFormat.parseIsoTimestamp(source_timestamp).getTime());
                        processChange(fault_state, source_name, source_hostname, timestamp);
                    } catch (Exception e) {
                        logger.log(AcsLogLevel.ERROR, "unable to terminate alarm by backup", e);
                    }
                }
            }
        }
    }
    source.getStatus().setLastContact(new Timestamp(System.currentTimeMillis()));
    sourceDAO.updateSource(source);
    logger.log(AcsLogLevel.DEBUG, "backup processed");
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) FaultState(cern.laser.source.alarmsysteminterface.FaultState) Timestamp(java.sql.Timestamp) Source(cern.laser.business.data.Source) ParseException(java.text.ParseException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 2 with Alarm

use of cern.laser.business.data.Alarm in project ACS by ACS-Community.

the class CategoryDefinitionServiceImpl method createCategoryLink.

public void createCategoryLink(String userId, CategoryLink link) throws LaserDefinitionException {
    if (link == null) {
        throw new LaserDefinitionNotValidException("category/alarm link is null");
    }
    if (link.getCategory() == null) {
        throw new LaserDefinitionNotValidException("malformed category/alarm link: category is null");
    }
    if (link.getAlarm() == null) {
        throw new LaserDefinitionNotValidException("malformed category/alarm link: alarm is null");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    Category category = categoryDAO.getCategoryByPath(link.getCategory().getPath());
    if (category == null) {
        throw new LaserDefinitionNotFoundException("category with path " + link.getCategory().getPath() + " does not exists");
    }
    if (!admin_user.administersCategory(category.getCategoryId())) {
        throw new LaserDefinitionNotAllowedException("not an administrators for the category : " + link.getCategory());
    }
    Alarm alarm = alarmDAO.getAlarm(link.getAlarm().getAlarmId());
    if (alarm == null) {
        throw new LaserDefinitionNotFoundException("alarm with id " + link.getAlarm().getAlarmId() + " does not exist");
    }
    Alarm surveillance_alarm = alarmDAO.findAlarm(alarm.getSource().getSurveillanceAlarmId());
    if (category.containsAlarm(alarm)) {
        throw new LaserDefinitionDuplicationException("alarm/category link already defined : " + link);
    }
    LOGGER.info("user " + admin_user.getName() + " creating alarm/category link : " + link);
    category.addAlarm(alarm);
    category.addAlarm(surveillance_alarm);
    categoryDAO.updateCategory(category);
    try {
        alarmCache.invalidate(alarm.getAlarmId());
        alarmCache.invalidate(surveillance_alarm.getAlarmId());
    } catch (AlarmCacheException e) {
        LOGGER.error("unable to propagate category link : " + link, e);
    }
    LOGGER.info("link created");
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 3 with Alarm

use of cern.laser.business.data.Alarm in project ACS by ACS-Community.

the class AlarmDefinitionServiceImpl method removeAlarm.

public void removeAlarm(String userId, AlarmDefinition alarm) throws LaserDefinitionException {
    removeAlarmInternal(userId, alarm);
    Alarm alarm_obj = null;
    try {
        alarm_obj = alarmCache.getCopy(alarm.getAlarmId());
        invalidateAlarm(alarm_obj);
        propagateRemovedAlarm(alarm_obj);
    } catch (Exception e) {
        LOGGER.warn("unable to handle removed alarm " + alarm_obj.getTriplet() + " : " + e.getMessage());
    }
}
Also used : Alarm(cern.laser.business.data.Alarm) 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)

Example 4 with Alarm

use of cern.laser.business.data.Alarm in project ACS by ACS-Community.

the class AlarmCacheServerImpl method notify.

public void notify(Collection alarmChanges) {
    try {
        Iterator iterator = alarmChanges.iterator();
        while (iterator.hasNext()) {
            AlarmChange alarm_change = (AlarmChange) iterator.next();
            Alarm current_alarm = alarm_change.getCurrent();
            if (!current_alarm.getStatus().getActive().equals(alarm_change.getPrevious().getStatus().getActive())) {
                if (current_alarm.getPiquetGSM() != null) {
                    sendSMS(current_alarm);
                }
                if (current_alarm.getPiquetEmail() != null) {
                    sendEmail(current_alarm);
                }
            }
        }
    } catch (Exception e) {
        throw new LaserRuntimeException("unable to notify alarm(s)", e);
    }
}
Also used : AlarmChange(cern.laser.business.data.AlarmChange) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Example 5 with Alarm

use of cern.laser.business.data.Alarm in project ACS by ACS-Community.

the class AlarmDefinitionServiceImpl method createAlarmInternal.

//
// -- PRIVATE METHODS ----------------------------------------------
//
private Alarm createAlarmInternal(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 LaserDefinitionDuplicationException("alarm " + alarmDefinition.getAlarmId() + " does already exist");
    }
    if (alarmDefinition.getSourceName() == null) {
        throw new LaserDefinitionNotValidException("source name for the alarm definition is null");
    }
    Source source = sourceDAO.getSource(alarmDefinition.getSourceName());
    if (source == null) {
        throw new LaserDefinitionNotFoundException("source " + alarmDefinition.getSourceName() + " does not exist");
    }
    if (alarmDefinition.getResponsiblePersonId() == null) {
        throw new LaserDefinitionNotValidException("responsible id for the alarm definition is null");
    }
    ResponsiblePerson responsible = responsiblePersonDAO.getResponsiblePerson(alarmDefinition.getResponsiblePersonId());
    if (responsible == null) {
        throw new LaserDefinitionNotFoundException("responsible with id " + alarmDefinition.getResponsiblePersonId() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    if (!admin_user.administersSource(source)) {
        throw new LaserDefinitionNotAllowedException("not an administrator for the alarm : " + alarmDefinition);
    }
    LOGGER.info("user " + admin_user.getName() + " creating alarm : " + alarmDefinition);
    alarm = new AlarmImpl(alarmDefinition, source, responsible);
    String building_number = alarmDefinition.getBuilding();
    if (building_number != null && !building_number.equals("")) {
        Building building = alarmDAO.findBuilding(building_number);
        alarm.getLocation().setBuilding(building);
    }
    return alarm;
}
Also used : Building(cern.laser.business.data.Building) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) Source(cern.laser.business.data.Source) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Aggregations

Alarm (cern.laser.business.data.Alarm)91 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)24 LaserRuntimeException (cern.laser.business.LaserRuntimeException)21 ArrayList (java.util.ArrayList)21 Category (cern.laser.business.data.Category)16 Collection (java.util.Collection)14 AlarmImpl (cern.laser.business.data.AlarmImpl)13 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)12 AdminUser (cern.laser.business.data.AdminUser)11 AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)10 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)10 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)10 Iterator (java.util.Iterator)10 LaserProcessingException (cern.laser.business.LaserProcessingException)9 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)9 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)7 ReductionRule (cl.utfsm.acs.acg.core.ReductionRule)7 FaultCode (alma.acs.alarmsystem.generated.FaultCode)6 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)6 FaultMember (alma.acs.alarmsystem.generated.FaultMember)6