Search in sources :

Example 11 with RRDv1

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

the class RrdConvertUtils method convert.

/**
 * Converts a RRDtool object into a JRobin object.
 *
 * @param rrd the RRDtool object representation
 * @return the JRobin object representation
 * @throws IllegalArgumentException the illegal argument exception (when the conversion is not possible)
 */
protected static RRDv1 convert(RRDv3 rrd) throws IllegalArgumentException {
    RRDv1 jrb = new RRDv1();
    jrb.setStep(rrd.getStep());
    jrb.setLastUpdate(rrd.getLastUpdate());
    for (org.opennms.netmgt.rrd.model.v3.RRA rrav3 : rrd.getRras()) {
        org.opennms.netmgt.rrd.model.v1.RRA rrav1 = new org.opennms.netmgt.rrd.model.v1.RRA();
        try {
            rrav1.setConsolidationFunction(rrav3.getConsolidationFunction().name());
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("RRDv1 doesn't support the consolidation function " + rrav3.getConsolidationFunction().value());
        }
        rrav1.setPdpPerRow(rrav3.getPdpPerRow());
        rrav1.setRows(rrav3.getRows());
        rrav1.setXff(rrav3.getParameters().getXff());
        for (org.opennms.netmgt.rrd.model.v3.RRADS rradsv3 : rrav3.getDataSources()) {
            org.opennms.netmgt.rrd.model.v1.RRADS rradsv1 = new org.opennms.netmgt.rrd.model.v1.RRADS();
            rradsv1.setUnknownDataPoints(rradsv3.getUnknownDataPoints());
            rradsv1.setValue(rradsv3.getValue());
            rrav1.getDataSources().add(rradsv1);
        }
        jrb.addRRA(rrav1);
    }
    for (org.opennms.netmgt.rrd.model.v3.DS dsv3 : rrd.getDataSources()) {
        org.opennms.netmgt.rrd.model.v1.DS dsv1 = new org.opennms.netmgt.rrd.model.v1.DS();
        try {
            dsv1.setType(dsv3.getType().value());
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("RRDv1 doesn't support the data source type " + dsv3.getType().value());
        }
        dsv1.setName(dsv3.getName());
        dsv1.setLastDs(dsv3.getLastDs());
        dsv1.setMin(dsv3.getMax());
        dsv1.setMax(dsv3.getMax());
        dsv1.setMinHeartbeat(dsv3.getMinHeartbeat());
        dsv1.setUnknownSec(dsv3.getUnknownSec());
        dsv1.setValue(dsv3.getValue());
        jrb.addDataSource(dsv1);
    }
    return jrb;
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3)

Example 12 with RRDv1

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

the class RrdConvertUtils method convert.

/**
 * Converts a JRobin object into an RRDtool object.
 *
 * @param jrb the source JRobin object representation
 * @return the RRDtool object representation
 * @throws IllegalArgumentException the illegal argument exception (when the conversion is not possible)
 */
protected static RRDv3 convert(RRDv1 jrb) throws IllegalArgumentException {
    RRDv3 rrd = new RRDv3();
    rrd.setStep(jrb.getStep());
    rrd.setLastUpdate(jrb.getLastUpdate());
    for (org.opennms.netmgt.rrd.model.v1.RRA rrav1 : jrb.getRras()) {
        org.opennms.netmgt.rrd.model.v3.RRA rrav3 = new org.opennms.netmgt.rrd.model.v3.RRA();
        rrav3.setConsolidationFunction(rrav1.getConsolidationFunction().name());
        rrav3.setPdpPerRow(rrav1.getPdpPerRow());
        rrav3.setRows(rrav1.getRows());
        rrav3.getParameters().setXff(rrav1.getXff());
        for (org.opennms.netmgt.rrd.model.v1.RRADS rradsv1 : rrav1.getDataSources()) {
            org.opennms.netmgt.rrd.model.v3.RRADS rradsv3 = new org.opennms.netmgt.rrd.model.v3.RRADS();
            rradsv3.setUnknownDataPoints(rradsv1.getUnknownDataPoints());
            rradsv3.setValue(rradsv1.getValue());
            rrav3.getDataSources().add(rradsv3);
        }
        rrd.addRRA(rrav3);
    }
    for (org.opennms.netmgt.rrd.model.v1.DS dsv1 : jrb.getDataSources()) {
        org.opennms.netmgt.rrd.model.v3.DS dsv3 = new org.opennms.netmgt.rrd.model.v3.DS();
        dsv3.setName(dsv1.getName());
        dsv3.setLastDs(dsv1.getLastDs());
        dsv3.setMin(dsv1.getMax());
        dsv3.setMax(dsv1.getMax());
        dsv3.setMinHeartbeat(dsv1.getMinHeartbeat());
        dsv3.setUnknownSec(dsv1.getUnknownSec());
        dsv3.setValue(dsv1.getValue());
        dsv3.setType(dsv1.getType().value());
        rrd.addDataSource(dsv3);
    }
    return rrd;
}
Also used : RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3)

