use of org.opennms.netmgt.rrd.model.Row in project opennms by OpenNMS.
the class NodeLevelDataWithRrdtoolTest method validateRrd.
/**
* Validates a RRD.
* <p>It assumes storeByGroup=true</p>
*
* @param file the RRD file instance
* @param dsnames the array of data source names
* @param dsvalues the array of data source values
* @throws Exception the exception
*/
protected void validateRrd(File file, String[] dsnames, Double[] dsvalues) throws Exception {
Assert.assertTrue(file.exists());
RRDv3 rrd = RrdConvertUtils.dumpRrd(file);
Assert.assertEquals(dsnames.length, rrd.getDataSources().size());
for (int i = 0; i < dsnames.length; i++) {
Assert.assertEquals(dsvalues[i], Double.valueOf(rrd.getDataSource(i).getLastDs()));
List<Row> rows = rrd.getRras().get(0).getRows();
// All the last values stored on the RRA must be valid numbers
Assert.assertFalse(rows.get(rows.size() - 1).isNan());
}
}
use of org.opennms.netmgt.rrd.model.Row in project opennms by OpenNMS.
the class SnmpInterfaceRrdMigratorOnlineTest method testUpgrade.
/**
* Test upgrade.
*
* @throws Exception the exception
*/
@Test
public void testUpgrade() throws Exception {
// Check Current JRBs
RRDv1 rrd = RrdConvertUtils.dumpJrb(new File("target/home/rrd/1/eth0/ifInOctets.jrb"));
Row r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381500900l);
Assert.assertNotNull(r);
Assert.assertEquals(new Double(-6.0), r.getValues().get(0));
r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381512300l);
Assert.assertNull(r);
rrd = RrdConvertUtils.dumpJrb(new File("target/home/rrd/1/eth0-005056c00008/ifInOctets.jrb"));
r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381500900l);
Assert.assertNotNull(r);
Assert.assertTrue(r.getValues().get(0).isNaN());
r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381512300l);
Assert.assertNotNull(r);
Assert.assertEquals(new Double(12.0), r.getValues().get(0));
// Perform Migration
SnmpInterfaceRrdMigratorOnline obj = new SnmpInterfaceRrdMigratorOnline() {
protected List<SnmpInterfaceUpgrade> getInterfacesToMerge() throws OnmsUpgradeException {
List<SnmpInterfaceUpgrade> interfaces = new ArrayList<>();
interfaces.add(new SnmpInterfaceUpgrade(1, null, null, "eth0", "eth0", "005056c00008", false));
return interfaces;
}
};
obj.preExecute();
obj.execute();
obj.postExecute();
// Verify if the backups have been removed
Assert.assertFalse(new File("target/home/rrd/1/eth0.zip").exists());
Assert.assertFalse(new File("target/home/rrd/1/eth0-005056c00008.zip").exists());
// Check Merged JRB
rrd = RrdConvertUtils.dumpJrb(new File("target/home/rrd/1/eth0-005056c00008/ifInOctets.jrb"));
r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381500900l);
Assert.assertNotNull(r);
Assert.assertEquals(new Double(-6.0), r.getValues().get(0));
r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381512300l);
Assert.assertNotNull(r);
Assert.assertEquals(new Double(12.0), r.getValues().get(0));
}
use of org.opennms.netmgt.rrd.model.Row 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));
}
}
use of org.opennms.netmgt.rrd.model.Row 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));
}
Aggregations