List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:com.google.devtools.build.xcode.actoolzip.ActoolZip.java
public static void main(String[] args) throws IOException, InterruptedException { Optional<File> infoPlistPath = replaceInfoPlistPath(args); try {//from w w w. j av a 2 s. c o m OutErr outErr = Wrappers.executeCapturingOutput(args, new ActoolZip()); if (infoPlistPath.isPresent() && !infoPlistPath.get().exists()) { outErr.print(); System.exit(1); } } catch (CommandFailedException e) { Wrappers.handleException(e); } }
From source file:io.crate.frameworks.mesos.Main.java
public static void main(String[] args) throws Exception { BasicConfigurator.configure();//from w ww. j av a 2 s . c o m Configuration configuration = parseConfiguration(args); final double frameworkFailoverTimeout = 31536000d; // 60 * 60 * 24 * 365 = 1y final String host = System.getenv("MESOS_HOSTNAME"); final String webUri = UriBuilder.fromPath("/cluster").scheme("http") .host(host == null ? currentHost() : host).port(configuration.apiPort).build().toString(); Protos.FrameworkInfo.Builder frameworkBuilder = Protos.FrameworkInfo.newBuilder() .setName(configuration.frameworkName).setUser(configuration.user).setRole(configuration.role) .setWebuiUrl(webUri).setCheckpoint(true) // will be enabled by default in Mesos 0.22 .setFailoverTimeout(frameworkFailoverTimeout); PersistentStateStore stateStore = new PersistentStateStore( new ZooKeeperState(configuration.zookeeper, 20_000, TimeUnit.MILLISECONDS, String.format("/%s/%s", configuration.frameworkName, configuration.clusterName)), configuration.nodeCount); Optional<String> frameworkId = stateStore.state().frameworkId(); if (frameworkId.isPresent()) { frameworkBuilder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkId.get()).build()); } final Scheduler scheduler = new CrateScheduler(stateStore, configuration); // create the driver MesosSchedulerDriver driver; String mesosMaster = configuration.mesosMaster(); Optional<Protos.Credential> credential = readCredentials(); if (credential.isPresent()) { frameworkBuilder.setPrincipal(credential.get().getPrincipal()); driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMaster, credential.get()); } else { frameworkBuilder.setPrincipal("crate-framework"); driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMaster); } CrateHttpService api = new CrateHttpService(stateStore, configuration); api.start(); int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1; // Ensure that the driver process terminates. api.stop(); driver.stop(); System.exit(status); }
From source file:io.urmia.st.Main.java
public static void main(String[] args) throws Exception { final int port; final String base; boolean autoRegister = ArgumentParseUtil.isAutoRegister(args); String zkURL = ArgumentParseUtil.getZooKeeperURL(args); log.info("starting with zk at: {}, auto register: {}", zkURL, autoRegister); ns = new ZkNamingServiceImpl(zkURL, AZ); Optional<ServiceInstance<NodeType>> meOpt = ns.whoAmI(NodeType.ODS, autoRegister); if (!meOpt.isPresent()) { System.err.println("unable to find my instance. use auto register or cli-admin to add my node"); System.exit(1);//from w ww . j ava 2 s . c o m return; } Runtime.getRuntime().addShutdownHook(new ShutdownHook()); EventLoopGroup bossGroup = new NioEventLoopGroup(/*1*/); //EventLoopGroup bossGroup = new EpollEventLoopGroup(1); //EventLoopGroup workerGroup = new NioEventLoopGroup(); try { me = meOpt.get(); log.info("my service instance: {}", me); ns.register(me); base = me.getUriSpec().getParts().get(0).getValue(); port = me.getPort(); if (!(new File(base).isDirectory())) { System.err.println("base in not directory: " + base); return; } int nHeapArena = 1; int nDirectArena = 1; int pageSize = /*8192*/4096; int maxOrder = 1; // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#14.0 ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup).channel(NioServerSocketChannel.class).childOption(ChannelOption.AUTO_READ, false) .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true, nHeapArena, nDirectArena, pageSize, maxOrder)) .childHandler(new HttpUploadServerInitializer(base)); Channel ch = b.bind(port).sync().channel(); log.info("object storage Server (ODS) at port: {}", port); System.err.println("starting ODS " + me.getId() + " on port: " + port + ", base: " + base); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); //workerGroup.shutdownGracefully(); } }
From source file:cn.lhfei.spark.rdd.PairRDDLeftJoinApp.java
public static void main(String[] args) { SparkConf conf = new SparkConf().setMaster("local").setAppName("PairRDD"); SparkContext sc = new SparkContext(conf); JavaSparkContext jsc = new JavaSparkContext(sc); JavaRDD<String> ipRepo = jsc.textFile("src/test/resources/data/IP_REPO_CN.txt").cache(); JavaRDD<String> logs = jsc.textFile("src/test/resources/data/IP_LOGS.log").cache(); JavaPairRDD<String, String> ipRepoPair = ipRepo.mapToPair(new PairFunction<String, String, String>() { @Override//from w ww .java2s .c om public Tuple2<String, String> call(String line) throws Exception { //log.debug("====================={}", line); String ip = line.split("\t")[0].trim(); return new Tuple2(ip, line.replaceAll(ip + "\t", "")); } }).distinct().cache(); // collect logs by cat code and format time to time range. JavaRDD<VideologPair> logRdd = logs.map(new Function<String, VideologPair>() { @Override public VideologPair call(String line) throws Exception { VideologPair pair = VideologFilter.filte(line, "2015-07-02", "0000"); return pair; } }).cache(); // JavaPairRDD<String, String> ipPair = logRdd.mapToPair(new PairFunction<VideologPair, String, String>() { @Override public Tuple2<String, String> call(VideologPair pair) throws Exception { return new Tuple2<String, String>(pair.getIp(), pair.getKey() + "\t" + pair.getValue()); } }).cache(); // JavaPairRDD<String, Tuple2<String, Optional<String>>> logsFullyRdd = ipPair.leftOuterJoin(ipRepoPair) .cache(); JavaRDD<String> resultRdd = logsFullyRdd .map(new Function<Tuple2<String, Tuple2<String, Optional<String>>>, String>() { @Override public String call(Tuple2<String, Tuple2<String, Optional<String>>> val) throws Exception { Tuple2<String, Optional<String>> option = val._2(); String line = option._1(); Optional<String> isp = option._2(); String result = new String(line + "\t"); if (isp.isPresent()) { result += isp.get(); } else { result += NORMAL_ISP_OPTIONAL.get(); } log.debug("{}", result); return result; } }).cache(); resultRdd.count(); jsc.close(); }
From source file:com.accumulobook.designs.graph.TwitterGraph.java
public static void main(String[] args) throws Exception { Connector conn = ExampleMiniCluster.getConnector(); // create our table and get some data BatchWriter writer = Graph.setupTable(conn, TWITTER_GRAPH_TABLE, true); int seconds = 30; ingest(args, writer, seconds);//from ww w . j av a 2 s.c o m // visualize our graph, one node at a time System.out.println("visualizing graph ..."); UbigraphClient client = new UbigraphClient(); for (String startNode : new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }) { Scanner startNodeScanner = conn.createScanner(TWITTER_GRAPH_TABLE, Authorizations.EMPTY); Optional<String> node = Graph.discoverNode(startNode, startNodeScanner); startNodeScanner.close(); if (node.isPresent()) { // visualize start node int nodeId = client.newVertex(); client.setVertexAttribute(nodeId, "label", node.get()); Scanner neighborScanner = conn.createScanner(TWITTER_GRAPH_TABLE, Authorizations.EMPTY); for (String neighbor : Graph.getNeighbors(node.get(), neighborScanner, "ALL")) { // visualize neighbor node int neighborId = client.newVertex(); client.setVertexAttribute(neighborId, "label", neighbor); // visualize edge client.newEdge(nodeId, neighborId); } neighborScanner.close(); } } }
From source file:com.amazonaws.services.dynamodbv2.streams.connectors.CommandLineInterface.java
/** * Command line main method entry point/*from ww w .jav a2 s . co m*/ * * @param args * command line arguments */ public static void main(String[] args) { try { final Optional<Worker> workerOption = mainUnsafe(args); if (!workerOption.isPresent()) { return; } System.out.println("Starting replication now, check logs for more details."); workerOption.get().run(); } catch (ParameterException e) { log.error(e); JCommander.getConsole().println(e.toString()); System.exit(StatusCodes.EINVAL); } catch (Exception e) { log.fatal(e); JCommander.getConsole().println(e.toString()); System.exit(StatusCodes.EINVAL); } }
From source file:io.urmia.api.Main.java
public static void main(String[] args) throws Exception { boolean autoRegister = ArgumentParseUtil.isAutoRegister(args); String zkURL = ArgumentParseUtil.getZooKeeperURL(args); log.info("starting with zk at: {}, auto register: {}", zkURL, autoRegister); ns = new ZkNamingServiceImpl(zkURL, AZ); Optional<ServiceInstance<NodeType>> meOpt = ns.whoAmI(NodeType.MDS, autoRegister); if (!meOpt.isPresent()) { System.err.println("unable to find my instance. use auto register or cli-admin to add my node"); System.exit(1);//from w w w. j a va2 s .c o m return; } Runtime.getRuntime().addShutdownHook(new ShutdownHook()); uuid = new RandomUuidImpl(); //Properties properties = parseArguments(args); EventLoopGroup bossGroup = new NioEventLoopGroup(/*1*/); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { me = meOpt.get(); log.info("my service instance: {}", me); BoneCPConfig boneCPConfig = getBoneCPConfig(ns); ns.register(me); int port = me.getPort(); JdbcPool pool = new JdbcPool.BoneCPJdbcPool(boneCPConfig); MetadataRepository repository = new PsqlMetadataRepositoryImpl(pool); mds = new DefaultMetadataServiceImpl(repository); // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#14.0 ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childOption(ChannelOption.AUTO_READ, false) .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)) .childHandler(new HttpUploadServerInitializer()); Channel ch = b.bind(port).sync().channel(); log.info("object metadata API server (MDS) at port: {}", port); ch.closeFuture().sync(); } finally { ns.deregister(me); bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:io.urmia.job.Main.java
public static void main(String[] args) throws Exception { boolean autoRegister = ArgumentParseUtil.isAutoRegister(args); String zkURL = ArgumentParseUtil.getZooKeeperURL(args); log.info("starting with zk at: {}, auto register: {}", zkURL, autoRegister); ns = new ZkNamingServiceImpl(zkURL, AZ); Optional<ServiceInstance<NodeType>> meOpt = ns.whoAmI(NodeType.JDS, autoRegister); if (!meOpt.isPresent()) { System.err.println("unable to find my instance. use auto register or cli-admin to add my node"); System.exit(1);/* ww w. j a va2 s . c om*/ return; } Runtime.getRuntime().addShutdownHook(new ShutdownHook()); EventLoopGroup bossGroup = new NioEventLoopGroup(/*1*/); try { me = meOpt.get(); log.info("my service instance: {}", me); BoneCPConfig boneCPConfig = getBoneCPConfig(ns); ns.register(me); int port = me.getPort(); CuratorFramework client = CuratorFrameworkFactory.newClient(zkURL, new ExponentialBackoffRetry(1000, 3)); client.start(); JdbcPool pool = new JdbcPool.BoneCPJdbcPool(boneCPConfig); MetadataRepository repository = new PsqlMetadataRepositoryImpl(pool); MetadataService mds = new DefaultMetadataServiceImpl(repository); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup).channel(NioServerSocketChannel.class).childOption(ChannelOption.AUTO_READ, true) .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator()) .childHandler(new JobApiServerInitializer(client, mds)); Channel ch = b.bind(port).sync().channel(); log.info("Job API Server (JDS) at port: {}", port); ch.closeFuture().sync(); } finally { ns.deregister(me); bossGroup.shutdownGracefully(); //workerGroup.shutdownGracefully(); } }
From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.Main.java
public static void main(String[] args) { try {/* w ww .j a v a 2 s . c o m*/ Map<Command, Optional<String>> cmds = Command.parse(args); if ((cmds.containsKey(Command.HELP)) || (!cmds.containsKey(Command.CONFIG))) { usage(); return; } final JDBCConfig config = config(cmds.get(Command.CONFIG).get()); String pwd = config.password.orNull(); if (null == pwd) { Optional<String> opt = passwordOf("database", config.user); if (!opt.isPresent()) { throw new ExitException(RetCode.ERR_CANCELLED); } pwd = opt.get(); } try (JDBCConnection from = create(config, pwd); CSVWriter writer = makeLog(config.user)) { Stopwatch watch = Stopwatch.createStarted(); Stores stores = StoresReader.STORESREADER.apply(from); System.out.println("spent " + watch.stop() + " to load stores"); final Function<DecoratedContent, Checks.Result> checker = Checks.checker(stores); final Multiset<Checks.Code> codes = TreeMultiset.create(); watch.reset().start(); ResponseUI rui = ResponseUI.create(1024, 64); try (CloseableIterator<DecoratedContent> it = DCReader.reader(from, stores)) { long count = 0L; while (it.hasNext()) { DecoratedContent dc = it.next(); count++; final Checks.Result result = checker.apply(dc); assert null != result; rui.onResponse(result); final Checks.Code code = result.code; codes.add(code); if (code != Checks.Code.OK) { // we've got an error then .... writer.writeError(dc, result); } } rui.finish(); System.out.println("spent " + watch.stop() + " to read " + count + " d.c."); System.out.println("stats: " + codes); System.out.println("bye"); } } } catch (SQLException e) { e.printStackTrace(System.err); System.err.flush(); System.out.println(); usage(); System.exit(RetCode.ERR_SQL.ordinal()); } catch (ExitException e) { e.exit(); } catch (RuntimeException | IOException e) { e.printStackTrace(System.err); System.err.flush(); System.out.println(); usage(); System.exit(RetCode.ERR_OTHER.ordinal()); } }
From source file:io.urmia.job.run.Main.java
public static void main(String[] args) throws Exception { LoggerContext loggerContext = ((ch.qos.logback.classic.Logger) log).getLoggerContext(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(loggerContext); System.err.println(mainURL);//from ww w . j av a 2 s .c o m // or even log.info("Logback used '{}' as the configuration file.", mainURL); CuratorFramework client = null; PathChildrenCache cache = null; boolean autoRegister = ArgumentParseUtil.isAutoRegister(args); String zkURL = ArgumentParseUtil.getZooKeeperURL(args); log.info("starting with zk at: {}, auto register: {}", zkURL, autoRegister); ns = new ZkNamingServiceImpl(zkURL, AZ); Optional<ServiceInstance<NodeType>> meOpt = ns.whoAmI(NodeType.JRS, autoRegister); if (!meOpt.isPresent()) { System.err.println("unable to find my instance. use auto register or cli-admin to add my node"); System.exit(1); return; } Runtime.getRuntime().addShutdownHook(new ShutdownHook()); try { me = meOpt.get(); log.info("my service instance: {}", me); ServiceInstance<NodeType> ods = getMyMatchingODSInstance(me); id = getId(ods);//me.getId(); //ns.register(me); meWithOdsId = meWithId(me, id); ns.register(meWithOdsId); mountPoint = getMountPoint(ods); String zkPath = getPath(AZ, id); System.err.println("instance id: " + me.getId()); System.err.println("ODS q id : " + id); System.err.println("zk path : " + zkPath); System.err.println("mount point: " + mountPoint); client = CuratorFrameworkFactory.newClient(zkURL, new ExponentialBackoffRetry(1000, 3)); client.start(); cache = new PathChildrenCache(client, zkPath, true); cache.start(); cache.getListenable().addListener(new ChildrenListener(), executor); log.info("listening path: {}", zkPath); loopForever(); } finally { System.err.println("finally block..."); ns.deregister(meWithOdsId); CloseableUtils.closeQuietly(cache); CloseableUtils.closeQuietly(client); } }