@Override public void onNodeRemoved(OperationsNodeInfo node) { for (int i = 0; i < replicas; i++) { LOG.trace("Removing node {} replica {} from the circle", node.getConnectionInfo(), i); circle.remove(hash(node, i)); } }
@Override public void onNodeAdded(OperationsNodeInfo node) { for (int i = 0; i < replicas; i++) { LOG.trace("Adding node {} replica {} to the circle", node.getConnectionInfo(), i); circle.put(hash(node, i), node); } }
@Override public boolean isMainUserNode(String userId) { OperationsNodeInfo info = resolver.getNode(userId); if (info == null) { return false; } LOG.trace("comparing {} to {} for user {}", id, info.getConnectionInfo(), userId); return id.equals(Neighbors.getServerId(info.getConnectionInfo())); }
private byte[] hash(OperationsNodeInfo node, int replica) { byte[] key = node.getConnectionInfo().getPublicKey().array(); ByteBuffer data = ByteBuffer.wrap(new byte[key.length + SIZE_OF_INT]); data.put(key); data.putInt(replica); return md5.get().digest(data.array()); }
private String constructEndpointAddress(OperationsNodeInfo nodeInfo) { return nodeInfo.getConnectionInfo().getThriftHost() + ":" + String.valueOf(nodeInfo.getConnectionInfo().getThriftPort()); }
private void addOpsServer(OperationsNodeInfo opServer) { LOG.trace("[{}] Building id for {}", zkId, opServer.getConnectionInfo()); String opId = getServerId(serviceType, opServer.getConnectionInfo()); if (!zkId.equals(opId)) { LOG.trace("Adding {} to {}", opId, neigbors); neigbors.putIfAbsent(opId, new NeighborConnection<T, V>(opServer.getConnectionInfo(), maxNumberNeighborConnections, template)); neigbors.get(opId).start(); LOG.info("Operations server {} added/updated to {} Neighbors list. Now {} neighbors", opId, zkId, neigbors.size()); } } }
@Override public void onNodeRemoved(OperationsNodeInfo nodeInfo) { String dnsName = getNameFromConnectionInfo(nodeInfo.getConnectionInfo()); int accessPointId = ServerNameUtil.crc32(nodeInfo.getConnectionInfo()); opsServersMap.remove(accessPointId); LOG.info("Operations server [{}][{}] removed. Updating {} Bootstrap servers", accessPointId, dnsName, bootstrapsMap.size()); for (BootstrapNodeInfo bootstrapNodeInfo : bootstrapsMap.values()) { updateBootstrap(bootstrapNodeInfo); } }
private void addNode(OperationsNodeInfo info) { LOG.info("Add/Update node {}", info); opsMap.put(getNameFromConnectionInfo(info.getConnectionInfo()), info); LOG.info("Cleanup cached responses"); cache.clear(); }
private void removeNode(OperationsNodeInfo info) { if (opsMap.remove(getNameFromConnectionInfo(info.getConnectionInfo())) != null) { LOG.info("Removed node {}", info); } else { LOG.warn("Failed to remove node {}", info); } LOG.info("Cleanup cached responses"); cache.clear(); }
@Override public String toString() { return "OperationsNode {" + "host =" + nodeInfo.getConnectionInfo().getThriftHost() + "port =" + nodeInfo.getConnectionInfo().getThriftPort() + "timeStarted =" + nodeInfo.getTimeStarted() + '}'; } }
@Override public void onNodeRemoved(OperationsNodeInfo nodeInfo) { String opId = getServerId(nodeInfo.getConnectionInfo()); if (!zkId.equals(opId)) { NeighborConnection<T, V> connection = neigbors.remove(opId); if (connection != null) { connection.shutdown(); } LOG.info("Operations server {} removed to {} Neighbors list ({}). Now {} neighbors", opId, neigbors.size()); } } });
@Override public void onNodeAdded(OperationsNodeInfo nodeInfo) { String dnsName = getNameFromConnectionInfo(nodeInfo.getConnectionInfo()); int accessPointId = ServerNameUtil.crc32(nodeInfo.getConnectionInfo()); addNewOperationsServer(accessPointId, dnsName, nodeInfo); LOG.info("Operations server [{}][{}] added. Updating {} Bootstrap servers", accessPointId, dnsName, bootstrapsMap.size()); for (BootstrapNodeInfo bootstrapNodeInfo : bootstrapsMap.values()) { updateBootstrap(bootstrapNodeInfo); } }
@Override public String getUserNode(String userId) { OperationsNodeInfo info = resolver.getNode(userId); if (info != null) { return Neighbors.getServerId(info.getConnectionInfo()); } return null; }
@Override public void onNodeUpdated(OperationsNodeInfo nodeInfo) { String dnsName = getNameFromConnectionInfo(nodeInfo.getConnectionInfo()); int accessPointId = ServerNameUtil.crc32(nodeInfo.getConnectionInfo()); LOG.info("Operations server [{}][{}] updated", accessPointId, dnsName); if (opsServersMap.containsKey(accessPointId)) { opsServersMap.get(accessPointId).history.addOpsServerLoad(nodeInfo.getLoadInfo()); } else { addNewOperationsServer(accessPointId, dnsName, nodeInfo); } }
@Override public boolean isMainEntityNode(byte[] entityId) { String entityIdStr = Base64Util.encode(entityId); OperationsNodeInfo info = resolver.getNode(entityIdStr); if (info == null) { return false; } String nodeId = Neighbors.getServerId(info.getConnectionInfo()); LOG.trace("Comparing {} to {} for entity {}", id, nodeId, entityIdStr); return id.equals(nodeId); }
private static String toString(OperationsNodeInfo node) { return "[" + node.getConnectionInfo().getThriftHost() + ":" + node.getConnectionInfo().getThriftPort() + ":" + node.getTimeStarted() + "]-[" + node.getLoadInfo() + "]"; }
@Override public void setZkNode(OperationsNode operationsNode) { this.operationsNode = operationsNode; this.id = Neighbors.getServerId(this.operationsNode.getNodeInfo().getConnectionInfo()); neighbors.setZkNode( KaaThriftService.OPERATIONS_SERVICE, this.operationsNode.getNodeInfo().getConnectionInfo(), operationsNode); if (resolver != null) { updateResolver(this.resolver); } }
@Override public void setZkNode(OperationsNode operationsNode) { this.operationsNode = operationsNode; this.id = Neighbors.getServerId( KaaThriftService.OPERATIONS_SERVICE, this.operationsNode.getNodeInfo().getConnectionInfo()); neighbors.setZkNode( KaaThriftService.OPERATIONS_SERVICE, this.operationsNode.getNodeInfo().getConnectionInfo(), operationsNode); if (resolver != null) { updateResolver(this.resolver); } }
@Override public String getEntityNode(byte[] entityId) { OperationsNodeInfo info = resolver.getNode(Base64Util.encode(entityId)); if (info != null) { return Neighbors.getServerId(info.getConnectionInfo()); } return null; }
@Override public void sendEndpointRouteInfo(GlobalRouteInfo routeInfo) { LOG.trace("calculating server for user {}", routeInfo.getUserId()); String serverId = Neighbors.getServerId( resolver.getNode(routeInfo.getUserId()).getConnectionInfo()); sendMessagesToServer(packMessage(routeInfo), serverId); }