Search in sources :

Example 6 with RRA

use of org.opennms.netmgt.rrd.model.v3.RRA 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 7 with RRA

use of org.opennms.netmgt.rrd.model.v3.RRA 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 8 with RRA

use of org.opennms.netmgt.rrd.model.v3.RRA in project opennms by OpenNMS.

the class RRDv3IT method testSplit.

/**
 * Test split and merge
 *
 * @throws Exception the exception
 */
@Test
public void testSplit() throws Exception {
    RRDv3 masterRrd = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-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++) {
        RRDv3 singleRRD = (RRDv3) 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.v3.RRA) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) AbstractRRD(org.opennms.netmgt.rrd.model.AbstractRRD) Row(org.opennms.netmgt.rrd.model.Row) File(java.io.File) Test(org.junit.Test)

Example 9 with RRA

use of org.opennms.netmgt.rrd.model.v3.RRA in project opennms by OpenNMS.

the class RrdMergeIT method testRrdMerge.

/**
 * Test RRD merge.
 * <p>Both test XML contains data from different range of times, and the value is always increasing.</p>
 *
 * @throws Exception the exception
 */
@Test
public void testRrdMerge() throws Exception {
    RRDv3 tempA = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-tempA-rrd.xml"));
    RRDv3 tempB = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-tempB-rrd.xml"));
    // Retrieve a list of the time stamps of the rows with data from tempA.rrd
    // Verify the max value
    Double value = Double.NEGATIVE_INFINITY;
    List<Long> timestampsA = new ArrayList<>();
    for (RRA rra : tempA.getRras()) {
        for (Row row : rra.getRows()) {
            if (!row.isNan()) {
                timestampsA.add(tempA.findTimestampByRow(rra, row));
                Double current = row.getValues().get(0);
                if (current > value) {
                    value = current;
                }
            }
        }
    }
    Assert.assertEquals(new Double(3.0), value);
    // Retrieve a list of the time stamps of the rows with data from tempB.rrd
    value = Double.NEGATIVE_INFINITY;
    List<Long> timestampsB = new ArrayList<>();
    for (RRA rra : tempB.getRras()) {
        for (Row row : rra.getRows()) {
            if (!row.isNan()) {
                timestampsB.add(tempB.findTimestampByRow(rra, row));
                Double current = row.getValues().get(0);
                if (current > value) {
                    value = current;
                }
            }
        }
    }
    Assert.assertEquals(new Double(18.0), value);
    // Verify that all the timestamps on timestampsA are different than the timestamps from timestampsB
    for (Long l : timestampsA) {
        if (timestampsB.contains(l)) {
            Assert.fail("The timestampsB should not contain any timestamp from timestampsA");
        }
    }
    for (Long l : timestampsB) {
        if (timestampsA.contains(l)) {
            Assert.fail("The timestampsA should not contain any timestamp from timestampsB");
        }
    }
    // Perform the Merge Operation, merging the data from tempA.rrd to tempB.rrd
    tempB.merge(tempA);
    // Retrieve the list of the non NaN rows from the updated tempB.rrd
    value = Double.NEGATIVE_INFINITY;
    List<Long> timestampsFinal = new ArrayList<>();
    for (RRA rra : tempB.getRras()) {
        for (Row row : rra.getRows()) {
            if (!row.isNan()) {
                timestampsFinal.add(tempB.findTimestampByRow(rra, row));
                Double current = row.getValues().get(0);
                if (current > value) {
                    value = current;
                }
            }
        }
    }
    Assert.assertEquals(new Double(18.0), value);
    // Verify that timestampsFinal contains timestampsA and timestampsB
    Assert.assertTrue(timestampsFinal.containsAll(timestampsA));
    Assert.assertTrue(timestampsFinal.containsAll(timestampsB));
}
Also used : RRA(org.opennms.netmgt.rrd.model.v3.RRA) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) ArrayList(java.util.ArrayList) Row(org.opennms.netmgt.rrd.model.Row) File(java.io.File) Test(org.junit.Test)

Aggregations

RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)7 File (java.io.File)6 Test (org.junit.Test)6 RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)4 ArrayList (java.util.ArrayList)3 Row (org.opennms.netmgt.rrd.model.Row)3 List (java.util.List)2 RRA (org.opennms.netmgt.rrd.model.v1.RRA)2 RRA (org.opennms.netmgt.rrd.model.v3.RRA)2 FileWriter (java.io.FileWriter)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 SortedMap (java.util.SortedMap)1 FileUtils (org.apache.commons.io.FileUtils)1 Assert (org.junit.Assert)1 JaxbUtils (org.opennms.core.xml.JaxbUtils)1 AbstractRRD (org.opennms.netmgt.rrd.model.AbstractRRD)1 CFType (org.opennms.netmgt.rrd.model.v1.CFType)1 DSType (org.opennms.netmgt.rrd.model.v1.DSType)1