use of org.opennms.netmgt.collection.api.CollectionAttribute in project opennms by OpenNMS.
the class CollectCommand method printCollectionSet.
private void printCollectionSet(CollectionSet collectionSet) {
AtomicBoolean didPrintAttribute = new AtomicBoolean(false);
collectionSet.visit(new AbstractCollectionSetVisitor() {
@Override
public void visitResource(CollectionResource resource) {
System.out.printf("%s\n", resource);
}
@Override
public void visitGroup(AttributeGroup group) {
System.out.printf("\tGroup: %s\n", group.getName());
}
@Override
public void visitAttribute(CollectionAttribute attribute) {
System.out.printf("\t\t%s\n", attribute);
didPrintAttribute.set(true);
}
});
if (!didPrintAttribute.get()) {
System.out.println("(Empty collection set)");
}
}
use of org.opennms.netmgt.collection.api.CollectionAttribute in project opennms by OpenNMS.
the class CollectionSetUtils method getAttributesByName.
public static Map<String, CollectionAttribute> getAttributesByName(CollectionSet collectionSet) {
final Map<String, CollectionAttribute> attributesByName = Maps.newHashMap();
collectionSet.visit(new AbstractCollectionSetVisitor() {
@Override
public void visitAttribute(CollectionAttribute attribute) {
attributesByName.put(attribute.getName(), attribute);
}
});
return attributesByName;
}
use of org.opennms.netmgt.collection.api.CollectionAttribute in project opennms by OpenNMS.
the class CollectionSetUtils method getAttributesByNameByGroup.
public static Map<String, Map<String, CollectionAttribute>> getAttributesByNameByGroup(CollectionSet collectionSet) {
final Map<String, Map<String, CollectionAttribute>> attributesByNameByGroup = Maps.newHashMap();
collectionSet.visit(new AbstractCollectionSetVisitor() {
private String groupName = null;
private Map<String, CollectionAttribute> attributesByName = Maps.newHashMap();
@Override
public void visitGroup(AttributeGroup group) {
groupName = group.getName();
}
@Override
public void visitAttribute(CollectionAttribute attribute) {
attributesByName.put(attribute.getName(), attribute);
}
@Override
public void completeGroup(AttributeGroup group) {
attributesByNameByGroup.put(groupName, attributesByName);
attributesByName = Maps.newHashMap();
}
});
return attributesByNameByGroup;
}
use of org.opennms.netmgt.collection.api.CollectionAttribute 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;
}
use of org.opennms.netmgt.collection.api.CollectionAttribute in project opennms by OpenNMS.
the class GroupPersister method visitGroup.
/** {@inheritDoc} */
@Override
public void visitGroup(AttributeGroup group) {
pushShouldPersist(group);
if (shouldPersist()) {
Map<String, String> dsNamesToRrdNames = new LinkedHashMap<String, String>();
for (CollectionAttribute a : group.getAttributes()) {
if (a.getType().isNumeric()) {
dsNamesToRrdNames.put(a.getName(), group.getName());
}
}
setBuilder(createBuilder(group.getResource(), group.getName(), group.getGroupType().getAttributeTypes()));
ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(getRepository(), group.getResource().getPath());
m_resourceStorageDao.updateMetricToResourceMappings(path, dsNamesToRrdNames);
}
}
Aggregations