Search in sources :

Example 11 with RRDv3

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

the class RrdConvertUtilsIT method testConvertJrbIntoRrd.

/**
 * Test convert JRB into RRD.
 *
 * @throws Exception the exception
 */
@Test
public void testConvertJrbIntoRrd() throws Exception {
    RRDv1 jrb = RrdConvertUtils.dumpJrb(new File("src/test/resources/tempA.jrb"));
    RRDv3 rrd = RrdConvertUtils.convert(jrb);
    Assert.assertNotNull(rrd);
}
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)

Example 12 with RRDv3

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

the class RrdConvertUtils method dumpRrd.

/**
 * Dumps a RRD.
 *
 * @param sourceFile the source file
 * @return the RRD Object
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws RrdException the RRD exception
 */
public static RRDv3 dumpRrd(File sourceFile) throws IOException, RrdException {
    String rrdBinary = System.getProperty("rrd.binary");
    if (rrdBinary == null) {
        throw new IllegalArgumentException("rrd.binary property must be set");
    }
    try {
        XMLReader xmlReader = XMLReaderFactory.createXMLReader();
        xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        Process process = Runtime.getRuntime().exec(new String[] { rrdBinary, "dump", sourceFile.getAbsolutePath() });
        SAXSource source = new SAXSource(xmlReader, new InputSource(new InputStreamReader(process.getInputStream())));
        JAXBContext jc = JAXBContext.newInstance(RRDv3.class);
        Unmarshaller u = jc.createUnmarshaller();
        return (RRDv3) u.unmarshal(source);
    } catch (Exception e) {
        throw new RrdException("Can't parse RRD Dump", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) InputStreamReader(java.io.InputStreamReader) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) JAXBContext(javax.xml.bind.JAXBContext) RrdException(org.jrobin.core.RrdException) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) IOException(java.io.IOException) RrdException(org.jrobin.core.RrdException)

Example 13 with RRDv3

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

the class RrdConvertUtils method convertFromRrdToJrobin.

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

Example 14 with RRDv3

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

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

Aggregations

RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)21 File (java.io.File)15 Test (org.junit.Test)14 RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)8 ArrayList (java.util.ArrayList)5 Row (org.opennms.netmgt.rrd.model.Row)4 List (java.util.List)3 RRA (org.opennms.netmgt.rrd.model.v3.RRA)3 FileWriter (java.io.FileWriter)2 Map (java.util.Map)2 NavigableMap (java.util.NavigableMap)2 SortedMap (java.util.SortedMap)2 AbstractRRD (org.opennms.netmgt.rrd.model.AbstractRRD)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 SAXSource (javax.xml.transform.sax.SAXSource)1 FileUtils (org.apache.commons.io.FileUtils)1 RrdException (org.jrobin.core.RrdException)1