use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class SnmpInterfaceRrdMigratorOnline method execute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#execute()
*/
@Override
public void execute() throws OnmsUpgradeException {
for (SnmpInterfaceUpgrade intf : interfacesToMerge) {
try {
createBackup(intf);
merge(intf.getOldInterfaceDir(), intf.getNewInterfaceDir());
removeBackup(intf);
} catch (Exception e) {
StringWriter w = new StringWriter();
PrintWriter p = new PrintWriter(w);
e.printStackTrace(p);
log("Error: Can't upgrade %s because %s: %s. Rolling back changes\n", intf, e.getMessage(), w.toString());
restoreBackup(intf);
}
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class JmxRrdMigratorOffline method execute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#execute()
*/
@Override
public void execute() throws OnmsUpgradeException {
try {
// Fixing JRB/RRD files
final boolean isRrdtool = isRrdToolEnabled();
final boolean storeByGroup = isStoreByGroupEnabled();
for (File jmxResourceDir : getJmxResourceDirectories()) {
if (storeByGroup) {
processGroupFiles(jmxResourceDir, isRrdtool);
} else {
processSingleFiles(jmxResourceDir, isRrdtool);
}
}
// Fixing JMX Configuration File
File jmxConfigFile = null;
try {
jmxConfigFile = ConfigFileConstants.getFile(ConfigFileConstants.JMX_DATA_COLLECTION_CONF_FILE_NAME);
} catch (IOException e) {
throw new OnmsUpgradeException("Can't find JMX Configuration file (ignoring processing)");
}
fixJmxConfigurationFile(jmxConfigFile);
// List Bad Metrics:
log("Found %s Bad Metrics: %s\n", badMetrics.size(), badMetrics);
// Fixing Graph Templates
File jmxGraphsFile = new File(ConfigFileConstants.getFilePathString(), "snmp-graph.properties");
fixJmxGraphTemplateFile(jmxGraphsFile);
} catch (Exception e) {
throw new OnmsUpgradeException("Can't upgrade the JRBs because " + e.getMessage(), e);
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class RequisitionsMigratorOffline method execute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#execute()
*/
@Override
public void execute() throws OnmsUpgradeException {
try {
for (File req : FileUtils.listFiles(getRequisitionDir(), new String[] { "xml" }, true)) {
log("Processing %s\n", req);
String content = IOUtils.toString(new FileInputStream(req), StandardCharsets.UTF_8);
String output = content.replaceAll(" non-ip-(snmp-primary|interfaces)=\"[^\"]+\"", "");
if (content.length() != output.length()) {
log(" Updating and parsing the requisition\n", req);
IOUtils.write(output, new FileOutputStream(req), StandardCharsets.UTF_8);
Requisition requisition = JaxbUtils.unmarshal(Requisition.class, req, true);
if (requisition == null) {
throw new OnmsUpgradeException("Can't parse requisition " + req);
}
}
}
} catch (Exception e) {
throw new OnmsUpgradeException("Can't upgrade requisitions because " + e.getMessage(), e);
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class EOLServiceConfigMigratorOffline method preExecute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
*/
@Override
public void preExecute() throws OnmsUpgradeException {
try {
log("Backing up %s\n", configFile);
zipFile(configFile);
} catch (Exception e) {
throw new OnmsUpgradeException("Can't backup service-configurations.xml because " + e.getMessage());
}
}
use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.
the class JettyConfigMigratorOffline method execute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#execute()
*/
@Override
public void execute() throws OnmsUpgradeException {
String jettySSL = getMainProperties().getProperty("org.opennms.netmgt.jetty.https-port", null);
String jettyAJP = getMainProperties().getProperty("org.opennms.netmgt.jetty.ajp-port", null);
boolean sslWasFixed = false;
boolean ajpWasFixed = false;
try {
log("SSL Enabled ? %s\n", jettySSL != null);
log("AJP Enabled ? %s\n", jettyAJP != null);
if (jettySSL != null || jettyAJP != null) {
File jettyXmlExample = new File(getHomeDirectory(), "etc" + File.separator + "examples" + File.separator + "jetty.xml");
File jettyXml = new File(getHomeDirectory(), "etc" + File.separator + "jetty.xml");
if (!jettyXml.exists() && !jettyXmlExample.exists()) {
throw new FileNotFoundException("The required file doesn't exist: " + jettyXmlExample);
}
if (!jettyXml.exists()) {
log("Copying %s into %s\n", jettyXmlExample, jettyXml);
FileUtils.copyFile(jettyXmlExample, jettyXml);
}
log("Creating %s\n", jettyXml);
File tempFile = new File(jettyXml.getAbsoluteFile() + ".tmp");
FileWriter w = new FileWriter(tempFile);
LineIterator it = FileUtils.lineIterator(jettyXmlExample);
boolean startSsl = false;
boolean startAjp = false;
while (it.hasNext()) {
String line = it.next();
if (startAjp) {
if (line.matches("^\\s+[<][!]--\\s*$")) {
continue;
}
if (line.matches("^\\s+--[>]\\s*$")) {
startAjp = false;
ajpWasFixed = true;
continue;
}
}
if (startSsl) {
if (line.matches("^\\s+[<][!]--\\s*$")) {
continue;
}
if (line.matches("^\\s+--[>]\\s*$")) {
startSsl = false;
sslWasFixed = true;
continue;
}
}
w.write(line + "\n");
if (startAjp == false && line.contains("<!-- Add AJP support -->") && jettyAJP != null) {
startAjp = true;
log("Enabling AjpConnector\n");
}
if (startSsl == false && line.contains("<!-- Add HTTPS support -->") && jettySSL != null) {
startSsl = true;
log("Enabling SslSelectChannelConnector\n");
}
}
LineIterator.closeQuietly(it);
w.close();
FileUtils.copyFile(tempFile, jettyXml);
FileUtils.deleteQuietly(tempFile);
} else {
log("Neither SSL nor AJP are enabled.\n");
}
} catch (Exception e) {
throw new OnmsUpgradeException("Can't fix Jetty configuration because " + e.getMessage(), e);
}
if (jettyAJP != null && !ajpWasFixed) {
throw new OnmsUpgradeException("Can't enable APJ, please manually edit jetty.xml and uncomment the section where org.eclipse.jetty.ajp.Ajp13SocketConnector is defined.");
}
if (jettySSL != null && !sslWasFixed) {
throw new OnmsUpgradeException("Can't enable SSL, please manually edit jetty.xml and uncomment the section where org.eclipse.jetty.server.ssl.SslSelectChannelConnector is defined.");
}
}
Aggregations