Example usage for java.util.logging Level ALL

List of usage examples for java.util.logging Level ALL

Introduction

In this page you can find the example usage for java.util.logging Level ALL.

Prototype

Level ALL

To view the source code for java.util.logging Level ALL.

Click Source Link

Document

ALL indicates that all messages should be logged.

Usage

From source file:org.kontalk.Kontalk.java

/**
 * @param args the command line arguments
 *///from  w  ww .  java  2  s .  c  om
public static void main(String[] args) {

    LOGGER.setLevel(Level.ALL);

    Kontalk model = new Kontalk(args);
    model.start();
}

From source file:com.flagleader.builder.FlagLeader.java

public static void main(String[] paramArrayOfString) {
    Shell localShell = new Shell(16777216);
    localShell.setLocation(new Point(300, 200));
    localShell.setLayout(new FillLayout());
    Composite localComposite = new Composite(localShell, 0);
    localComposite.setLayout(new FillLayout());
    Label localLabel = new Label(localComposite, 0);
    Image localImage = ImageDescriptor
            .createFromURL(localShell.getClass().getClassLoader().getResource("icons/start.jpg")).createImage();
    localLabel.setImage(localImage);//from   ww w.ja va 2  s . co m
    localShell.setSize(400, 300);
    localShell.setText("Visual Rules Solution");
    localShell.open();
    Init.a();
    String str = null;
    if (BuilderConfig.getInstance().isLoadDefault())
        str = RuleRepository.DEFAULTEXT;
    if (paramArrayOfString.length > 0)
        str = "";
    for (int i = 0; i < paramArrayOfString.length; i++)
        str = str + paramArrayOfString[i] + " ";
    Logger localLogger = Logger.getLogger("ruleengine");
    Object localObject;
    try {
        new File(SystemUtils.USER_HOME + File.separator + ".visualrules" + File.separator + "logs").mkdirs();
        FileHandler localFileHandler = new FileHandler(SystemUtils.USER_HOME + File.separator + ".visualrules"
                + File.separator + "logs" + File.separator + "logfile%u.%g.txt", 0, 10);
        localFileHandler.setFormatter(new com.flagleader.server.c());
        localFileHandler.setLevel(Level.ALL);
        Logger.getLogger("flagleader").addHandler(localFileHandler);
        localLogger.addHandler(localFileHandler);
    } catch (Exception localException1) {
        if (!b) {
            localObject = new ConsoleHandler();
            ((ConsoleHandler) localObject).setFormatter(new com.flagleader.server.c());
            ((ConsoleHandler) localObject).setLevel(Level.ALL);
            Logger.getLogger("flagleader").addHandler((Handler) localObject);
            localLogger.addHandler((Handler) localObject);
        }
    }
    if (!BuilderManager.checkLicense()) {
        localImage.dispose();
        localShell.dispose();
        return;
    }
    Property.getInstance().setEngineImplement("com.flagleader.engine.impl.SingleRuleEngineFactory");
    FlagLeader localFlagLeader = new FlagLeader();
    Property.getInstance().setUpdateInternateTime(0L);
    localFlagLeader.setBlockOnOpen(true);
    localFlagLeader.builderManager = new BuilderManager(localFlagLeader);
    if ((com.flagleader.manager.d.c.a("needLogin", false)) || (BuilderConfig.getInstance().isFirstLogin()))
        try {
            localObject = localFlagLeader.builderManager.getUserServer();
            if ((localObject == null) || (((String) localObject).length() == 0)
                    || (localFlagLeader.builderManager.getUserType() == 0)
                    || (localFlagLeader.builderManager.getUserid() == 0)) {
                localImage.dispose();
                localShell.dispose();
                return;
            }
        } catch (Exception localException2) {
            MessageDialog.openError(null, "",
                    ResourceTools.getMessage("loginserver.error") + localException2.getLocalizedMessage());
            localImage.dispose();
            localShell.dispose();
            return;
        }
    if ((str != null) && (new File(str).exists()))
        localFlagLeader.builderManager.getRulesManager().a(new File(str));
    localFlagLeader.initWindow();
    if (new File(SystemUtils.JAVA_IO_TMPDIR, "engine.jar").exists())
        new File(SystemUtils.JAVA_IO_TMPDIR, "engine.jar").delete();
    if (new File(SystemUtils.JAVA_IO_TMPDIR, "export.jar").exists())
        new File(SystemUtils.JAVA_IO_TMPDIR, "export.jar").delete();
    if (BuilderConfig.getInstance().isAutosave())
        new com.flagleader.builder.d.c(localFlagLeader.builderManager).b();
    if (BuilderConfig.getInstance().isAutoCheckVersion())
        new a(localFlagLeader.builderManager).b();
    new e().b();
    localImage.dispose();
    localShell.dispose();
    localFlagLeader.open();
    BuilderManager localBuilderManager = localFlagLeader.builderManager;
    localFlagLeader.getShell().addShellListener(new d(localBuilderManager));
}

