use of alma.cdbErrType.CDBRecordDoesNotExistEx in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method updateFaultFamily.
public void updateFaultFamily(FaultFamily ff) {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
if (ff == null)
throw new IllegalArgumentException("Null FaultFamily argument");
StringWriter FFWriter = new StringWriter();
Marshaller FF_marshaller;
try {
FF_marshaller = new Marshaller(FFWriter);
} catch (IOException e) {
e.printStackTrace();
return;
}
FF_marshaller.setValidation(false);
try {
FF_marshaller.marshal(ff);
} catch (MarshalException e) {
e.printStackTrace();
return;
} catch (ValidationException e) {
e.printStackTrace();
return;
}
String path = ALARM_DEFINITION_PATH + "/" + ff.getName();
try {
try {
conf.getConfiguration(path);
conf.deleteConfiguration(path);
} catch (CDBRecordDoesNotExistEx e) {
//Record does not exist, so we skip removing it.
throw new IllegalStateException("FaultFamily doesn't exist");
}
conf.addConfiguration(path, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (IllegalStateException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
return;
}
Vector<FaultFamily> ffs = new Vector<FaultFamily>();
ffs.add(ff);
removeAlarmsMap(ffs);
generateAlarmsMap(ffs);
}
use of alma.cdbErrType.CDBRecordDoesNotExistEx 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 alma.cdbErrType.CDBRecordDoesNotExistEx in project ACS by ACS-Community.
the class ACSAlarmSystemDAOImpl method getConfiguration.
public AlarmSystemConfiguration getConfiguration() {
if (conf == null)
throw new IllegalStateException("null configuration accessor");
AlarmSystemConfiguration asc;
String xml;
try {
xml = conf.getConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH);
} catch (CDBRecordDoesNotExistEx e) {
asc = new AlarmSystemConfiguration();
ConfigurationProperty cp = new ConfigurationProperty();
cp.setName("Implementation");
cp.setContent("ACS");
asc.addConfigurationProperty(cp);
return asc;
} catch (Exception e) {
e.printStackTrace();
return null;
}
StringReader FFReader = new StringReader(xml);
Unmarshaller FF_unmarshaller = new Unmarshaller(AlarmSystemConfiguration.class);
FF_unmarshaller.setValidation(false);
try {
asc = (AlarmSystemConfiguration) FF_unmarshaller.unmarshal(FFReader);
} catch (MarshalException e) {
e.printStackTrace();
return null;
} catch (ValidationException e) {
e.printStackTrace();
return null;
}
try {
asc.validate();
} catch (ValidationException e) {
e.printStackTrace();
}
return asc;
}
use of alma.cdbErrType.CDBRecordDoesNotExistEx in project ACS by ACS-Community.
the class ACSAlarmSystemDAOImpl method flushConfiguration.
public void flushConfiguration(AlarmSystemConfiguration asc) {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
if (asc == null)
throw new IllegalArgumentException("Null Alarm System Configuration argument");
StringWriter FFWriter = new StringWriter();
Marshaller FF_marshaller;
try {
FF_marshaller = new Marshaller(FFWriter);
} catch (IOException e) {
e.printStackTrace();
return;
}
FF_marshaller.setValidation(false);
try {
FF_marshaller.marshal(asc);
} catch (MarshalException e) {
e.printStackTrace();
return;
} catch (ValidationException e) {
e.printStackTrace();
return;
}
try {
conf.deleteConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH);
conf.addConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (CDBRecordDoesNotExistEx e) {
try {
conf.addConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (Exception e1) {
e1.printStackTrace();
}
} catch (org.omg.CORBA.UNKNOWN e) {
try {
conf.addConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (Exception e1) {
e1.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of alma.cdbErrType.CDBRecordDoesNotExistEx in project ACS by ACS-Community.
the class DALRead method main.
public static void main(String[] args) {
Logger m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("DALRead", false);
try {
String curl;
String strIOR = null;
boolean rawOutput = false;
if (args.length < 1) {
System.out.println("Usage: cmd curl [-d ior -raw -h]");
return;
}
curl = args[0];
// test for IOR in cmd line
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-d")) {
if (i < args.length - 1) {
strIOR = args[++i];
}
}
if (args[i].equals("-raw")) {
rawOutput = true;
}
if (args[i].equals("-h")) {
System.out.println("Usage: cmd curl [-d ior -raw -h]");
return;
}
}
if (strIOR == null) {
// use default
strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
}
// create and initialize the ORB
ORB orb = ORB.init(args, null);
DAL dal = DALHelper.narrow(orb.string_to_object(strIOR));
String xml = dal.get_DAO(curl);
if (rawOutput) {
m_logger.log(AcsLogLevel.INFO, "Curl data:\n" + xml);
return;
}
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
XMLHandler xmlSolver = new XMLHandler(false, m_logger);
saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
if (xmlSolver.m_errorString != null) {
String info = "XML parser error: " + xmlSolver.m_errorString;
AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx();
System.err.println(info);
throw xmlErr;
}
System.out.println("Env " + System.getProperty("HOMEPATH"));
// dump contents
System.out.println("________________________________________________________");
walk(xmlSolver.m_rootNode);
System.out.println("________________________________________________________");
} catch (AcsJCDBXMLErrorEx e) {
e.printStackTrace();
e.log(m_logger);
} catch (CDBXMLErrorEx e) {
AcsJCDBXMLErrorEx je = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(e);
String smsg = "XML Error \tCURL='" + je.getCurl() + "'\n\t\tFilename='" + je.getFilename() + "'\n\t\tNodename='" + je.getNodename() + "'\n\t\tMSG='" + je.getErrorString() + "'";
je.log(m_logger);
m_logger.log(AcsLogLevel.NOTICE, smsg, je);
} catch (CDBRecordDoesNotExistEx e) {
AcsJCDBRecordDoesNotExistEx je = AcsJCDBRecordDoesNotExistEx.fromCDBRecordDoesNotExistEx(e);
String smsg = "Record does not exist \tCURL='" + je.getCurl() + "'";
je.log(m_logger);
m_logger.log(AcsLogLevel.NOTICE, smsg, je);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations