Example usage for org.apache.hadoop.hdfs.server.namenode NameNode createNameNode

List of usage examples for org.apache.hadoop.hdfs.server.namenode NameNode createNameNode

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.server.namenode NameNode createNameNode.

Prototype

public static NameNode createNameNode(String argv[], Configuration conf) throws IOException 

Source Link

Usage

From source file:com.griddynamics.jagger.storage.fs.hdfs.HDFSNamenodeServer.java

License:Open Source License

public void start() {
    log.info("Starting NameNode...");
    try {/* w  w w .  j a  va  2 s .  c  om*/
        try {
            nameNode = NameNode.createNameNode(null, HadoopUtils.toConfiguration(startupProperties));
        } catch (InconsistentFSStateException e) {
            log.info("HDFS is in inconsistent state. Reformatting...");
            formatStorage();
            nameNode = NameNode.createNameNode(null, HadoopUtils.toConfiguration(startupProperties));
        }
        nameNode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
    } catch (IOException e) {
        throw new TechnicalException(e);
    }
    log.info("NameNode started.");
}

From source file:com.mellanox.r4h.MiniDFSCluster.java

License:Apache License

private void createNameNode(int nnIndex, Configuration conf, int numDataNodes, boolean format,
        StartupOption operation, String clusterId, String nameserviceId, String nnId) throws IOException {
    // Format and clean out DataNode directories
    if (format) {
        DFSTestUtil.formatNameNode(conf);
    }/*from w ww . j a  v  a2  s.com*/
    if (operation == StartupOption.UPGRADE) {
        operation.setClusterId(clusterId);
    }

    // Start the NameNode after saving the default file system.
    String originalDefaultFs = conf.get(FS_DEFAULT_NAME_KEY);
    String[] args = createArgs(operation);
    NameNode nn = NameNode.createNameNode(args, conf);
    if (operation == StartupOption.RECOVER) {
        return;
    }

    // After the NN has started, set back the bound ports into
    // the conf
    conf.set(DFSUtil.addKeySuffixes(DFS_NAMENODE_RPC_ADDRESS_KEY, nameserviceId, nnId),
            nn.getNameNodeAddressHostPortString());
    if (nn.getHttpAddress() != null) {
        conf.set(DFSUtil.addKeySuffixes(DFS_NAMENODE_HTTP_ADDRESS_KEY, nameserviceId, nnId),
                NetUtils.getHostPortString(nn.getHttpAddress()));
    }
    if (nn.getHttpsAddress() != null) {
        conf.set(DFSUtil.addKeySuffixes(DFS_NAMENODE_HTTPS_ADDRESS_KEY, nameserviceId, nnId),
                NetUtils.getHostPortString(nn.getHttpsAddress()));
    }

    DFSUtil.setGenericConf(conf, nameserviceId, nnId, DFS_NAMENODE_HTTP_ADDRESS_KEY);
    nameNodes[nnIndex] = new NameNodeInfo(nn, nameserviceId, nnId, operation, new Configuration(conf));
    // Restore the default fs name
    if (originalDefaultFs == null) {
        conf.set(FS_DEFAULT_NAME_KEY, "");
    } else {
        conf.set(FS_DEFAULT_NAME_KEY, originalDefaultFs);
    }
}

From source file:com.mellanox.r4h.MiniDFSCluster.java

License:Apache License

/**
 * Restart the namenode at a given index. Optionally wait for the cluster
 * to become active./* w  w  w  .  jav a  2 s  .  co  m*/
 */
public synchronized void restartNameNode(int nnIndex, boolean waitActive, String... args) throws IOException {
    String nameserviceId = nameNodes[nnIndex].nameserviceId;
    String nnId = nameNodes[nnIndex].nnId;
    StartupOption startOpt = nameNodes[nnIndex].startOpt;
    Configuration conf = nameNodes[nnIndex].conf;
    shutdownNameNode(nnIndex);
    if (args.length != 0) {
        startOpt = null;
    } else {
        args = createArgs(startOpt);
    }
    NameNode nn = NameNode.createNameNode(args, conf);
    nameNodes[nnIndex] = new NameNodeInfo(nn, nameserviceId, nnId, startOpt, conf);
    if (waitActive) {
        waitClusterUp();
        LOG.info("Restarted the namenode");
        waitActive();
    }
}

From source file:hudson.gridmaven.gridlayer.NameNodeStartTask.java

License:Open Source License

public Void call() throws IOException {
    File hadoopRoot = new File(hudsonRoot, "hadoop");
    if (hadoopRoot.mkdirs())
        format = true;//from   ww w .ja  v a2 s.c om

    final Configuration conf = new Configuration();
    // location of the name node
    conf.set("fs.default.name", hdfsUrl);
    conf.set("dfs.http.address", "0.0.0.0:" + HTTP_PORT);
    // namespace node stores information here
    File namedir = new File(hadoopRoot, "namedir");
    if (namedir.mkdirs())
        format = true;
    conf.set("dfs.name.dir", namedir.getPath());
    // dfs node stores information here
    File datadir = new File(hadoopRoot, "datadir");
    conf.set("dfs.namenode.logging.level", "ALL");
    if (datadir.mkdirs())
        format = true;
    conf.set("dfs.data.dir", datadir.getPath());

    conf.setInt("dfs.replication", 1);
    conf.set("dfs.safemode.extension", "1");
    conf.set("dfs.block.size", "1048576");
    //if(format) {
    // This will provide format HDFS with every start
    System.out.println("Formatting HDFS");
    NameNode.format(conf);
    //}

    System.out.println("Starting namenode");
    NameNode.createNameNode(new String[0], conf);
    return null;
}

From source file:hudson.plugins.hadoop.NameNodeStartTask.java

License:Open Source License

public Void call() throws IOException {
    File hadoopRoot = new File(hudsonRoot, "hadoop");
    if (hadoopRoot.mkdirs())
        format = true;//from   ww w  .  j a v  a  2 s .c  o  m

    final Configuration conf = new Configuration();
    // location of the name node
    conf.set("fs.default.name", hdfsUrl);
    conf.set("dfs.http.address", "0.0.0.0:" + HTTP_PORT);
    // namespace node stores information here
    File namedir = new File(hadoopRoot, "namedir");
    if (namedir.mkdirs())
        format = true;
    conf.set("dfs.name.dir", namedir.getPath());
    // dfs node stores information here
    File datadir = new File(hadoopRoot, "datadir");
    if (datadir.mkdirs())
        format = true;
    conf.set("dfs.data.dir", datadir.getPath());

    conf.setInt("dfs.replication", 1);

    if (format) {
        System.out.println("Formatting HDFS");
        NameNode.format(conf);
    }

    System.out.println("Starting namenode");
    NameNode.createNameNode(new String[0], conf);
    return null;
}

From source file:io.fabric8.hadoop.hdfs.NameNodeFactory.java

License:Apache License

@Override
protected NameNode doCreate(Dictionary properties) throws Exception {
    Configuration conf = new Configuration();
    for (Enumeration e = properties.keys(); e.hasMoreElements();) {
        Object key = e.nextElement();
        Object val = properties.get(key);
        conf.set(key.toString(), val.toString());
    }/*from  ww w  .j  a  va2s  .  c om*/
    boolean exists = false;
    for (File file : FSNamesystem.getNamespaceDirs(conf)) {
        exists |= file.exists();
    }
    if (!exists) {
        NameNode.format(conf);
    }
    NameNode nameNode = NameNode.createNameNode(null, conf);
    return nameNode;
}