use of org.opennms.netmgt.model.OnmsResourceType 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.OnmsResourceType 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();
}
};
}
Aggregations