use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class JmxRrdMigratorOffline method rollback.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
*/
@Override
public void rollback() throws OnmsUpgradeException {
try {
for (File jmxResourceDir : getJmxResourceDirectories()) {
File zip = new File(jmxResourceDir.getAbsolutePath() + ZIP_EXT);
FileUtils.deleteDirectory(jmxResourceDir);
if (!jmxResourceDir.mkdirs()) {
LOG.warn("Could not make directory: {}", jmxResourceDir.getPath());
}
unzipFile(zip, jmxResourceDir);
if (!zip.delete()) {
LOG.warn("Could not delete file: {}", zip.getPath());
}
}
File configDir = new File(ConfigFileConstants.getFilePathString());
for (File backupFile : backupFiles) {
unzipFile(backupFile, configDir);
}
} catch (IOException e) {
throw new OnmsUpgradeException("Can't restore the backup files because " + e.getMessage());
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class KscReportsMigrator method preExecute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
*/
public void preExecute() throws OnmsUpgradeException {
try {
log("Backing up %s\n", configFile);
zipFile(configFile);
initializeDatasource();
KSC_PerformanceReportFactory.init();
} catch (Exception e) {
throw new OnmsUpgradeException("Can't initialize ksc-performance-reports.xml because " + e.getMessage());
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class MagicUsersMigratorOffline method preExecute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
*/
@Override
public void preExecute() throws OnmsUpgradeException {
if (!canRun())
return;
try {
File[] files = { magicUsersFile, magicUsersFileRPM, magicUsersFileDEB, usersFile };
for (File file : files) {
if (file.exists()) {
log("Backing up %s\n", file);
zipFile(file);
}
}
} catch (Exception e) {
throw new OnmsUpgradeException("Can't backup files because " + e.getMessage());
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class DataCollectionConfigMigratorOffline method migrateDataCollectionConfig.
private void migrateDataCollectionConfig(File cfgFile) throws OnmsUpgradeException {
try {
log(" %s\n", cfgFile.getAbsolutePath());
// Read the file into memory
String cfgFileContents = FileUtils.readFileToString(cfgFile);
// Perform the required substitutions
for (final Map.Entry<String, String> substitution : substitutionMap.entrySet()) {
cfgFileContents = cfgFileContents.replace(substitution.getKey(), substitution.getValue());
}
// Write the (modified) file back to disk
FileUtils.write(cfgFile, cfgFileContents);
} catch (IOException e) {
throw new OnmsUpgradeException(String.format("Failed to update %s", cfgFile), e);
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class DiscoveryConfigurationLocationMigratorOffline method execute.
@Override
public void execute() throws OnmsUpgradeException {
Writer out = null;
try {
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
final Document doc = docBuilder.parse(m_configFile);
updateLocations(doc, "discovery-configuration");
updateLocations(doc, "include-range");
updateLocations(doc, "include-url");
updateLocations(doc, "specific");
final Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
tf.setOutputProperty(OutputKeys.INDENT, "yes");
out = new StringWriter();
tf.transform(new DOMSource(doc), new StreamResult(out));
FileUtils.write(m_configFile, out.toString());
} catch (final IOException | SAXException | ParserConfigurationException | TransformerException e) {
throw new OnmsUpgradeException("Failed to upgrade discovery-configuration.xml", e);
} finally {
IOUtils.closeQuietly(out);
}
}
Aggregations