Example usage for org.apache.hadoop.net NetUtils createSocketAddr

List of usage examples for org.apache.hadoop.net NetUtils createSocketAddr

Introduction

In this page you can find the example usage for org.apache.hadoop.net NetUtils createSocketAddr.

Prototype

public static InetSocketAddress createSocketAddr(String target, int defaultPort) 

Source Link

Document

Util method to build socket addr from either: : ://:/

Usage

From source file:com.bigstep.datalake.DLFileSystem.java

License:Apache License

/**
 * Resolve an HDFS URL into real INetSocketAddress. It works like a DNS
 * resolver when the URL points to an non-HA cluster. When the URL points to
 * an HA cluster with its logical name, the resolver further resolves the
 * logical name(i.e., the authority in the URL) into real namenode addresses.
 *///from w ww  .  j  a v a  2s  .c om
private InetSocketAddress[] resolveNNAddr() throws IOException {
    Configuration conf = getConf();
    final String scheme = baseUri.getScheme();

    ArrayList<InetSocketAddress> ret = new ArrayList<InetSocketAddress>();

    if (!HAUtil.isLogicalUri(conf, baseUri)) {
        InetSocketAddress addr = NetUtils.createSocketAddr(baseUri.getAuthority(), getDefaultPort());
        ret.add(addr);

    } else {
        Map<String, Map<String, InetSocketAddress>> addresses = DFSUtil.getHaNnWebHdfsAddresses(conf, scheme);

        // Extract the entry corresponding to the logical name.
        Map<String, InetSocketAddress> addrs = addresses.get(baseUri.getHost());
        for (InetSocketAddress addr : addrs.values()) {
            ret.add(addr);
        }
    }

    InetSocketAddress[] r = new InetSocketAddress[ret.size()];
    return ret.toArray(r);
}

From source file:com.cloudera.llama.am.LlamaAMServer.java

License:Apache License

protected synchronized void startHttpServer() {
    if (httpServer != null && httpServer.isRunning()) {
        return;//  ww w  .  j  a v  a2 s  . c  om
    }

    restData = new RestData(this);
    httpServer = new Server();
    QueuedThreadPool qtp = new QueuedThreadPool(JETTY_MAX_THREADS);
    qtp.setName("llama-jetty");
    qtp.setDaemon(true);
    httpServer.setThreadPool(qtp);
    String strAddress = getServerConf().getHttpAddress();
    InetSocketAddress address = NetUtils.createSocketAddr(strAddress, getServerConf().getHttpDefaultPort());
    Connector connector = new SocketConnector();
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    httpServer.setConnectors(new Connector[] { connector });

    Context context = new Context();
    context.setContextPath("");
    context.setAttribute("hadoop.conf", new Configuration());
    context.addServlet(JMXJsonServlet.class, "/jmx");
    context.addServlet(LlamaServlet.class, "/*");
    context.addServlet(Log4jLoggersServlet.class, "/loggers");
    context.setAttribute(Log4jLoggersServlet.READ_ONLY, getServerConf().getLoggerServletReadOnly());
    context.addServlet(LlamaJsonServlet.class, LlamaJsonServlet.BIND_PATH);
    context.setAttribute(LlamaJsonServlet.REST_DATA, restData);
    httpServer.addHandler(context);

    try {
        httpServer.start();
        httpJmx = "http://" + getHostname(connector.getHost()) + ":" + connector.getLocalPort() + "/jmx";
        httpLlama = "http://" + getHostname(connector.getHost()) + ":" + connector.getLocalPort() + "/";

        LOG.info("HTTP JSON JMX     : {}", httpJmx);
        LOG.info("HTTP Llama Web UI : {}", httpLlama);
    } catch (Throwable ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.cloudera.llama.server.ThriftEndPoint.java

License:Apache License

public static TServerSocket createTServerSocket(ServerConfiguration conf) throws Exception {
    String strAddress = conf.getThriftAddress();
    int timeout = conf.getTransportTimeOut();
    int defaultPort = conf.getThriftDefaultPort();
    InetSocketAddress address = NetUtils.createSocketAddr(strAddress, defaultPort);
    return new TServerSocket(address, timeout);
}

From source file:com.cloudera.llama.server.ThriftEndPoint.java

License:Apache License

public static TServerSocket createAdminTServerSocket(ServerConfiguration conf) throws Exception {
    String strAddress = conf.getAdminThriftAddress();
    int timeout = 2000;
    int defaultPort = conf.getAdminThriftDefaultPort();
    InetSocketAddress address = NetUtils.createSocketAddr(strAddress, defaultPort);
    return new TServerSocket(address, timeout);
}

From source file:com.cloudera.llama.server.ThriftEndPoint.java

License:Apache License

public static String getServerAddress(ServerConfiguration conf) {
    String strAddress = conf.getThriftAddress();
    int defaultPort = conf.getThriftDefaultPort();
    InetSocketAddress address = NetUtils.createSocketAddr(strAddress, defaultPort);
    return address.getHostName();
}

From source file:com.cloudera.llama.server.ThriftEndPoint.java

License:Apache License

public static int getServerPort(ServerConfiguration conf) {
    String strAddress = conf.getThriftAddress();
    int defaultPort = conf.getThriftDefaultPort();
    InetSocketAddress address = NetUtils.createSocketAddr(strAddress, defaultPort);
    return address.getPort();
}

From source file:com.thinkbiganalytics.nifi.security.ApplySecurityPolicy.java

License:Apache License

protected void checkHdfsUriForTimeout(Configuration config) throws IOException {
    URI hdfsUri = FileSystem.getDefaultUri(config);
    String address = hdfsUri.getAuthority();
    int port = hdfsUri.getPort();
    if (address == null || address.isEmpty() || port < 0) {
        return;//from  w w  w  . j a va2  s .  c  o  m
    }
    InetSocketAddress namenode = NetUtils.createSocketAddr(address, port);
    SocketFactory socketFactory = NetUtils.getDefaultSocketFactory(config);
    Socket socket = null;
    try {
        socket = socketFactory.createSocket();
        NetUtils.connect(socket, namenode, 1000); // 1 second timeout
    } finally {
        IOUtils.closeQuietly(socket);
    }
}

From source file:com.trendmicro.hdfs.webdav.Main.java

License:Apache License

private static InetSocketAddress getAddress(Configuration conf) {
    return NetUtils.createSocketAddr(conf.get("hadoop.webdav.bind.address", "0.0.0.0"),
            conf.getInt("hadoop.webdav.port", 8080));
}

From source file:common.NameNode.java

License:Apache License

public static InetSocketAddress getAddress(String address) {
    return NetUtils.createSocketAddr(address, DEFAULT_PORT);
}

From source file:de.hpi.fgis.hdrs.Peer.java

License:Apache License

public InetSocketAddress getConnectAddress() {
    return NetUtils.createSocketAddr(address, port);
}