use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class EventParameterMigratorOffline method execute.
@Override
public void execute() throws OnmsUpgradeException {
long eventCount = 0, parameterCount = 0;
try (final Connection connection = DataSourceFactory.getInstance().getConnection()) {
connection.setAutoCommit(false);
do {
try (final Statement selectStatement = connection.createStatement();
final ResultSet resultSet = selectStatement.executeQuery("SELECT eventid, eventparms FROM events WHERE eventparms IS NOT NULL LIMIT " + BATCH_SIZE)) {
if (!resultSet.next()) {
break;
}
try (final PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO event_parameters (eventid, name, value, type) VALUES (?,?,?,?)");
final PreparedStatement nullifyStatement = connection.prepareStatement("UPDATE events SET eventparms=NULL WHERE eventid=?")) {
do {
final Integer eventId = resultSet.getInt("eventid");
final String eventParms = resultSet.getString("eventparms");
final List<Parm> parmList = EventParameterUtils.decode(eventParms);
if (parmList != null) {
final Map<String, Parm> parmMap = EventParameterUtils.normalize(parmList);
for (Map.Entry<String, Parm> entry : parmMap.entrySet()) {
insertStatement.setInt(1, eventId);
insertStatement.setString(2, entry.getValue().getParmName());
insertStatement.setString(3, entry.getValue().getValue().getContent());
insertStatement.setString(4, entry.getValue().getValue().getType());
insertStatement.execute();
parameterCount++;
}
}
nullifyStatement.setInt(1, eventId);
nullifyStatement.execute();
eventCount++;
} while (resultSet.next());
log("Processed %d eventparms entries, %d event parameters inserted...\n", eventCount, parameterCount);
connection.commit();
} catch (SQLException e) {
connection.rollback();
connection.setAutoCommit(true);
throw e;
}
}
} while (true);
connection.setAutoCommit(true);
log("Rows migrated. Dropping column 'eventparms'...\n");
final Statement postMigrationStatement = connection.createStatement();
postMigrationStatement.execute("ALTER TABLE events DROP COLUMN eventparms");
} catch (Throwable e) {
throw new OnmsUpgradeException("Can't move event parameters to table: " + e.getMessage(), e);
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class Upgrade method getUpgradeObjects.
/**
* Gets the upgrade objects.
*
* @return the upgrade objects
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
protected List<OnmsUpgrade> getUpgradeObjects() throws OnmsUpgradeException {
List<OnmsUpgrade> upgrades = new ArrayList<>();
try {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.addIncludeFilter(new AssignableTypeFilter(OnmsUpgrade.class));
Set<BeanDefinition> components = provider.findCandidateComponents(getClassScope());
for (BeanDefinition component : components) {
if (component.isAbstract()) {
continue;
}
Class<?> cls = Class.forName(component.getBeanClassName());
if (cls.getAnnotation(Ignore.class) != null) {
continue;
}
OnmsUpgrade upgrade = (OnmsUpgrade) cls.newInstance();
upgrades.add(upgrade);
log("Found upgrade task %s\n", upgrade.getId());
}
Collections.sort(upgrades, new OnmsUpgradeComparator());
} catch (Exception e) {
throw new OnmsUpgradeException(" Can't find the upgrade classes because: " + e.getMessage(), e);
}
return upgrades;
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class DataCollectionConfigMigrator17OfflineTest method canFix.
/**
* Can fix.
*
* @throws OnmsUpgradeException the OpenNMS upgrade exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void canFix() throws OnmsUpgradeException, IOException {
DataCollectionConfigMigrator17Offline task = new DataCollectionConfigMigrator17Offline();
task.preExecute();
task.execute();
task.postExecute();
DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, new File(tempFolder.getRoot(), "etc/datacollection-config.xml"));
Assert.assertNotNull(config);
config.getSnmpCollections().forEach(s -> {
Assert.assertTrue(s.getIncludeCollections().stream().filter(i -> i.getDataCollectionGroup().equals("SNMP-Informant")).findFirst().isPresent());
});
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class SnmpInterfaceRrdMigratorOnline method preExecute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
*/
public void preExecute() throws OnmsUpgradeException {
printMainSettings();
if (getRrdExtension() == null) {
throw new OnmsUpgradeException("Can't find the configured extension for JRB/RRD.");
}
try {
// Manually initialization of the DataCollectionConfigDao to avoid bootstrap Spring Framework and create a new connection pool.
File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.DATA_COLLECTION_CONF_FILE_NAME);
DefaultDataCollectionConfigDao config = new DefaultDataCollectionConfigDao();
config.setConfigResource(new FileSystemResource(cfgFile));
config.afterPropertiesSet();
config.getConfiguredResourceTypes();
DataCollectionConfigFactory.setInstance(config);
} catch (Exception e) {
throw new OnmsUpgradeException("Can't initialize datacollection-config.xml because " + e.getMessage());
}
interfacesToMerge = getInterfacesToMerge();
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class EOLServiceConfigMigratorOffline method execute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#execute()
*/
@Override
public void execute() throws OnmsUpgradeException {
final String[] eol = { "OpenNMS:Name=Linkd", "OpenNMS:Name=Xmlrpcd", "OpenNMS:Name=XmlrpcProvisioner", "OpenNMS:Name=AccessPointMonitor" };
try {
final ServiceConfiguration currentCfg = JaxbUtils.unmarshal(ServiceConfiguration.class, configFile);
// Remove any end-of-life'd daemons from service configuration
for (final String serviceName : eol) {
final Service eolService = getService(currentCfg, serviceName);
if (eolService == null) {
continue;
}
final String eolServiceName = eolService.getName();
if (eolServiceName.equals(serviceName)) {
final String displayName = serviceName.replace("OpenNMS:Name=", "");
log("Disabling EOL service: " + displayName + "\n");
eolService.setEnabled(false);
}
}
final StringWriter sw = new StringWriter();
sw.write("<?xml version=\"1.0\"?>\n");
sw.write("<!-- NOTE!!!!!!!!!!!!!!!!!!!\n");
sw.write("The order in which these services are specified is important - for example, Eventd\n");
sw.write("will need to come up last so that none of the event topic subcribers loose any event.\n");
sw.write("\nWhen splitting services to run on mutiple VMs, the order of the services should be\n");
sw.write("maintained\n");
sw.write("-->\n");
JaxbUtils.marshal(currentCfg, sw);
final FileWriter fw = new FileWriter(configFile);
fw.write(sw.toString());
fw.close();
} catch (final Exception e) {
throw new OnmsUpgradeException("Can't fix services configuration because " + e.getMessage(), e);
}
}
Aggregations