use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.
the class FileReloadContainer method reload.
/**
* Force a reload of the configuration.
*/
public synchronized void reload() {
/*
* Always update the timestamp, even if we have an error.
* XXX What if someone is writing the file while we are reading it,
* we get an error, and the (correct) file is written completely
* within the same second, so lastModified doesn't get updated.
*/
m_lastModified = m_file.lastModified();
m_lastFileSize = m_file.length();
final T object;
try {
object = m_callback.reload(m_object, m_resource);
} catch (Throwable t) {
final String message = String.format("Failed reloading data for object '%s' from file '%s'. Unexpected Throwable received while issuing reload.", m_object, m_file.getAbsolutePath());
LOG.error(message, t);
throw new DataAccessResourceFailureException(message, t);
}
if (object == null) {
LOG.info("Not updating object for file '{}' due to reload callback returning null.", m_file.getAbsolutePath());
} else {
m_object = object;
}
m_lastUpdate = System.currentTimeMillis();
}
use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.
the class HeartbeatConsumer method provision.
private void provision(final OnmsMinion minion, final String prevLocation, final String nextLocation) {
// Return fast if automatic provisioning is disabled
if (!PROVISIONING) {
return;
}
// Return fast until the provisioner is running to pick up the events sent below
if (!this.eventSubscriptionService.hasEventListener(EventConstants.RELOAD_IMPORT_UEI)) {
return;
}
final String prevForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, prevLocation);
final String nextForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, nextLocation);
final Set<String> alteredForeignSources = Sets.newHashSet();
// Remove the node from the previous requisition, if location has changed
if (!Objects.equals(prevForeignSource, nextForeignSource)) {
final Requisition prevRequisition = this.deployedForeignSourceRepository.getRequisition(prevForeignSource);
if (prevRequisition != null && prevRequisition.getNode(minion.getId()) != null) {
prevRequisition.deleteNode(minion.getId());
prevRequisition.updateDateStamp();
deployedForeignSourceRepository.save(prevRequisition);
deployedForeignSourceRepository.flush();
alteredForeignSources.add(prevForeignSource);
}
}
Requisition nextRequisition = deployedForeignSourceRepository.getRequisition(nextForeignSource);
if (nextRequisition == null) {
nextRequisition = new Requisition(nextForeignSource);
nextRequisition.updateDateStamp();
// We have to save the requisition before we can alter the according foreign source definition
deployedForeignSourceRepository.save(nextRequisition);
// Remove all policies and detectors from the foreign source
final ForeignSource foreignSource = deployedForeignSourceRepository.getForeignSource(nextForeignSource);
foreignSource.setDetectors(Collections.emptyList());
foreignSource.setPolicies(Collections.emptyList());
deployedForeignSourceRepository.save(foreignSource);
alteredForeignSources.add(nextForeignSource);
}
RequisitionNode requisitionNode = nextRequisition.getNode(minion.getId());
if (requisitionNode == null) {
final RequisitionMonitoredService requisitionMonitoredService = new RequisitionMonitoredService();
requisitionMonitoredService.setServiceName("Minion-Heartbeat");
final RequisitionInterface requisitionInterface = new RequisitionInterface();
requisitionInterface.setIpAddr("127.0.0.1");
requisitionInterface.putMonitoredService(requisitionMonitoredService);
requisitionNode = new RequisitionNode();
requisitionNode.setNodeLabel(minion.getId());
requisitionNode.setForeignId(minion.getLabel() != null ? minion.getLabel() : minion.getId());
requisitionNode.setLocation(minion.getLocation());
requisitionNode.putInterface(requisitionInterface);
nextRequisition.putNode(requisitionNode);
nextRequisition.setDate(new Date());
deployedForeignSourceRepository.save(nextRequisition);
deployedForeignSourceRepository.flush();
alteredForeignSources.add(nextForeignSource);
}
for (final String alteredForeignSource : alteredForeignSources) {
final EventBuilder eventBuilder = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
eventBuilder.addParam(EventConstants.PARM_URL, String.valueOf(deployedForeignSourceRepository.getRequisitionURL(alteredForeignSource)));
try {
eventProxy.send(eventBuilder.getEvent());
} catch (final EventProxyException e) {
throw new DataAccessResourceFailureException("Unable to send event to import group " + alteredForeignSource, e);
}
}
}
use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.
the class FilterDaoFactory method init.
/**
* <p>init</p>
*/
protected static synchronized void init() {
if (m_filterDao != null) {
return;
}
JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
jdbcFilterDao.setDataSource(DataSourceFactory.getInstance());
try {
DatabaseSchemaConfigFactory.init();
} catch (Throwable e) {
throw new DataAccessResourceFailureException("Could not initialize DatabaseSchemaConfigFactory: " + e, e);
}
jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
jdbcFilterDao.afterPropertiesSet();
setInstance(jdbcFilterDao);
}
use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.
the class DefaultRrdDaoTest method testPrintValueWithBogusLine.
public void testPrintValueWithBogusLine() throws Exception {
long end = System.currentTimeMillis();
long start = end - (24 * 60 * 60 * 1000);
String printLine = "blah blah blah this should be a floating point number blah blah blah";
OnmsResource childResource = preparePrintValueTest(start, end, printLine);
m_mocks.replayAll();
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new DataAccessResourceFailureException("Value of line 1 of output from RRD is not a valid floating point number: '" + printLine + "'"));
try {
m_dao.getPrintValue(childResource.getAttributes().iterator().next(), "AVERAGE", start, end);
} catch (Throwable t) {
ta.throwableReceived(t);
}
m_mocks.verifyAll();
ta.verifyAnticipated();
}
use of org.springframework.dao.DataAccessResourceFailureException in project opennms by OpenNMS.
the class ReportDefinitionBuilder method buildReportDefinitions.
/**
* Builds and schedules all reports enabled in the statsd-configuration.
* This method has the capability to throw a ton of exceptions, just generically throwing <code>Exception</code>
*
* @return a <code>Collection</code> of enabled reports from the statsd-configuration.
* @throws java.lang.Exception if any.
*/
public Collection<ReportDefinition> buildReportDefinitions() throws Exception {
Set<ReportDefinition> reportDefinitions = new HashSet<ReportDefinition>();
for (StatsdPackage pkg : m_statsdConfigDao.getPackages()) {
for (PackageReport packageReport : pkg.getReports()) {
Report report = packageReport.getReport();
if (!packageReport.isEnabled()) {
LOG.debug("skipping report '{}' in package '{}' because the report is not enabled", report.getName(), pkg.getName());
continue;
}
Class<? extends AttributeStatisticVisitorWithResults> clazz;
try {
clazz = createClassForReport(report);
} catch (ClassNotFoundException e) {
throw new DataAccessResourceFailureException("Could not find class '" + report.getClassName() + "'; nested exception: " + e, e);
}
Assert.isAssignable(AttributeStatisticVisitorWithResults.class, clazz, "the class specified by class-name in the '" + report.getName() + "' report does not implement the interface " + AttributeStatisticVisitorWithResults.class.getName() + "; ");
ReportDefinition reportDef = new ReportDefinition();
reportDef.setReport(packageReport);
reportDef.setReportClass(clazz);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(reportDef);
try {
bw.setPropertyValues(packageReport.getAggregateParameters());
} catch (BeansException e) {
LOG.error("Could not set properties on report definition: {}", e.getMessage(), e);
}
reportDef.afterPropertiesSet();
reportDefinitions.add(reportDef);
}
}
return reportDefinitions;
}
Aggregations