public static Set<String> fetchMasterAndSlaveAddrByClusterName(final MQAdminExt adminExt, final String clusterName) throws InterruptedException, RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, MQBrokerException { Set<String> brokerAddressSet = new HashSet<String>(); ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName); if (brokerNameSet != null) { for (String brokerName : brokerNameSet) { BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName); if (brokerData != null) { final Collection<String> addrs = brokerData.getBrokerAddrs().values(); brokerAddressSet.addAll(addrs); } } } else { System.out.printf("[error] %s", ERROR_MESSAGE); } return brokerAddressSet; }
public byte[] getAllClusterInfo() { ClusterInfo clusterInfoSerializeWrapper = new ClusterInfo(); clusterInfoSerializeWrapper.setBrokerAddrTable(this.brokerAddrTable); clusterInfoSerializeWrapper.setClusterAddrTable(this.clusterAddrTable); return clusterInfoSerializeWrapper.encode(); }
public boolean cleanUnusedTopicByCluster(ClusterInfo clusterInfo, String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; String[] addrs = clusterInfo.retrieveAllAddrByCluster(cluster); for (String addr : addrs) { result = cleanUnusedTopicByAddr(addr); } return result; }
public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final String addr) throws Exception { ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); HashMap<String/* brokerName */, BrokerData> brokerAddrTable = clusterInfoSerializeWrapper.getBrokerAddrTable(); Iterator<Map.Entry<String, BrokerData>> it = brokerAddrTable.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, BrokerData> entry = it.next(); HashMap<Long, String> brokerAddrs = entry.getValue().getBrokerAddrs(); if (brokerAddrs.containsValue(addr)) { return entry.getKey(); } } throw new Exception(ERROR_MESSAGE); }
public static Set<String> fetchBrokerNameByClusterName(final MQAdminExt adminExt, final String clusterName) throws Exception { ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName); if (brokerNameSet.isEmpty()) { throw new Exception(ERROR_MESSAGE); } return brokerNameSet; }
public ClusterInfo getBrokerClusterInfo( final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { return ClusterInfo.decode(response.getBody(), ClusterInfo.class); } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
@Override public boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; try { ClusterInfo clusterInfo = examineBrokerClusterInfo(); if (null == cluster || "".equals(cluster)) { for (String targetCluster : clusterInfo.retrieveAllClusterNames()) { result = cleanUnusedTopicByCluster(clusterInfo, targetCluster); } } else { result = cleanUnusedTopicByCluster(clusterInfo, cluster); } } catch (MQBrokerException e) { log.error("cleanExpiredConsumerQueue error.", e); } return result; }
public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { ConsumeStats cstats = this.examineConsumeStats(group); ClusterInfo ci = this.examineBrokerClusterInfo(); Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator(); while (it.hasNext()) { Entry<MessageQueue, OffsetWrapper> next = it.next(); MessageQueue mq = next.getKey(); if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) { BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName()); if (brokerData != null) { String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID); if (RemotingUtil.socketAddress2String(msg.getStoreHost()).equals(addr)) { if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) { return true; } } } } } return false; }
private String findTopicBelongToWhichCluster(final String topic, final ClusterInfo clusterInfo, final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException, InterruptedException { TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic); BrokerData brokerData = topicRouteData.getBrokerDatas().get(0); String brokerName = brokerData.getBrokerName(); Iterator<Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator(); while (it.hasNext()) { Entry<String, Set<String>> next = it.next(); if (next.getValue().contains(brokerName)) { return next.getKey(); } } return null; } }
public ClusterInfo getBrokerClusterInfo( final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { return ClusterInfo.decode(response.getBody(), ClusterInfo.class); } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
@Override public boolean cleanExpiredConsumerQueue( String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; try { ClusterInfo clusterInfo = examineBrokerClusterInfo(); if (null == cluster || "".equals(cluster)) { for (String targetCluster : clusterInfo.retrieveAllClusterNames()) { result = cleanExpiredConsumerQueueByCluster(clusterInfo, targetCluster); } } else { result = cleanExpiredConsumerQueueByCluster(clusterInfo, cluster); } } catch (MQBrokerException e) { log.error("cleanExpiredConsumerQueue error.", e); } return result; }
public static Set<String> fetchMasterAddrByClusterName(final MQAdminExt adminExt, final String clusterName) throws InterruptedException, RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, MQBrokerException { Set<String> masterSet = new HashSet<String>(); ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName); if (brokerNameSet != null) { for (String brokerName : brokerNameSet) { BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName); if (brokerData != null) { String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID); if (addr != null) { masterSet.add(addr); } } } } else { System.out.printf("[error] %s", ERROR_MESSAGE); } return masterSet; }
public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final String addr) throws Exception { ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); HashMap<String/* brokerName */, BrokerData> brokerAddrTable = clusterInfoSerializeWrapper.getBrokerAddrTable(); Iterator<Map.Entry<String, BrokerData>> it = brokerAddrTable.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, BrokerData> entry = it.next(); HashMap<Long, String> brokerAddrs = entry.getValue().getBrokerAddrs(); if (brokerAddrs.containsValue(addr)) return entry.getKey(); } throw new Exception( "Make sure the specified broker addr exists or the nameserver which connected is correct."); }
public byte[] getAllClusterInfo() { ClusterInfo clusterInfoSerializeWrapper = new ClusterInfo(); clusterInfoSerializeWrapper.setBrokerAddrTable(this.brokerAddrTable); clusterInfoSerializeWrapper.setClusterAddrTable(this.clusterAddrTable); return clusterInfoSerializeWrapper.encode(); }
@Override public Set<String> getTopicClusterList( final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException { Set<String> clusterSet = new HashSet<String>(); ClusterInfo clusterInfo = examineBrokerClusterInfo(); TopicRouteData topicRouteData = examineTopicRouteInfo(topic); BrokerData brokerData = topicRouteData.getBrokerDatas().get(0); String brokerName = brokerData.getBrokerName(); Iterator<Map.Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Set<String>> next = it.next(); if (next.getValue().contains(brokerName)) { clusterSet.add(next.getKey()); } } return clusterSet; }
public ClusterInfo getBrokerClusterInfo( final String addr, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { return ClusterInfo.decode(response.getBody(), ClusterInfo.class); } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
public boolean cleanExpiredConsumerQueueByCluster(ClusterInfo clusterInfo, String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; String[] addrs = clusterInfo.retrieveAllAddrByCluster(cluster); for (String addr : addrs) { result = cleanExpiredConsumerQueueByAddr(addr); } return result; }
@Override public boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; try { ClusterInfo clusterInfo = examineBrokerClusterInfo(); if (null == cluster || "".equals(cluster)) { for (String targetCluster : clusterInfo.retrieveAllClusterNames()) { result = cleanUnusedTopicByCluster(clusterInfo, targetCluster); } } else { result = cleanUnusedTopicByCluster(clusterInfo, cluster); } } catch (MQBrokerException e) { log.error("cleanExpiredConsumerQueue error.", e); } return result; }
public static Map<String/*master addr*/, List<String>/*slave addr*/> fetchMasterAndSlaveDistinguish( final MQAdminExt adminExt, final String clusterName) throws InterruptedException, RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, MQBrokerException { Map<String, List<String>> masterAndSlaveMap = new HashMap<String, List<String>>(4); ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName); if (brokerNameSet == null) { System.out.printf("[error] %s", ERROR_MESSAGE); return masterAndSlaveMap; } for (String brokerName : brokerNameSet) { BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName); if (brokerData == null || brokerData.getBrokerAddrs() == null) { continue; } String masterAddr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID); masterAndSlaveMap.put(masterAddr, new ArrayList<String>()); for (Long id : brokerData.getBrokerAddrs().keySet()) { if (brokerData.getBrokerAddrs().get(id) == null || id == MixAll.MASTER_ID) { continue; } masterAndSlaveMap.get(masterAddr).add(brokerData.getBrokerAddrs().get(id)); } } return masterAndSlaveMap; }
public static boolean isBrokerExist(String ns, String ip) { ClusterInfo clusterInfo = getCluster(ns); if (clusterInfo == null) { return false; } else { HashMap<String, BrokerData> brokers = clusterInfo.getBrokerAddrTable(); for (String brokerName : brokers.keySet()) { HashMap<Long, String> brokerIps = brokers.get(brokerName).getBrokerAddrs(); for (long brokerId : brokerIps.keySet()) { if (brokerIps.get(brokerId).contains(ip)) return true; } } } return false; }