/** * <p>getDefaultFileExtension</p> * * @return a {@link java.lang.String} object. */ @Override public String getDefaultFileExtension() { return m_delegate.getDefaultFileExtension(); }
/** * <p>closeFile</p> * * @param rrd a {@link java.util.List} object. * @throws java.lang.Exception if any. */ @Override public void closeFile(List<Object> rrd) throws Exception { for (int i = 0; i < rrd.size(); i++) { m_strategies.get(i).closeFile(rrd.get(i)); } }
/** {@inheritDoc} */ @Override public CreateOperation createDefinition(String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList) throws Exception { String fileName = directory + File.separator + rrdName + m_delegate.getDefaultFileExtension(); Object def = m_delegate.createDefinition(creator, directory, rrdName, step, dataSources, rraList); return makeCreateOperation(fileName, def); }
params.put("rrd-base-name", "smtp-base"); EasyMock.expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".jrb").atLeastOnce(); m_rrdStrategy.createDefinition(EasyMock.eq("192.168.1.5"), EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime).toString()), EasyMock.eq("smtp-base"), EasyMock.expectLastCall().andReturn(null).once(); m_rrdStrategy.createFile(EasyMock.anyObject()); EasyMock.expectLastCall().once(); m_rrdStrategy.openFile(EasyMock.eq(getResponseTimeRoot().toPath() .resolve(pathToResourceInResponseTime.resolve("smtp-base.jrb")).toString())); EasyMock.expectLastCall().andReturn(null).once(); m_rrdStrategy.updateFile(EasyMock.isNull(), EasyMock.eq("192.168.1.5"), EasyMock.endsWith(":42.1:1:2:3")); EasyMock.expectLastCall().once();
@Test @Transactional @JUnitCollector( datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config.xml", datacollectionType = "snmp", anticipateRrds = { "test" }, anticipateMetaFiles = false ) public void testUsingFetch() throws Exception { System.err.println("=== testUsingFetch ==="); File snmpDir = (File)m_context.getAttribute("rrdDirectory"); // We initialize an empty attribute map, key=e.g OID; value=e.g. datasource name Map<String,String> attributeMappings = new HashMap<String, String>(); int stepSize = 1; int numUpdates = 2; long start = System.currentTimeMillis(); final int stepSizeInMillis = stepSize*1000; final int rangeSizeInMillis = stepSizeInMillis + 20000; File rrdFile = new File(snmpDir, rrd("test")); RrdStrategy<RrdDef,RrdDb> m_rrdStrategy = new JRobinRrdStrategy(); RrdDataSource rrdDataSource = new RrdDataSource("testAttr", RrdAttributeType.GAUGE, stepSize*2, "U", "U"); RrdDef def = m_rrdStrategy.createDefinition("test", snmpDir.getAbsolutePath(), "test", stepSize, Collections.singletonList(rrdDataSource), Collections.singletonList("RRA:AVERAGE:0.5:1:100")); m_rrdStrategy.createFile(def); RrdDb rrdFileObject = m_rrdStrategy.openFile(rrdFile.getAbsolutePath()); for (int i = 0; i < numUpdates; i++) { m_rrdStrategy.updateFile(rrdFileObject, "test", ((start/1000) - (stepSize*(numUpdates-i))) + ":1"); } m_rrdStrategy.closeFile(rrdFileObject); assertEquals(Double.valueOf(1.0), m_rrdStrategy.fetchLastValueInRange(rrdFile.getAbsolutePath(), "testAttr", stepSizeInMillis, rangeSizeInMillis)); }
String rrdFile = repositoryDir + File.separator + rrdName + rrdStrategy.getDefaultFileExtension(); long time = (timestamp + 500L) / 1000L; Object rrd = null; try { rrd = strategy.openFile(rrdFile); strategy.updateFile(rrd, owner, updateVal); } catch (Throwable e) { LOG.error("updateRRD: Error updating RRD file {} with values '{}'", rrdFile, updateVal, e); try { if (rrd != null) { strategy.closeFile(rrd);
/** * <p>createRRD</p> * * @param creator a {@link java.lang.String} object. * @param directory a {@link java.lang.String} object. * @param rrdName a {@link java.lang.String} object. * @param step a int. * @param dataSources a {@link java.util.List} object. * @param rraList a {@link java.util.List} object. * @return a boolean. * @throws org.opennms.netmgt.rrd.RrdException if any. */ private static boolean createRRD(RrdStrategy<?, ?> rrdStrategy, String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList) throws RrdException { Object def = null; try { RrdStrategy<Object, Object> strategy = toGenericType(rrdStrategy); def = strategy.createDefinition(creator, directory, rrdName, step, dataSources, rraList); // def can be null if the rrd-db exists already, but doesn't have to be (see MultiOutput/QueuingRrdStrategy strategy.createFile(def); return true; } catch (Throwable e) { String path = directory + File.separator + rrdName + rrdStrategy.getDefaultFileExtension(); LOG.error("createRRD: An error occurred creating rrdfile {}", path, e); throw new org.opennms.netmgt.rrd.RrdException("An error occurred creating rrdfile " + path + ": " + e, e); } }
@Override Object process(Object rrd) throws Exception { // open the file if we need to if (rrd == null) rrd = m_delegate.openFile(getFileName()); final String update = (String) getData(); try { // process the update m_delegate.updateFile(rrd, "", update); } catch (final Throwable e) { final String error = String.format("Error processing update for file %s: %s", getFileName(), update); m_log.debug(error, e); throw new Exception(error, e); } // keep stats setUpdatesCompleted(getUpdatesCompleted() + 1); if (getUpdatesCompleted() % m_modulus == 0) { logStats(); } // return the open rrd for further processing return rrd; }
/** {@inheritDoc} */ @Override public Double fetchLastValueInRange(String rrdFile, String ds, int interval, int range) throws NumberFormatException, RrdException { // TODO: handle queued values with fetch. Fetch could pull values off // the queue or force // an immediate file update. return m_delegate.fetchLastValueInRange(rrdFile, ds, interval, range); }
@Override Object process(Object rrd) throws Exception { // if the rrd is already open we are confused if (rrd != null) { m_log.debug("WHAT! rrd open but not created?"); m_delegate.closeFile(rrd); rrd = null; } // create the file m_delegate.createFile(getData()); // keep stats setCreatesCompleted(getCreatesCompleted() + 1); // return the file return rrd; }
/** {@inheritDoc} */ @Override public void createFile(List<Object> rrdDef) throws Exception { for (int i = 0; i < rrdDef.size(); i++) { m_strategies.get(i).createFile(rrdDef.get(i)); } }
/** {@inheritDoc} */ @Override public InputStream createGraph(String command, File workDir) throws IOException, RrdException { return m_delegate.createGraph(command, workDir); }
/** {@inheritDoc} */ @Override public RrdGraphDetails createGraphReturnDetails(String command, File workDir) throws IOException, RrdException { return m_delegate.createGraphReturnDetails(command, workDir); }
/** {@inheritDoc} */ @Override public void updateFile(List<Object> rrd, String owner, String data) throws Exception { for (int i = 0; i < rrd.size(); i++) { m_strategies.get(i).updateFile(rrd.get(i), owner, data); } } }
/** {@inheritDoc} */ @Override public List<Object> openFile(String fileName) throws Exception { List<Object> retval = new ArrayList<>(); for (RrdStrategy<Object, Object> strategy : m_strategies) { retval.add(strategy.openFile(fileName)); } return retval; }
/** {@inheritDoc} */ @Override public List<Object> createDefinition(String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList) throws Exception { List<Object> retval = new ArrayList<>(); for (RrdStrategy<Object, Object> strategy : m_strategies) { retval.add(strategy.createDefinition(creator, directory, rrdName, step, dataSources, rraList)); } return retval; }
expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".myLittleEasyMockedStrategyAndMe").anyTimes(); expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object()); m_rrdStrategy.createFile(isA(Object.class)); expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object()); m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), matches(".*:" + matchValue)); m_rrdStrategy.closeFile(isA(Object.class));
String rrdFile = repositoryDir + File.separator + rrdName + rrdStrategy.getDefaultFileExtension(); long time = (timestamp + 500L) / 1000L; Object rrd = null; try { rrd = strategy.openFile(rrdFile); strategy.updateFile(rrd, owner, updateVal); } catch (Throwable e) { LOG.error("updateRRD: Error updating RRD file {} with values '{}'", rrdFile, updateVal, e); try { if (rrd != null) { strategy.closeFile(rrd);
/** * <p>createRRD</p> * * @param creator a {@link java.lang.String} object. * @param directory a {@link java.lang.String} object. * @param rrdName a {@link java.lang.String} object. * @param step a int. * @param dataSources a {@link java.util.List} object. * @param rraList a {@link java.util.List} object. * @return a boolean. * @throws org.opennms.netmgt.rrd.RrdException if any. */ private static boolean createRRD(RrdStrategy<?, ?> rrdStrategy, String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList) throws RrdException { Object def = null; try { RrdStrategy<Object, Object> strategy = toGenericType(rrdStrategy); def = strategy.createDefinition(creator, directory, rrdName, step, dataSources, rraList); // def can be null if the rrd-db exists already, but doesn't have to be (see MultiOutput/QueuingRrdStrategy strategy.createFile(def); return true; } catch (Throwable e) { String path = directory + File.separator + rrdName + rrdStrategy.getDefaultFileExtension(); LOG.error("createRRD: An error occurred creating rrdfile {}", path, e); throw new org.opennms.netmgt.rrd.RrdException("An error occurred creating rrdfile " + path + ": " + e, e); } }
@Override Object process(Object rrd) throws Exception { // open the file if we need to if (rrd == null) rrd = m_delegate.openFile(getFileName()); final String update = (String) getData(); try { // process the update m_delegate.updateFile(rrd, "", update); } catch (final Throwable e) { final String error = String.format("Error processing update for file %s: %s", getFileName(), update); m_log.debug(error, e); throw new Exception(error, e); } // keep stats setUpdatesCompleted(getUpdatesCompleted() + 1); if (getUpdatesCompleted() % m_modulus == 0) { logStats(); } // return the open rrd for further processing return rrd; }