From source file:com.twitter.heron.scheduler.RuntimeManagerMain.java

public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException,
        InstantiationException, IOException, ParseException {

    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);

    if (cmd.hasOption("h")) {
        usage(options);//from   w  w  w . j  a va2  s . c  o  m
        return;
    }

    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }

    Boolean verbose = false;
    Level logLevel = Level.INFO;
    if (cmd.hasOption("v")) {
        logLevel = Level.ALL;
        verbose = true;
    }

    // init log
    LoggingHelper.loggerInit(logLevel, false);

    String cluster = cmd.getOptionValue("cluster");
    String role = cmd.getOptionValue("role");
    String environ = cmd.getOptionValue("environment");
    String heronHome = cmd.getOptionValue("heron_home");
    String configPath = cmd.getOptionValue("config_path");
    String overrideConfigFile = cmd.getOptionValue("override_config_file");
    String releaseFile = cmd.getOptionValue("release_file");
    String topologyName = cmd.getOptionValue("topology_name");
    String commandOption = cmd.getOptionValue("command");

    // Optional argument in the case of restart
    // TODO(karthik): convert into CLI
    String containerId = Integer.toString(-1);
    if (cmd.hasOption("container_id")) {
        containerId = cmd.getOptionValue("container_id");
    }

    Command command = Command.makeCommand(commandOption);

    // first load the defaults, then the config from files to override it
    Config.Builder defaultsConfig = Config.newBuilder().putAll(ClusterDefaults.getDefaults())
            .putAll(ClusterConfig.loadConfig(heronHome, configPath, releaseFile));

    // add config parameters from the command line
    Config.Builder commandLineConfig = Config.newBuilder().put(Keys.cluster(), cluster).put(Keys.role(), role)
            .put(Keys.environ(), environ).put(Keys.verbose(), verbose)
            .put(Keys.topologyContainerId(), containerId);

    Config.Builder topologyConfig = Config.newBuilder().put(Keys.topologyName(), topologyName);

    Config.Builder overrideConfig = Config.newBuilder()
            .putAll(ClusterConfig.loadOverrideConfig(overrideConfigFile));

    // build the final config by expanding all the variables
    Config config = Config
            .expand(Config.newBuilder().putAll(defaultsConfig.build()).putAll(overrideConfig.build())
                    .putAll(commandLineConfig.build()).putAll(topologyConfig.build()).build());

    LOG.fine("Static config loaded successfully ");
    LOG.fine(config.toString());

    // Create a new instance of RuntimeManagerMain
    RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, command);
    boolean isSuccessful = runtimeManagerMain.manageTopology();

    // Log the result and exit
    if (!isSuccessful) {
        throw new RuntimeException(String.format("Failed to %s topology %s", command, topologyName));
    } else {
        LOG.log(Level.FINE, "Topology {0} {1} successfully", new Object[] { topologyName, command });
    }
}

From source file:com.frostvoid.trekwar.server.TrekwarServer.java

