Search in sources :

Example 6 with ServiceConfiguration

use of org.opennms.netmgt.config.service.ServiceConfiguration 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);
    }
}
Also used : ServiceConfiguration(org.opennms.netmgt.config.service.ServiceConfiguration) StringWriter(java.io.StringWriter) 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)

Aggregations

ServiceConfiguration (org.opennms.netmgt.config.service.ServiceConfiguration)6 Service (org.opennms.netmgt.config.service.Service)5 File (java.io.File)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 Test (org.junit.Test)3 ServiceConfigFactory (org.opennms.netmgt.config.ServiceConfigFactory)3 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)3 Attribute (org.opennms.netmgt.config.service.Attribute)1