Search in sources :

Example 16 with CollectionSetVisitor

use of org.opennms.netmgt.collection.api.CollectionSetVisitor in project opennms by OpenNMS.

the class MockCollectionResource method visit.

@Override
public void visit(CollectionSetVisitor visitor) {
    for (Entry<String, String> entry : attributes.entrySet()) {
        final CollectionResource resource = this;
        final String attrName = entry.getKey();
        final String attrValue = entry.getValue();
        CollectionAttribute attribute = new CollectionAttribute() {

            @Override
            public CollectionResource getResource() {
                return resource;
            }

            @Override
            public String getStringValue() {
                return attrValue;
            }

            @Override
            public Double getNumericValue() {
                try {
                    return Double.parseDouble(attrValue);
                } catch (NumberFormatException | NullPointerException e) {
                    return null;
                }
            }

            @Override
            public String getName() {
                return attrName;
            }

            @Override
            public void storeAttribute(Persister persister) {
            }

            @Override
            public boolean shouldPersist(ServiceParameters params) {
                return true;
            }

            @Override
            public CollectionAttributeType getAttributeType() {
                return null;
            }

            @Override
            public void visit(CollectionSetVisitor visitor) {
            }

            @Override
            public AttributeType getType() {
                return AttributeType.STRING;
            }

            @Override
            public String getMetricIdentifier() {
                return "MOCK_" + getName();
            }
        };
        visitor.visitAttribute(attribute);
    }
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) Persister(org.opennms.netmgt.collection.api.Persister) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters)

Aggregations

CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)16 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)14 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)10 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)9 File (java.io.File)7 HashMap (java.util.HashMap)7 RrdDb (org.jrobin.core.RrdDb)6 Test (org.junit.Test)6 Datasource (org.jrobin.core.Datasource)5 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)5 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)5 XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)5 Date (java.util.Date)3 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)2 RrdPersisterFactory (org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory)2 CollectionSetVisitorWrapper (org.opennms.netmgt.collection.support.CollectionSetVisitorWrapper)2 ConstantTimeKeeper (org.opennms.netmgt.collection.support.ConstantTimeKeeper)2 SingleResourceCollectionSet (org.opennms.netmgt.collection.support.SingleResourceCollectionSet)2 Path (java.nio.file.Path)1