Exemple #1
0
  /**
   * Lista os {@link DataNode}s conectados no momento ao ClusterService.
   *
   * @return datanodes
   * @throws KeeperException
   * @throws InterruptedException
   * @throws IOException
   */
  public static List<NodeStatus> getDatanodesConnected() {
    List<NodeStatus> datanodes = new ArrayList<NodeStatus>();
    try {
      List<String> nodesIds = zk.getChildren(ZkConf.DATANODES_PATH, true);
      LOG.info("Cluster com " + nodesIds.size() + " datanode(s) ativo(s) no momento.");

      for (String hostName : nodesIds) {
        String path = ZkConf.DATANODES_PATH + "/" + hostName;
        byte[] bytes = zk.getData(path, true, null);
        NodeStatus node = (NodeStatus) Serializer.toObject(bytes);
        datanodes.add(node);
      }

    } catch (ClassNotFoundException e) {
      LOG.error(e.getMessage(), e);
    } catch (KeeperException e) {
      LOG.error(e.getMessage(), e);
    } catch (InterruptedException e) {
      LOG.error(e.getMessage(), e);
    } catch (IOException e) {
      LOG.error(e.getMessage(), e);
    }

    return datanodes;
  }
Exemple #2
0
  private static List<String> getDatanodesDesconnected()
      throws KeeperException, InterruptedException, IOException, ClassNotFoundException {
    List<String> nodesDesconnected = new ArrayList<String>();
    byte[] bytes = zk.getData(ZkConf.DATANODES_DESCONNECTED, false, null);
    if (bytes != null) {
      nodesDesconnected = (List<String>) Serializer.toObject(bytes);
    }

    return nodesDesconnected;
  }
Exemple #3
0
  private static Map<String, List<String>> getHistoricSendDatanodesDesconnected()
      throws KeeperException, InterruptedException, IOException, ClassNotFoundException {
    Map<String, List<String>> historicSendNodesDesconnected = new HashMap<String, List<String>>();
    byte[] bytes = zk.getData(ZkConf.HISTORIC_SEND, false, null);
    if (bytes != null) {
      historicSendNodesDesconnected = (Map<String, List<String>>) Serializer.toObject(bytes);
    }

    return historicSendNodesDesconnected;
  }
Exemple #4
0
  private static Map<String, List<String>> getManagerDatanodesResponding()
      throws KeeperException, InterruptedException, IOException, ClassNotFoundException {
    Map<String, List<String>> managerDatanodesResponding = new HashMap<String, List<String>>();
    byte[] bytes = zk.getData(ZkConf.MANAGER_NODES_RESPONDING, false, null);
    if (bytes != null) {
      managerDatanodesResponding = ((Map<String, List<String>>) Serializer.toObject(bytes));
    }

    return managerDatanodesResponding;
  }
Exemple #5
0
 private static NodeStatus getDatanodeLeader(String hostNameDesc)
     throws KeeperException, InterruptedException, IOException, ClassNotFoundException {
   String path;
   NodeStatus datanode = null;
   List<String> list = historicSendDatanodesDesconnected.get(hostNameDesc);
   for (String nameLeader : list) {
     path = ZkConf.DATANODES_PATH + "/" + nameLeader;
     if (zk.exists(path, true) != null) {
       byte[] bytes = zk.getData(path, true, null);
       datanode = (NodeStatus) Serializer.toObject(bytes);
       break;
     }
   }
   return datanode;
 }
Exemple #6
0
  public static synchronized void managerNodesChanged(String hostName, NodeStatus nodeLocal) {
    try {

      String path = ZkConf.DATANODES_PATH + "/" + hostName;

      List<String> listSend = getListDatanodesSendReply(hostName);
      if (listSend.contains(HOSTNAME)) {
        zk.exists(path, true);
      }

      if (hostName.equals(HOSTNAME)) {
        managerDatanodesResponding = getManagerDatanodesResponding();

        byte[] bytes = zk.getData(path, true, null);
        List<String> nodesResponding = new ArrayList<String>();
        NodeStatus datanode = (NodeStatus) Serializer.toObject(bytes);

        managerDatanodesResponding.put(datanode.getHostname(), datanode.getNodesResponding());
        nodesResponding = managerDatanodesResponding.get(datanode.getHostname());
        if (nodesResponding.isEmpty()) managerDatanodesResponding.remove(datanode.getHostname());

        nodeLocal.setNodesResponding(datanode.getNodesResponding());
        zk.setData(
            ZkConf.MANAGER_NODES_RESPONDING,
            Serializer.fromObject((Serializable) managerDatanodesResponding),
            -1);
      }

      if (nodeLocal.getNodesResponding().size() > 0) {
        LOG.info("Este datanode esta respondendo pelo(s): " + nodeLocal.getNodesResponding());
      } else {
        LOG.info("Este datanode não está respondendo por nenhum outro.");
      }

      clear();

    } catch (KeeperException e) {
      LOG.error(e.getMessage(), e);
    } catch (InterruptedException e) {
      LOG.error(e.getMessage(), e);
    } catch (IOException e) {
      LOG.error(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
      LOG.error(e.getMessage(), e);
    }
  }
Exemple #7
0
  private static List<NodeStatus> getDatanodesExists(List<String> datanodes) {
    List<NodeStatus> datanodesExits = new ArrayList<NodeStatus>();

    for (String hostName : datanodes) {
      String path = ZkConf.DATANODES_PATH + "/" + hostName;
      try {
        if (zk.exists(path, true) != null) {
          byte[] bytes = zk.getData(path, true, null);
          NodeStatus datanode = (NodeStatus) Serializer.toObject(bytes);
          datanodesExits.add(datanode);
        }
      } catch (KeeperException e) {
        LOG.error(e.getMessage(), e);
      } catch (InterruptedException e) {
        LOG.error(e.getMessage(), e);
      } catch (IOException e) {
        LOG.error(e.getMessage(), e);
      } catch (ClassNotFoundException e) {
        LOG.error(e.getMessage(), e);
      }
    }

    return datanodesExits;
  }