Search in sources :

Example 1 with Invoker

use of org.opennms.netmgt.vmmgr.Invoker 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<Invoke>();
    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<Service>();
    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)

Aggregations

StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 MBeanServer (javax.management.MBeanServer)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 Options (org.apache.commons.cli.Options)1 Invoke (org.opennms.netmgt.config.service.Invoke)1 Service (org.opennms.netmgt.config.service.Service)1 Invoker (org.opennms.netmgt.vmmgr.Invoker)1 InvokerService (org.opennms.netmgt.vmmgr.InvokerService)1