use of org.opennms.netmgt.model.ResourceId in project opennms by OpenNMS.
the class DefaultGraphResultsService method findResults.
@Override
public GraphResults findResults(ResourceId[] resourceIds, String[] reports, long start, long end, String relativeTime) {
if (resourceIds == null) {
throw new IllegalArgumentException("resourceIds argument cannot be null");
}
if (reports == null) {
throw new IllegalArgumentException("reports argument cannot be null");
}
if (end < start) {
throw new IllegalArgumentException("end time cannot be before start time");
}
GraphResults graphResults = new GraphResults();
graphResults.setStart(new Date(start));
graphResults.setEnd(new Date(end));
graphResults.setRelativeTime(relativeTime);
graphResults.setRelativeTimePeriods(m_periods);
graphResults.setReports(reports);
HashMap<ResourceId, List<OnmsResource>> resourcesMap = new HashMap<>();
for (ResourceId resourceId : resourceIds) {
LOG.debug("findResults: parent, childType, childName = {}, {}, {}", resourceId.parent, resourceId.type, resourceId.name);
OnmsResource resource = null;
if (!resourcesMap.containsKey(resourceId.parent)) {
List<OnmsResource> resourceList = m_resourceDao.getResourceById(resourceId).getChildResources();
if (resourceList == null) {
LOG.warn("findResults: zero child resources found for {}", resourceId.parent);
} else {
resourcesMap.put(resourceId.parent, resourceList);
LOG.debug("findResults: add resourceList to map for {}", resourceId.parent);
}
}
for (OnmsResource r : resourcesMap.get(resourceId.parent)) {
if (resourceId.type.equals(r.getResourceType().getName()) && resourceId.name.equals(r.getName())) {
resource = r;
LOG.debug("findResults: found resource in map{}", r.toString());
break;
}
}
try {
graphResults.addGraphResultSet(createGraphResultSet(resourceId, resource, reports, graphResults));
} catch (IllegalArgumentException e) {
LOG.warn(e.getMessage(), e);
continue;
}
}
graphResults.setGraphTopOffsetWithText(m_rrdDao.getGraphTopOffsetWithText());
graphResults.setGraphLeftOffset(m_rrdDao.getGraphLeftOffset());
graphResults.setGraphRightOffset(m_rrdDao.getGraphRightOffset());
return graphResults;
}
use of org.opennms.netmgt.model.ResourceId in project opennms by OpenNMS.
the class DefaultKscReportService method buildNodeSourceReport.
/**
* {@inheritDoc}
*/
@Override
public Report buildNodeSourceReport(String nodeSource) {
ResourceId resourceId = ResourceId.get("nodeSource", nodeSource);
OnmsResource res = getResourceService().getResourceById(resourceId);
return buildResourceReport(getResourceService(), res, "Node Report for Foreign Source:Id " + nodeSource);
}
use of org.opennms.netmgt.model.ResourceId in project opennms by OpenNMS.
the class DefaultKscReportService method buildNodeReport.
/**
* {@inheritDoc}
*/
@Override
public Report buildNodeReport(int node_id) {
ResourceId resourceId = ResourceId.get("node", Integer.toString(node_id));
OnmsResource node = getResourceService().getResourceById(resourceId);
return buildResourceReport(getResourceService(), node, "Node Report for Node Number " + node_id);
}
use of org.opennms.netmgt.model.ResourceId in project opennms by OpenNMS.
the class AbstractRrdBasedFetchStrategy method fetch.
/**
* {@inheritDoc}
*/
@Override
public FetchResults fetch(long start, long end, long step, int maxrows, Long interval, Long heartbeat, List<Source> sources, boolean relaxed) throws Exception {
final Map<String, Object> constants = Maps.newHashMap();
final Map<Source, String> rrdsBySource = Maps.newHashMap();
for (final Source source : sources) {
final ResourceId resourceId;
try {
resourceId = ResourceId.fromString(source.getResourceId());
} catch (final IllegalArgumentException ex) {
if (relaxed)
continue;
LOG.error("Ill-formed resource id: {}", source.getResourceId(), ex);
return null;
}
// Grab the resource
final OnmsResource resource = m_resourceDao.getResourceById(resourceId);
if (resource == null) {
if (relaxed)
continue;
LOG.error("No resource with id: {}", source.getResourceId());
return null;
}
// Grab the attribute
RrdGraphAttribute rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
if (rrdGraphAttribute == null && !Strings.isNullOrEmpty(source.getFallbackAttribute())) {
LOG.error("No attribute with name '{}', using fallback-attribute with name '{}'", source.getAttribute(), source.getFallbackAttribute());
source.setAttribute(source.getFallbackAttribute());
source.setFallbackAttribute(null);
rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
}
if (rrdGraphAttribute == null) {
if (relaxed)
continue;
LOG.error("No attribute with name: {}", source.getAttribute());
return null;
}
// Gather the values from strings.properties
Utils.convertStringAttributesToConstants(source.getLabel(), resource.getStringPropertyAttributes(), constants);
// Build the path to the archive
final String rrdFile = System.getProperty("rrd.base.dir") + File.separator + rrdGraphAttribute.getRrdRelativePath();
rrdsBySource.put(source, rrdFile);
}
// Fetch
return fetchMeasurements(start, end, step, maxrows, rrdsBySource, constants, sources, relaxed);
}
use of org.opennms.netmgt.model.ResourceId 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<>();
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;
}
Aggregations