Search in sources :

Example 96 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class JMXDataCollectionConfigDao method translateConfig.

@Override
public JmxDatacollectionConfig translateConfig(JmxDatacollectionConfig config) {
    for (JmxCollection collection : config.getJmxCollectionList()) {
        if (collection.hasImportMbeans()) {
            for (String importMbeans : collection.getImportGroupsList()) {
                final File file = getOpennmsHome().resolve(Paths.get("etc", importMbeans)).toFile();
                LOG.debug("parseJmxMbeans: parsing {}", file);
                final Mbeans mbeans = JaxbUtils.unmarshal(Mbeans.class, new FileSystemResource(file));
                collection.addMbeans(mbeans.getMbeanList());
            }
        }
    }
    return config;
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection) File(java.io.File) Mbeans(org.opennms.netmgt.config.collectd.jmx.Mbeans)

Example 97 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method createRequisition.

private Requisition createRequisition() throws Exception {
    FileSystemResource resource = new FileSystemResource(getRequisitionFile());
    Requisition r = m_foreignSourceRepository.importResourceRequisition(resource);
    m_foreignSourceRepository.save(r);
    m_foreignSourceRepository.flush();
    // Give enough time to watcher's thread to cache the requisition
    Thread.sleep(2000);
    return r;
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 98 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class AccessPointMonitorConfigDaoJaxbTest method testAfterPropertiesSetWithBogusFileResource.

public void testAfterPropertiesSetWithBogusFileResource() throws Exception {
    Resource resource = new FileSystemResource("/bogus-file");
    AccessPointMonitorConfigDaoJaxb dao = new AccessPointMonitorConfigDaoJaxb();
    dao.setConfigResource(resource);
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new MarshallingResourceFailureException(ThrowableAnticipator.IGNORE_MESSAGE));
    try {
        dao.afterPropertiesSet();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : MarshallingResourceFailureException(org.opennms.core.xml.MarshallingResourceFailureException) InputStreamResource(org.springframework.core.io.InputStreamResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Example 99 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class WmiPeerFactory method init.

/**
     * Load the config from the default config file and create the singleton
     * instance of this factory.
     * 
     * @exception java.io.IOException
     *                Thrown if the specified config file cannot be read
     * @throws java.io.IOException
     *             if any.
     */
public static synchronized void init() throws IOException {
    if (m_loaded) {
        // to reload, reload() will need to be called
        return;
    }
    WmiPeerFactory factory = new WmiPeerFactory(new FileSystemResource(ConfigFileConstants.getFile(ConfigFileConstants.WMI_CONFIG_FILE_NAME)));
    factory.afterPropertiesSet();
    setInstance(factory);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 100 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class LatencyThresholdingSetIT method setUp.

@Before
public void setUp() throws Exception {
    BeanUtils.setStaticApplicationContext(m_context);
    // Resets Counters Cache Data
    CollectionResourceWrapper.s_cache.clear();
    MockLogAppender.setupLogging();
    m_fileAnticipator = new FileAnticipator();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
    // Use a mock FilterDao that always returns 127.0.0.1 in the active IP list
    FilterDao filterDao = EasyMock.createMock(FilterDao.class);
    EasyMock.expect(filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
    filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    FilterDaoFactory.setInstance(filterDao);
    EasyMock.replay(filterDao);
    DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
    StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
    sb.append("<outages>");
    sb.append("<outage name=\"junit outage\" type=\"specific\">");
    sb.append("<time begins=\"");
    sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
    sb.append("\" ends=\"");
    sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
    sb.append("\"/>");
    sb.append("<interface address=\"match-any\"/>");
    sb.append("</outage>");
    sb.append("</outages>");
    File file = new File("target/poll-outages.xml");
    FileWriter writer = new FileWriter(file);
    writer.write(sb.toString());
    writer.close();
    PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
    PollOutagesConfigFactory.getInstance().afterPropertiesSet();
    initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
    m_anticipatedEvents = new ArrayList<Event>();
}
Also used : FileWriter(java.io.FileWriter) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) FileSystemResource(org.springframework.core.io.FileSystemResource) Date(java.util.Date) FilterDao(org.opennms.netmgt.filter.api.FilterDao) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Event(org.opennms.netmgt.xml.event.Event) FileAnticipator(org.opennms.test.FileAnticipator) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Before(org.junit.Before)

Aggregations

FileSystemResource (org.springframework.core.io.FileSystemResource)128 File (java.io.File)66 Test (org.junit.Test)41 Resource (org.springframework.core.io.Resource)35 Before (org.junit.Before)21 ClassPathResource (org.springframework.core.io.ClassPathResource)13 IOException (java.io.IOException)11 FileWriter (java.io.FileWriter)10 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)8 FileOutputStream (java.io.FileOutputStream)7 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 InputStreamResource (org.springframework.core.io.InputStreamResource)7 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)6 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)5 FileReader (java.io.FileReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Ehcache (net.sf.ehcache.Ehcache)4