use of org.opennms.netmgt.rrd.model.v1.RRA 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();
}
use of org.opennms.netmgt.rrd.model.v1.RRA 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));
}
}
use of org.opennms.netmgt.rrd.model.v1.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;
}
use of org.opennms.netmgt.rrd.model.v1.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;
}
use of org.opennms.netmgt.rrd.model.v1.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<Long>();
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<Long>();
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<Long>();
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