Java Code Examples for org.apache.hadoop.hdfs.server.datanode.DataNode#refreshNamenodes()

The following examples show how to use org.apache.hadoop.hdfs.server.datanode.DataNode#refreshNamenodes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MiniDFSCluster.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Add a namenode to a federated cluster and start it. Configuration of
 * datanodes in the cluster is refreshed to register with the new namenode.
 * 
 * @return newly started namenode
 */
public NameNode addNameNode(Configuration conf, int namenodePort)
    throws IOException {
  if(!federation)
    throw new IOException("cannot add namenode to non-federated cluster");

  int nnIndex = nameNodes.length;
  int numNameNodes = nameNodes.length + 1;
  NameNodeInfo[] newlist = new NameNodeInfo[numNameNodes];
  System.arraycopy(nameNodes, 0, newlist, 0, nameNodes.length);
  nameNodes = newlist;
  String nameserviceId = NAMESERVICE_ID_PREFIX + (nnIndex + 1);
  
  String nameserviceIds = conf.get(DFS_NAMESERVICES);
  nameserviceIds += "," + nameserviceId;
  conf.set(DFS_NAMESERVICES, nameserviceIds);

  String nnId = null;
  initNameNodeAddress(conf, nameserviceId,
      new NNConf(nnId).setIpcPort(namenodePort));
  initNameNodeConf(conf, nameserviceId, nnId, true, true, nnIndex);
  createNameNode(nnIndex, conf, numDataNodes, true, null, null,
      nameserviceId, nnId);

  // Refresh datanodes with the newly started namenode
  for (DataNodeProperties dn : dataNodes) {
    DataNode datanode = dn.datanode;
    datanode.refreshNamenodes(conf);
  }

  // Wait for new namenode to get registrations from all the datanodes
  waitActive(nnIndex);
  return nameNodes[nnIndex].nameNode;
}
 
Example 2
Source File: MiniDFSCluster.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Add a namenode to a federated cluster and start it. Configuration of
 * datanodes in the cluster is refreshed to register with the new namenode.
 * 
 * @return newly started namenode
 */
public NameNode addNameNode(Configuration conf, int namenodePort)
    throws IOException {
  if(!federation)
    throw new IOException("cannot add namenode to non-federated cluster");

  int nnIndex = nameNodes.length;
  int numNameNodes = nameNodes.length + 1;
  NameNodeInfo[] newlist = new NameNodeInfo[numNameNodes];
  System.arraycopy(nameNodes, 0, newlist, 0, nameNodes.length);
  nameNodes = newlist;
  String nameserviceId = NAMESERVICE_ID_PREFIX + (nnIndex + 1);
  
  String nameserviceIds = conf.get(DFS_NAMESERVICES);
  nameserviceIds += "," + nameserviceId;
  conf.set(DFS_NAMESERVICES, nameserviceIds);

  String nnId = null;
  initNameNodeAddress(conf, nameserviceId,
      new NNConf(nnId).setIpcPort(namenodePort));
  initNameNodeConf(conf, nameserviceId, nnId, true, true, nnIndex);
  createNameNode(nnIndex, conf, numDataNodes, true, null, null,
      nameserviceId, nnId);

  // Refresh datanodes with the newly started namenode
  for (DataNodeProperties dn : dataNodes) {
    DataNode datanode = dn.datanode;
    datanode.refreshNamenodes(conf);
  }

  // Wait for new namenode to get registrations from all the datanodes
  waitActive(nnIndex);
  return nameNodes[nnIndex].nameNode;
}
 
Example 3
Source File: MiniDFSCluster.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Add a namenode to cluster and start it. Configuration of datanodes
 * in the cluster is refreshed to register with the new namenode.
 * @return newly started namenode
 */
