use of cern.laser.business.data.Alarm in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method loadReductionRules.
/**
* Load the reduction rules from the CDB.
*
* Read the reduction rules from the CDB and set up the alarms accordingly
*/
private void loadReductionRules() {
if (conf == null) {
throw new IllegalStateException("Missing dal");
}
// The reduction rules (<parent, child>)
ArrayList<LinkSpec> reductionRules = new ArrayList<LinkSpec>();
String xml;
try {
xml = conf.getConfiguration(REDUCTION_DEFINITION_PATH);
} catch (CDBRecordDoesNotExistEx cdbEx) {
// No reduction rules defined in CDB
logger.log(AcsLogLevel.WARNING, "No reduction rules defined in CDB");
return;
} catch (Exception e) {
throw new RuntimeException("Couldn't read " + REDUCTION_DEFINITION_PATH, e);
}
ReductionDefinitions rds;
try {
rds = (ReductionDefinitions) ReductionDefinitions.unmarshalReductionDefinitions(new StringReader(xml));
} catch (Exception e) {
throw new RuntimeException("Couldn't parse " + REDUCTION_DEFINITION_PATH, e);
}
// Read the links to create from the CDB
ReductionLinkDefinitionListType ltc = rds.getLinksToCreate();
// Read the thresholds from the CDB
Thresholds thresholds = rds.getThresholds();
if (ltc != null) {
ReductionLinkType[] rls = ltc.getReductionLink();
for (ReductionLinkType link : rls) {
Parent p = link.getParent();
Child c = link.getChild();
if (p == null || c == null) {
throw new RuntimeException("Missing child or parent in a reduction link");
}
boolean isMulti;
if ("MULTIPLICITY".equals(link.getType())) {
isMulti = true;
} else if ("NODE".equals(link.getType())) {
isMulti = false;
} else {
throw new RuntimeException("Unknown reduction-link type: " + link.getType());
}
if (p.getAlarmDefinition() == null || c.getAlarmDefinition() == null)
throw new RuntimeException("Missing alarm-definition in child or parent");
LinkSpec newRule = new LinkSpec(toMatcher(p.getAlarmDefinition()), toMatcher(c.getAlarmDefinition()), isMulti);
reductionRules.add(newRule);
StringBuffer buf = new StringBuffer();
buf.replace(0, buf.length(), "");
if (newRule.isMultiplicity) {
buf.append("Found MULTIPLICITY RR: parent <");
} else {
buf.append("Found NODE RR: parent=<");
}
buf.append(newRule.parent.family + ", " + newRule.parent.member + ", " + newRule.parent.minCode + "-" + newRule.parent.minCode + ">");
buf.append(" child=<" + newRule.child.family + ", " + newRule.child.member + ", " + newRule.child.minCode + "-" + newRule.child.minCode + ">");
logger.log(AcsLogLevel.DEBUG, buf.toString());
}
}
logger.log(AcsLogLevel.DEBUG, reductionRules.size() + " reduction rules read from CDB");
Collection<Alarm> cc = alarmDefs.values();
AlarmImpl[] allAlarms = new AlarmImpl[cc.size()];
cc.toArray(allAlarms);
LinkSpec[] ls = new LinkSpec[reductionRules.size()];
reductionRules.toArray(ls);
int num = allAlarms.length;
int numls = ls.length;
for (int a = 0; a < num; a++) {
AlarmImpl parent = allAlarms[a];
for (LinkSpec lsb : ls) {
if (lsb.matchParent(parent)) {
AlarmRefMatcher childMatcher = lsb.child;
boolean isMulti = lsb.isMultiplicity();
for (int c = 0; c < num; c++) {
if (a == c) {
continue;
}
AlarmImpl aic = allAlarms[c];
if (childMatcher.isMatch(aic)) {
if (isMulti) {
parent.addMultiplicityChild(aic);
logger.log(AcsLogLevel.DEBUG, "Added MULTI RR node child " + aic.getAlarmId() + " to " + parent.getAlarmId());
} else {
parent.addNodeChild(aic);
logger.log(AcsLogLevel.DEBUG, "Added NODE RR node child " + aic.getAlarmId() + " to " + parent.getAlarmId());
}
}
}
}
}
}
if (thresholds != null && thresholds.getThresholdCount() > 0) {
Threshold[] ta = thresholds.getThreshold();
for (AlarmImpl alarm : allAlarms) {
String alarmFF = alarm.getTriplet().getFaultFamily();
String alarmFM = alarm.getTriplet().getFaultMember();
Integer alarmFC = alarm.getTriplet().getFaultCode();
for (Threshold threshold : ta) {
String thresholdFF = threshold.getAlarmDefinition().getFaultFamily();
String thresholdFM = threshold.getAlarmDefinition().getFaultMember();
int thresholdFC = threshold.getAlarmDefinition().getFaultCode();
int thresholdVal = threshold.getValue();
if (alarmFF.equals(thresholdFF) && alarmFM.equals(thresholdFM) && alarmFC == thresholdFC) {
alarm.setMultiplicityThreshold(thresholdVal);
logger.log(AcsLogLevel.DEBUG, "Threshold = " + thresholdVal + " set in alarm " + alarm.getAlarmId());
}
}
}
}
}
use of cern.laser.business.data.Alarm in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method addThreshold.
public void addThreshold(ReductionDefinitions rds, Threshold th) {
if (th == null)
throw new IllegalArgumentException("Null Threshold argument");
//alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds = getReductionRules();
alma.alarmsystem.alarmmessage.generated.Threshold[] tmp = rds.getThresholds().getThreshold();
for (int i = 0; i < tmp.length; i++) {
alma.alarmsystem.alarmmessage.generated.AlarmDefinition p1 = th.getAlarmDefinition();
alma.alarmsystem.alarmmessage.generated.AlarmDefinition p2 = tmp[i].getAlarmDefinition();
String n1 = new String(p1.getFaultFamily() + ":" + p1.getFaultMember() + ":" + p1.getFaultCode());
String n2 = new String(p2.getFaultFamily() + ":" + p2.getFaultMember() + ":" + p2.getFaultCode());
if (n1.compareTo(n2) == 0)
throw new IllegalStateException("Threshold entry already exists");
}
rds.getThresholds().addThreshold(th);
//Reflect the changes into the AlarmDAO
alma.alarmsystem.alarmmessage.generated.AlarmDefinition in = th.getAlarmDefinition();
Alarm p = getAlarm(in.getFaultFamily() + ":" + in.getFaultMember() + ":" + in.getFaultCode());
p.setMultiplicityThreshold(th.getValue());
//flushReductionRules(rds);
}
use of cern.laser.business.data.Alarm in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method flushCategory.
public void flushCategory() {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
CategoryDefinitions acds = new CategoryDefinitions();
CategoryDefinitionListType ctc = new CategoryDefinitionListType();
acds.setCategoriesToCreate(ctc);
AlarmCategoryDefinitions linksTop = new AlarmCategoryDefinitions();
AlarmCategoryLinkDefinitionListType cltc = new AlarmCategoryLinkDefinitionListType();
linksTop.setCategoryLinksToCreate(cltc);
Iterator<Category> i = catPathToCategory.values().iterator();
while (i.hasNext()) {
CategoryDefinition cd = new CategoryDefinition();
CategoryImpl ci = (CategoryImpl) i.next();
cd.setDescription(ci.getDescription());
cd.setPath(ci.getPath());
ctc.addCategoryDefinition(cd);
Iterator aidsi = ci.getAlarmIds().iterator();
while (aidsi.hasNext()) {
String aid = (String) aidsi.next();
Alarm a = alarmDao.getAlarm(aid);
if (a == null)
throw new RuntimeException("Category has a link to a non-existent alarm");
AlarmCategoryLinkType link = new AlarmCategoryLinkType();
alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = new alma.alarmsystem.alarmmessage.generated.Alarm();
alma.alarmsystem.alarmmessage.generated.Category linkCat = new alma.alarmsystem.alarmmessage.generated.Category();
link.setAlarm(linkAlarm);
link.setCategory(linkCat);
AlarmDefinition linkAlarmDef = new AlarmDefinition();
CategoryDefinition linkCatDef = new CategoryDefinition();
linkAlarm.setAlarmDefinition(linkAlarmDef);
linkCat.setCategoryDefinition(linkCatDef);
linkAlarmDef.setFaultCode(a.getTriplet().getFaultCode().intValue());
linkAlarmDef.setFaultFamily(a.getTriplet().getFaultFamily());
linkAlarmDef.setFaultMember(a.getTriplet().getFaultMember());
linkCatDef.setPath(ci.getPath());
cltc.addAlarmCategoryLink(link);
}
}
StringWriter catList = new StringWriter();
try {
acds.marshal(catList);
} catch (Exception e) {
throw new RuntimeException("Failed to encode categories", e);
}
StringWriter linkList = new StringWriter();
try {
acds.marshal(linkList);
} catch (Exception e) {
throw new RuntimeException("Failed to encode link", e);
}
try {
conf.setConfiguration(CATEGORY_DEFINITION_PATH, catList.toString().replaceFirst("xsi:type=\".*\"", ""));
conf.setConfiguration(ALARM_CATEGORY_DEFINITION_PATH, linkList.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (Exception e) {
throw new RuntimeException("Failed to store configuration", e);
}
}
use of cern.laser.business.data.Alarm in project ACS by ACS-Community.
the class ReductionManager method addReductionRule.
/**
* Adds a Reduction Rule
* @param rrL List of Reduction Rules where the rule will be added (if it is null).
* @param rr Reduction Rule to add to (if not null).
* @param p Parent of the Rule to be added
* @param c Child of the Rule to be added
*/
private void addReductionRule(List<ReductionRule> rrL, ReductionRule rr, Alarm p, Alarm c, boolean isNodeReductionRule) throws IllegalOperationException, NullPointerException {
if (rr == null) {
rr = new ReductionRule(p);
rr.setIsNodeReduction(isNodeReductionRule);
rrL.add(rr);
}
List<Alarm> chL = rr.getChildren();
for (Alarm alarm : chL) {
if (alarm.getAlarmId().compareTo(c.getAlarmId()) == 0) {
throw new IllegalOperationException("The reduction rule already exists");
}
}
rr.addChild(c);
ObjectState os;
if (rr.getIsNodeReduction())
os = _objState.get(new String(p.getAlarmId() + "," + c.getAlarmId() + ",n"));
else
os = _objState.get(new String(p.getAlarmId() + "," + c.getAlarmId() + ",m"));
if (os == null) {
os = new ObjectState(true);
os.create();
if (rr.getIsNodeReduction())
_objState.put(new String(p.getAlarmId() + "," + c.getAlarmId() + ",n"), os);
else
_objState.put(new String(p.getAlarmId() + "," + c.getAlarmId() + ",m"), os);
} else
os.update();
}
use of cern.laser.business.data.Alarm in project ACS by ACS-Community.
the class ReductionManager method loadFromCDB.
/* (non-Javadoc)
* @see cl.utfsm.acs.acg.core.EntityManager#loadFromCDB()
*/
public void loadFromCDB() {
String[] ids = ((ACSAlarmDAOImpl) _alarmDAO).getAllAlarmIDs();
String[] children = null;
Alarm alarm = null;
ReductionRule rr = null;
_nodeReductionRules.clear();
_multiReductionRules.clear();
_objState.clear();
_thrState.clear();
/* Add the reduction rules defined in the CDB */
for (int i = 0; i < ids.length; i++) {
alarm = ((ACSAlarmDAOImpl) _alarmDAO).getAlarm(ids[i]);
/* First the Node Reduction rules */
children = alarm.getNodeChildren();
if (children.length > 0) {
rr = new ReductionRule(alarm);
rr.setIsNodeReduction(true);
}
for (int j = 0; j < children.length; j++) {
rr.addChild(((ACSAlarmDAOImpl) _alarmDAO).getAlarm(children[j]));
_objState.put(new String(ids[i] + "," + children[j] + ",n"), new ObjectState(false));
}
if (children.length > 0)
_nodeReductionRules.add(rr);
/* And the Multiplicity Reduction rules */
children = alarm.getMultiplicityChildren();
if (children.length > 0) {
rr = new ReductionRule(((ACSAlarmDAOImpl) _alarmDAO).getAlarm(ids[i]));
rr.setIsNodeReduction(false);
if (alarm.getMultiplicityThreshold() == null) {
System.out.println("Skipping Multi Reduction Rule: No Threshold set.");
continue;
}
rr.setThreshold(alarm.getMultiplicityThreshold().intValue());
}
for (int j = 0; j < children.length; j++) {
rr.addChild(((ACSAlarmDAOImpl) _alarmDAO).getAlarm(children[j]));
_objState.put(new String(ids[i] + "," + children[j] + ",m"), new ObjectState(false));
_thrState.put(ids[i], new ObjectState(false));
}
if (children.length > 0)
_multiReductionRules.add(rr);
}
}
Aggregations