use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class PropertiesGraphDao method loadIncludedFile.
private void loadIncludedFile(PrefabGraphTypeDao type, File file) throws FileNotFoundException, IOException {
Properties props = new Properties();
InputStream fileIn = new FileInputStream(file);
try {
props.load(fileIn);
} finally {
IOUtils.closeQuietly(fileIn);
}
// Clear any malformed setting; if everything goes ok, it'll remain cleared
// If there's problems, it'll be re-added.
type.removeMalformedFile(file);
try {
List<PrefabGraph> subGraphs = loadPrefabGraphDefinitions(type, props);
for (PrefabGraph graph : subGraphs) {
if (graph == null) {
// Indicates a multi-graph file that had a munted graph definition
// Record that the file was partly broken
type.addMalformedFile(file);
} else {
type.addPrefabGraph(new FileReloadContainer<PrefabGraph>(graph, new FileSystemResource(file), type.getCallback()));
}
}
} catch (DataAccessResourceFailureException e) {
LOG.error("Problem while attempting to load {}", file, e);
// Record that the file was completely broken
type.addMalformedFile(file);
}
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class EventConfDaoReloadTest method canReloadEventsOnDisk.
/**
* Verify that the reload operation does not throw any errors
* when reloading event files on disk.
*/
@Test
public void canReloadEventsOnDisk() throws IOException {
// Copy the resources to the file system
File eventconfXml = tempFolder.newFile("eventconf.xml");
File bgp4eventsXml = tempFolder.newFile("BGP4.events.xml");
FileUtils.copyInputStreamToFile(getResourceForRelativePath("reloaded/eventconf.xml").getInputStream(), eventconfXml);
FileUtils.copyInputStreamToFile(getResourceForRelativePath("reloaded/BGP4.events.xml").getInputStream(), bgp4eventsXml);
// Load
DefaultEventConfDao eventConfDao = new DefaultEventConfDao();
eventConfDao.setConfigResource(new FileSystemResource(eventconfXml));
eventConfDao.afterPropertiesSet();
assertEquals(3, eventConfDao.getAllEvents().size());
// Reload
eventConfDao.reload();
assertEquals(3, eventConfDao.getAllEvents().size());
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class EventConfDaoReloadTest method canMaintainOrderOnReload.
/**
* Verify that the order of the includes is maintained
* when new event configuration files are added, and reloaded.
*/
@Test
public void canMaintainOrderOnReload() throws Exception {
// Copy the resources to the file system
File eventconfXml = copyEventConfig("order/eventconf.empty.xml", "eventconf.xml");
// Load
DefaultEventConfDao eventConfDao = new DefaultEventConfDao();
eventConfDao.setConfigResource(new FileSystemResource(eventconfXml));
eventConfDao.afterPropertiesSet();
assertEquals(0, eventConfDao.getAllEvents().size());
EventBuilder eb = new EventBuilder("uei.opennms.org/test/order", "JUnit");
Event event = eventConfDao.findByEvent(eb.getEvent());
assertNull("no event should match", event);
// Replace the eventconf.xml with one that references 1
Thread.sleep(1000);
copyEventConfig("order/eventconf.1.xml", "eventconf.xml");
copyEventConfig("order/1.events.xml", "1.events.xml");
// Reload
eventConfDao.reload();
assertEquals(1, eventConfDao.getAllEvents().size());
event = eventConfDao.findByEvent(eb.getEvent());
assertEquals("Critical", event.getSeverity());
// Replace the eventconf.xml with one that references 2 and then 1
Thread.sleep(1000);
copyEventConfig("order/eventconf.21.xml", "eventconf.xml");
copyEventConfig("order/2.events.xml", "2.events.xml");
// Reload
eventConfDao.reload();
assertEquals(2, eventConfDao.getAllEvents().size());
event = eventConfDao.findByEvent(eb.getEvent());
assertEquals("Major", event.getSeverity());
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class EventconfFactoryIT method testLoadStandardConfiguration.
/**
* Test the standard eventconf.xml configuration file and its include files.
*/
@Test
public void testLoadStandardConfiguration() throws Exception {
DefaultEventConfDao dao = new DefaultEventConfDao();
dao.setConfigResource(new FileSystemResource(ConfigurationTestUtils.getFileForConfigFile("eventconf.xml")));
dao.afterPropertiesSet();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class PollOutagesConfigManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
String xml = "<?xml version=\"1.0\"?>\n" + "<outages>\n" + " <outage name=\"one\" type=\"weekly\">\n" + " <time day=\"sunday\" begins=\"12:30:00\" ends=\"12:45:00\"/>\n" + " <time day=\"sunday\" begins=\"13:30:00\" ends=\"14:45:00\"/>\n" + " <time day=\"monday\" begins=\"13:30:00\" ends=\"14:45:00\"/>\n" + " <time day=\"tuesday\" begins=\"13:00:00\" ends=\"14:45:00\"/>\n" + " <interface address=\"192.168.0.1\"/>\n" + " <interface address=\"192.168.0.36\"/>\n" + " <interface address=\"192.168.0.38\"/>\n" + " </outage>\n" + "\n" + " <outage name=\"two\" type=\"monthly\">\n" + " <time day=\"1\" begins=\"23:30:00\" ends=\"23:45:00\"/>\n" + " <time day=\"15\" begins=\"21:30:00\" ends=\"21:45:00\"/>\n" + " <time day=\"15\" begins=\"23:30:00\" ends=\"23:45:00\"/>\n" + " <interface address=\"192.168.100.254\"/>\n" + " <interface address=\"192.168.101.254\"/>\n" + " <interface address=\"192.168.102.254\"/>\n" + " <interface address=\"192.168.103.254\"/>\n" + " <interface address=\"192.168.104.254\"/>\n" + " <interface address=\"192.168.105.254\"/>\n" + " <interface address=\"192.168.106.254\"/>\n" + " <interface address=\"192.168.107.254\"/>\n" + " </outage>\n" + "\n" + " <outage name=\"three\" type=\"specific\">\n" + " <time begins=\"21-Feb-2005 05:30:00\" ends=\"21-Feb-2005 15:00:00\"/>\n" + " <interface address=\"192.168.0.1\"/>\n" + " </outage>\n";
final StringBuilder sb = new StringBuilder(xml);
// Fake a really big poll-outages.xml
for (int i = 1; i <= 10000; i++) {
sb.append("<outage name=\"o" + i + "\" type=\"specific\">\n");
sb.append("<time begins=\"21-Feb-2005 05:30:00\" ends=\"21-Feb-2005 15:00:00\"/>\n");
sb.append("<node id=\"" + i + "\"/>");
sb.append("</outage>");
}
sb.append("</outages>\n");
m_manager = new PollOutagesConfigManager() {
@Override
public void update() {
}
};
FileWriter w = new FileWriter(m_configFile);
w.write(sb.toString());
w.close();
m_manager.setConfigResource(new FileSystemResource(m_configFile));
m_manager.afterPropertiesSet();
assertEquals(10003, m_manager.getOutages().size());
}
Aggregations