org.apache.rocketmq.common.protocol.body.ClusterInfo Java Examples

The following examples show how to use org.apache.rocketmq.common.protocol.body.ClusterInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterInfoTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private ClusterInfo buildClusterInfo() throws Exception {
    ClusterInfo clusterInfo = new ClusterInfo();
    HashMap<String, BrokerData> brokerAddrTable = new HashMap<String, BrokerData>();
    HashMap<String, Set<String>> clusterAddrTable = new HashMap<String, Set<String>>();

    //build brokerData
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("master");
    brokerData.setCluster("DEFAULT_CLUSTER");

    //build brokerAddrs
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(MixAll.MASTER_ID, MixAll.getLocalhostByNetworkInterface());

    brokerData.setBrokerAddrs(brokerAddrs);
    brokerAddrTable.put("master", brokerData);

    Set<String> brokerNames = new HashSet<String>();
    brokerNames.add("master");

    clusterAddrTable.put("DEFAULT_CLUSTER", brokerNames);

    clusterInfo.setBrokerAddrTable(brokerAddrTable);
    clusterInfo.setClusterAddrTable(clusterAddrTable);
    return clusterInfo;
}
 
Example #2
Source File: TopicListSubCommand.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #4
Source File: CommandUtil.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public static Set<String> fetchMasterAndSlaveAddrByClusterName(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) {
                final Collection<String> addrs = brokerData.getBrokerAddrs().values();
                masterSet.addAll(addrs);
            }
        }
    } else {
        System.out
            .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct.");
    }

    return masterSet;
}
 
Example #5
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: BrokerOuterAPI.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #7
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: TopicListSubCommand.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: TopicListSubCommand.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: CommandUtil.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static Set<String> fetchMasterAndSlaveAddrByClusterName(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) {
                final Collection<String> addrs = brokerData.getBrokerAddrs().values();
                masterSet.addAll(addrs);
            }
        }
    } else {
        System.out
            .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct.");
    }

    return masterSet;
}
 
Example #11
Source File: CommandUtil.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #13
Source File: DefaultMQAdminExtImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: DefaultMQAdminExtImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #15
Source File: DefaultMQAdminExtImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #16
Source File: BrokerOuterAPI.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public Map<String, ClusterInfo> getBrokerClusterInfoOfAllNS() {
    Map<String, ClusterInfo> clusterInfos = new HashMap<>();
    List<String> nameServerAddressList = this.remotingClient.getNameServerAddressList();
    if (nameServerAddressList != null) {
        for (String namesrvAddr : nameServerAddressList) {
            try {
                ClusterInfo clusterInfo = this.getBrokerClusterInfo(namesrvAddr, 100);
                clusterInfos.put(namesrvAddr, clusterInfo);
                log.info("getBrokerClusterInfo OK, NamesrvAddr: {}, ClusterInfo:{}", namesrvAddr, clusterInfo == null ? null : clusterInfo.getBrokerAddrTable());
            } catch (Exception e) {
                log.warn("getBrokerClusterInfo Exception, {}", namesrvAddr, e);
                clusterInfos.put(namesrvAddr, null);//get failed
            }
        }
    }

    return clusterInfos;
}
 
Example #17
Source File: DefaultMQAdminExtImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #18
Source File: MQClientAPIImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #19
Source File: DefaultMQAdminExtImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #20
Source File: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #21
Source File: TopicListSubCommand.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #22
Source File: DefaultMQAdminExtImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #23
Source File: CommandUtil.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #24
Source File: CommandUtil.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #25
Source File: TopicListSubCommand.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #26
Source File: DefaultMQAdminExtTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testExamineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
    HashMap<String, BrokerData> brokerList = clusterInfo.getBrokerAddrTable();
    assertThat(brokerList.get("default-broker").getBrokerName()).isEqualTo("default-broker");
    assertThat(brokerList.containsKey("broker-test")).isTrue();

    HashMap<String, Set<String>> clusterMap = new HashMap<>();
    Set<String> brokers = new HashSet<>();
    brokers.add("default-broker");
    brokers.add("broker-test");
    clusterMap.put("default-cluster", brokers);
    ClusterInfo cInfo = mock(ClusterInfo.class);
    when(cInfo.getClusterAddrTable()).thenReturn(clusterMap);
    HashMap<String, Set<String>> clusterAddress = cInfo.getClusterAddrTable();
    assertThat(clusterAddress.containsKey("default-cluster")).isTrue();
    assertThat(clusterAddress.get("default-cluster").size()).isEqualTo(2);
}
 
Example #27
Source File: MQAdmin.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #28
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #29
Source File: MetricsCollectTask.java    From rocketmq-exporter with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() throws InterruptedException, RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, MQBrokerException {
    log.info("MetricsCollectTask init starting....");
    long start = System.currentTimeMillis();
    ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
    StringBuilder infoOut = new StringBuilder();
    for (String clusterName : clusterInfo.getClusterAddrTable().keySet()) {
        infoOut.append(String.format("cluster name= %s, broker name = %s%n", clusterName, clusterInfo.getClusterAddrTable().get(clusterName)));
        if (clusterName != null && MetricsCollectTask.clusterName == null) {
            MetricsCollectTask.clusterName = clusterName;
        }
    }
    for (String brokerName : clusterInfo.getBrokerAddrTable().keySet()) {
        infoOut.append(String.format("broker name = %s, master broker address= %s%n", brokerName, clusterInfo.getBrokerAddrTable().get(brokerName).getBrokerAddrs().get(MixAll.MASTER_ID)));
    }
    log.info(infoOut.toString());
    if (clusterName == null) {
        log.error("get cluster info error" );
    }
    log.info(String.format("MetricsCollectTask init finished....cost:%d", System.currentTimeMillis() - start));
}
 
Example #30
Source File: MQAdmin.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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;
}