Search in sources :

Example 11 with FaultState

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

the class SourcesListener method receive.

/**
	 * The method receives all the messages published in the NC by the sources
	 * 
	 *  
	 * @param msg The message received from the NC
	 */
@Override
public void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    logger.fine("Msg received");
    ASIMessage asiMsg;
    Collection<FaultState> faultStates;
    try {
        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();
        return;
    }
    Iterator<FaultState> iter = faultStates.iterator();
    while (iter.hasNext()) {
        FaultState fs = iter.next();
        StringBuilder str = new StringBuilder("Alarm message received: <");
        str.append(fs.getFamily());
        str.append(",");
        str.append(fs.getMember());
        str.append(",");
        str.append(fs.getCode());
        str.append(">");
        str.append(" Status: ");
        str.append(fs.getDescriptor());
        System.out.println(str.toString());
    }
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 12 with FaultState

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

the class AlarmsDelayCoreAlarmTest method sendAlarm.

/**
	 * Send a alarm to the alarm NC bypassing the ACS API because we want to simulate a delay!
	 * 
	 * @param faultFamily
	 * @param faultMember
	 * @param code
	 * @param active
	 * @param timeStamp
	 * @throws Exception
	 */
private void sendAlarm(String faultFamily, String faultMember, int code, boolean active, long timeStamp) throws Exception {
    FaultState fs = new FaultStateImpl(faultFamily, faultMember, code);
    if (active) {
        fs.setDescriptor(FaultState.ACTIVE);
    } else {
        fs.setDescriptor(FaultState.TERMINATE);
    }
    Timestamp timestamp = new Timestamp(timeStamp);
    fs.setUserTimestamp(timestamp);
    Vector<FaultState> states = new Vector<FaultState>();
    states.add(fs);
    ASIMessage asiMessage = ASIMessageHelper.marshal(states);
    // Set the timestamp by adding a dealy greater then AlarmMessageProcessorImpl.delayThreashold
    String nowStr = IsoDateFormat.formatDate(new Date(timeStamp));
    asiMessage.setSourceTimestamp(nowStr);
    // Set a fake hostname
    asiMessage.setSourceHostname("alma");
    asiMessage.setSourceName("ALARM_SYSTEM_SOURCES");
    ACSJMSTextMessage textMessage = new ACSJMSTextMessage(contSvcs);
    textMessage.setText(XMLMessageHelper.marshal(asiMessage));
    // Finally send the alarm
    sourceNC.publishEvent(textMessage.getEntity());
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) LaserCoreFaultState(alma.alarmsystem.core.alarms.LaserCoreFaultState) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) FaultStateImpl(cern.laser.source.alarmsysteminterface.impl.FaultStateImpl) Timestamp(java.sql.Timestamp) Vector(java.util.Vector) Date(java.util.Date) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 13 with FaultState

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

the class LaserCoreFaultState method createJMSMessage.

/**
	 * Create an acs text jms message containing the passed
	 * fault state in form of XML (ASIMessage) in the body.
	 *  
	 * @param fs The <code>FaultState</code> to set in the message
	 * @param cs The <code>ContainerServicesBase</code>
	 * @return The jms text message containing the fault state
	 */
public static ACSJMSTextMessage createJMSMessage(FaultState fs, ContainerServicesBase cs) throws Exception {
    if (fs == null) {
        throw new IllegalArgumentException("The fault state can't be null");
    }
    if (cs == null) {
        throw new IllegalArgumentException("The container services can't be null");
    }
    Vector<FaultState> states = new Vector<FaultState>();
    states.add(fs);
    ASIMessage asiMessage = ASIMessageHelper.marshal(states);
    // Set the timestamp
    String sourceTimestamp = IsoDateFormat.formatCurrentDate();
    asiMessage.setSourceTimestamp(sourceTimestamp);
    // Set the hostname
    if (hostName == null) {
        InetAddress iAddr = InetAddress.getLocalHost();
        hostName = iAddr.getHostName();
    }
    asiMessage.setSourceHostname(hostName);
    asiMessage.setSourceName("ALARM_SYSTEM_SOURCES");
    ACSJMSTextMessage textMessage = new ACSJMSTextMessage(cs);
    textMessage.setText(XMLMessageHelper.marshal(asiMessage));
    return textMessage;
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) Vector(java.util.Vector) InetAddress(java.net.InetAddress) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 14 with FaultState

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

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

the class ASIMessageHelper method marshal.

/**
   * DOCUMENT ME!
   *
   * @param states DOCUMENT ME!
   *
   * @return DOCUMENT ME!
   */
public static ASIMessage marshal(Collection states) {
    if (states == null) {
        throw (new IllegalArgumentException("states collection is null"));
    }
    ASIMessage asi_message = new ASIMessage();
    Iterator iterator = states.iterator();
    FaultStates fault_states = new FaultStates();
    while (iterator.hasNext()) {
        Object ref = iterator.next();
        if (ref instanceof FaultState) {
            fault_states.addFaultState(FaultStateHelper.marshal((FaultState) ref));
        } else {
            throw new IllegalArgumentException("collection does not contain FaultState instances");
        }
    }
    asi_message.setFaultStates(fault_states);
    return asi_message;
}
Also used : FaultStates(cern.laser.source.alarmsysteminterface.impl.message.FaultStates) Iterator(java.util.Iterator) FaultState(cern.laser.source.alarmsysteminterface.FaultState) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

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