use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class GenericTypeResource method instantiateStorageStrategy.
private StorageStrategy instantiateStorageStrategy(String className, String resourceTypeName) {
Class<?> cinst;
try {
cinst = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class", e);
}
try {
StorageStrategy storageStrategy = (StorageStrategy) cinst.newInstance();
storageStrategy.setResourceTypeName(resourceTypeName);
return storageStrategy;
} catch (InstantiationException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
} catch (IllegalAccessException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
}
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class JsmiMibParserTest method testGenerateGraphTemplates.
/**
* Test generate graph templates.
*
* @throws Exception the exception
*/
@Test
public void testGenerateGraphTemplates() throws Exception {
if (parser.parseMib(new File(MIB_DIR, "Clavister-MIB.mib"))) {
List<PrefabGraph> graphs = parser.getPrefabGraphs();
StringWriter writer = new StringWriter();
PrefabGraphDumper dumper = new PrefabGraphDumper();
dumper.dump(graphs, writer);
System.out.println(writer.getBuffer().toString());
// FIXME we should implement a more comprehensive check here.
Assert.assertEquals(102533, writer.getBuffer().toString().length());
PropertiesGraphDao dao = new PropertiesGraphDao();
StringBuffer sb = new StringBuffer();
sb.append("command.prefix=/usr/bin/rrdtool\n");
sb.append("output.mime=image/png\n");
sb.append(writer.getBuffer().toString());
dao.loadProperties("performance", new ByteArrayInputStream(sb.toString().getBytes()));
Assert.assertEquals(graphs.size(), dao.getAllPrefabGraphs().size());
for (PrefabGraph g : graphs) {
try {
PrefabGraph graph = dao.getPrefabGraph(g.getName());
Assert.assertEquals(g.getTitle(), graph.getTitle());
} catch (ObjectRetrievalFailureException e) {
Assert.fail(e.getMessage());
}
}
} else {
Assert.fail("The Clavister-MIB.mib file couldn't be parsed successfully.");
}
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class DefaultDistributedStatusService method getServiceGraphForService.
private ServiceGraph getServiceGraphForService(OnmsLocationMonitor locMon, OnmsMonitoredService service, long[] times) {
OnmsResource resource;
try {
resource = m_resourceDao.getResourceForIpInterface(service.getIpInterface(), locMon);
} catch (ObjectRetrievalFailureException e) {
resource = null;
}
if (resource == null) {
return new ServiceGraph(service, new String[] { "Resource could not be found. Has any response time data been collected for this service from this remote poller?" });
}
String graphName = service.getServiceName().toLowerCase();
try {
m_graphDao.getPrefabGraph(graphName);
} catch (ObjectRetrievalFailureException e) {
return new ServiceGraph(service, new String[] { "Graph definition could not be found for '" + graphName + "'. A graph definition needs to be created for this service." });
}
PrefabGraph[] prefabGraphs = m_graphDao.getPrefabGraphsForResource(resource);
for (PrefabGraph graph : prefabGraphs) {
if (graph.getName().equals(graphName)) {
String url = "graph/graph.png" + "?report=" + Util.encode(graph.getName()) + "&resourceId=" + Util.encode(resource.getId().toString()) + "&start=" + times[0] + "&end=" + times[1];
return new ServiceGraph(service, url);
}
}
return new ServiceGraph(service, new String[] { "Graph could not be found for '" + graphName + "' on this resource. Has any response time data been collected for this service from this remote poller and is the graph definition correct?" });
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testPrefabGraphPartlyBorkedConfig.
/**
* Test that we can load a partly borked config file (i.e. if one graph is incorrectly specified,
* we load as many of the rest as we can).
* The borked'ness we can tolerate does not include poor double quoting which confuses the underlying
* Java properties parser, but misspelled property names should only affect the graph in question.
*
* NB: It should still complain with an Error log. Should there be an event as well?
* @throws Exception
*/
@Test
public void testPrefabGraphPartlyBorkedConfig() throws Exception {
//We're expecting an ERROR log, and will be most disappointed if
// we don't get it. Turn off the default check in runTest
m_testSpecificLoggingTest = true;
PropertiesGraphDao dao = createPropertiesGraphDao(s_emptyMap, s_emptyMap);
dao.loadProperties("foo", new ByteArrayInputStream(s_partlyBorkedPrefab.getBytes(StandardCharsets.UTF_8)));
//We expect to be able to get a mib2.HCbits, and a mib2.discards, but no mib2.bits
try {
PrefabGraph mib2bits = dao.getPrefabGraph("mib2.bits");
fail("Should have thrown an ObjectRetrievalFailureException retrieving graph " + mib2bits);
} catch (ObjectRetrievalFailureException e) {
}
PrefabGraph mib2HCbits = dao.getPrefabGraph("mib2.HCbits");
assertNotNull(mib2HCbits);
PrefabGraph mib2Discards = dao.getPrefabGraph("mib2.discards");
assertNotNull(mib2Discards);
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testIncludeDirectoryIncludeMissingReportId.
@Test
public void testIncludeDirectoryIncludeMissingReportId() throws Exception {
//We're expecting an ERROR log, and will be most disappointed if
// we don't get it. Turn off the default check in runTest
m_testSpecificLoggingTest = true;
File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
File graphBits = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits.properties");
m_outputStream = new FileOutputStream(rootFile);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_baseIncludePrefab);
m_writer.close();
m_outputStream.close();
graphDirectory.mkdir();
m_outputStream = new FileOutputStream(graphBits);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_separateBitsGraph.replace("report.id", "report.noid"));
m_writer.close();
m_outputStream.close();
HashMap<String, Resource> perfConfig = new HashMap<String, Resource>();
perfConfig.put("performance", new FileSystemResource(rootFile));
PropertiesGraphDao dao = createPropertiesGraphDao(perfConfig, s_emptyMap);
try {
PrefabGraph graph = dao.getPrefabGraph("mib2.bits");
fail("Shouldn't have gotten here; expecting an exception fetching " + graph);
} catch (ObjectRetrievalFailureException e) {
//Expected; no such graph
}
}
Aggregations