Example usage for org.apache.hadoop.net DNS getDefaultIP

List of usage examples for org.apache.hadoop.net DNS getDefaultIP

Introduction

In this page you can find the example usage for org.apache.hadoop.net DNS getDefaultIP.

Prototype

public static String getDefaultIP(String strInterface) throws UnknownHostException 

Source Link

Document

Returns the first available IP address associated with the provided network interface or the local host IP if "default" is given.

Usage

From source file:common.DataNode.java

License:Apache License

public static void setNewStorageID(DatanodeRegistration dnReg) {
    /* Return //from   ww w  . j  a v a  2 s .  c om
     * "DS-randInt-ipaddr-currentTimeMillis"
     * It is considered extermely rare for all these numbers to match
     * on a different machine accidentally for the following 
     * a) SecureRandom(INT_MAX) is pretty much random (1 in 2 billion), and
     * b) Good chance ip address would be different, and
     * c) Even on the same machine, Datanode is designed to use different ports.
     * d) Good chance that these are started at different times.
     * For a confict to occur all the 4 above have to match!.
     * The format of this string can be changed anytime in future without
     * affecting its functionality.
     */
    String ip = "unknownIP";
    try {
        ip = DNS.getDefaultIP("default");
    } catch (UnknownHostException ignored) {
        LOG.warn("Could not find ip address of \"default\" inteface.");
    }

    int rand = 0;
    try {
        rand = SecureRandom.getInstance("SHA1PRNG").nextInt(Integer.MAX_VALUE);
    } catch (NoSuchAlgorithmException e) {
        LOG.warn("Could not use SecureRandom");
        rand = R.nextInt(Integer.MAX_VALUE);
    }
    dnReg.storageID = "DS-" + rand + "-" + ip + "-" + dnReg.getPort() + "-" + System.currentTimeMillis();
}

From source file:io.hops.experiments.benchmarks.blockreporting.TinyDatanode.java

License:Apache License

void register(boolean isDataNodePopulated) throws Exception {
    List<BlockReportingNameNodeHandle> namenodes = nameNodeSelector.getNameNodes();
    // get versions from the namenode
    nsInfo = namenodes.get(0).getDataNodeRPC().versionRequest();
    dnRegistration = new DatanodeRegistration(
            new DatanodeID(DNS.getDefaultIP("default"), DNS.getDefaultHost("default", "default"), "",
                    getNodePort(dnIdx), DFSConfigKeys.DFS_DATANODE_HTTP_DEFAULT_PORT,
                    DFSConfigKeys.DFS_DATANODE_IPC_DEFAULT_PORT),
            new DataStorage(nsInfo, ""), new ExportedBlockKeys(), VersionInfo.getVersion());
    dnRegistration.setStorageID(createNewStorageId(dnRegistration.getXferPort(), dnIdx));
    // register datanode
    for (BlockReportingNameNodeHandle nn : namenodes) {
        dnRegistration = nn.getDataNodeRPC().registerDatanode(dnRegistration);
    }//w w w  . ja  v  a2 s .  c  om
    //first block reports
    storage = new DatanodeStorage(dnRegistration.getStorageID());
    if (!isDataNodePopulated) {
        firstBlockReport(new BlockListAsLongs(null, null).getBlockListAsLongs());
    }
}

From source file:io.hops.experiments.benchmarks.blockreporting.TinyDatanode.java

License:Apache License

private static String createNewStorageId(int port, int dnIdx) {
    // It is unlikely that we will create a non-unique storage ID
    // for the following reasons:
    // a) SecureRandom is a cryptographically strong random number generator
    // b) IP addresses will likely differ on different hosts
    // c) DataNode xfer ports will differ on the same host
    // d) StorageIDs will likely be generated at different times (in ms)
    // A conflict requires that all four conditions are violated.
    // NB: The format of this string can be changed in the future without
    // requiring that old SotrageIDs be updated.
    String ip = "unknownIP";
    try {//from w w  w. j  av a2  s. com
        ip = DNS.getDefaultIP("default");
    } catch (UnknownHostException ignored) {
        LOG.warn("Could not find an IP address for the \"default\" inteface.");
    }
    return "DS-" + dnIdx + "-" + ip + "-" + port + "-" + dnIdx;
}