Skip to content

Commit

Permalink
NMS-15839: Measurements API: Include node metadata even if resource n…
Browse files Browse the repository at this point in the history
…ot found
  • Loading branch information
synqotik committed Jul 7, 2023
1 parent 335beaa commit d11eece
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public FetchResults fetch(long start, long end, long step, int maxrows,
final Map<String, Object> constants = Maps.newHashMap();

final List<QueryResource> resources = new ArrayList<>();
final List<QueryResource> additionalResources = new ArrayList<>();

final Map<Source, String> rrdsBySource = Maps.newHashMap();

Expand All @@ -98,7 +99,18 @@ public FetchResults fetch(long start, long end, long step, int maxrows,
final OnmsResource resource = resourceCache.computeIfAbsent(resourceId, r -> m_resourceDao.getResourceById(r));

if (resource == null) {
if (relaxed) continue;
if (relaxed) {
// Attempt to get parent resource, e.g. the node, to put into response metadata
final OnmsResource parentResource = resourceCache.computeIfAbsent(resourceId, r -> m_resourceDao.getResourceById(r.getParent()));

if (parentResource != null) {
final QueryResource parentResourceInfo = getResourceInfo(parentResource, source);
additionalResources.add(parentResourceInfo);
}

continue;
}

LOG.error("No resource with id: {}", source.getResourceId());
resources.add(null);
return null;
Expand Down Expand Up @@ -133,6 +145,10 @@ public FetchResults fetch(long start, long end, long step, int maxrows,
rrdsBySource.put(source, rrdFile);
}

if (!additionalResources.isEmpty()) {
resources.addAll(additionalResources);
}

// Fetch
return fetchMeasurements(start, end, step, maxrows, rrdsBySource, constants, sources, new QueryMetadata(resources), relaxed);
}
Expand Down

0 comments on commit d11eece

Please sign in to comment.