use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class GenericTypeResourceTest method getInstanceInResourcePath.
private String getInstanceInResourcePath(String instance) {
// Mock the ResourceType
ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
when(rt.getName()).thenReturn("type");
when(rt.getStorageStrategy().getClazz()).thenReturn(IndexStorageStrategy.class.getCanonicalName());
when(rt.getStorageStrategy().getParameters()).thenReturn(Collections.emptyList());
when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(PersistAllSelectorStrategy.class.getCanonicalName());
when(rt.getPersistenceSelectorStrategy().getParameters()).thenReturn(Collections.emptyList());
// Create the GenericTypeResource
NodeLevelResource nlr = new NodeLevelResource(1);
GenericTypeResource gtr = new GenericTypeResource(nlr, rt, instance);
// Mock the CollectionResource
CollectionResource resource = mock(CollectionResource.class);
when(resource.getInstance()).thenReturn(gtr.getInstance());
// Build the resource path, and extract the instance (the last element of the path)
ResourcePath path = gtr.getPath(resource);
String[] elements = path.elements();
return elements[elements.length - 1];
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class ResourceTypeFilteringResourceVisitorTest method testVisitWithMatch.
public void testVisitWithMatch() throws Exception {
ResourceTypeFilteringResourceVisitor filteringVisitor = new ResourceTypeFilteringResourceVisitor();
filteringVisitor.setDelegatedVisitor(m_delegatedVisitor);
filteringVisitor.setResourceTypeMatch("interfaceSnmp");
filteringVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsResource resource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
m_delegatedVisitor.visit(resource);
m_mocks.replayAll();
filteringVisitor.visit(resource);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class SiblingColumnStorageStrategyTest method testMatchIndex.
@Test
public void testMatchIndex() throws Exception {
strategy.setResourceTypeName("macIndex");
List<org.opennms.netmgt.collection.api.Parameter> params = new ArrayList<>();
params.add(createParameter("sibling-column-name", "_index"));
params.add(createParameter("replace-first", "s/^(([\\d]{1,3}\\.){8,8}).*$/$1/"));
params.add(createParameter("replace-first", "s/\\.$//"));
strategy.setParameters(params);
ResourcePath parentResource = ResourcePath.get("1");
MockCollectionResource resource = new MockCollectionResource(parentResource, "0.132.43.51.76.89.2.144.10.1.1.1", "macIndex");
String resourceName = strategy.getResourceNameFromIndex(resource);
Assert.assertEquals("0.132.43.51.76.89.2.144", resourceName);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NewtsConverter method processStringsProperties.
private void processStringsProperties(final Path path) {
try {
// Find an process all 'strings.properties' files
Files.walk(path).filter(p -> p.endsWith("strings.properties")).forEach(p -> {
final Properties properties = new Properties();
try (final BufferedReader r = Files.newBufferedReader(p)) {
properties.load(r);
} catch (final IOException e) {
throw Throwables.propagate(e);
}
final ResourcePath resourcePath = buildResourcePath(p.getParent());
if (resourcePath == null) {
return;
}
this.injectStringPropertiesToNewts(resourcePath, Maps.fromProperties(properties));
});
} catch (Exception e) {
LOG.error("Error while reading string.properties", e);
return;
}
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NewtsConverter method processResource.
/**
* Process metric.
*
* @param resourceDir the path where the resource file lives in
* @param fileName the RRD file name without extension
* @param group the group name
*/
private void processResource(final Path resourceDir, final String fileName, final String group) {
LOG.info("Processing resource: dir={}, file={}, group={}", resourceDir, fileName, group);
final ResourcePath resourcePath = buildResourcePath(resourceDir);
if (resourcePath == null) {
return;
}
// Load the RRD file
final Path file;
switch(this.storageTool) {
case RRDTOOL:
file = resourceDir.resolve(fileName + ".rrd");
break;
case JROBIN:
file = resourceDir.resolve(fileName + ".jrb");
break;
default:
file = null;
}
if (!Files.exists(file)) {
LOG.error("File not found: {}", file);
return;
}
final AbstractRRD rrd;
try {
switch(this.storageTool) {
case RRDTOOL:
rrd = RrdConvertUtils.dumpRrd(file.toFile());
break;
case JROBIN:
rrd = RrdConvertUtils.dumpJrb(file.toFile());
break;
default:
rrd = null;
}
} catch (final Exception e) {
LOG.error("Can't parse JRB/RRD file: {}", file, e);
return;
}
// Inject the samples from the RRD file to NewTS
try {
this.injectSamplesToNewts(resourcePath, group, rrd.getDataSources(), rrd.generateSamples());
} catch (final Exception e) {
LOG.error("Failed to convert file: {}", file, e);
return;
}
}
Aggregations