public static void main(String[] args) {
    // load language
    try {/*w ww . j ava2 s  . com*/
        lang = new Language(Language.ENGLISH);
    } catch (IOException ioe) {
        System.err.println("FATAL ERROR: Unable to load language file!");
        System.exit(1);
    }

    System.out.println(lang.get("trekwar_server") + " " + VERSION);
    System.out.println("==============================================".substring(0,
            lang.get("trekwar_server").length() + 1 + VERSION.length()));

    // Handle parameters
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("file").withLongOpt("galaxy").hasArg()
            .withDescription("the galaxy file to load").create("g")); //"g", "galaxy", true, "the galaxy file to load");
    options.addOption(OptionBuilder.withArgName("port number").withLongOpt("port").hasArg()
            .withDescription("the port number to bind to (default 8472)").create("p"));
    options.addOption(OptionBuilder.withArgName("number").withLongOpt("save-interval").hasArg()
            .withDescription("how often (in turns) to save the galaxy to disk (default: 5)").create("s"));
    options.addOption(OptionBuilder.withArgName("log level").withLongOpt("log").hasArg()
            .withDescription("sets the log level: ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF")
            .create("l"));
    options.addOption("h", "help", false, "prints this help message");

    CommandLineParser cliParser = new BasicParser();

    try {
        CommandLine cmd = cliParser.parse(options, args);
        String portStr = cmd.getOptionValue("p");
        String galaxyFileStr = cmd.getOptionValue("g");
        String saveIntervalStr = cmd.getOptionValue("s");
        String logLevelStr = cmd.getOptionValue("l");

        if (cmd.hasOption("h")) {
            HelpFormatter help = new HelpFormatter();
            help.printHelp("TrekwarServer", options);
            System.exit(0);
        }

        if (cmd.hasOption("g") && galaxyFileStr != null) {
            galaxyFileName = galaxyFileStr;
        } else {
            throw new ParseException("galaxy file not specified");
        }

        if (cmd.hasOption("p") && portStr != null) {
            port = Integer.parseInt(portStr);
            if (port < 1 || port > 65535) {
                throw new NumberFormatException(lang.get("port_number_out_of_range"));
            }
        } else {
            port = 8472;
        }

        if (cmd.hasOption("s") && saveIntervalStr != null) {
            saveInterval = Integer.parseInt(saveIntervalStr);
            if (saveInterval < 1 || saveInterval > 100) {
                throw new NumberFormatException("Save Interval out of range (1-100)");
            }
        } else {
            saveInterval = 5;
        }

        if (cmd.hasOption("l") && logLevelStr != null) {
            if (logLevelStr.equalsIgnoreCase("finest")) {
                LOG.setLevel(Level.FINEST);
            } else if (logLevelStr.equalsIgnoreCase("finer")) {
                LOG.setLevel(Level.FINER);
            } else if (logLevelStr.equalsIgnoreCase("fine")) {
                LOG.setLevel(Level.FINE);
            } else if (logLevelStr.equalsIgnoreCase("config")) {
                LOG.setLevel(Level.CONFIG);
            } else if (logLevelStr.equalsIgnoreCase("info")) {
                LOG.setLevel(Level.INFO);
            } else if (logLevelStr.equalsIgnoreCase("warning")) {
                LOG.setLevel(Level.WARNING);
            } else if (logLevelStr.equalsIgnoreCase("severe")) {
                LOG.setLevel(Level.SEVERE);
            } else if (logLevelStr.equalsIgnoreCase("off")) {
                LOG.setLevel(Level.OFF);
            } else if (logLevelStr.equalsIgnoreCase("all")) {
                LOG.setLevel(Level.ALL);
            } else {
                System.err.println("ERROR: invalid log level: " + logLevelStr);
                System.err.println("Run again with -h flag to see valid log level values");
                System.exit(1);
            }
        } else {
            LOG.setLevel(Level.INFO);
        }
        // INIT LOGGING
        try {
            LOG.setUseParentHandlers(false);
            initLogging();
        } catch (IOException ex) {
            System.err.println("Unable to initialize logging to file");
            System.err.println(ex);
            System.exit(1);
        }

    } catch (Exception ex) {
        System.err.println("ERROR: " + ex.getMessage());
        System.err.println("use -h for help");
        System.exit(1);
    }

    LOG.log(Level.INFO, "Trekwar2 server " + VERSION + " starting up");

    // LOAD GALAXY
    File galaxyFile = new File(galaxyFileName);
    if (galaxyFile.exists()) {
        try {
            long timer = System.currentTimeMillis();
            LOG.log(Level.INFO, "Loading galaxy file {0}", galaxyFileName);
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(galaxyFile));
            galaxy = (Galaxy) ois.readObject();
            timer = System.currentTimeMillis() - timer;
            LOG.log(Level.INFO, "Galaxy file loaded in {0} ms", timer);
            ois.close();
        } catch (IOException ioe) {
            LOG.log(Level.SEVERE, "IO error while trying to load galaxy file", ioe);
        } catch (ClassNotFoundException cnfe) {
            LOG.log(Level.SEVERE, "Unable to find class while loading galaxy", cnfe);
        }
    } else {
        System.err.println("Error: file " + galaxyFileName + " not found");
        System.exit(1);
    }

    // if turn == 0 (start of game), execute first turn to update fog of war.
    if (galaxy.getCurrentTurn() == 0) {
        TurnExecutor.executeTurn(galaxy);
    }

    LOG.log(Level.INFO, "Current turn  : {0}", galaxy.getCurrentTurn());
    LOG.log(Level.INFO, "Turn speed    : {0} seconds", galaxy.getTurnSpeed() / 1000);
    LOG.log(Level.INFO, "Save Interval : {0}", saveInterval);
    LOG.log(Level.INFO, "Users / max   : {0} / {1}",
            new Object[] { galaxy.getUserCount(), galaxy.getMaxUsers() });

    // START SERVER
    try {
        server = new ServerSocket(port);
        LOG.log(Level.INFO, "Server listening on port {0}", port);
    } catch (BindException be) {
        LOG.log(Level.SEVERE, "Error: Unable to bind to port {0}", port);
        System.err.println(be);
        System.exit(1);
    } catch (IOException ioe) {
        LOG.log(Level.SEVERE, "Error: IO error while binding to port {0}", port);
        System.err.println(ioe);
        System.exit(1);
    }

    galaxy.startup();

    Thread timerThread = new Thread(new Runnable() {

        @Override
        @SuppressWarnings("SleepWhileInLoop")
        public void run() {
            while (true) {
                try {
                    Thread.sleep(1000);
                    // && galaxy.getLoggedInUsers().size() > 0 will make server pause when nobody is logged in (TESTING)
                    if (System.currentTimeMillis() > galaxy.nextTurnDate) {
                        StringBuffer loggedInUsers = new StringBuffer();
                        for (User u : galaxy.getLoggedInUsers()) {
                            loggedInUsers.append(u.getUsername()).append(", ");
                        }

                        long time = TurnExecutor.executeTurn(galaxy);
                        LOG.log(Level.INFO, "Turn {0} executed in {1} ms",
                                new Object[] { galaxy.getCurrentTurn(), time });
                        LOG.log(Level.INFO, "Logged in users: " + loggedInUsers.toString());
                        LOG.log(Level.INFO,
                                "====================================================================================");

                        if (galaxy.getCurrentTurn() % saveInterval == 0) {
                            saveGalaxy();
                        }

                        galaxy.lastTurnDate = System.currentTimeMillis();
                        galaxy.nextTurnDate = galaxy.lastTurnDate + galaxy.turnSpeed;
                    }

                } catch (InterruptedException e) {
                    LOG.log(Level.SEVERE, "Error in main server loop, interrupted", e);
                }
            }
        }
    });
    timerThread.start();

    // ACCEPT CONNECTIONS AND DELEGATE TO CLIENT SESSIONS
    while (true) {
        Socket clientConnection;
        try {
            clientConnection = server.accept();
            ClientSession c = new ClientSession(clientConnection, galaxy);
            Thread t = new Thread(c);
            t.start();
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, "IO Exception while trying to handle incoming client connection", ex);
        }
    }
}

