Search in sources :

Example 1 with OnmsUpgradeException

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);
        }
    }
}
Also used : StringWriter(java.io.StringWriter) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 2 with OnmsUpgradeException

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);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException)

Example 3 with OnmsUpgradeException

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);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 4 with OnmsUpgradeException

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());
    }
}
Also used : OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 5 with OnmsUpgradeException

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.");
    }
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) LineIterator(org.apache.commons.io.LineIterator) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) FileNotFoundException(java.io.FileNotFoundException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Aggregations

OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)31 IOException (java.io.IOException)23 File (java.io.File)14 FileWriter (java.io.FileWriter)8 StringWriter (java.io.StringWriter)6 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 Map (java.util.Map)3 Pattern (java.util.regex.Pattern)3 LineIterator (org.apache.commons.io.LineIterator)3 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)3 Service (org.opennms.netmgt.config.service.Service)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Writer (java.io.Writer)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2