/** * Create the instance of the CategoryModel. */ private CategoryModel() throws IOException { CategoryFactory.init(); m_factory = CategoryFactory.getInstance(); LOG.debug("The CategoryModel object was created"); }
/** * Load the config from the default config file and create the singleton * instance of this factory. * * @exception java.io.IOException * Thrown if the specified config file cannot be read * @throws java.io.IOException if any. */ public static synchronized void init() throws IOException { if (m_loaded) { // init already called - return // to reload, reload() will need to be called return; } final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.CATEGORIES_CONF_FILE_NAME); setInstance(new CategoryFactory(cfgFile.getPath())); }
/** * {@inheritDoc} * * Return the normal value for the specified category. */ @Override public double getNormal(final String catlabel) { final Category cat = getCategory(catlabel); return (cat == null? -1.0 : cat.getNormalThreshold()); }
@Override protected void setUp() throws Exception { super.setUp(); m_mockCatFactory = new MockCategoryFactory(MOCK_CATEGORY_CONFIG); CategoryFactory.setInstance(m_mockCatFactory); m_catFactory = CategoryFactory.getInstance(); }
/** {@inheritDoc} */ @Override public Category getCategoryByLabel(String label) { return CategoryFactory.getInstance().getCategory(label); }
/** * Reload the config from the default config file * * @exception java.io.IOException * Thrown if the specified config file cannot be read/loaded * @throws java.io.IOException if any. */ public static synchronized void reload() throws IOException { m_singleton = null; m_loaded = false; init(); }
/** * Add a categorygroup. * * @param group * category group to be added */ public void addCategoryGroup(final CategoryGroup group) { try { getWriteLock().lock(); m_config.addCategoryGroup(group); } finally { getWriteLock().unlock(); } }
/** * Return the categories configuration. * * @return the categories configuration */ @Override public Catinfo getConfig() { try { getReadLock().lock(); return m_config; } finally { getReadLock().unlock(); } }
/** {@inheritDoc} */ @Override public Category getCategoryByLabel(String label) { return CategoryFactory.getInstance().getCategory(label); }
/** * <p>Constructor for DefaultCategoryConfigDao.</p> */ public DefaultCategoryConfigDao() { try { CategoryFactory.init(); } catch (FileNotFoundException e) { throw new DataRetrievalFailureException("Unable to locate categories file", e); } catch (IOException e) { throw new DataRetrievalFailureException("Error load categories file", e); } }
/** * Delete a categorygroup. * * @param groupname * category group to be removed * @return true if categorygroup is successfully deleted */ public boolean deleteCategoryGroup(final String groupname) { try { getWriteLock().lock(); return m_config.removeCategoryGroup(groupname); } finally { getWriteLock().unlock(); } }
/** * {@inheritDoc} * * Return the category specified by name. */ @Override public Category getCategory(final String name) { try { getReadLock().lock(); for (final CategoryGroup cg: m_config.getCategoryGroups()) { for (final Category cat : cg.getCategories()) { if (cat.getLabel().equals(name)) { return cat; } } } } finally { getReadLock().unlock(); } return null; }
/** * Create the instance of the CategoryModel. */ private CategoryModel() throws IOException { CategoryFactory.init(); m_factory = CategoryFactory.getInstance(); LOG.debug("The CategoryModel object was created"); }
/** * <p>findAll</p> * * @return a {@link java.util.Collection} object. */ @Override public Collection<Category> findAll() { List<Category> catList = new ArrayList<>(); Catinfo catInfo = CategoryFactory.getInstance().getConfig(); List<CategoryGroup> catGroupList = catInfo.getCategoryGroups(); if (catGroupList != null) { for (final CategoryGroup cg : catGroupList) { catList.addAll(cg.getCategories()); } } return catList; } }
/** * <p>Constructor for DefaultCategoryConfigDao.</p> */ public DefaultCategoryConfigDao() { try { CategoryFactory.init(); } catch (FileNotFoundException e) { throw new DataRetrievalFailureException("Unable to locate categories file", e); } catch (IOException e) { throw new DataRetrievalFailureException("Error load categories file", e); } }
CategoryFactory.setInstance(new CategoryFactory(categoryResource));
/** * Delete a categorygroup. * * @param group * category group to be removed * @return true if categorygroup is successfully deleted */ public boolean deleteCategoryGroup(final CategoryGroup group) { try { getWriteLock().lock(); return m_config.removeCategoryGroup(group); } finally { getWriteLock().unlock(); } }
/** * {@inheritDoc} * * Return the warning value for the specified category. */ @Override public double getWarning(final String catlabel) { final Category cat = getCategory(catlabel); return (cat == null? -1.0 : cat.getWarningThreshold()); }
/** * {@inheritDoc} * * Return the effective rule for the specified category. The category rule * ANDed with the rule of the category group that the category belongs to. */ @Override public String getEffectiveRule(final String catlabel) { try { getReadLock().lock(); for (final CategoryGroup cg : m_config.getCategoryGroups()) { for (final Category cat : cg.getCategories()) { if (cat.getLabel().equals(catlabel)) { return "(" + cg.getCommon().getRule() + ") & (" + cat.getRule() + ")"; } } } } finally { getReadLock().unlock(); } return null; }
/** * Creates the categories map. Reads the categories from the categories.xml * and creates the 'RTCCategory's map */ public static HashMap<String, RTCCategory> createCategoriesMap() { CatFactory cFactory = null; try { CategoryFactory.init(); cFactory = CategoryFactory.getInstance(); } catch (IOException ex) { LOG.error("Failed to load categories information", ex); throw new UndeclaredThrowableException(ex); } HashMap<String, RTCCategory> retval = new HashMap<String, RTCCategory>(); cFactory.getReadLock().lock(); try { for (CategoryGroup cg : cFactory.getConfig().getCategoryGroups()) { final String commonRule = cg.getCommon().getRule(); for (final org.opennms.netmgt.config.categories.Category cat : cg.getCategories()) { RTCCategory rtcCat = new RTCCategory(cat, commonRule); retval.put(rtcCat.getLabel(), rtcCat); } } } finally { cFactory.getReadLock().unlock(); } return retval; }