Search in sources :

Example 1 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState 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 FaultState

use of cern.laser.source.alarmsysteminterface.FaultState in project ACS by ACS-Community.

the class AlarmMessageProcessorImpl method processChanges.

private void processChanges(ASIMessage asiMessage) {
    String source_name = asiMessage.getSourceName();
    String source_hostname = asiMessage.getSourceHostname();
    String source_timestamp = asiMessage.getSourceTimestamp();
    logger.log(AcsLogLevel.DEBUG, "processing changes from " + source_name + "@" + source_hostname + " [" + source_timestamp + "]");
    Collection<FaultState> change_fault_states = ASIMessageHelper.unmarshal(asiMessage);
    logger.log(AcsLogLevel.DEBUG, "processing " + change_fault_states.size() + " changes");
    for (FaultState fault_state : change_fault_states) {
        try {
            // 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));
            Timestamp timestamp = new Timestamp(IsoDateFormat.parseIsoTimestamp(source_timestamp).getTime());
            processChange(fault_state, source_name, source_hostname, timestamp);
        } catch (Throwable t) {
            logger.log(AcsLogLevel.ERROR, "exception caught processing fault state : \n" + fault_state, t);
        }
    }
    logger.log(AcsLogLevel.DEBUG, "changes processed");
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) Timestamp(java.sql.Timestamp)

Example 3 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState in project ACS by ACS-Community.

the class SendTest method receive.

/**
	 * The method receives all the messages published in the NC
	 * For each message received it checks if its content is right
	 * i.e. the name of the class, the member and the code contains the 
	 * number of the message in the sequence. In this way it also checks
	 * if the messages are received in the same order they were sent.
	 * The method also checks if all the messages have been received
	 * and prints a message if receives more messages then the messages 
	 * pushed
	 *  
	 * @param msg The message received from the NC
	 * @see alma.acs.nc.Consumer
	 */
@Override
public synchronized void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    Collection<FaultState> faultStates;
    try {
        ASIMessage asiMsg = XMLMessageHelper.unmarshal(msg.text);
        faultStates = ASIMessageHelper.unmarshal(asiMsg);
    } catch (Exception e) {
        System.out.println("Exception caught while unmarshalling the msg " + e.getMessage());
        e.printStackTrace();
        receiverError = e;
        return;
    }
    Iterator<FaultState> iter = faultStates.iterator();
    while (iter.hasNext()) {
        FaultStateImpl fs = (FaultStateImpl) iter.next();
        if (!isValidFSMessage(fs, nMsgReceived)) {
            receiverError = "Invalid FaultState received as #" + nMsgReceived;
        }
        nMsgReceived++;
        if (nMsgReceived == ITERATIONS) {
            System.out.println("All alarms sent and received");
        } else if (nMsgReceived > ITERATIONS) {
            System.out.println("Received an alarm that has never been sent");
        }
    }
}
Also used : ACSFaultState(alma.alarmsystem.source.ACSFaultState) FaultState(cern.laser.source.alarmsysteminterface.FaultState) FaultStateImpl(cern.laser.source.alarmsysteminterface.impl.FaultStateImpl) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 4 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState in project ACS by ACS-Community.

the class SourceStressTest method receive.

@Override
public synchronized void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    ASIMessage asiMsg = null;
    try {
        asiMsg = XMLMessageHelper.unmarshal(msg.text);
    } catch (Exception e) {
        System.out.println("Exception caught while unmarshalling the msg " + e.getMessage());
        e.printStackTrace();
        //			receiverError = e; // SendTest works with checking these errors in the test..
        return;
    }
    Collection<FaultState> faultStates = ASIMessageHelper.unmarshal(asiMsg);
    assertNotNull(faultStates);
    for (FaultState fs : faultStates) {
        assertNotNull(fs);
        receivedFS.add(new FaultStateReceived(fs));
    }
}
Also used : ACSFaultState(alma.alarmsystem.source.ACSFaultState) FaultState(cern.laser.source.alarmsysteminterface.FaultState) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 5 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState in project ACS by ACS-Community.

the class ASIMessageHelper method unmarshal.

/**
	 * DOCUMENT ME!
	 * 
	 * @param asiMessage
	 *            DOCUMENT ME!
	 * 
	 * @return DOCUMENT ME!
	 */
public static Collection<FaultState> unmarshal(ASIMessage asiMessage) {
    if (asiMessage == null) {
        throw (new IllegalArgumentException("ASI message is null"));
    }
    Collection<FaultState> ret = new ArrayList<FaultState>();
    FaultStates generated_states = asiMessage.getFaultStates();
    if (generated_states != null) {
        for (cern.laser.source.alarmsysteminterface.impl.message.FaultState generated_state : generated_states.getFaultState()) {
            ret.add(FaultStateHelper.unmarshal(generated_state));
        }
    }
    return ret;
}
Also used : FaultStates(cern.laser.source.alarmsysteminterface.impl.message.FaultStates) ArrayList(java.util.ArrayList) FaultState(cern.laser.source.alarmsysteminterface.FaultState)

Aggregations

FaultState (cern.laser.source.alarmsysteminterface.FaultState)16 ASIMessage (cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)9 Timestamp (java.sql.Timestamp)6 ACSFaultState (alma.alarmsystem.source.ACSFaultState)3 FaultStateImpl (cern.laser.source.alarmsysteminterface.impl.FaultStateImpl)3 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Alarm (cern.laser.business.data.Alarm)2 Source (cern.laser.business.data.Source)2 FaultStates (cern.laser.source.alarmsysteminterface.impl.message.FaultStates)2 Property (cern.laser.source.alarmsysteminterface.impl.message.Property)2 ParseException (java.text.ParseException)2 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 Vector (java.util.Vector)2 DummyContainerServices (alma.acs.container.testsupport.DummyContainerServices)1 LaserCoreFaultState (alma.alarmsystem.core.alarms.LaserCoreFaultState)1 LaserRuntimeException (cern.laser.business.LaserRuntimeException)1