Search in sources :

Example 1 with RpcNameNodeService

use of org.apache.crail.rpc.RpcNameNodeService 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

URI (java.net.URI)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 CrailConfiguration (org.apache.crail.conf.CrailConfiguration)1 RpcBinding (org.apache.crail.rpc.RpcBinding)1 RpcNameNodeService (org.apache.crail.rpc.RpcNameNodeService)1 RpcServer (org.apache.crail.rpc.RpcServer)1