List of usage examples for java.util Arrays toString
public static String toString(Object[] a)
From source file:hdfs.MiniHDFS.java
public static void main(String[] args) throws Exception { if (args.length != 1 && args.length != 3) { throw new IllegalArgumentException( "Expected: MiniHDFS <baseDirectory> [<kerberosPrincipal> <kerberosKeytab>], " + "got: " + Arrays.toString(args)); }// ww w . j av a 2 s. co m boolean secure = args.length == 3; // configure Paths Path baseDir = Paths.get(args[0]); // hadoop-home/, so logs will not complain if (System.getenv("HADOOP_HOME") == null) { Path hadoopHome = baseDir.resolve("hadoop-home"); Files.createDirectories(hadoopHome); System.setProperty("hadoop.home.dir", hadoopHome.toAbsolutePath().toString()); } // hdfs-data/, where any data is going Path hdfsHome = baseDir.resolve("hdfs-data"); // configure cluster Configuration cfg = new Configuration(); cfg.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsHome.toAbsolutePath().toString()); // lower default permission: TODO: needed? cfg.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_PERMISSION_KEY, "766"); // optionally configure security if (secure) { String kerberosPrincipal = args[1]; String keytabFile = args[2]; cfg.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); cfg.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, "true"); cfg.set(DFSConfigKeys.DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal); cfg.set(DFSConfigKeys.DFS_DATANODE_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal); cfg.set(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal); cfg.set(DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY, keytabFile); cfg.set(DFSConfigKeys.DFS_DATANODE_KEYTAB_FILE_KEY, keytabFile); cfg.set(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, "true"); cfg.set(DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY, "true"); cfg.set(DFSConfigKeys.IGNORE_SECURE_PORTS_FOR_TESTING_KEY, "true"); } UserGroupInformation.setConfiguration(cfg); // TODO: remove hardcoded port! MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(cfg); if (secure) { builder.nameNodePort(9998); } else { builder.nameNodePort(9999); } MiniDFSCluster dfs = builder.build(); // Configure contents of the filesystem org.apache.hadoop.fs.Path esUserPath = new org.apache.hadoop.fs.Path("/user/elasticsearch"); try (FileSystem fs = dfs.getFileSystem()) { // Set the elasticsearch user directory up fs.mkdirs(esUserPath); if (UserGroupInformation.isSecurityEnabled()) { List<AclEntry> acls = new ArrayList<>(); acls.add(new AclEntry.Builder().setType(AclEntryType.USER).setName("elasticsearch") .setPermission(FsAction.ALL).build()); fs.modifyAclEntries(esUserPath, acls); } // Install a pre-existing repository into HDFS String directoryName = "readonly-repository"; String archiveName = directoryName + ".tar.gz"; URL readOnlyRepositoryArchiveURL = MiniHDFS.class.getClassLoader().getResource(archiveName); if (readOnlyRepositoryArchiveURL != null) { Path tempDirectory = Files.createTempDirectory(MiniHDFS.class.getName()); File readOnlyRepositoryArchive = tempDirectory.resolve(archiveName).toFile(); FileUtils.copyURLToFile(readOnlyRepositoryArchiveURL, readOnlyRepositoryArchive); FileUtil.unTar(readOnlyRepositoryArchive, tempDirectory.toFile()); fs.copyFromLocalFile(true, true, new org.apache.hadoop.fs.Path( tempDirectory.resolve(directoryName).toAbsolutePath().toUri()), esUserPath.suffix("/existing/" + directoryName)); FileUtils.deleteDirectory(tempDirectory.toFile()); } } // write our PID file Path tmp = Files.createTempFile(baseDir, null, null); String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; Files.write(tmp, pid.getBytes(StandardCharsets.UTF_8)); Files.move(tmp, baseDir.resolve(PID_FILE_NAME), StandardCopyOption.ATOMIC_MOVE); // write our port file tmp = Files.createTempFile(baseDir, null, null); Files.write(tmp, Integer.toString(dfs.getNameNodePort()).getBytes(StandardCharsets.UTF_8)); Files.move(tmp, baseDir.resolve(PORT_FILE_NAME), StandardCopyOption.ATOMIC_MOVE); }
From source file:controllerTas.Main.Main2.java
public static void main(String args[]) throws NotBoundException, RemoteException, UnknownHostException { PropertyConfigurator.configure("conf/log4j.properties"); log.trace("Going to create WpmConnector"); WPMConnector connector = new WPMConnector(); log.trace("Connector created"); WPMStatisticsRemoteListener listener = new TestWPMStatisticsRemoteListenerImpl();//new TasWPMStatisticsRemoteListenerImpl(); String[] VMs = new String[1]; VMs[0] = "10.100.0.11"; log.trace("Registering statisticRemoteListener for " + Arrays.toString(VMs)); connector.registerStatisticsRemoteListener(new SubscribeEvent(VMs), listener); while (true) { }//w w w. j a va 2s. co m }
From source file:net.cliftonsnyder.svgchart.Main.java
public static void main(String[] args) { Options options = new Options(); options.addOption("c", "stylesheet", true, "CSS stylesheet (default: " + SVGChart.DEFAULT_STYLESHEET + ")"); options.addOption("h", "height", true, "chart height"); options.addOption("i", "input-file", true, "input file [default: stdin]"); options.addOption("o", "output-file", true, "output file [default: stdout]"); options.addOption("w", "width", true, "chart width"); options.addOption("?", "help", false, "print a brief help message"); Option type = new Option("t", "type", true, "chart type " + Arrays.toString(SVGChart.TYPES)); type.setRequired(true);//from w ww .ja v a 2s . com options.addOption(type); CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); if (line.hasOption("help")) { formatter.printHelp(USAGE, options); System.exit(0); } } catch (ParseException exp) { // oops, something went wrong System.err.println("unable to parse command line: " + exp.getMessage()); formatter.printHelp(USAGE, options); System.exit(1); } SVGChart chart = null; String tmp = line.getOptionValue("type"); Matcher m = null; for (Pattern p : SVGChart.TYPE_PATTERNS) { if ((m = p.matcher(tmp)).matches()) { switch (m.group().charAt(0)) { case 'l': // DEBUG System.err.println("line"); break; case 'b': System.err.println("bar"); chart = new BarChart(); break; case 'p': System.err.println("pie"); break; default: System.err.println("unknown or unimplemented chart type: '" + tmp + "'"); System.exit(1); } } } try { chart.setWidth(Double.parseDouble(line.getOptionValue("width", "" + SVGChart.DEFAULT_WIDTH))); } catch (NumberFormatException e) { System.err.println( "unable to parse command line: invalid width value '" + line.getOptionValue("width") + "'"); System.exit(1); } try { chart.setHeight(Double.parseDouble(line.getOptionValue("height", "" + SVGChart.DEFAULT_HEIGHT))); } catch (NumberFormatException e) { System.err.println( "unable to parse command line: invalid height value '" + line.getOptionValue("height") + "'"); System.exit(1); } InputStream in = System.in; tmp = line.getOptionValue("input-file", "-"); if ("-".equals(tmp)) { in = System.in; } else { try { in = new FileInputStream(tmp); } catch (FileNotFoundException e) { System.err.println("input file not found: '" + tmp + "'"); System.exit(1); } } PrintStream out = System.out; tmp = line.getOptionValue("output-file", "-"); if ("-".equals(tmp)) { out = System.out; } else { try { out = new PrintStream(new FileOutputStream(tmp)); } catch (FileNotFoundException e) { System.err.println("output file not found: '" + tmp + "'"); System.exit(1); } } tmp = line.getOptionValue("stylesheet", SVGChart.DEFAULT_STYLESHEET); chart.setStyleSheet(tmp); try { chart.parseInput(in); } catch (IOException e) { System.err.println("I/O error while reading input"); System.exit(1); } catch (net.cliftonsnyder.svgchart.parse.ParseException e) { System.err.println("error parsing input: " + e.getMessage()); } chart.createChart(); try { chart.printChart(out, true); } catch (IOException e) { System.err.println("error serializing output"); System.exit(1); } }
From source file:com.github.xbn.examples.io.non_xbn.DelimitWordsInATextFile.java
public static final void main(String[] as_1RqdPathToInput) { //Read command-line String sSrc = null;/* w ww . j av a 2s .c o m*/ try { sSrc = as_1RqdPathToInput[0]; } catch (IndexOutOfBoundsException ibx) { System.out.println("Missing one-and-only required parameter: The full path to input file."); return; } //Open input file File fSrc = new File(sSrc); Iterator<String> lineItr = null; try { lineItr = FileUtils.lineIterator(fSrc); } catch (IOException iox) { System.out.println("Cannot open \"" + sSrc + "\". " + iox); return; } int i = 0; while (lineItr.hasNext()) { i++; String as[] = lineItr.next().split(" "); System.out.println("Line " + i + ": " + Arrays.toString(as)); } }
From source file:com.machinelinking.cli.loader.java
public static void main(String[] args) { if (args.length != 2) { System.err.println("Usage: $0 <config-file> <dump>"); System.exit(1);/* w w w . j a va 2 s . co m*/ } try { final File configFile = check(args[0]); final File dumpFile = check(args[1]); final Properties properties = new Properties(); properties.load(FileUtils.openInputStream(configFile)); final Flag[] flags = WikiPipelineFactory.getInstance().toFlags(getPropertyOrFail(properties, LOADER_FLAGS_PROP, "valid flags: " + Arrays.toString(WikiPipelineFactory.getInstance().getDefinedFlags()))); final JSONStorageFactory jsonStorageFactory = MultiJSONStorageFactory .loadJSONStorageFactory(getPropertyOrFail(properties, LOADER_STORAGE_FACTORY_PROP, null)); final String jsonStorageConfig = getPropertyOrFail(properties, LOADER_STORAGE_CONFIG_PROP, null); final URL prefixURL = readURL(getPropertyOrFail(properties, LOADER_PREFIX_URL_PROP, "expected a valid URL prefix like: http://en.wikipedia.org/"), LOADER_PREFIX_URL_PROP); final DefaultJSONStorageLoader[] loader = new DefaultJSONStorageLoader[1]; final boolean[] finalReportProduced = new boolean[] { false }; Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { if (!finalReportProduced[0] && loader[0] != null) { System.err.println( "Process interrupted. Partial loading report: " + loader[0].createReport()); } System.err.println("Shutting down."); } })); final JSONStorageConfiguration storageConfig = jsonStorageFactory .createConfiguration(jsonStorageConfig); try (final JSONStorage storage = jsonStorageFactory.createStorage(storageConfig)) { loader[0] = new DefaultJSONStorageLoader(WikiPipelineFactory.getInstance(), flags, storage); final StorageLoaderReport report = loader[0].load(prefixURL, FileUtil.openDecompressedInputStream(dumpFile)); System.err.println("Loading report: " + report); finalReportProduced[0] = true; } System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }
From source file:RequesterTool.java
public static void main(String[] args) { RequesterTool requesterTool = new RequesterTool(); String[] unknown = CommandLineSupport.setOptions(requesterTool, args); if (unknown.length > 0) { System.out.println("Unknown options: " + Arrays.toString(unknown)); System.exit(-1);//from www .j a v a 2 s. c om } requesterTool.run(); }
From source file:com.notifier.desktop.Main.java
public static void main(String[] args) { Options options = createCommandLineOptions(); try {//from ww w .ja v a 2s . c o m CommandLineParser commandLineParser = new GnuParser(); CommandLine line = commandLineParser.parse(options, args); if (line.getOptions().length > 1) { showMessage("Only one parameter may be specified"); } if (line.getArgs().length > 0) { showMessage("Non-recognized parameters: " + Arrays.toString(line.getArgs())); } if (line.hasOption(HELP_SHORT)) { printHelp(options); return; } if (line.hasOption(IS_RUNNING_SHORT)) { ServiceClient client = new ServiceClientImpl(); if (client.isRunning()) { showMessage(Application.NAME + " is running"); } else { showMessage(Application.NAME + " is not running"); } return; } if (line.hasOption(STOP_SHORT)) { ServiceClient client = new ServiceClientImpl(); if (client.stop()) { showMessage("Sent stop signal to " + Application.NAME + " successfully"); } else { showMessage(Application.NAME + " is not running or an error occurred, see log for details"); } return; } boolean trayIcon = !line.hasOption(NO_TRAY_SHORT); boolean showPreferences = line.hasOption(SHOW_PREFERENCES_SHORT); if (!getExclusiveExecutionLock()) { showMessage("There can be only one instance of " + Application.NAME + " running at a time"); return; } Injector injector = Guice.createInjector(Stage.PRODUCTION, new ApplicationModule()); Application application = injector.getInstance(Application.class); application.start(trayIcon, showPreferences); } catch (Throwable t) { System.out.println(t.getMessage()); logger.error("Error starting", t); } }
From source file:com.garyclayburg.BootUp.java
public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(BootUp.class); log.info("active profiles: " + Arrays.toString(ctx.getEnvironment().getActiveProfiles())); log.info("Beans loaded by spring / spring boot"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames);/*from ww w. j av a2s. co m*/ for (String beanName : beanNames) { log.info(beanName); } log.info(""); log.info("Server is ready for e-business"); }
From source file:ProducerTool.java
public static void main(String[] args) { ArrayList<ProducerTool> threads = new ArrayList(); ProducerTool producerTool = new ProducerTool(); String[] unknown = CommandLineSupport.setOptions(producerTool, args); if (unknown.length > 0) { System.out.println("Unknown options: " + Arrays.toString(unknown)); System.exit(-1);/*from w ww. j a va 2 s .c o m*/ } producerTool.showParameters(); for (int threadCount = 1; threadCount <= parallelThreads; threadCount++) { producerTool = new ProducerTool(); CommandLineSupport.setOptions(producerTool, args); producerTool.start(); threads.add(producerTool); } while (true) { Iterator<ProducerTool> itr = threads.iterator(); int running = 0; while (itr.hasNext()) { ProducerTool thread = itr.next(); if (thread.isAlive()) { running++; } } if (running <= 0) { System.out.println("All threads completed their work"); break; } try { Thread.sleep(1000); } catch (Exception e) { } } }
From source file:com.hdfstoftp.main.HdfsToFtp.java
/** * ?/*from ww w .j av a2 s . co m*/ * * @param args * @throws IOException * @throws ParseException */ public static void main(String[] args) throws IOException, ParseException { args = new String[] { "D:/input", "/home/heaven/whd", "-c d:/conf/hdfs-to-ftp.properties", "-t 20150820000000", "-r .*bak.*", "-o false" }; // args = new String[] { "d:/failed", "/home/heaven/whd" }; try { logger.info("your input param is=" + Arrays.toString(args)); Config config = new Config(args); logger.info("your config is =" + config.toString()); copyFromHDFSToFTP(config); } catch (URISyntaxException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }