use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class CollectionSetUtils method flatten.
public static List<String> flatten(CollectionSet collectionSet) {
final List<String> strings = new ArrayList<>();
collectionSet.visit(new AbstractCollectionSetVisitor() {
CollectionResource resource;
AttributeGroup group;
@Override
public void visitResource(CollectionResource resource) {
this.resource = resource;
}
@Override
public void visitGroup(AttributeGroup group) {
this.group = group;
}
@Override
public void visitAttribute(CollectionAttribute attribute) {
strings.add(String.format("%s/%s/%s[%s,%s]", resource.getPath(), group.getName(), attribute.getName(), attribute.getStringValue(), attribute.getNumericValue()));
}
});
return strings;
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class GenericTypeResourceTest method getInstanceInResourcePath.
private String getInstanceInResourcePath(String instance) {
// Mock the ResourceType
ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
when(rt.getName()).thenReturn("type");
when(rt.getStorageStrategy().getClazz()).thenReturn(IndexStorageStrategy.class.getCanonicalName());
when(rt.getStorageStrategy().getParameters()).thenReturn(Collections.emptyList());
when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(PersistAllSelectorStrategy.class.getCanonicalName());
when(rt.getPersistenceSelectorStrategy().getParameters()).thenReturn(Collections.emptyList());
// Create the GenericTypeResource
NodeLevelResource nlr = new NodeLevelResource(1);
GenericTypeResource gtr = new GenericTypeResource(nlr, rt, instance);
// Mock the CollectionResource
CollectionResource resource = mock(CollectionResource.class);
when(resource.getInstance()).thenReturn(gtr.getInstance());
// Build the resource path, and extract the instance (the last element of the path)
ResourcePath path = gtr.getPath(resource);
String[] elements = path.elements();
return elements[elements.length - 1];
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class CollectionSetDTO method visit.
@Override
public void visit(CollectionSetVisitor visitor) {
visitor.visitCollectionSet(this);
for (CollectionResource resource : buildCollectionResources()) {
resource.visit(visitor);
}
visitor.completeCollectionSet(this);
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class XmpCollector method handleTableQuery.
/* handleScalarQuery */
// handle a tabular query, save each row in its own
// collection resource
private boolean handleTableQuery(String groupName, String resourceType, CollectionAgent agent, CollectionSetBuilder collectionSetBuilder, String[] tableInfo, XmpSession session, NodeLevelResource nodeLevelResource, XmpVar[] queryVars) throws CollectionException {
int numColumns, numRows;
XmpMessage reply;
int i, j;
XmpVar[] vars;
String targetInstance;
numColumns = queryVars.length;
// make sure we have an instance or * for all rows; preserve
// passed in value as targetInstance so we know if we are
// are going to use targetInstance for saving results or
// use returned instance for saving values
// if resourceType is present, we use it as a subDir in
// our RRD dir
targetInstance = tableInfo[2];
if ((tableInfo[2] == null) || (tableInfo[2].length() == 0)) {
tableInfo[2] = new String("*");
targetInstance = null;
}
LOG.debug("sending table query {},{},{} target: {}", tableInfo[0], tableInfo[1], tableInfo[2], targetInstance);
reply = session.queryTableVars(tableInfo, 0, queryVars);
if (reply == null) {
LOG.warn("collect: query to {} failed, {}", agent, Xmp.errorStatusToString(session.getErrorStatus()));
return false;
}
vars = reply.getMIBVars();
// we have to go through the reply and find out how
// many rows we have
// for each row: create a CollectionResource of
// appropriate type, instance, etc.
// create AttributeGroup to put
// the values in
numRows = vars.length / numColumns;
LOG.info("query returned valid table data for {} numRows={} numColumns={}", groupName, numRows, numColumns);
for (i = 0; i < numRows; i++) {
String rowInstance;
// determine instance for this row
// we use either the rowInstance or targetInstance for
// naming the instance for saving RRD file; if user
// wanted all rows (blank instance), then we will use
// the returned instance; if user specified an instance
// we use that instance for specifying the RRD file
// and collection resource
rowInstance = vars[i * numColumns].getKey();
// instead of using '*' for the nodeTypeName, use the
// table name so that the proper rrd file is spec'd
final String instanceName;
if (targetInstance != null) {
instanceName = targetInstance;
} else {
instanceName = rowInstance;
}
// node type can be "node" for scalars or
// "if" for network interface resources and
// "*" for all other resource types
final String nodeTypeName = tableInfo[1];
final Resource resource = getResource(nodeLevelResource, nodeTypeName, resourceType, instanceName);
LOG.debug("queryTable instance={}", rowInstance);
for (j = 0; j < numColumns; j++) {
final XmpVar var = vars[i * numColumns + j];
collectionSetBuilder.withAttribute(resource, groupName, var.getObjName(), var.getValue(), getType(var));
}
/* for each column */
}
return true;
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class NewtsPersister method visitGroup.
/** {@inheritDoc} */
@Override
public void visitGroup(AttributeGroup group) {
pushShouldPersist(group);
if (shouldPersist()) {
// Set the builder before any calls to persistNumericAttribute are made
CollectionResource resource = group.getResource();
m_builder = new NewtsPersistOperationBuilder(m_newtsWriter, m_context, m_repository, resource, group.getName());
if (resource.getTimeKeeper() != null) {
m_builder.setTimeKeeper(resource.getTimeKeeper());
}
setBuilder(m_builder);
}
}
Aggregations