Search in sources :

Example 6 with Category

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;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Category(cern.laser.business.data.Category) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition) HashSet(java.util.HashSet) Categories(alma.acs.alarmsystem.generated.Categories) NodeList(org.w3c.dom.NodeList) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) CategoryImpl(cern.laser.business.data.CategoryImpl) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 7 with Category

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());
            }
        }
    }
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) MalformedURLException(java.net.MalformedURLException) SourceDefinition(cern.laser.business.definition.data.SourceDefinition) Category(cern.laser.business.data.Category) URL(java.net.URL) Source(cern.laser.business.data.Source) InputSource(org.xml.sax.InputSource) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) HashSet(java.util.HashSet) FaultMember(alma.acs.alarmsystem.generated.FaultMember) Triplet(cern.laser.business.data.Triplet) Contact(alma.acs.alarmsystem.generated.Contact) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) AlarmImpl(cern.laser.business.data.AlarmImpl) Location(cern.laser.business.data.Location)

Example 8 with Category

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);
}
Also used : Category(cern.laser.business.data.Category)

Example 9 with Category

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());
}
Also used : Category(cern.laser.business.data.Category)

Example 10 with Category

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;
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) Category(cern.laser.business.data.Category) HashSet(java.util.HashSet) Set(java.util.Set)

Aggregations

Category (cern.laser.business.data.Category)47 Alarm (cern.laser.business.data.Alarm)16 CategoryImpl (cern.laser.business.data.CategoryImpl)14 HashSet (java.util.HashSet)9 AdminUser (cern.laser.business.data.AdminUser)8 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)8 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)7 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)7 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)7 CategoryDefinition (alma.alarmsystem.alarmmessage.generated.CategoryDefinition)6 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)6 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)6 Source (cern.laser.business.data.Source)6 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)5 AlarmCategoryDefinitions (alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions)4 AlarmCategoryLinkDefinitionListType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType)4 AlarmCategoryLinkType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType)4 AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)4 AlarmImpl (cern.laser.business.data.AlarmImpl)4 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)4