use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class DataCollectionConfigParser method parseExternalResources.
/**
* Read all XML files from datacollection directory and parse them to create a list of DatacollectionGroup objects.
*/
private void parseExternalResources() {
// Ensure that this is called only once.
if (externalGroupsMap != null && externalGroupsMap.size() > 0) {
LOG.info("parseExternalResources: external data collection groups are already parsed");
return;
}
// Check configuration files repository
File folder = new File(configDirectory);
if (!folder.exists() || !folder.isDirectory()) {
LOG.info("parseExternalResources: directory {} does not exist or is not a folder.", folder);
return;
}
// Get external configuration files
File[] listOfFiles = folder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return name.endsWith(".xml");
}
});
// Parse configuration files (populate external groups map)
final CountDownLatch latch = new CountDownLatch(listOfFiles.length);
int i = 0;
for (final File file : listOfFiles) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
LOG.debug("parseExternalResources: parsing {}", file);
DatacollectionGroup group = JaxbUtils.unmarshal(DatacollectionGroup.class, new FileSystemResource(file));
// Synchronize around the map that holds the results
synchronized (externalGroupsMap) {
externalGroupsMap.put(group.getName(), group);
}
} catch (Throwable e) {
throwException("Can't parse XML file " + file + "; nested exception: " + e.getMessage(), e);
} finally {
latch.countDown();
}
}
}, "DataCollectionConfigParser-Thread-" + i++);
thread.start();
}
try {
latch.await();
} catch (InterruptedException e) {
throwException("Exception while waiting for XML parsing threads to complete: " + e.getMessage(), e);
}
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class DiscoveryConfigFactory method reload.
/**
* Reload the config from the default config file.
* @throws IOException
*
* @exception java.io.IOException
* Thrown if the specified config file cannot be read/loaded
* @throws java.io.IOException if any.
*/
public synchronized void reload() throws IOException {
try {
File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.DISCOVERY_CONFIG_FILE_NAME);
LOG.debug("reload: config file path {}", cfgFile.getPath());
final FileSystemResource resource = new FileSystemResource(cfgFile);
m_config = JaxbUtils.unmarshal(DiscoveryConfiguration.class, resource);
try {
getInitialSleepTime();
getRestartSleepTime();
getIntraPacketDelay();
getConfiguredAddresses();
} catch (final Throwable e) {
throw new IOException("An error occurred while validating the configuration: " + e.getMessage(), e);
}
} catch (IOException e) {
LOG.error("Could not unmarshal configuration file: " + ConfigFileConstants.getFileName(ConfigFileConstants.DISCOVERY_CONFIG_FILE_NAME), e);
throw e;
}
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class SyslogdConfigFactory method reload.
/**
* Reload the config from the default config file
*
* @throws java.io.IOException Thrown if the specified config file cannot be
* read/loaded
*/
public synchronized void reload() throws IOException {
File configFile = ConfigFileConstants.getFile(ConfigFileConstants.SYSLOGD_CONFIG_FILE_NAME);
m_config = JaxbUtils.unmarshal(SyslogdConfiguration.class, new FileSystemResource(configFile));
parseIncludedFiles();
}
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);
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class EventConfMatcherTest method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
eventConfDao = new DefaultEventConfDao();
eventConfDao.setConfigResource(new FileSystemResource(new File("src/test/resources/matcher-test.events.xml")));
eventConfDao.afterPropertiesSet();
Assert.assertEquals(5, eventConfDao.getAllEvents().size());
}
Aggregations