From source file:org.apache.heron.scheduler.RuntimeManagerMain.java

public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException,
        InstantiationException, IOException, ParseException {

    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);

    if (cmd.hasOption("h")) {
        usage(options);/*from   w  w  w.j  av  a2s.  co m*/
        return;
    }

    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }

    Boolean verbose = false;
    Level logLevel = Level.INFO;
    if (cmd.hasOption("v")) {
        logLevel = Level.ALL;
        verbose = true;
    }

    // init log
    LoggingHelper.loggerInit(logLevel, false);

    String cluster = cmd.getOptionValue("cluster");
    String role = cmd.getOptionValue("role");
    String environ = cmd.getOptionValue("environment");
    String submitUser = cmd.getOptionValue("submit_user");
    String heronHome = cmd.getOptionValue("heron_home");
    String configPath = cmd.getOptionValue("config_path");
    String overrideConfigFile = cmd.getOptionValue("override_config_file");
    String releaseFile = cmd.getOptionValue("release_file");
    String topologyName = cmd.getOptionValue("topology_name");
    String commandOption = cmd.getOptionValue("command");

    // Optional argument in the case of restart
    // TODO(karthik): convert into CLI
    String containerId = Integer.toString(-1);
    if (cmd.hasOption("container_id")) {
        containerId = cmd.getOptionValue("container_id");
    }

    Boolean dryRun = false;
    if (cmd.hasOption("u")) {
        dryRun = true;
    }

    // Default dry-run output format type
    DryRunFormatType dryRunFormat = DryRunFormatType.TABLE;
    if (dryRun && cmd.hasOption("t")) {
        String format = cmd.getOptionValue("dry_run_format");
        dryRunFormat = DryRunFormatType.getDryRunFormatType(format);
        LOG.fine(String.format("Running dry-run mode using format %s", format));
    }

    Command command = Command.makeCommand(commandOption);

    // add config parameters from the command line
    Config.Builder commandLineConfig = Config.newBuilder().put(Key.CLUSTER, cluster).put(Key.ROLE, role)
            .put(Key.ENVIRON, environ).put(Key.SUBMIT_USER, submitUser).put(Key.DRY_RUN, dryRun)
            .put(Key.DRY_RUN_FORMAT_TYPE, dryRunFormat).put(Key.VERBOSE, verbose)
            .put(Key.TOPOLOGY_CONTAINER_ID, containerId);

    // This is a command line option, but not a valid config key. Hence we don't use Keys
    translateCommandLineConfig(cmd, commandLineConfig);

    Config.Builder topologyConfig = Config.newBuilder().put(Key.TOPOLOGY_NAME, topologyName);

    // build the final config by expanding all the variables
    Config config = Config.toLocalMode(Config.newBuilder()
            .putAll(ConfigLoader.loadConfig(heronHome, configPath, releaseFile, overrideConfigFile))
            .putAll(commandLineConfig.build()).putAll(topologyConfig.build()).build());

    LOG.fine("Static config loaded successfully ");
    LOG.fine(config.toString());

    /* Meaning of exit status code:
      - status code = 0:
        program exits without error
      - 0 < status code < 100:
        program fails to execute before program execution. For example,
        JVM cannot find or load main class
      - 100 <= status code < 200:
        program fails to launch after program execution. For example,
        topology definition file fails to be loaded
      - status code == 200
        program sends out dry-run response */
    /* Since only stderr is used (by logging), we use stdout here to
       propagate any message back to Python's executor.py (invoke site). */
    // Create a new instance of RuntimeManagerMain
    RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, command);
    try {
        runtimeManagerMain.manageTopology();
        // SUPPRESS CHECKSTYLE IllegalCatch
    } catch (UpdateDryRunResponse response) {
        LOG.log(Level.FINE, "Sending out dry-run response");
        // Output may contain UTF-8 characters, so we should print using UTF-8 encoding
        PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8.name());
        out.print(DryRunRenders.render(response, Context.dryRunFormatType(config)));
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        // Exit with status code 200 to indicate dry-run response is sent out
        System.exit(200);
        // SUPPRESS CHECKSTYLE IllegalCatch
    } catch (Exception e) {
        LOG.log(Level.FINE, "Exception when executing command " + commandOption, e);
        System.out.println(e.getMessage());
        // Exit with status code 100 to indicate that error has happened on user-land
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        System.exit(100);
    }
}

