Beispiel #1
0
  public static synchronized void managerDatanodesCreated(String hostName, NodeStatus nodeLocal) {
    try {

      if (nodeLocal.getNodesResponding().contains(hostName)) {
        String path = ZkConf.DATANODES_PATH + "/" + HOSTNAME;
        nodeLocal.getNodesResponding().remove(nodeLocal.getNodesResponding().indexOf(hostName));
        zk.setData(path, Serializer.fromObject(nodeLocal), -1);
      }

      if (HOSTNAME.equals(hostName)) {
        loadDada();

        if (managerDatanodesResponding.containsKey(hostName)) {
          managerDatanodesResponding.remove(hostName);
          zk.setData(
              ZkConf.MANAGER_NODES_RESPONDING,
              Serializer.fromObject((Serializable) managerDatanodesResponding),
              -1);
        }

        if (datanodesDesconnected.contains(hostName)) {
          datanodesDesconnected.remove(hostName);

          if (historicSendDatanodesDesconnected.containsKey(hostName)) {
            historicSendDatanodesDesconnected.remove(hostName);
          }

          zk.setData(
              ZkConf.DATANODES_DESCONNECTED,
              Serializer.fromObject((Serializable) datanodesDesconnected),
              -1);
          zk.setData(
              ZkConf.HISTORIC_SEND,
              Serializer.fromObject((Serializable) historicSendDatanodesDesconnected),
              -1);
        }

        if (datanodesConnected.size() > 1) {
          new SupportReplyText().checkRepliesText(datanodesReplyReceive);
          new SupportReplyImage().checkRepliesImage(datanodesReplyReceive);
        }

        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);
    }
  }
Beispiel #2
0
  private static void loadCache() {
    if (!cacheMapReplyUtil.isEmpty()) {
      cacheMapReplyUtil.clear();
    }
    cacheMapReplyUtil.putAll(mapReplyUtil);

    cacheReplyFrequency = replyFrequency;

    if (!cacheDatanodesReplyReceive.isEmpty()) {
      cacheDatanodesReplyReceive.clear();
    }
    for (NodeStatus node : datanodesReplyReceive) {
      cacheDatanodesReplyReceive.add(node.getHostname());
    }
  }
Beispiel #3
0
  private static List<String> getListDatanodesReceiveReply(String hostName) {
    List<String> nodes = new ArrayList<String>();

    int idNode = getIdDatanode(hostName);
    for (int i = 0; i < cacheReplyFrequency; i++) {
      NodeStatus node = null;
      while (node == null) {
        idNode--;
        if (idNode == 0) idNode = idLastNode;

        if (idNode != getIdDatanode(hostName)) node = cacheMapReplyUtil.get(idNode);

        if (node != null) nodes.add(node.getHostname());
      }
    }
    return nodes;
  }
Beispiel #4
0
  private static synchronized void setUpSendReceiveReply() {
    if (datanodesConnected.isEmpty()) loadRoundRobinPartitionPolicy();

    if (datanodesConnected.size() <= REPLY_FREQUENCY) {
      replyFrequency = (datanodesConnected.size() - 1);
    } else {
      replyFrequency = REPLY_FREQUENCY;
    }

    if (!mapReplyUtil.isEmpty()) mapReplyUtil.clear();

    for (NodeStatus node : datanodesConnected) {
      int id = getIdDatanode(node.getHostname());
      mapReplyUtil.put(id, node);
      if (id > idLastNode) idLastNode = id;

      if (id < idFirstNode) idFirstNode = id;
    }
  }
Beispiel #5
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);
    }
  }
Beispiel #6
0
 private static NodeStatus getDatanodeResponder(List<NodeStatus> datanodes, String hostName) {
   NodeStatus responder = null;
   int aux = 999999999;
   for (NodeStatus node : datanodes) {
     if (!node.getNodesResponding().contains(hostName)) {
       if (node.getNodesResponding().size() < aux) {
         responder = node;
       }
       aux = node.getNodesResponding().size();
     } else {
       if (responder != null) responder.setHostname("");
       break;
     }
   }
   return responder;
 }
