Search in sources :

Example 46 with FileSystemResource

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

the class DroolsCorrelationEngineBuilder method locatePluginConfigurations.

private PluginConfiguration[] locatePluginConfigurations() throws Exception {
    List<PluginConfiguration> pluginConfigs = new LinkedList<>();
    // first we see if the config is etc exists
    if (m_configResource != null && m_configResource.isReadable()) {
        LOG.info("Found Drools Plugin config file {}.", m_configResource);
        pluginConfigs.add(new PluginConfiguration(m_configResource));
    }
    // then we look in each plugin dir for a config
    File[] pluginDirs = getPluginDirs();
    for (File pluginDir : pluginDirs) {
        File configFile = new File(pluginDir, PLUGIN_CONFIG_FILE_NAME);
        if (!configFile.exists()) {
            LOG.error("Drools Plugin directory {} does not contains a {} config file.  Ignoring plugin.", pluginDir, PLUGIN_CONFIG_FILE_NAME);
        } else {
            LOG.info("Found Drools Plugin directory {} containing a {} config file.", pluginDir, PLUGIN_CONFIG_FILE_NAME);
            pluginConfigs.add(new PluginConfiguration(new FileSystemResource(configFile)));
        }
    }
    return pluginConfigs.toArray(new PluginConfiguration[0]);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) LinkedList(java.util.LinkedList)

Example 47 with FileSystemResource

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

the class PollOutagesConfigFactory 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;
    }
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(new FileSystemResource(ConfigFileConstants.getFile(ConfigFileConstants.POLL_OUTAGES_CONFIG_FILE_NAME)));
    factory.afterPropertiesSet();
    setInstance(factory);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 48 with FileSystemResource

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

the class SnmpPeerFactory method init.

public static synchronized void init() throws IOException {
    if (!s_loaded.get()) {
        final File cfgFile = getFile();
        LOG.debug("init: config file path: {}", cfgFile.getPath());
        final FileSystemResource resource = new FileSystemResource(cfgFile);
        s_singleton = new SnmpPeerFactory(resource);
        s_loaded.set(true);
    }
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File)

Example 49 with FileSystemResource

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

the class SyslogdConfigFactory method parseIncludedFiles.

/**
 * Parse import-file tags and add all uei-matchs and hide-messages.
 *
 * @throws IOException
 */
private void parseIncludedFiles() throws IOException {
    final File configDir;
    try {
        configDir = ConfigFileConstants.getFile(ConfigFileConstants.SYSLOGD_CONFIG_FILE_NAME).getParentFile();
    } catch (final Throwable t) {
        LOG.warn("Error getting default syslogd configuration location. <import-file> directives will be ignored.  This should really only happen in unit tests.");
        return;
    }
    for (final String fileName : m_config.getImportFiles()) {
        final File configFile = new File(configDir, fileName);
        final SyslogdConfigurationGroup includeCfg = JaxbUtils.unmarshal(SyslogdConfigurationGroup.class, new FileSystemResource(configFile));
        if (includeCfg.getUeiMatches() != null) {
            for (final UeiMatch ueiMatch : includeCfg.getUeiMatches()) {
                if (m_config.getUeiMatches() == null) {
                    m_config.setUeiMatches(new ArrayList<>());
                }
                m_config.addUeiMatch(ueiMatch);
            }
        }
        if (includeCfg.getHideMatches() != null) {
            for (final HideMatch hideMatch : includeCfg.getHideMatches()) {
                if (m_config.getHideMatches() == null) {
                    m_config.setHideMatches(new ArrayList<>());
                }
                m_config.addHideMatch(hideMatch);
            }
        }
    }
}
Also used : SyslogdConfigurationGroup(org.opennms.netmgt.config.syslogd.SyslogdConfigurationGroup) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) UeiMatch(org.opennms.netmgt.config.syslogd.UeiMatch) HideMatch(org.opennms.netmgt.config.syslogd.HideMatch)

Example 50 with FileSystemResource

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

the class DroolsNorthbounderIT method setUp.

/**
 * Sets up the test.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    // Setup the Drools northbounder configuration DAO
    System.setProperty("opennms.home", "src/test/resources");
    DroolsNorthbounderConfigDao configDao = new DroolsNorthbounderConfigDao();
    configDao.setConfigResource(new FileSystemResource(new File("src/test/resources/etc/drools-northbounder-config.xml")));
    configDao.afterPropertiesSet();
    // Setup the northbounder
    nbi = new DroolsNorthbounder(null, configDao, null, "JUnit");
    nbi.afterPropertiesSet();
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Before(org.junit.Before)

Aggregations

FileSystemResource (org.springframework.core.io.FileSystemResource)148 File (java.io.File)77 Test (org.junit.Test)44 Resource (org.springframework.core.io.Resource)42 Before (org.junit.Before)27 ClassPathResource (org.springframework.core.io.ClassPathResource)16 IOException (java.io.IOException)12 FileWriter (java.io.FileWriter)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Properties (java.util.Properties)8 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)8 FileOutputStream (java.io.FileOutputStream)7 URL (java.net.URL)7 InputStreamResource (org.springframework.core.io.InputStreamResource)7 UrlResource (org.springframework.core.io.UrlResource)7 Date (java.util.Date)5 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)5 FileReader (java.io.FileReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4