From source file:com.twitter.heron.scheduler.SubmitterMain.java

public static void main(String[] args) throws Exception {
    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);

    if (cmd.hasOption("h")) {
        usage(options);//from   w w w.ja  v  a2s.  co  m
        return;
    }

    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }

    Boolean verbose = false;
    Level logLevel = Level.INFO;
    if (cmd.hasOption("v")) {
        logLevel = Level.ALL;
        verbose = true;
    }

    // init log
    LoggingHelper.loggerInit(logLevel, false);

    String cluster = cmd.getOptionValue("cluster");
    String role = cmd.getOptionValue("role");
    String environ = cmd.getOptionValue("environment");
    String heronHome = cmd.getOptionValue("heron_home");
    String configPath = cmd.getOptionValue("config_path");
    String overrideConfigFile = cmd.getOptionValue("override_config_file");
    String releaseFile = cmd.getOptionValue("release_file");
    String topologyPackage = cmd.getOptionValue("topology_package");
    String topologyDefnFile = cmd.getOptionValue("topology_defn");
    String topologyJarFile = cmd.getOptionValue("topology_jar");

    // load the topology definition into topology proto
    TopologyAPI.Topology topology = TopologyUtils.getTopology(topologyDefnFile);

    // first load the defaults, then the config from files to override it
    // next add config parameters from the command line
    // load the topology configs

    // build the final config by expanding all the variables
    Config config = Config.expand(Config.newBuilder().putAll(defaultConfigs(heronHome, configPath, releaseFile))
            .putAll(overrideConfigs(overrideConfigFile))
            .putAll(commandLineConfigs(cluster, role, environ, verbose))
            .putAll(topologyConfigs(topologyPackage, topologyJarFile, topologyDefnFile, topology)).build());

    LOG.fine("Static config loaded successfully ");
    LOG.fine(config.toString());

    SubmitterMain submitterMain = new SubmitterMain(config, topology);
    boolean isSuccessful = submitterMain.submitTopology();

    // Log the result and exit
    if (!isSuccessful) {
        throw new RuntimeException(String.format("Failed to submit topology %s", topology.getName()));
    } else {
        LOG.log(Level.FINE, "Topology {0} submitted successfully", topology.getName());
    }
}

