Search in sources :

Example 1 with RRDv1

use of org.opennms.netmgt.rrd.model.v1.RRDv1 in project opennms by OpenNMS.

the class RrdConvertUtils method convertFromJrobinToRrd.

/**
     * Convert from JRobin to RRDtool.
     *
     * @param sourceJrobinFile the source JRobin file
     * @param targetRrdFile the target RRDtool file
     * @throws IOException Signals that an I/O exception has occurred.
     * @throws RrdException the RRD exception
     */
public static void convertFromJrobinToRrd(File sourceJrobinFile, File targetRrdFile) throws IOException, RrdException {
    RRDv1 jrb = dumpJrb(sourceJrobinFile);
    RRDv3 rrd = convert(jrb);
    restoreRrd(rrd, targetRrdFile);
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3)

Example 2 with RRDv1

use of org.opennms.netmgt.rrd.model.v1.RRDv1 in project opennms by OpenNMS.

the class NMS6369IT method testJrobinParse.

/**
     * Test JRobin parse.
     *
     * @throws Exception the exception
     */
@Test
public void testJrobinParse() throws Exception {
    RRDv1 rrd = RrdConvertUtils.dumpJrb(new File("src/test/resources/mib2-interfaces.jrb"));
    Assert.assertNotNull(rrd);
    File target = new File("target/mib2-interfaces.jrb");
    RrdConvertUtils.restoreJrb(rrd, target);
    Assert.assertTrue(target.exists());
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) File(java.io.File) Test(org.junit.Test)

Example 3 with RRDv1

use of org.opennms.netmgt.rrd.model.v1.RRDv1 in project opennms by OpenNMS.

the class RRDv1IT method testMerge.

/**
     * Test merge.
     *
     * @throws Exception the exception
     */
@Test
public void testMerge() throws Exception {
    File sourceFile = new File("src/test/resources/rrd-temp-multids-jrb.xml");
    File targetFile = new File("target/multimetric.xml");
    RRDv1 multimetric = JaxbUtils.unmarshal(RRDv1.class, sourceFile);
    Assert.assertNotNull(multimetric);
    Assert.assertEquals("tempA", multimetric.getDataSource(0).getName());
    Assert.assertEquals("tempB", multimetric.getDataSource(1).getName());
    multimetric.getRras().stream().flatMap(rra -> rra.getRows().stream()).forEach(row -> {
        List<Double> values = new ArrayList<Double>();
        row.getValues().forEach(d -> values.add(Double.NaN));
        row.setValues(values);
    });
    List<RRDv1> singleMetricArray = new ArrayList<RRDv1>();
    RRDv1 tempA = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/rrd-tempA-jrb.xml"));
    Assert.assertNotNull(tempA);
    Assert.assertEquals("tempA", tempA.getDataSource(0).getName());
    singleMetricArray.add(tempA);
    RRDv1 tempB = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/rrd-tempB-jrb.xml"));
    Assert.assertNotNull(tempB);
    Assert.assertEquals("tempB", tempB.getDataSource(0).getName());
    singleMetricArray.add(tempB);
    multimetric.merge(singleMetricArray);
    JaxbUtils.marshal(multimetric, new FileWriter(targetFile));
    Assert.assertTrue(FileUtils.contentEquals(sourceFile, targetFile));
    targetFile.delete();
}
Also used : List(java.util.List) FileWriter(java.io.FileWriter) JaxbUtils(org.opennms.core.xml.JaxbUtils) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) CFType(org.opennms.netmgt.rrd.model.v1.CFType) DSType(org.opennms.netmgt.rrd.model.v1.DSType) Assert(org.junit.Assert) File(java.io.File) ArrayList(java.util.ArrayList) RRA(org.opennms.netmgt.rrd.model.v1.RRA) RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 4 with RRDv1

use of org.opennms.netmgt.rrd.model.v1.RRDv1 in project opennms by OpenNMS.

the class RRDv1IT method testSplit.

/**
     * Test split and merge
     *
     * @throws Exception the exception
     */
@Test
public void testSplit() throws Exception {
    RRDv1 masterRrd = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/jrb-dump.xml"));
    Assert.assertNotNull(masterRrd);
    List<AbstractRRD> rrds = masterRrd.split();
    Assert.assertEquals(masterRrd.getDataSources().size(), rrds.size());
    RRA masterRRA = masterRrd.getRras().get(0);
    for (int i = 0; i < rrds.size(); i++) {
        RRDv1 singleRRD = (RRDv1) rrds.get(i);
        Assert.assertEquals(1, singleRRD.getDataSources().size());
        Assert.assertEquals(masterRrd.getDataSource(i).getName(), singleRRD.getDataSource(0).getName());
        RRA singleRRA = singleRRD.getRras().get(0);
        Assert.assertEquals(1, singleRRA.getDataSources().size());
        Assert.assertEquals(masterRRA.getPdpPerRow(), singleRRA.getPdpPerRow());
        Assert.assertEquals(masterRRA.getRows().size(), singleRRA.getRows().size());
        Assert.assertEquals(masterRRA.getConsolidationFunction().name(), singleRRA.getConsolidationFunction().name());
        for (int j = 0; j < masterRRA.getRows().size(); j++) {
            Row masterRow = masterRRA.getRows().get(j);
            Row row = singleRRA.getRows().get(j);
            Assert.assertEquals(1, row.getValues().size());
            Assert.assertEquals(masterRow.getValues().get(i), row.getValues().get(0));
            masterRow.getValues().set(i, Double.NaN);
        }
    }
    int dsIndex = 3;
    masterRrd.merge(rrds);
    for (int j = 0; j < masterRRA.getRows().size(); j++) {
        Row masterRow = masterRRA.getRows().get(j);
        Row row = rrds.get(dsIndex).getRras().get(0).getRows().get(j);
        Assert.assertEquals(1, row.getValues().size());
        Assert.assertEquals(masterRow.getValues().get(dsIndex), row.getValues().get(0));
    }
}
Also used : RRA(org.opennms.netmgt.rrd.model.v1.RRA) RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) File(java.io.File) Test(org.junit.Test)

Example 5 with RRDv1

use of org.opennms.netmgt.rrd.model.v1.RRDv1 in project opennms by OpenNMS.

the class RrdConvertUtilsIT method testJrobinRestore.

/**
     * Test JRobin restore.
     *
     * @throws Exception the exception
     */
@Test
public void testJrobinRestore() throws Exception {
    RRDv1 jrb = RrdConvertUtils.dumpJrb(new File("src/test/resources/tempA.jrb"));
    File target = new File("target/tempA-converted.jrb");
    RrdConvertUtils.restoreJrb(jrb, target);
    Assert.assertTrue(target.exists());
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) File(java.io.File) Test(org.junit.Test)

Aggregations

RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)18 File (java.io.File)13 Test (org.junit.Test)11 RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)8 ArrayList (java.util.ArrayList)3 RRA (org.opennms.netmgt.rrd.model.v1.RRA)2 FileWriter (java.io.FileWriter)1 List (java.util.List)1 FileUtils (org.apache.commons.io.FileUtils)1 RrdDb (org.jrobin.core.RrdDb)1 Assert (org.junit.Assert)1 JaxbUtils (org.opennms.core.xml.JaxbUtils)1 AbstractDS (org.opennms.netmgt.rrd.model.AbstractDS)1 Row (org.opennms.netmgt.rrd.model.Row)1 CFType (org.opennms.netmgt.rrd.model.v1.CFType)1 DSType (org.opennms.netmgt.rrd.model.v1.DSType)1