use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.
the class AlarmManager method deleteFaultCode.
/**
* Deletes a Fault Code of a given Fault Family. The Fault Code to be
* deleted is checked against the existing Reduction Rules in order to
* preserve the consistency of the application (i.e., a Fault Code cannot
* be deleted if it is currently present in a Reduction Rule).
* @param ff The Fault Family of the Fault Code to be deleted
* @param fc The Fault Code to be deleted
* @return True if it deletes the given Fault Code, false otherwise
* @throws NullPointerException If the given Fault Family or Fault Code
* is null
* @throws IllegalOperationException If the Fault Code is part of an
* existing Reduction Rule
*/
public boolean deleteFaultCode(FaultFamily ff, FaultCode fc) throws NullPointerException, IllegalOperationException {
if (ff == null || ff.getName() == null)
throw new NullPointerException("The Fault Family (or its name) owner of the Fault Code to be deleted is null");
if (fc == null)
throw new NullPointerException("The Fault Code to be deleted is null");
List<ReductionRule> rrL = _reductionManager.getNodeReductionRules();
for (ReductionRule rr : rrL) {
String[] tr = rr.getParent().getAlarmId().split(":");
if (tr[0].compareTo(ff.getName()) == 0 && Integer.parseInt(tr[2]) == fc.getValue())
throw new IllegalOperationException("The Fault Code is currently associated to a Reduction Rule");
}
for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
FaultFamily fft = (FaultFamily) iterator.next();
if (fft.getName().compareTo(ff.getName()) == 0) {
for (Iterator<FaultCode> iterator2 = Arrays.asList(fft.getFaultCode()).iterator(); iterator2.hasNext(); ) {
FaultCode fct = (FaultCode) iterator2.next();
if (fct.getValue() == fc.getValue()) {
fft.removeFaultCode(fc);
ObjectState os = _objState.get(fft.getName());
if (os == null)
throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
os.update();
Vector<FaultFamily> ffs = new Vector<FaultFamily>();
ffs.add(ff);
((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
((ACSAlarmDAOImpl) _alarmDAO).generateAlarmsMap(ffs);
return true;
}
}
}
}
return false;
}
use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.
the class AlarmManager method setFaultMemberDefault.
public boolean setFaultMemberDefault(FaultFamily ff, FaultMemberDefault fmd) throws NullPointerException, IllegalOperationException {
if (ff == null || ff.getName() == null)
throw new NullPointerException("The Fault Family (or its name) owner of the Fault Member to be deleted is null");
List<ReductionRule> rrL = _reductionManager.getNodeReductionRules();
for (ReductionRule rr : rrL) {
String[] tr = rr.getParent().getAlarmId().split(":");
if (tr[0].compareTo(ff.getName()) == 0 && tr[1].compareTo("*") == 0)
throw new IllegalOperationException("The Fault Member is currently associated to a Reduction Rule");
}
for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
FaultFamily fft = (FaultFamily) iterator.next();
if (fft.getName().compareTo(ff.getName()) == 0) {
FaultMemberDefault tfmd = fft.getFaultMemberDefault();
fft.setFaultMemberDefault(fmd);
ObjectState os = _objState.get(fft.getName());
if (os == null)
throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
os.update();
if ((tfmd == null && fmd != null) || (tfmd != null && fmd == null)) {
Vector<FaultFamily> ffs = new Vector<FaultFamily>();
ffs.add(ff);
((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
((ACSAlarmDAOImpl) _alarmDAO).generateAlarmsMap(ffs);
}
return true;
}
}
return false;
}
use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method loadAlarms.
/**
* Load alarms from CDB.
*
* Read the alarms by the alarm definitions file of the CDB.
* The initialization of the alarms is not complete at this stage.
* In fact the categories are assigned to alarms when reading the
* categories from the CDB by ACSCategoryDAOImpl
*
*
* @throws Exception In case of error while parsing XML definition files
*
* @see ACSCategoryDAOImpl
*/
public List<FaultFamily> loadAlarms() throws Exception {
if (conf == null) {
throw new IllegalStateException("Missing dal");
}
String xml;
try {
xml = conf.getConfiguration(ALARM_DEFINITION_PATH);
} catch (Throwable t) {
throw new RuntimeException("Couldn't read alarm XML: " + ALARM_DEFINITION_PATH, t);
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (Exception e) {
throw new Exception("Error building the DocumentBuilder from the DocumentBuilderFactory", e);
}
StringReader stringReader = new StringReader(xml);
InputSource inputSource = new InputSource(stringReader);
Document doc;
try {
doc = builder.parse(inputSource);
if (doc == null) {
throw new Exception("The builder returned a null Document after parsing");
}
} catch (Exception e) {
throw new Exception("Error parsing XML: " + xml, e);
}
NodeList docChilds = doc.getChildNodes();
if (docChilds == null || docChilds.getLength() != 1) {
throw new Exception("Malformed xml: only one node (AlarmDefinitions) expected");
}
Node alarmDefNode = docChilds.item(0);
if (alarmDefNode == null || alarmDefNode.getNodeName() != XML_DOCUMENT_TYPE) {
throw new Exception("Malformed xml: " + XML_DOCUMENT_TYPE + " not found");
}
NodeList alarmDefsNodes = alarmDefNode.getChildNodes();
Unmarshaller FF_unmarshaller = new Unmarshaller(FaultFamily.class);
FF_unmarshaller.setValidation(false);
FF_unmarshaller.setWhitespacePreserve(true);
Vector<FaultFamily> cdbFamilies = new Vector<FaultFamily>();
for (int t = 0; t < alarmDefsNodes.getLength(); t++) {
Node alarmDef = alarmDefsNodes.item(t);
try {
FaultFamily family = (FaultFamily) FF_unmarshaller.unmarshal(alarmDef);
if (family == null) {
throw new Exception("Error unmarshalling a family node");
}
cdbFamilies.add(family);
} catch (Exception e) {
throw new Exception("Error parsing " + alarmDef.getNodeName(), e);
}
}
generateAlarmsMap(cdbFamilies);
loadReductionRules();
return cdbFamilies;
}
use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.
the class CDBSender method readAlarmsFromCDB.
/**
* Read alarms from the TM/CDB with the help of {@link ACSAlarmDAOImpl}.
* <P>
* This method can be quite slow so it would be better to run
* in a dedicated thread.
*
* @throws Exception
*/
private void readAlarmsFromCDB() throws Exception {
ConfigurationAccessor conf;
conf = ConfigurationAccessorFactory.getInstance(contSvcs);
ACSAlarmDAOImpl alarmDAO = new ACSAlarmDAOImpl(contSvcs.getLogger());
alarmDAO.setConfAccessor(conf);
List<FaultFamily> FFs = alarmDAO.loadAlarms();
synchronized (alarms) {
for (FaultFamily ff : FFs) {
String faultFamily = ff.getName();
for (FaultMember fm : ff.getFaultMember()) {
for (FaultCode fc : ff.getFaultCode()) {
alarms.add(new AlarmRead(faultFamily + "," + fm.getName() + "," + fc.getValue(), null));
}
}
// Has this FF a default fault member?
if (ff.getFaultMemberDefault() != null) {
System.out.println("Found a default fault member for " + ff.getName());
for (FaultCode fc : ff.getFaultCode()) {
alarms.add(new AlarmRead(faultFamily + ",*," + fc.getValue(), null));
}
}
}
}
}
use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.
the class CategoryManager method deleteCategory.
/**
* Deletes a category. The category to be deleted is checked against the existing
* Fault Families in order to preserve the consistency of the application
* (i.e., a category cannot be deleted if it currently being used
* by a Fault Family).
* @param c The category to be deleted
* @return True if it deletes the given category, false otherwise
* @throws NullPointerException If the given category is null
* @throws IllegalOperationException If the category is part of a existing Fault Family
*/
public boolean deleteCategory(Category c) throws NullPointerException, IllegalOperationException {
if (c == null || c.getPath() == null)
throw new NullPointerException("The category to be deleted (or its name) is null");
// Check the category FFs with the existing FFs
AlarmManager alarmManager = AlarmSystemManager.getInstance().getAlarmManager();
List<FaultFamily> ffList = alarmManager.getAllAlarms();
if (c.getAlarms() != null) {
String[] categoryFFs = c.getAlarms().getFaultFamily();
for (FaultFamily ff : ffList) for (int i = 0; i != categoryFFs.length; i++) if (categoryFFs[i].compareTo(ff.getName()) == 0)
throw new IllegalOperationException("The Category can't be removed since it has a FaultFamily assigned");
}
for (Iterator<Category> iterator = _categoryList.iterator(); iterator.hasNext(); ) {
Category ct = (Category) iterator.next();
if (ct.getPath().compareTo(c.getPath()) == 0) {
iterator.remove();
ObjectState os = _objState.get(c.getPath());
if (os == null)
throw new IllegalOperationException("There is no ObjectState associated with the given Category");
os.delete();
return true;
}
}
return false;
}
Aggregations