From source file:Main.java

public static void setLoggerhandler(Logger logger) {
    Handler handler = new ExceptionHandler();
    logger.addHandler(handler);//  w  w  w. j  a va 2 s.c o m

    logger.setLevel(Level.ALL);
}

From source file:org.apache.heron.scheduler.SubmitterMain.java

public static void main(String[] args) throws Exception {
    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);

    if (cmd.hasOption("h")) {
        usage(options);//from  w  w w  .  j  a v a  2  s  .co  m
        return;
    }

    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }

    Level logLevel = Level.INFO;
    if (isVerbose(cmd)) {
        logLevel = Level.ALL;
    }

    // init log
    LoggingHelper.loggerInit(logLevel, false);

    // load the topology definition into topology proto
    TopologyAPI.Topology topology = TopologyUtils.getTopology(cmd.getOptionValue("topology_defn"));
    Config config = loadConfig(cmd, topology);

    LOG.fine("Static config loaded successfully");
    LOG.fine(config.toString());

    SubmitterMain submitterMain = new SubmitterMain(config, topology);
    /* Meaning of exit status code:
       - status code = 0:
         program exits without error
       - 0 < status code < 100:
         program fails to execute before program execution. For example,
         JVM cannot find or load main class
       - 100 <= status code < 200:
         program fails to launch after program execution. For example,
         topology definition file fails to be loaded
       - status code >= 200
         program sends out dry-run response */
    try {
        submitterMain.submitTopology();
    } catch (SubmitDryRunResponse response) {
        LOG.log(Level.FINE, "Sending out dry-run response");
        // Output may contain UTF-8 characters, so we should print using UTF-8 encoding
        PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8.name());
        out.print(DryRunRenders.render(response, Context.dryRunFormatType(config)));
        // Exit with status code 200 to indicate dry-run response is sent out
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        System.exit(200);
        // SUPPRESS CHECKSTYLE IllegalCatch
    } catch (Exception e) {
        /* Since only stderr is used (by logging), we use stdout here to
           propagate error message back to Python's executor.py (invoke site). */
        LOG.log(Level.FINE, "Exception when submitting topology", e);
        System.out.println(e.getMessage());
        // Exit with status code 100 to indicate that error has happened on user-land
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        System.exit(100);
    }
    LOG.log(Level.FINE, "Topology {0} submitted successfully", topology.getName());
}

