Search in sources :

Example 6 with Service

use of org.opennms.netmgt.config.service.Service in project opennms by OpenNMS.

the class Invoker method invokeMethods.

/**
 * <p>invokeMethods</p>
 *
 * @return a {@link java.util.List} object.
 */
public List<InvokerResult> invokeMethods() {
    List<InvokerService> invokerServicesOrdered;
    if (isReverse()) {
        invokerServicesOrdered = new ArrayList<InvokerService>(getServices());
        Collections.reverse(invokerServicesOrdered);
    } else {
        // We can  use the original list
        invokerServicesOrdered = getServices();
    }
    List<InvokerResult> resultInfo = new ArrayList<InvokerResult>(invokerServicesOrdered.size());
    for (int pass = 0, end = getLastPass(); pass <= end; pass++) {
        LOG.debug("starting pass {}", pass);
        for (InvokerService invokerService : invokerServicesOrdered) {
            Service service = invokerService.getService();
            String name = invokerService.getService().getName();
            ObjectInstance mbean = invokerService.getMbean();
            if (invokerService.isBadService()) {
                resultInfo.add(new InvokerResult(service, mbean, null, invokerService.getBadThrowable()));
                if (isFailFast()) {
                    return resultInfo;
                }
            }
            for (final Invoke invoke : invokerService.getService().getInvokes()) {
                if (invoke.getPass() != pass || !getAtType().equals(invoke.getAt())) {
                    continue;
                }
                LOG.debug("pass {} on service {} will invoke method \"{}\"", pass, name, invoke.getMethod());
                try {
                    Object result = invoke(invoke, mbean);
                    resultInfo.add(new InvokerResult(service, mbean, result, null));
                } catch (Throwable t) {
                    resultInfo.add(new InvokerResult(service, mbean, null, t));
                    if (isFailFast()) {
                        return resultInfo;
                    }
                }
            }
        }
        LOG.debug("completed pass {}", pass);
    }
    return resultInfo;
}
Also used : ArrayList(java.util.ArrayList) ObjectInstance(javax.management.ObjectInstance) Service(org.opennms.netmgt.config.service.Service) Invoke(org.opennms.netmgt.config.service.Invoke)

Example 7 with Service

use of org.opennms.netmgt.config.service.Service in project opennms by OpenNMS.

the class ServiceConfig1701MigratorOffline method execute.

/* (non-Javadoc)
     * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
     */
@Override
public void execute() throws OnmsUpgradeException {
    try {
        ServiceConfiguration currentCfg = JaxbUtils.unmarshal(ServiceConfiguration.class, configFile);
        log("Current configuration: " + currentCfg.getServices().size() + " services.\n");
        for (int i = currentCfg.getServices().size() - 1; i >= 0; i--) {
            final Service localSvc = (Service) currentCfg.getServices().get(i);
            final String name = localSvc.getName();
            if (oldServices.contains(name)) {
                log("Removing old service %s\n", name);
                currentCfg.getServices().remove(i);
            }
        }
        log("New configuration: " + currentCfg.getServices().size() + " services.\n");
        // now remove
        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 (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)

Example 8 with Service

use of org.opennms.netmgt.config.service.Service in project opennms by OpenNMS.

the class ServiceConfigurationPublicConstructorIT method getClasses.

@Override
protected List<Class<? extends Object>> getClasses() throws IOException, ClassNotFoundException {
    List<Class<? extends Object>> retval = new ArrayList<Class<? extends Object>>();
    Service[] services = new ServiceConfigFactory().getServices();
    for (Service service : services) {
        retval.add(Class.forName(service.getClassName()));
    }
    return retval;
}
Also used : ArrayList(java.util.ArrayList) Service(org.opennms.netmgt.config.service.Service)

Example 9 with Service

use of org.opennms.netmgt.config.service.Service in project opennms by OpenNMS.

the class Main method main.

@SuppressWarnings({ "static-access", "deprecation" })
public static void main(final String... args) throws Exception {
    final Options options = new Options();
    options.addOption(OptionBuilder.withDescription("this help").withLongOpt("help").create("h"));
    options.addOption(OptionBuilder.hasArg().withArgName("DIRECTORY").withDescription("OpenNMS home directory").withLongOpt("opennms-home").create("o"));
    final CommandLineParser parser = new GnuParser();
    try {
        final CommandLine line = parser.parse(options, args);
        if (line.hasOption("help")) {
            final HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("syslog-profiler", options, true);
            System.exit(1);
        }
        if (line.hasOption("opennms-home")) {
            OPENNMS_HOME = line.getOptionValue("opennms-home");
        } else {
            final HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("syslog-profiler", "You must specify your OpenNMS home.", options, null);
            System.exit(1);
        }
    } catch (Throwable e) {
        LOG.warn("An error occurred trying to parse the command-line.", e);
    }
    System.out.println("- using " + OPENNMS_HOME + "/etc for configuration files");
    System.setProperty("opennms.home", OPENNMS_HOME);
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    List<Invoke> invokes = new ArrayList<>();
    invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"start\" pass=\"0\" method=\"init\"/>")));
    invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"start\" pass=\"1\" method=\"start\"/>")));
    invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"status\" pass=\"0\" method=\"status\"/>")));
    invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"stop\" pass=\"0\" method=\"stop\"/>")));
    List<Service> services = new ArrayList<>();
    Invoker invoker = new Invoker();
    invoker.setServer(server);
    invoker.setAtType(InvokeAtType.START);
    for (final Service s : Invoker.getDefaultServiceConfigFactory().getServices()) {
        if (s.getName().contains("Eventd") || s.getName().contains("Syslogd")) {
            services.add(s);
        }
    }
    List<InvokerService> invokerServices = InvokerService.createServiceList(services.toArray(new Service[0]));
    System.err.println(invokerServices);
    invoker.setServices(invokerServices);
    invoker.instantiateClasses();
    Thread.sleep(10000);
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) ArrayList(java.util.ArrayList) Service(org.opennms.netmgt.config.service.Service) InvokerService(org.opennms.netmgt.vmmgr.InvokerService) Invoke(org.opennms.netmgt.config.service.Invoke) HelpFormatter(org.apache.commons.cli.HelpFormatter) InvokerService(org.opennms.netmgt.vmmgr.InvokerService) CommandLine(org.apache.commons.cli.CommandLine) Invoker(org.opennms.netmgt.vmmgr.Invoker) StringReader(java.io.StringReader) CommandLineParser(org.apache.commons.cli.CommandLineParser) MBeanServer(javax.management.MBeanServer)

Example 10 with Service

use of org.opennms.netmgt.config.service.Service 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

Service (org.opennms.netmgt.config.service.Service)12 ServiceConfiguration (org.opennms.netmgt.config.service.ServiceConfiguration)5 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 ObjectName (javax.management.ObjectName)3 ServiceConfigFactory (org.opennms.netmgt.config.ServiceConfigFactory)3 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)3 File (java.io.File)2 MBeanServer (javax.management.MBeanServer)2 Test (org.junit.Test)2 Invoke (org.opennms.netmgt.config.service.Invoke)2 StringReader (java.io.StringReader)1 Attribute (javax.management.Attribute)1 ObjectInstance (javax.management.ObjectInstance)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 GnuParser (org.apache.commons.cli.GnuParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1