Search in sources :

Example 11 with CrailConfiguration

use of org.apache.crail.conf.CrailConfiguration in project incubator-crail by apache.

the class NameNode method main.

public static void main(String[] args) throws Exception {
    LOG.info("initalizing namenode ");
    CrailConfiguration conf = new CrailConfiguration();
    CrailConstants.updateConstants(conf);
    URI uri = CrailUtils.getPrimaryNameNode();
    String address = uri.getHost();
    int port = uri.getPort();
    if (args != null) {
        Option addressOption = Option.builder("a").desc("ip address namenode is started on").hasArg().build();
        Option portOption = Option.builder("p").desc("port namenode is started on").hasArg().build();
        Options options = new Options();
        options.addOption(portOption);
        options.addOption(addressOption);
        CommandLineParser parser = new DefaultParser();
        try {
            CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length));
            if (line.hasOption(addressOption.getOpt())) {
                address = line.getOptionValue(addressOption.getOpt());
            }
            if (line.hasOption(portOption.getOpt())) {
                port = Integer.parseInt(line.getOptionValue(portOption.getOpt()));
            }
        } catch (ParseException e) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Namenode", options);
            System.exit(-1);
        }
    }
    String namenode = "crail://" + address + ":" + port;
    long serviceId = CrailUtils.getServiceId(namenode);
    long serviceSize = CrailUtils.getServiceSize();
    if (!CrailUtils.verifyNamenode(namenode)) {
        throw new Exception("Namenode address/port [" + namenode + "] has to be listed in crail.namenode.address " + CrailConstants.NAMENODE_ADDRESS);
    }
    CrailConstants.NAMENODE_ADDRESS = namenode + "?id=" + serviceId + "&size=" + serviceSize;
    CrailConstants.printConf();
    CrailConstants.verify();
    RpcNameNodeService service = RpcNameNodeService.createInstance(CrailConstants.NAMENODE_RPC_SERVICE);
    if (!CrailConstants.NAMENODE_LOG.isEmpty()) {
        LogDispatcher logDispatcher = new LogDispatcher(service);
        service = logDispatcher;
    }
    RpcBinding rpcBinding = RpcBinding.createInstance(CrailConstants.NAMENODE_RPC_TYPE);
    RpcServer rpcServer = rpcBinding.launchServer(service);
    rpcServer.init(conf, null);
    rpcServer.printConf(LOG);
    rpcServer.run();
    System.exit(0);
    ;
}
Also used : Options(org.apache.commons.cli.Options) URI(java.net.URI) ParseException(org.apache.commons.cli.ParseException) RpcNameNodeService(org.apache.crail.rpc.RpcNameNodeService) HelpFormatter(org.apache.commons.cli.HelpFormatter) RpcBinding(org.apache.crail.rpc.RpcBinding) CommandLine(org.apache.commons.cli.CommandLine) RpcServer(org.apache.crail.rpc.RpcServer) Option(org.apache.commons.cli.Option) CrailConfiguration(org.apache.crail.conf.CrailConfiguration) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

CrailConfiguration (org.apache.crail.conf.CrailConfiguration)11 CrailStore (org.apache.crail.CrailStore)3 CoreDataStore (org.apache.crail.core.CoreDataStore)3 HashMap (java.util.HashMap)2 CommandLine (org.apache.commons.cli.CommandLine)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 DefaultParser (org.apache.commons.cli.DefaultParser)2 HelpFormatter (org.apache.commons.cli.HelpFormatter)2 Option (org.apache.commons.cli.Option)2 Options (org.apache.commons.cli.Options)2 ParseException (org.apache.commons.cli.ParseException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 StringTokenizer (java.util.StringTokenizer)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CrailBlockLocation (org.apache.crail.CrailBlockLocation)1 CrailDirectory (org.apache.crail.CrailDirectory)1