From source file:geva.Main.Run.java

/**
 * Run/*from  w w  w  .  j  a va2s.c  o m*/
 * @param args arguments
 */
public static void main(String[] args) {
    initJavaLogging(Level.ALL);
    Run mainRun = new Run();
    mainRun.experiment(args);
    System.exit(0);
}

From source file:com.twitter.heron.metricscachemgr.MetricsCacheManager.java

public static void main(String[] args) throws Exception {
    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();

    CommandLineParser parser = new DefaultParser();

    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);
    if (cmd.hasOption("h")) {
        usage(options);//from   w w w . j a  v a 2 s  .c  om
        return;
    }

    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }

    Level logLevel = Level.INFO;
    if (cmd.hasOption("v")) {
        logLevel = Level.ALL;
    }

    String cluster = cmd.getOptionValue("cluster");
    String role = cmd.getOptionValue("role");
    String environ = cmd.getOptionValue("environment");
    int masterPort = Integer.valueOf(cmd.getOptionValue("master_port"));
    int statsPort = Integer.valueOf(cmd.getOptionValue("stats_port"));
    String systemConfigFilename = cmd.getOptionValue("system_config_file");
    String overrideConfigFilename = cmd.getOptionValue("override_config_file");
    String metricsSinksConfigFilename = cmd.getOptionValue("sink_config_file");
    String topologyName = cmd.getOptionValue("topology_name");
    String topologyId = cmd.getOptionValue("topology_id");
    String metricsCacheMgrId = cmd.getOptionValue("metricscache_id");

    // read heron internal config file
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(systemConfigFilename, true)
            .putAll(overrideConfigFilename, true).build();

    // Log to file and sink(exception)
    LoggingHelper.loggerInit(logLevel, true);
    LoggingHelper.addLoggingHandler(
            LoggingHelper.getFileHandler(metricsCacheMgrId, systemConfig.getHeronLoggingDirectory(), true,
                    systemConfig.getHeronLoggingMaximumSize(), systemConfig.getHeronLoggingMaximumFiles()));
    LoggingHelper.addLoggingHandler(new ErrorReportLoggingHandler());

    LOG.info(String.format(
            "Starting MetricsCache for topology %s with topologyId %s with "
                    + "MetricsCache Id %s, master port: %d.",
            topologyName, topologyId, metricsCacheMgrId, masterPort));

    LOG.info("System Config: " + systemConfig);

    // read sink config file
    MetricsSinksConfig sinksConfig = new MetricsSinksConfig(metricsSinksConfigFilename);
    LOG.info("Sinks Config: " + sinksConfig.toString());

    // build config from cli
    Config config = Config.toClusterMode(Config.newBuilder().putAll(ConfigLoader.loadClusterConfig())
            .putAll(Config.newBuilder().put(Key.CLUSTER, cluster).put(Key.ROLE, role).put(Key.ENVIRON, environ)
                    .build())
            .putAll(Config.newBuilder().put(Key.TOPOLOGY_NAME, topologyName).put(Key.TOPOLOGY_ID, topologyId)
                    .build())
            .build());
    LOG.info("Cli Config: " + config.toString());

    // build metricsCache location
    TopologyMaster.MetricsCacheLocation metricsCacheLocation = TopologyMaster.MetricsCacheLocation.newBuilder()
            .setTopologyName(topologyName).setTopologyId(topologyId)
            .setHost(InetAddress.getLocalHost().getHostName()).setControllerPort(-1) // not used for metricscache
            .setMasterPort(masterPort).setStatsPort(statsPort).build();

    MetricsCacheManager metricsCacheManager = new MetricsCacheManager(topologyName, METRICS_CACHE_HOST,
            masterPort, statsPort, systemConfig, sinksConfig, config, metricsCacheLocation);
    metricsCacheManager.start();

    LOG.info("Loops terminated. MetricsCache Manager exits.");
}