use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class NodeSnmpResourceType method getResourceForNode.
private OnmsResource getResourceForNode(OnmsResource node) {
final LazyResourceAttributeLoader loader = new LazyResourceAttributeLoader(m_resourceStorageDao, node.getPath());
final Set<OnmsAttribute> attributes = new LazySet<OnmsAttribute>(loader);
final OnmsResource resource = new OnmsResource("", "Node-level Performance Data", this, attributes, node.getPath());
resource.setParent(node);
return resource;
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class NewtsResourceStorageDao method getAttributes.
@Override
public Set<OnmsAttribute> getAttributes(ResourcePath path) {
Set<OnmsAttribute> attributes = Sets.newHashSet();
// Fetch the resource-level attributes in parallel
Future<Map<String, String>> stringAttributes = ForkJoinPool.commonPool().submit(getResourceAttributesCallable(path));
// Gather the list of metrics available under the resource path
SearchResults results = searchFor(path, 0, true);
for (Result result : results) {
final String resourceId = result.getResource().getId();
final ResourcePath resultPath = toResourcePath(resourceId);
if (!path.equals(resultPath)) {
// This shouldn't happen
LOG.warn("Encountered non-child resource {} when searching for {} with depth {}. Ignoring resource.", result.getResource(), path, 0);
continue;
}
for (String metric : result.getMetrics()) {
// Use the metric name as the dsName
// Store the resource id in the rrdFile field
attributes.add(new RrdGraphAttribute(metric, "", resourceId));
}
}
// Add the resource level attributes to the result set
try {
stringAttributes.get().entrySet().stream().map(e -> new StringPropertyAttribute(e.getKey(), e.getValue())).forEach(attr -> attributes.add(attr));
} catch (InterruptedException | ExecutionException e) {
throw Throwables.propagate(e);
}
return attributes;
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class NewtsFetchStrategyTest method createMockResource.
public Source createMockResource(final String label, final String attr, final String node, boolean expect) {
OnmsResourceType type = EasyMock.createNiceMock(OnmsResourceType.class);
final int nodeId = node.hashCode();
final String newtsResourceId = "response:" + node + ":" + attr;
final ResourceId resourceId = ResourceId.get("nodeSource", "NODES:" + nodeId).resolve("responseTime", node);
OnmsResource resource = m_resources.get(resourceId);
if (resource == null) {
resource = new OnmsResource(attr, label, type, Sets.newHashSet(), ResourcePath.get("foo"));
m_resources.put(resourceId, resource);
}
Set<OnmsAttribute> attributes = resource.getAttributes();
attributes.add(new RrdGraphAttribute(attr, "", newtsResourceId));
Results<Measurement> results = new Results<Measurement>();
Resource res = new Resource(newtsResourceId);
Row<Measurement> row = new Row<Measurement>(Timestamp.fromEpochSeconds(0), res);
Measurement measurement = new Measurement(Timestamp.fromEpochSeconds(0), res, label, 0.0d);
row.addElement(measurement);
results.addRow(row);
if (expect) {
EasyMock.expect(m_sampleRepository.select(EasyMock.eq(m_context), EasyMock.eq(res), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(results);
}
final Source source = new Source();
source.setAggregation("AVERAGE");
source.setAttribute(attr);
source.setLabel(label);
source.setResourceId(resourceId.toString());
source.setTransient(false);
return source;
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class CustomSpringConfiguration method createResourceDao.
@Bean(name = "resourceDao")
public ResourceDao createResourceDao() {
return new ResourceDao() {
@Override
public Collection<OnmsResourceType> getResourceTypes() {
throw new UnsupportedOperationException();
}
@Override
public List<OnmsResource> findTopLevelResources() {
throw new UnsupportedOperationException();
}
@Override
public OnmsResource getResourceById(ResourceId id) {
if (id.toString().startsWith("node[1]")) {
final OnmsResource onmsResource = new OnmsResource(id.toString(), id.toString(), new InterfaceSnmpResourceType(null), new HashSet<OnmsAttribute>(), new ResourcePath());
if (id.toString().contains("interfaceSnmp[127.0.0.1]")) {
final RrdGraphAttribute attribute = new RrdGraphAttribute();
attribute.setName("ifInErrors");
attribute.setResource(onmsResource);
onmsResource.getAttributes().add(attribute);
}
return onmsResource;
}
return null;
}
@Override
public OnmsResource getResourceForNode(OnmsNode node) {
throw new UnsupportedOperationException();
}
@Override
public OnmsResource getResourceForIpInterface(OnmsIpInterface ipInterface, OnmsLocationMonitor locationMonitor) {
throw new UnsupportedOperationException();
}
@Override
public boolean deleteResourceById(ResourceId resourceId) {
throw new UnsupportedOperationException();
}
};
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class TopNAttributeStatisticVisitorTest method testVisit.
public void testVisit() throws Exception {
BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
visitor.setCount(20);
visitor.afterPropertiesSet();
Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
attributes.put(new MockAttribute("foo"), 0.0);
OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
resource.getAttributes();
for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
visitor.visit(entry.getKey(), entry.getValue());
}
}
Aggregations