use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method loadCategories.
/**
* Load the categories from the CDB.
* <P>
* Loads all the category from the CDB and build an internal
* representation of category.
* The category is also added to all the alarms having the
* fault family specified in the XML.
* <P>
* All the categories derive from ROOT that is built here
* as default (in this way the user does ot need to add the ROOT
* entry in the CDB).
*
* @return list of Category entries read from CDB
* @throws Exception In case of error reading the values from the CDB
*/
public alma.acs.alarmsystem.generated.Category[] loadCategories() throws Exception {
if (conf == null) {
throw new IllegalStateException("Missing dal");
}
String xml;
try {
xml = conf.getConfiguration(CATEGORY_DEFINITION_PATH);
} catch (Throwable t) {
throw new RuntimeException("Couldn't read alarm list", 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 (categories) expected");
}
Node categoriesNode = docChilds.item(0);
Unmarshaller FF_unmarshaller = new Unmarshaller(Categories.class);
FF_unmarshaller.setValidation(false);
FF_unmarshaller.setWhitespacePreserve(true);
Categories daoCategories;
try {
daoCategories = (Categories) FF_unmarshaller.unmarshal(categoriesNode);
logger.log(AcsLogLevel.DEBUG, "Categories definition read");
} catch (Exception e) {
throw new Exception("Error parsing " + CATEGORY_DEFINITION_PATH, e);
}
alma.acs.alarmsystem.generated.Category[] daoCategory = daoCategories.getCategory();
if (daoCategory == null || daoCategory.length == 0) {
logger.log(AcsLogLevel.DEBUG, "No category defined");
}
// Add the root Category
addRootCategory();
// Goes through all the Categories read from the CDB
for (alma.acs.alarmsystem.generated.Category category : daoCategory) {
cern.laser.business.definition.data.CategoryDefinition definition = new cern.laser.business.definition.data.CategoryDefinition(category.getPath(), category.getDescription());
CategoryImpl ci = new CategoryImpl();
// will get filled in later
ci.setAlarmIds(new HashSet());
ci.setCategoryId(new Integer(nextCatID++));
ci.setChildrenIds(new HashSet<Integer>());
ci.setDescription(definition.getDescription());
ci.setName(definition.getPath());
ci.setPath(definition.getPath());
ci.setAlarmIds(new HashSet());
setParentID(ci);
// Stores the categories
categories.put(ci.getCategoryId(), ci);
catPathToCategory.put(ci.getPath(), ci);
logger.log(AcsLogLevel.DEBUG, "Category " + ci.getName() + " added with ID=" + ci.getCategoryId());
// Check if the category is defined as default.
if (category.hasIsDefault() && category.getIsDefault() == true) {
if (defaultCategory != null) {
StringBuilder str = new StringBuilder("CDB misconfiguration: default category defined more then once (actual default: ");
str.append(defaultCategory.getPath());
str.append(", new default: ");
str.append(category.getPath());
logger.log(AcsLogLevel.WARNING, str.toString());
} else {
defaultCategory = ci;
}
}
// A category contains a set of child ids.
// This method adjusts the references of categories between the parent
// and the child
adjustParentIDs(ci.getName(), ci.getCategoryId());
// Connect alarms to this category
for (alma.acs.alarmsystem.generated.Category cat : daoCategories.getCategory()) {
if (cat.getPath().equals(ci.getPath())) {
String[] families = cat.getAlarms().getFaultFamily();
for (String faultFamily : families) {
assignCategoryToAlarms(ci, faultFamily);
}
}
}
}
// Assign core alarms to ROOT category
assignCategoryOfCoreAlarms();
// Log a message if no category has been defined in the CDB
if (defaultCategory == null) {
logger.log(AcsLogLevel.WARNING, "No default category defined in CDB");
} else {
// Check if there are alarms without category to assign to the default
assignDefaultCategory(defaultCategory);
}
return daoCategory;
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method generateAlarmsMap.
/**
* Generate the alarms from the definition of the fault families.
* The alarms will be added into the HashMap with their triplet as key.
* The default item has FM="*".
*
* The sources read from the families are also added to the HashMap of the sources
*
* @param families The FF read from the CDB
*/
private void generateAlarmsMap(Vector<FaultFamily> families) {
if (families == null) {
throw new IllegalArgumentException("Invalid null vector of FFs");
}
for (FaultFamily family : families) {
String FF = family.getName();
String helpUrl = family.getHelpUrl();
String source = family.getAlarmSource();
Contact contactPerson = family.getContact();
FaultMember[] FMs = family.getFaultMember();
FaultMemberDefault defaultFM = family.getFaultMemberDefault();
FaultCode[] FCs = family.getFaultCode();
// There should be at least one FC in the CDB
if (FCs == null || FCs.length == 0) {
logger.log(AcsLogLevel.WARNING, "No FC defined for family " + family.getName());
continue;
}
// There should be at least one FM or a default FM defined in the CDB
if (defaultFM == null && (FMs == null || FMs.length == 0)) {
logger.log(AcsLogLevel.WARNING, "No FM defined for family " + family.getName());
continue;
}
// Iterate over the FCs
for (FaultCode code : FCs) {
int FC = code.getValue();
int priority = code.getPriority();
String action = code.getAction();
String cause = code.getCause();
String consequence = code.getConsequence();
String problemDesc = code.getProblemDescription();
boolean instant = code.getInstant();
// Iterate over all the FMs
for (FaultMember member : FMs) {
alma.acs.alarmsystem.generated.Location loc = member.getLocation();
if (loc == null) {
loc = new alma.acs.alarmsystem.generated.Location();
}
if (loc.getBuilding() == null) {
loc.setBuilding("");
}
if (loc.getFloor() == null) {
loc.setFloor("");
}
if (loc.getMnemonic() == null) {
loc.setMnemonic("");
}
if (loc.getPosition() == null) {
loc.setPosition("");
}
if (loc.getRoom() == null) {
loc.setRoom("");
}
String FM = member.getName();
if (FM.equals(DEFAULT_FM)) {
logger.log(AcsLogLevel.ERROR, "In the CDB, FM=" + DEFAULT_FM + " in family " + FF + " is not allowed");
}
AlarmImpl alarm = new AlarmImpl();
alarm.setMultiplicityChildrenIds(new HashSet());
alarm.setMultiplicityParentIds(new HashSet());
alarm.setNodeChildrenIds(new HashSet());
alarm.setNodeParentIds(new HashSet());
alarm.setAction(action);
alarm.setTriplet(new Triplet(FF, FM, FC));
alarm.setCategories(new HashSet<Category>());
alarm.setCause(cause);
alarm.setConsequence(consequence);
alarm.setProblemDescription(problemDesc);
try {
alarm.setHelpURL(new URL(helpUrl));
} catch (MalformedURLException e) {
alarm.setHelpURL(null);
}
alarm.setInstant(instant);
Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
alarm.setLocation(location);
if (contactPerson.getEmail() != null) {
alarm.setPiquetEmail(contactPerson.getEmail());
} else {
alarm.setPiquetEmail("");
}
if (contactPerson.getGsm() != null) {
alarm.setPiquetGSM(contactPerson.getGsm());
} else {
alarm.setPiquetGSM("");
}
alarm.setPriority(priority);
ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
alarm.setResponsiblePerson(responsible);
SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
Source src = new Source(srcDef, responsible);
alarm.setSource(src);
alarm.setIdentifier(alarm.getTriplet().toIdentifier());
addAlarmToCache(alarm);
if (!srcDefs.containsKey(source)) {
srcDefs.put(src.getSourceId(), src);
logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
}
logger.log(AcsLogLevel.DEBUG, "Alarm added " + alarm.getAlarmId());
}
// Add the default
if (defaultFM != null) {
alma.acs.alarmsystem.generated.Location loc = defaultFM.getLocation();
if (loc == null) {
loc = new alma.acs.alarmsystem.generated.Location();
}
if (loc.getBuilding() == null) {
loc.setBuilding("");
}
if (loc.getFloor() == null) {
loc.setFloor("");
}
if (loc.getMnemonic() == null) {
loc.setMnemonic("");
}
if (loc.getPosition() == null) {
loc.setPosition("");
}
if (loc.getRoom() == null) {
loc.setRoom("");
}
AlarmImpl defaultAlarm = new AlarmImpl();
defaultAlarm.setMultiplicityChildrenIds(new HashSet());
defaultAlarm.setMultiplicityParentIds(new HashSet());
defaultAlarm.setNodeChildrenIds(new HashSet());
defaultAlarm.setNodeParentIds(new HashSet());
defaultAlarm.setAction(action);
defaultAlarm.setCategories(new HashSet<Category>());
defaultAlarm.setCause(cause);
defaultAlarm.setConsequence(consequence);
defaultAlarm.setProblemDescription(problemDesc);
try {
defaultAlarm.setHelpURL(new URL(helpUrl));
} catch (MalformedURLException e) {
defaultAlarm.setHelpURL(null);
}
defaultAlarm.setInstant(instant);
Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
defaultAlarm.setLocation(location);
defaultAlarm.setPiquetEmail(contactPerson.getEmail());
defaultAlarm.setPiquetGSM(contactPerson.getGsm());
defaultAlarm.setPriority(priority);
ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
defaultAlarm.setResponsiblePerson(responsible);
SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
Source src = new Source(srcDef, responsible);
defaultAlarm.setSource(src);
defaultAlarm.setIdentifier(defaultAlarm.getTriplet().toIdentifier());
Triplet triplet = new Triplet(FF, DEFAULT_FM, FC);
defaultAlarm.setTriplet(triplet);
defaultAlarm.setIdentifier(triplet.toIdentifier());
addAlarmToCache(defaultAlarm);
if (!srcDefs.containsKey(source)) {
srcDefs.put(src.getSourceId(), src);
logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
}
logger.log(AcsLogLevel.DEBUG, "Default alarm added " + defaultAlarm.getAlarmId());
}
}
}
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method assignCategoryOfCoreAlarms.
/**
* Assign core alarms to the root category.
*
* @see LaserCoreFaultState
* @see LaserCoreFaultCodes
*/
private void assignCategoryOfCoreAlarms() {
String[] coreIds = LaserCoreFaultState.getCoreAlarmIds();
Category rootCategory = getCategoryByPath("ROOT");
assignCategoryToAlarms(rootCategory, LaserCoreFaultState.FaultFamily);
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOTest method testGetRoot.
/**
* Get the ROOT category
*/
public void testGetRoot() throws Exception {
Category root = categoryDAO.getCategoryByPath("ROOT");
assertNotNull("Found a null ROOT category", root);
// The ROOT has a null parentID
assertNull("The parentID of ROOT is not null", root.getParentId());
// Check the name and the path
assertEquals(root.getName(), "ROOT");
assertEquals(root.getPath(), "ROOT");
// ROOT is not a Leaf
assertFalse("ROOT is not a leaf", root.isLeaf());
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method getAlarms.
public String[] getAlarms(Integer categoryId) {
Category c = getCategory(categoryId);
if (c == null)
return new String[0];
Set ids = ((CategoryImpl) c).getAlarmIds();
String[] result = new String[ids.size()];
ids.toArray(result);
return result;
}
Aggregations