Beispiel #7
0
  public static synchronized void managerDatanodesDeleted(
      String hostNameDesc, NodeStatus nodeLocal) {
    try {

      if (cacheDatanodesReplyReceive.contains(hostNameDesc)) {
        String path;
        NodeStatus leader = null;

        loadDada();

        if (!datanodesDesconnected.contains(hostNameDesc)) {
          datanodesDesconnected.add(hostNameDesc);
        }

        List<String> listSend = getListDatanodesSendReply(hostNameDesc);
        if (!historicSendDatanodesDesconnected.containsKey(hostNameDesc)) {
          historicSendDatanodesDesconnected.put(hostNameDesc, listSend);
        }

        leader = getDatanodeLeader(hostNameDesc);
        if (HOSTNAME.equals(leader.getHostname())) {
          zk.setData(
              ZkConf.DATANODES_DESCONNECTED,
              Serializer.fromObject((Serializable) datanodesDesconnected),
              -1);
          zk.setData(
              ZkConf.HISTORIC_SEND,
              Serializer.fromObject((Serializable) historicSendDatanodesDesconnected),
              -1);
        }

        if (!managerDatanodesResponding.containsKey(hostNameDesc)) {
          List<NodeStatus> nodesExists = null;
          NodeStatus nodeResponder = null;

          nodesExists = getDatanodesExists(listSend);
          nodeResponder = getDatanodeResponder(nodesExists, hostNameDesc);

          if (nodeResponder != null) {
            if (nodeResponder.getHostname().equals(HOSTNAME)) {
              path = ZkConf.DATANODES_PATH + "/" + HOSTNAME;
              nodeLocal.getNodesResponding().add(hostNameDesc);
              try {
                zk.setData(path, Serializer.fromObject(nodeLocal), -1);
              } catch (KeeperException e) {
              }
            }
          }

        } else {

          List<NodeStatus> nodesExists = null;
          NodeStatus nodeResponder = null;

          nodesExists = getDatanodesExists(listSend);
          nodeResponder = getDatanodeResponder(nodesExists, hostNameDesc);

          if (nodeResponder != null) {
            if (nodeResponder.getHostname().equals(HOSTNAME)) {
              path = ZkConf.DATANODES_PATH + "/" + HOSTNAME;
              nodeLocal.getNodesResponding().add(hostNameDesc);
              try {
                zk.setData(path, Serializer.fromObject(nodeLocal), -1);
              } catch (KeeperException e) {
              }
            }
          }

          Thread.sleep(2000);
          nodesExists.clear();

          List<String> listNodesResponding = managerDatanodesResponding.get(hostNameDesc);
          List<String> listHistoric = new ArrayList<String>();

          for (String nodeName : listNodesResponding) {
            listHistoric = historicSendDatanodesDesconnected.get(nodeName);

            nodesExists = getDatanodesExists(listHistoric);
            nodeResponder = getDatanodeResponder(nodesExists, nodeName);

            if ((nodeResponder != null) && (!nodeResponder.getHostname().equals(""))) {
              path = ZkConf.DATANODES_PATH + "/" + nodeResponder.getHostname();
              nodeResponder.getNodesResponding().add(nodeName);
              try {
                zk.setData(path, Serializer.fromObject(nodeResponder), -1);
              } catch (KeeperException e) {
              }
            }
          }
        }

        if (managerDatanodesResponding.containsKey(hostNameDesc)) {
          managerDatanodesResponding.remove(hostNameDesc);
        }

        if (HOSTNAME.equals(leader.getHostname())) {
          zk.setData(
              ZkConf.MANAGER_NODES_RESPONDING,
              Serializer.fromObject((Serializable) managerDatanodesResponding),
              -1);
        }
      }

      List<String> datanodesReceive = getListDatanodesReceiveReply(hostNameDesc);
      if (datanodesReceive.contains(HOSTNAME)) {
        if (datanodesConnected.size() > 1) {
          new SupportReplyText().checkRepliesText(datanodesReplyReceive);
          new SupportReplyImage().checkRepliesImage(datanodesReplyReceive);
        }
      }

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