Example 13 with RRDv1

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

the class RrdConvertUtils method dumpJrb.

/**
 * Dumps a JRB.
 *
 * @param sourceFile the source file
 * @return the RRD Object (old version)
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws RrdException the RRD exception
 */
public static RRDv1 dumpJrb(File sourceFile) throws IOException, RrdException {
    RrdDb jrb = new RrdDb(sourceFile, true);
    RRDv1 rrd = JaxbUtils.unmarshal(RRDv1.class, jrb.getXml());
    jrb.close();
    return rrd;
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) RrdDb(org.jrobin.core.RrdDb)

Example 14 with RRDv1

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

the class RRDv1IT method parseRrdSimple.

/**
 * Parses a simple RRD.
 *
 * @throws Exception the exception
 */
@Test
public void parseRrdSimple() throws Exception {
    RRDv1 rrd = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/jrb-dump.xml"));
    Assert.assertNotNull(rrd);
    Assert.assertEquals(new Long(300), rrd.getStep());
    Assert.assertEquals(new Long(1233926670), rrd.getLastUpdate());
    // Test Data Source
    Assert.assertEquals("ifInDiscards", rrd.getDataSources().get(0).getName());
    Assert.assertEquals(DSType.COUNTER, rrd.getDataSources().get(0).getType());
    Assert.assertEquals(new Long(0), rrd.getDataSources().get(0).getUnknownSec());
    // Test RRA
    Assert.assertEquals(CFType.AVERAGE, rrd.getRras().get(0).getConsolidationFunction());
    Assert.assertEquals(new Long(1), rrd.getRras().get(0).getPdpPerRow());
    Assert.assertEquals(new Long(12), rrd.getRras().get(1).getPdpPerRow());
    Assert.assertEquals(new Long(288), rrd.getRras().get(4).getPdpPerRow());
    // Test time related functions : getEndTimestamp
    Assert.assertEquals(new Long(1233926400), rrd.getEndTimestamp(rrd.getRras().get(0)));
    Assert.assertEquals(new Long(1233925200), rrd.getEndTimestamp(rrd.getRras().get(1)));
    Assert.assertEquals(new Long(1233878400), rrd.getEndTimestamp(rrd.getRras().get(4)));
    // Test time related functions : getStartTimestamp
    Assert.assertEquals(new Long(1233321900), rrd.getStartTimestamp(rrd.getRras().get(0)));
    Assert.assertEquals(new Long(1228572000), rrd.getStartTimestamp(rrd.getRras().get(1)));
    Assert.assertEquals(new Long(1202342400), rrd.getStartTimestamp(rrd.getRras().get(4)));
    // Test time related functions : findRowByTimestamp
    AbstractRRA rra = rrd.getRras().get(0);
    Assert.assertEquals(rra.getRows().get(0), rrd.findRowByTimestamp(rra, new Long(1233321900)));
    Assert.assertEquals(rra.getRows().get(5), rrd.findRowByTimestamp(rra, new Long(1233323400)));
    // Test time related functions : findTimestampByRow
    Assert.assertEquals(new Long(1233321900), rrd.findTimestampByRow(rra, rra.getRows().get(0)));
    Assert.assertEquals(new Long(1233323400), rrd.findTimestampByRow(rra, rra.getRows().get(5)));
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) File(java.io.File) Test(org.junit.Test)

Example 15 with RRDv1

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

the class RrdConvertUtilsIT method testConvertAdvRrdIntoJrb2.

/**
 * Test convert Advanced RRD into JRB (2).
 *
 * @throws Exception the exception
 */
@Test(expected = IllegalArgumentException.class)
public void testConvertAdvRrdIntoJrb2() throws Exception {
    RRDv3 rrd = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-dump-aberrant-behavior-detection.xml"));
    RRDv1 jrb = RrdConvertUtils.convert(rrd);
    Assert.assertNull(jrb);
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) 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