List of usage examples for java.lang RuntimeException RuntimeException
public RuntimeException(String message, Throwable cause)
From source file:com.twitter.heron.ckptmgr.CheckpointManager.java
public static void main(String[] args) throws IOException, ParseException, CheckpointManagerException { 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);// w w w . j ava2s . 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); } String topologyName = cmd.getOptionValue("topologyname"); String topologyId = cmd.getOptionValue("topologyid"); String ckptmgrId = cmd.getOptionValue("ckptmgrid"); int port = Integer.parseInt(cmd.getOptionValue("ckptmgrport")); String stateConfigFilename = cmd.getOptionValue("ckptmgrconfig"); String heronInternalConfig = cmd.getOptionValue("heroninternalconfig"); SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(heronInternalConfig, true).build(); CheckpointManagerConfig ckptmgrConfig = CheckpointManagerConfig.newBuilder(true) .putAll(stateConfigFilename, true).build(); // Add the SystemConfig into SingletonRegistry SingletonRegistry.INSTANCE.registerSingleton(SystemConfig.HERON_SYSTEM_CONFIG, systemConfig); // Init the logging setting and redirect the stdout and stderr to logging // For now we just set the logging level as INFO; later we may accept an argument to set it. Level loggingLevel = Level.INFO; String loggingDir = systemConfig.getHeronLoggingDirectory(); // Log to file and TMaster LoggingHelper.loggerInit(loggingLevel, true); LoggingHelper.addLoggingHandler(LoggingHelper.getFileHandler(ckptmgrId, loggingDir, true, systemConfig.getHeronLoggingMaximumSize(), systemConfig.getHeronLoggingMaximumFiles())); LoggingHelper.addLoggingHandler(new ErrorReportLoggingHandler()); // Start the actual things LOG.info(String.format( "Starting topology %s with topologyId %s with " + "Checkpoint Manager Id %s, Port: %d.", topologyName, topologyId, ckptmgrId, port)); LOG.info("System Config: " + systemConfig); CheckpointManager checkpointManager = new CheckpointManager(topologyName, topologyId, ckptmgrId, CHECKPOINT_MANAGER_HOST, port, systemConfig, ckptmgrConfig); checkpointManager.startAndLoop(); LOG.info("Loops terminated. Exiting."); }
From source file:org.dspace.app.cris.batch.ScriptDeleteRP.java
/** * Batch script to delete a RP. See the technical documentation for further * details.//from ww w .j a v a2s. co m */ public static void main(String[] args) { log.info("#### START DELETE: -----" + new Date() + " ----- ####"); Context dspaceContext = null; ApplicationContext context = null; try { dspaceContext = new Context(); dspaceContext.turnOffAuthorisationSystem(); DSpace dspace = new DSpace(); ApplicationService applicationService = dspace.getServiceManager() .getServiceByName("applicationService", ApplicationService.class); CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("h", "help", false, "help"); options.addOption("r", "researcher", true, "RP id to delete"); options.addOption("s", "silent", false, "no interactive mode"); CommandLine line = parser.parse(options, args); if (line.hasOption('h')) { HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("ScriptHKURPDelete \n", options); System.out.println("\n\nUSAGE:\n ScriptHKURPDelete -r <id> \n"); System.out.println("Please note: add -s for no interactive mode"); System.exit(0); } Integer rpId = null; boolean delete = false; boolean silent = line.hasOption('s'); Item[] items = null; if (line.hasOption('r')) { rpId = ResearcherPageUtils.getRealPersistentIdentifier(line.getOptionValue("r"), ResearcherPage.class); ResearcherPage rp = applicationService.get(ResearcherPage.class, rpId); if (rp == null) { if (!silent) { System.out.println("RP not exist...exit"); } log.info("RP not exist...exit"); System.exit(0); } log.info("Use browse indexing"); BrowseIndex bi = BrowseIndex.getBrowseIndex(plugInBrowserIndex); // now start up a browse engine and get it to do the work for us BrowseEngine be = new BrowseEngine(dspaceContext); String authKey = ResearcherPageUtils.getPersistentIdentifier(rp); // set up a BrowseScope and start loading the values into it BrowserScope scope = new BrowserScope(dspaceContext); scope.setBrowseIndex(bi); // scope.setOrder(order); scope.setFilterValue(authKey); scope.setAuthorityValue(authKey); scope.setResultsPerPage(Integer.MAX_VALUE); scope.setBrowseLevel(1); BrowseInfo binfo = be.browse(scope); log.debug("Find " + binfo.getResultCount() + "item(s) for the reseracher " + authKey); items = binfo.getItemResults(dspaceContext); if (!silent && rp != null) { System.out.println(MESSAGE_ONE); // interactive mode System.out.println("Attempting to remove Researcher Page:"); System.out.println("StaffNo:" + rp.getSourceID()); System.out.println("FullName:" + rp.getFullName()); System.out .println("the researcher has " + items.length + " relation(s) with item(s) in the HUB"); System.out.println(); System.out.println(QUESTION_ONE); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(isr); String answer = reader.readLine(); if (answer.equals("yes")) { delete = true; } else { System.out.println("Exit without delete"); log.info("Exit without delete"); System.exit(0); } } else { delete = true; } } else { System.out.println("\n\nUSAGE:\n ScriptHKURPDelete <-v> -r <RPid> \n"); System.out.println("-r option is mandatory"); log.error("-r option is mandatory"); System.exit(1); } if (delete) { if (!silent) { System.out.println("Deleting..."); } log.info("Deleting..."); cleanAuthority(dspaceContext, items, rpId); applicationService.delete(ResearcherPage.class, rpId); dspaceContext.complete(); } if (!silent) { System.out.println("Ok...Bye"); } } catch (Exception e) { log.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } finally { if (dspaceContext != null && dspaceContext.isValid()) { dspaceContext.abort(); } if (context != null) { context.publishEvent(new ContextClosedEvent(context)); } } log.info("#### END: -----" + new Date() + " ----- ####"); System.exit(0); }
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 . 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 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:de.micromata.tpsb.doc.StaticTestDocGenerator.java
public static void main(String[] args) { ParserConfig.Builder bCfg = new ParserConfig.Builder(); ParserConfig.Builder tCfg = new ParserConfig.Builder(); tCfg.generateIndividualFiles(true);//w w w . j ava 2 s .c o m bCfg.generateIndividualFiles(true); List<String> la = Arrays.asList(args); Iterator<String> it = la.iterator(); boolean baseDirSet = false; boolean ignoreLocalSettings = false; List<String> addRepos = new ArrayList<String>(); StringResourceLoader.setRepository(StringResourceLoader.REPOSITORY_NAME_DEFAULT, new StringResourceRepositoryImpl()); try { while (it.hasNext()) { String arg = it.next(); String value = null; if ((value = getArgumentOption(it, arg, "--project-root", "-pr")) != null) { File f = new File(value); if (f.exists() == false) { System.err.print("project root doesn't exists: " + f.getAbsolutePath()); continue; } TpsbEnvironment.get().addProjectRoots(f); File ts = new File(f, "src/test"); if (ts.exists() == true) { tCfg.addSourceFileRespository(new FileSystemSourceFileRepository(ts.getAbsolutePath())); bCfg.addSourceFileRespository(new FileSystemSourceFileRepository(ts.getAbsolutePath())); } continue; } if ((value = getArgumentOption(it, arg, "--test-input", "-ti")) != null) { File f = new File(value); if (f.exists() == false) { System.err.print("test-input doesn't exists: " + f.getAbsolutePath()); } tCfg.addSourceFileRespository(new FileSystemSourceFileRepository(value)); bCfg.addSourceFileRespository(new FileSystemSourceFileRepository(value)); continue; } if ((value = getArgumentOption(it, arg, "--output-path", "-op")) != null) { if (baseDirSet == false) { tCfg.outputDir(value); bCfg.outputDir(value); TpsbEnvironment.setBaseDir(value); baseDirSet = true; } else { addRepos.add(value); } continue; } if ((value = getArgumentOption(it, arg, "--index-vmtemplate", "-ivt")) != null) { try { String content = FileUtils.readFileToString(new File(value), CharEncoding.UTF_8); StringResourceRepository repo = StringResourceLoader.getRepository(); repo.putStringResource("customIndexTemplate", content, CharEncoding.UTF_8); tCfg.indexTemplate("customIndexTemplate"); } catch (IOException ex) { throw new RuntimeException( "Cannot load file " + new File(value).getAbsolutePath() + ": " + ex.getMessage(), ex); } continue; } if ((value = getArgumentOption(it, arg, "--test-vmtemplate", "-tvt")) != null) { try { String content = FileUtils.readFileToString(new File(value), CharEncoding.UTF_8); StringResourceRepository repo = StringResourceLoader.getRepository(); repo.putStringResource("customTestTemplate", content, CharEncoding.UTF_8); tCfg.testTemplate("customTestTemplate"); } catch (IOException ex) { throw new RuntimeException( "Cannot load file " + new File(value).getAbsolutePath() + ": " + ex.getMessage(), ex); } continue; } if (arg.equals("--singlexml") == true) { tCfg.generateIndividualFiles(false); bCfg.generateIndividualFiles(false); } else if (arg.equals("--ignore-local-settings") == true) { ignoreLocalSettings = true; continue; } } } catch (RuntimeException ex) { System.err.print(ex.getMessage()); return; } if (ignoreLocalSettings == false) { readLocalSettings(bCfg, tCfg); } bCfg// .addSourceFileFilter(new MatcherSourceFileFilter("*Builder,*App,*builder")) // .addSourceFileFilter(new AnnotationSourceFileFilter(TpsbBuilder.class)) // .addSourceFileFilter(new AnnotationSourceFileFilter(TpsbApplication.class)) // ; tCfg// .addSourceFileFilter(new MatcherSourceFileFilter("*Test,*TestCase")) // .addSourceFileFilter(new AnnotationSourceFileFilter(TpsbTestSuite.class)) // ; StaticTestDocGenerator docGenerator = new StaticTestDocGenerator(bCfg.build(), tCfg.build()); TpsbEnvironment env = TpsbEnvironment.get(); if (addRepos.isEmpty() == false) { env.setIncludeRepos(addRepos); } docGenerator.parseTestBuilders(); docGenerator.parseTestCases(); }
From source file:Main.java
public static void sleepForInSecs(int secs) { try {//www . j av a2s .c om Thread.sleep(secs * 1000); } catch (InterruptedException x) { throw new RuntimeException("interrupted", x); } }
From source file:Main.java
public static JSONArray stringToJSONArray(String str) throws Exception { try {/*from ww w . j a v a2 s . c o m*/ return new JSONArray(str); } catch (JSONException e) { throw new RuntimeException(e.getMessage() + ":" + str, e); } }
From source file:Main.java
public static void startView(String viewTag) { try {// w ww . ja v a2s . co m Process p1 = Runtime.getRuntime().exec("cleartool startview " + viewTag); p1.waitFor(); p1.destroy(); } catch (Exception e) { throw new RuntimeException("cleartool startview error!", e); } }
From source file:Main.java
public static void sleep(long time) { if (time == 0l) { Thread.yield();// w w w .j av a2s . com } else if (time > 0) { try { Thread.sleep(time); } catch (InterruptedException e) { throw new RuntimeException("error while sleeping: " + time, e); } } }
From source file:Main.java
public static void rmView(String viewTag) { try {/* w ww.j a va 2s . c om*/ Process pr = Runtime.getRuntime().exec("cleartool rmview -tag ".concat(viewTag)); pr.waitFor(); pr.destroy(); } catch (Exception e) { throw new RuntimeException("cleartool rmview error!", e); } }
From source file:Main.java
public static int getId(String resourceName, Class<?> c) { try {//w w w . j ava2 s.c o m Field idField = c.getDeclaredField(resourceName); return idField.getInt(idField); } catch (Exception e) { throw new RuntimeException("No resource ID found for: " + resourceName + " / " + c, e); } }