Search in sources :

Example 1 with ObjectRetrievalFailureException

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);
    }
}
Also used : StorageStrategy(org.opennms.netmgt.collection.api.StorageStrategy) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 2 with ObjectRetrievalFailureException

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.");
    }
}
Also used : PrefabGraphDumper(org.opennms.features.mibcompiler.services.PrefabGraphDumper) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) PropertiesGraphDao(org.opennms.netmgt.dao.support.PropertiesGraphDao) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) File(java.io.File) Test(org.junit.Test)

Example 3 with ObjectRetrievalFailureException

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?" });
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) ServiceGraph(org.opennms.web.svclayer.model.DistributedStatusHistoryModel.ServiceGraph) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 4 with ObjectRetrievalFailureException

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);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) Test(org.junit.Test)

Example 5 with ObjectRetrievalFailureException

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
    }
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) FileSystemResource(org.springframework.core.io.FileSystemResource) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.springframework.core.io.Resource) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Aggregations

ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)22 OnmsResource (org.opennms.netmgt.model.OnmsResource)7 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)7 StorageStrategy (org.opennms.netmgt.collection.api.StorageStrategy)4 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Graph (org.opennms.netmgt.config.kscReports.Graph)2 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)2 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)2 ResourcePath (org.opennms.netmgt.model.ResourcePath)2 Resource (org.springframework.core.io.Resource)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1