public NameNode addNameNode(Configuration conf, int namenodePort)
    throws IOException {
  if(!federation) {
    throw new IOException("cannot add namenode to non-federated cluster");
  }
  int nnIndex = nameNodes.length;
  int numNameNodes = nameNodes.length + 1;
  NameNodeInfo[] newlist = new NameNodeInfo[numNameNodes];
  System.arraycopy(nameNodes, 0, newlist, 0, nameNodes.length);
  nameNodes = newlist;
  String nameserviceId = NAMESERVICE_ID_PREFIX + getNSId();
  String nameserviceIds = conf.get(FSConstants.DFS_FEDERATION_NAMESERVICES);
  nameserviceIds += "," + nameserviceId;
  conf.set(FSConstants.DFS_FEDERATION_NAMESERVICES, nameserviceIds);
  
  initFederatedNamenodeAddress(conf, nameserviceId, namenodePort); 
  createFederatedNameNode(nnIndex, conf, numDataNodes, true, true,
      null, nameserviceId);

  // Refresh datanodes with the newly started namenode
  for (DataNodeProperties dn : dataNodes) {
    DataNode datanode = dn.datanode;
    datanode.refreshNamenodes(conf);
  }

  // Wait for new namenode to get registrations from all the datanodes
  waitActive(true, nnIndex);
  return nameNodes[nnIndex].nameNode;
}
 
Example 4
Source File: MiniAvatarCluster.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Add a namenode to cluster and start it. Configuration of datanodes
 * in the cluster is refreshed to register with the new namenode.
 * @return newly started namenode
 */
public NameNodeInfo addNameNode(Configuration conf)
    throws IOException {
  if(!federation) {
    throw new IOException("cannot add namenode to non-federated cluster");
  }
  int nnIndex = nameNodes.length;
  int numNameNodes = nameNodes.length + 1;
  NameNodeInfo[] newlist = new NameNodeInfo[numNameNodes];
  System.arraycopy(nameNodes, 0, newlist, 0, nameNodes.length);
  nameNodes = newlist;
  nameNodes[nnIndex] = new NameNodeInfo(nnIndex);
  
  NameNodeInfo nni = nameNodes[nnIndex];
  nni.createAvatarDirs();
  String nameserviceId = NAMESERVICE_ID_PREFIX + getNSId();
  String nameserviceIds = conf.get(FSConstants.DFS_FEDERATION_NAMESERVICES);
  nameserviceIds += "," + nameserviceId;
  nni.initGeneralConf(conf, nameserviceId);
  conf.set(FSConstants.DFS_FEDERATION_NAMESERVICES, nameserviceIds);
  
  nni.updateAvatarConf(conf);
  startAvatarNode(nni, null);

  // Refresh datanodes with the newly started namenode
  for (DataNodeProperties dn : dataNodes) {
    DataNode datanode = dn.datanode;
    datanode.refreshNamenodes(conf);
  }
  // Wait for new namenode to get registrations from all the datanodes
  waitDataNodesActive(nnIndex);
  return nni;
}
 
Example 5
Source File: TestAvatarRefreshNamenodes.java    From RDFS with Apache License 2.0 5 votes vote down vote up
@Test
public void testRefreshNamenodes() throws Exception {
  MiniAvatarCluster cluster = null;
  try {
    cluster = new MiniAvatarCluster(conf, 1, true, null, null, 1, true); 
    DataNode dn = cluster.getDataNodes().get(0);
    assertEquals(dn.getAllNamespaceServices().length, 1);
    
    cluster.addNameNode(conf);
    assertEquals(dn.getAllNamespaceServices().length, 2);
    
    cluster.addNameNode(conf);
    assertEquals(dn.getAllNamespaceServices().length, 3);
    
    cluster.addNameNode(conf);
    assertEquals(dn.getAllNamespaceServices().length, 4);
    int[] nns = null;
    nns = new int[]{0, 1, 2, 3};
    compareAddress(cluster, dn, nns);
    nns = new int[]{0, 1};
    Configuration conf1 = new Configuration(conf);
    setupAddress(conf1, new int[]{0, 1});
    dn.refreshNamenodes(conf1);
    waitDataNodeInitialized(dn);
    compareAddress(cluster, dn, nns);
    
    nns = new int[]{0,2,3};
    Configuration conf2 = new Configuration(conf);
    setupAddress(conf2, new int[]{0,2,3});
    dn.refreshNamenodes(conf2);
    waitDataNodeInitialized(dn);
    compareAddress(cluster, dn, nns);
  } finally {
    cluster.shutDown();
  }
}