Search in sources :

Example 1 with AbstractCollectionAttributeType

use of org.opennms.netmgt.collection.support.AbstractCollectionAttributeType in project opennms by OpenNMS.

the class CollectionSetDTO method buildCollectionResources.

private Set<CollectionResource> buildCollectionResources() {
    final Set<CollectionResource> collectionResources = new LinkedHashSet<>();
    for (CollectionResourceDTO entry : this.collectionResources) {
        final Resource resource = entry.getResource();
        final AbstractCollectionResource collectionResource = CollectionSetBuilder.toCollectionResource(resource, agent);
        for (Attribute<?> attribute : entry.getAttributes()) {
            final AttributeGroupType groupType = new AttributeGroupType(attribute.getGroup(), AttributeGroupType.IF_TYPE_ALL);
            final AbstractCollectionAttributeType attributeType = new AbstractCollectionAttributeType(groupType) {

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

                @Override
                public String getName() {
                    return attribute.getName();
                }

                @Override
                public void storeAttribute(CollectionAttribute collectionAttribute, Persister persister) {
                    if (AttributeType.STRING.equals(attribute.getType())) {
                        persister.persistStringAttribute(collectionAttribute);
                    } else {
                        persister.persistNumericAttribute(collectionAttribute);
                    }
                }

                @Override
                public String toString() {
                    return attribute.toString();
                }
            };
            collectionResource.addAttribute(new AbstractCollectionAttribute(attributeType, collectionResource) {

                @Override
                public String getMetricIdentifier() {
                    return attribute.getName();
                }

                @Override
                public Number getNumericValue() {
                    return attribute.getNumericValue();
                }

                @Override
                public String getStringValue() {
                    return attribute.getStringValue();
                }

                @Override
                public boolean shouldPersist(ServiceParameters params) {
                    return !(Boolean.FALSE.equals(disableCounterPersistence) && AttributeType.COUNTER.equals(attribute.getType()));
                }

                @Override
                public String toString() {
                    return String.format("Attribute[%s:%s]", getMetricIdentifier(), attribute.getValue());
                }
            });
        }
        collectionResources.add(collectionResource);
    }
    return collectionResources;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) AbstractCollectionAttribute(org.opennms.netmgt.collection.support.AbstractCollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) AbstractCollectionAttribute(org.opennms.netmgt.collection.support.AbstractCollectionAttribute) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Persister(org.opennms.netmgt.collection.api.Persister) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) AbstractCollectionAttributeType(org.opennms.netmgt.collection.support.AbstractCollectionAttributeType)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)1 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)1 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)1 Persister (org.opennms.netmgt.collection.api.Persister)1 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)1 AbstractCollectionAttribute (org.opennms.netmgt.collection.support.AbstractCollectionAttribute)1 AbstractCollectionAttributeType (org.opennms.netmgt.collection.support.AbstractCollectionAttributeType)1 AbstractCollectionResource (org.opennms.netmgt.collection.support.AbstractCollectionResource)1 Resource (org.opennms.netmgt.collection.support.builder.Resource)1