Search in sources :

Example 6 with ResourceId

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;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId) HashMap(java.util.HashMap) GraphResults(org.opennms.web.svclayer.model.GraphResults) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Date(java.util.Date)

Example 7 with ResourceId

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);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId)

Example 8 with ResourceId

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);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId)

Example 9 with ResourceId

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);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId) Source(org.opennms.netmgt.measurements.model.Source) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute)

Example 10 with ResourceId

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;
}
Also used : Measurement(org.opennms.newts.api.Measurement) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.opennms.newts.api.Resource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) Results(org.opennms.newts.api.Results) Row(org.opennms.newts.api.Results.Row)

Aggregations

ResourceId (org.opennms.netmgt.model.ResourceId)16 OnmsResource (org.opennms.netmgt.model.OnmsResource)11 Date (java.util.Date)3 Test (org.junit.Test)3 Source (org.opennms.netmgt.measurements.model.Source)3 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)3 File (java.io.File)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ResourceDao (org.opennms.netmgt.dao.api.ResourceDao)2 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)2 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)2 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)2 MissingParameterException (org.opennms.web.servlet.MissingParameterException)2 GraphResults (org.opennms.web.svclayer.model.GraphResults)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1