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); } }
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); } }
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); } }