Search in sources :

Example 16 with KVTable

use of org.apache.rocketmq.common.protocol.body.KVTable in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method getKVListByNamespace.

public KVTable getKVListByNamespace(final String namespace, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetKVListByNamespaceRequestHeader requestHeader = new GetKVListByNamespaceRequestHeader();
    requestHeader.setNamespace(namespace);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_KVLIST_BY_NAMESPACE, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                return KVTable.decode(response.getBody(), KVTable.class);
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) GetKVListByNamespaceRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVListByNamespaceRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 17 with KVTable

use of org.apache.rocketmq.common.protocol.body.KVTable in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method getBrokerRuntimeInfo.

public KVTable getBrokerRuntimeInfo(final String addr, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_RUNTIME_INFO, null);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                return KVTable.decode(response.getBody(), KVTable.class);
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Example 18 with KVTable

use of org.apache.rocketmq.common.protocol.body.KVTable in project rocketmq by apache.

the class DefaultMQAdminExtTest method testPutKVConfig.

@Test
public void testPutKVConfig() throws RemotingException, MQClientException, InterruptedException {
    String topicConfig = defaultMQAdminExt.getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, "UnitTest");
    assertThat(topicConfig).isEqualTo("topicListConfig");
    KVTable kvs = defaultMQAdminExt.getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG);
    assertThat(kvs.getTable().get("broker-name")).isEqualTo("broker-one");
    assertThat(kvs.getTable().get("cluster-name")).isEqualTo("default-cluster");
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 19 with KVTable

use of org.apache.rocketmq.common.protocol.body.KVTable in project rocketmq by apache.

the class DefaultMQAdminExtTest method testFetchBrokerRuntimeStats.

@Test
public void testFetchBrokerRuntimeStats() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    KVTable brokerStats = defaultMQAdminExt.fetchBrokerRuntimeStats("127.0.0.1:10911");
    assertThat(brokerStats.getTable().get("id")).isEqualTo("1234");
    assertThat(brokerStats.getTable().get("brokerName")).isEqualTo("default-broker");
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) Test(org.junit.Test)

Example 20 with KVTable

use of org.apache.rocketmq.common.protocol.body.KVTable in project rocketmq by apache.

the class BrokerStatusSubCommandTest method init.

@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);
    KVTable kvTable = new KVTable();
    kvTable.setTable(new HashMap<String, String>());
    when(mQClientAPIImpl.getBrokerRuntimeInfo(anyString(), anyLong())).thenReturn(kvTable);
}
Also used : Field(java.lang.reflect.Field) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

KVTable (org.apache.rocketmq.common.protocol.body.KVTable)24 Map (java.util.Map)8 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)8 Set (java.util.Set)6 TreeSet (java.util.TreeSet)6 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)6 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)6 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Field (java.lang.reflect.Field)4 TreeMap (java.util.TreeMap)4 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)4 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)4 RemotingConnectException (org.apache.rocketmq.remoting.exception.RemotingConnectException)4 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)4 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)4 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 BeforeClass (org.junit.BeforeClass)3