Search in sources :

Example 1 with DS

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

the class NewtsConverterTest method cantConvertOutOfRangeCounterToSample.

@Test(expected = IllegalArgumentException.class)
public void cantConvertOutOfRangeCounterToSample() {
    Resource resource = new Resource("resource", Optional.absent());
    DS ds = new DS();
    ds.setType(DSType.COUNTER);
    Timestamp timestamp = Timestamp.fromEpochSeconds(0);
    NewtsConverter.toSample(ds, resource, timestamp, Double.MAX_VALUE);
}
Also used : Resource(org.opennms.newts.api.Resource) Timestamp(org.opennms.newts.api.Timestamp) DS(org.opennms.netmgt.rrd.model.v3.DS) Test(org.junit.Test)

Example 2 with DS

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

the class NewtsConverterTest method canConvertCounterToSample.

public void canConvertCounterToSample() {
    Resource resource = new Resource("resource", Optional.absent());
    DS ds = new DS();
    ds.setType(DSType.COUNTER);
    Timestamp timestamp = Timestamp.fromEpochSeconds(0);
    NewtsConverter.toSample(ds, resource, timestamp, UnsignedLong.MAX_VALUE.doubleValue());
}
Also used : Resource(org.opennms.newts.api.Resource) Timestamp(org.opennms.newts.api.Timestamp) DS(org.opennms.netmgt.rrd.model.v3.DS)

Example 3 with DS

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

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

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

the class RRDv3IT method parseRrdWithComputedDs.

/**
     * Parses the RRD with computed DS.
     *
     * @throws Exception the exception
     */
@Test
public void parseRrdWithComputedDs() throws Exception {
    RRDv3 rrd = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-dump-compute-ds.xml"));
    Assert.assertNotNull(rrd);
}
Also used : RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) File(java.io.File) Test(org.junit.Test)

Aggregations

RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)3 Test (org.junit.Test)2 RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)2 DS (org.opennms.netmgt.rrd.model.v3.DS)2 Resource (org.opennms.newts.api.Resource)2 Timestamp (org.opennms.newts.api.Timestamp)2 File (java.io.File)1