Skip to content

Commit

Permalink
NMS-7711: Allow nodes to be referenced via nodeSource, even when stor…
Browse files Browse the repository at this point in the history
…eByFs is disabled.
  • Loading branch information
Jesse White committed Aug 20, 2015
1 parent 50d12b7 commit 40d0baf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ public OnmsResource getResourceForNode(OnmsNode node) {
// If the nodeSource directory does not exist, but the node directory does
// then create the resource using the node type instead of the nodeSource type
if (createUsingNodeSourceType) {
final boolean nodeSourcePathExists = m_resourceStorageDao.existsWithin(m_nodeSourceResourceType.getResourcePathForNode(node), MAXIMUM_NODE_METRIC_RESOURCE_DEPTH);
final boolean nodeSourcePathExists = m_resourceStorageDao.existsWithin(NodeSourceResourceType.getResourcePathForNode(node), MAXIMUM_NODE_METRIC_RESOURCE_DEPTH);
if (!nodeSourcePathExists) {
final boolean nodePathExists = m_resourceStorageDao.existsWithin(m_nodeResourceType.getResourcePathForNode(node), MAXIMUM_NODE_METRIC_RESOURCE_DEPTH);
final boolean nodePathExists = m_resourceStorageDao.existsWithin(NodeResourceType.getResourcePathForNode(node), MAXIMUM_NODE_METRIC_RESOURCE_DEPTH);
createUsingNodeSourceType = !nodePathExists;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public OnmsResource getResourceByName(String nodeIdStr) {
return createResourceForNode(node);
}

protected ResourcePath getResourcePathForNode(OnmsNode node) {
return new ResourcePath(ResourceTypeUtils.SNMP_DIRECTORY, Integer.toString(node.getId()));
protected static ResourcePath getResourcePathForNode(OnmsNode node) {
return ResourcePath.get(ResourceTypeUtils.SNMP_DIRECTORY, Integer.toString(node.getId()));
}

protected OnmsResource createResourceForNode(OnmsNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class NodeSourceResourceType extends AbstractTopLevelResourceType {
* <p>Constructor for NodeSourceResourceType.</p>
*
* @param resourceDao a {@link org.opennms.netmgt.dao.api.ResourceDao} object.
* @param nodeDao
* @param nodeDao
*/
public NodeSourceResourceType(ResourceDao resourceDao, NodeDao nodeDao) {
m_resourceDao = resourceDao;
Expand Down Expand Up @@ -118,8 +118,14 @@ public OnmsResource getResourceByName(String nodeSource) {
return createResourceForNode(node);
}

protected ResourcePath getResourcePathForNode(OnmsNode node) {
return new ResourcePath(ResourceTypeUtils.SNMP_DIRECTORY, ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY, node.getForeignSource(), node.getForeignId());
protected static ResourcePath getResourcePathForNode(OnmsNode node) {
// Preserve backwards compatibility by allowing nodes to be referenced by FS:FID
// even when storeByFs is disabled
if(!ResourceTypeUtils.isStoreByForeignSource()) {
return NodeResourceType.getResourcePathForNode(node);
}

return ResourcePath.get(ResourceTypeUtils.SNMP_DIRECTORY, ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY, node.getForeignSource(), node.getForeignId());
}

public OnmsResource createResourceForNode(final OnmsNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,23 @@ public void testGetResourceByNodeAndIndexGetLabelStringAttribute() throws Except

@Test
public void testGetResourceByNodeSourceAndIndexGetLabelStringAttribute() throws IOException {
GenericIndexResourceType rt = new GenericIndexResourceType(m_resourceStorageDao, "foo", "Foo Resource", "${stringAttribute}", m_storageStrategy);
try {
System.setProperty("org.opennms.rrd.storeByForeignSource", "true");

File rrd = touch("snmp", "fs", "source1", "123", "foo", "1", RRD_FILE_NAME);
m_fileAnticipator.tempFile(rrd.getParentFile(), RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME, "stringAttribute=hello!!!!");
GenericIndexResourceType rt = new GenericIndexResourceType(m_resourceStorageDao, "foo", "Foo Resource", "${stringAttribute}", m_storageStrategy);

m_mocks.replayAll();
OnmsResource resource = rt.getChildByName(getNodeResource("source1", "123"), "1");
m_mocks.verifyAll();
File rrd = touch("snmp", "fs", "source1", "123", "foo", "1", RRD_FILE_NAME);
m_fileAnticipator.tempFile(rrd.getParentFile(), RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME, "stringAttribute=hello!!!!");

assertNotNull("resource", resource);
assertEquals("resource label", "hello!!!!", resource.getLabel());
m_mocks.replayAll();
OnmsResource resource = rt.getChildByName(getNodeResource("source1", "123"), "1");
m_mocks.verifyAll();

assertNotNull("resource", resource);
assertEquals("resource label", "hello!!!!", resource.getLabel());
} finally {
System.setProperty("org.opennms.rrd.storeByForeignSource", "false");
}
}

@Test
Expand Down

0 comments on commit 40d0baf

Please sign in to comment.