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());
}
}
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());
}
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;
}
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);
}
}
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;
}
Aggregations