Search in sources :

Example 6 with OnmsUpgradeException

use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.

the class ServiceConfig1701MigratorOffline 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 7 with OnmsUpgradeException

use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.

the class ServiceConfigMigratorOffline method execute.

/* (non-Javadoc)
     * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
     */
@Override
public void execute() throws OnmsUpgradeException {
    if (skipMe)
        return;
    try {
        ServiceConfiguration currentCfg = JaxbUtils.unmarshal(ServiceConfiguration.class, configFile);
        int index = 0;
        for (Service baseSvc : baseConfig.getServices()) {
            Service localSvc = getService(currentCfg, baseSvc.getName());
            if (localSvc == null) {
                if (baseSvc.isEnabled()) {
                    log("Adding new service %s\n", baseSvc.getName());
                } else {
                    log("Marking service %s as disabled\n", baseSvc.getName());
                }
                currentCfg.getServices().add(index, baseSvc);
                continue;
            }
            if (!baseSvc.isEnabled()) {
                log("Disabling service %s because it is not on the default list of enabled services\n", localSvc.getName());
                localSvc.setEnabled(false);
            }
            if (localSvc.getClassName().equals("org.opennms.netmgt.poller.jmx.RemotePollerBackEnd")) {
                log("Fixing the class path for RemotePollerBackEnd.\n");
                localSvc.setClassName("org.opennms.netmgt.poller.remote.jmx.RemotePollerBackEnd");
            }
            if (localSvc.getName().equals("OpenNMS:Name=Linkd")) {
                log("Disabling Linkd (to promote EnhancedLinkd)\n");
                localSvc.setEnabled(false);
            }
            Attribute a = getLoggingPrefix(localSvc);
            if (a != null) {
                String prefix = a.getValue().getContent().toLowerCase();
                // If the logging prefix isn't already lower case...
                if (!a.getValue().getContent().equals(prefix)) {
                    // then set it to the lower case value
                    log("Fixing logging prefix for service %s\n", localSvc.getName());
                    a.getValue().setContent(prefix);
                }
            }
            index++;
        }
        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);
        FileWriter fw = new FileWriter(configFile);
        fw.write(sw.toString());
        fw.close();
    } catch (Exception e) {
        throw new OnmsUpgradeException("Can't fix services configuration because " + e.getMessage(), e);
    }
}
Also used : ServiceConfiguration(org.opennms.netmgt.config.service.ServiceConfiguration) StringWriter(java.io.StringWriter) Attribute(org.opennms.netmgt.config.service.Attribute) FileWriter(java.io.FileWriter) Service(org.opennms.netmgt.config.service.Service) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 8 with OnmsUpgradeException

use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.

the class ServiceConfigMigratorOffline method preExecute.

/* (non-Javadoc)
     * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
     */
@Override
public void preExecute() throws OnmsUpgradeException {
    if (isInstalledVersionGreaterOrEqual(14, 0, 0)) {
        log("This upgrade procedure should only run against systems older than 14.0.0; the current version is " + getOpennmsVersion() + "\n");
        skipMe = true;
        return;
    }
    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 9 with OnmsUpgradeException

use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.

the class KscReportsMigrator method execute.

/* (non-Javadoc)
     * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
     */
@Override
public void execute() throws OnmsUpgradeException {
    log("Fixing KSC Reports.\n");
    boolean changed = false;
    List<SnmpInterface> interfacesToMerge = getInterfacesToMerge();
    for (Integer reportId : KSC_PerformanceReportFactory.getInstance().getReportList().keySet()) {
        Report report = KSC_PerformanceReportFactory.getInstance().getReportByIndex(reportId);
        log("  Checking report %s\n", report.getTitle());
        for (Graph graph : report.getGraphs()) {
            for (SnmpInterface intf : interfacesToMerge) {
                final String resourceId = graph.getResourceId().orElse(null);
                if (intf.shouldUpdate(resourceId)) {
                    changed = true;
                    log("  replacing resource ID %s with %s for %s\n", graph.getResourceId(), intf.getNewResourceId(), graph.getTitle());
                    graph.setResourceId(intf.getNewResourceId().toString());
                }
            }
        }
    }
    if (changed) {
        log("Updating the KSC reports configuration file.\n");
        try {
            KSC_PerformanceReportFactory.getInstance().saveCurrent();
        } catch (Exception e) {
            log("Warning: can't save KSC Reports because %s\n", e.getMessage());
        }
        if (isOpennmsRunning()) {
            log("In case the OpenNMS WebUI can't see the changes, go to Reports -> KSC Performance, Nodes, Domains and click on 'Request a Reload of KSC Reports Configuration'\n");
        }
    } else {
        log("No incomplete interface names detected.\n");
    }
}
Also used : Graph(org.opennms.netmgt.config.kscReports.Graph) Report(org.opennms.netmgt.config.kscReports.Report) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException)

Example 10 with OnmsUpgradeException

use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.

the class DataCollectionConfigMigrator17Offline method updateDataCollectionConfig.

/**
 * Update data collection configuration.
 *
 * @param snmpCollection the SNMP collection
 * @param dataCollectionGroup the data collection group
 * @throws OnmsUpgradeException the OpenNMS upgrade exception
 */
private void updateDataCollectionConfig(String snmpCollection, String dataCollectionGroup) throws OnmsUpgradeException {
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, sourceFile);
    if (config != null) {
        log("Adding datacollection-group %s to snmp-collection %s", dataCollectionGroup, snmpCollection);
        IncludeCollection ic = new IncludeCollection();
        ic.setDataCollectionGroup(dataCollectionGroup);
        config.getSnmpCollections().stream().filter(s -> s.getName().equals(snmpCollection)).findFirst().get().addIncludeCollection(ic);
        try {
            JaxbUtils.marshal(config, new FileWriter(sourceFile));
        } catch (IOException e) {
            throw new OnmsUpgradeException("Can't update " + sourceFile, e);
        }
    }
}
Also used : DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) Iterator(java.util.Iterator) Files(java.nio.file.Files) FileWriter(java.io.FileWriter) ConfigFileConstants(org.opennms.core.utils.ConfigFileConstants) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) HashMap(java.util.HashMap) FileUtils(org.apache.commons.io.FileUtils) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) File(java.io.File) AbstractOnmsUpgrade(org.opennms.upgrade.api.AbstractOnmsUpgrade) Matcher(java.util.regex.Matcher) Paths(java.nio.file.Paths) Map(java.util.Map) JaxbUtils(org.opennms.core.xml.JaxbUtils) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) Pattern(java.util.regex.Pattern) Path(java.nio.file.Path) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) FileWriter(java.io.FileWriter) IOException(java.io.IOException) 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