Search in sources :

Example 21 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class DivideTaskByTopic method divide.

@Override
public List<KeyValue> divide(Map<String, Set<TaskTopicInfo>> topicRouteMap, TaskDivideConfig tdc) {
    List<KeyValue> config = new ArrayList<KeyValue>();
    int parallelism = tdc.getTaskParallelism();
    int id = -1;
    Map<Integer, List<TaskTopicInfo>> taskTopicList = new HashMap<Integer, List<TaskTopicInfo>>();
    for (Map.Entry<String, Set<TaskTopicInfo>> entry : topicRouteMap.entrySet()) {
        int ind = ++id % parallelism;
        if (!taskTopicList.containsKey(ind)) {
            taskTopicList.put(ind, new ArrayList<TaskTopicInfo>());
        }
        taskTopicList.get(ind).addAll(entry.getValue());
    }
    for (int i = 0; i < parallelism; i++) {
        KeyValue keyValue = new DefaultKeyValue();
        keyValue.put(TaskConfigEnum.TASK_STORE_ROCKETMQ.getKey(), tdc.getStoreTopic());
        keyValue.put(TaskConfigEnum.TASK_SOURCE_ROCKETMQ.getKey(), tdc.getSourceNamesrvAddr());
        keyValue.put(TaskConfigEnum.TASK_DATA_TYPE.getKey(), DataType.COMMON_MESSAGE.ordinal());
        keyValue.put(TaskConfigEnum.TASK_TOPIC_INFO.getKey(), JSONObject.toJSONString(taskTopicList.get(i)));
        keyValue.put(TaskConfigEnum.TASK_SOURCE_RECORD_CONVERTER.getKey(), tdc.getSrcRecordConverter());
        keyValue.put(TaskConfigEnum.TASK_SOURCE_ACL_ENABLE.getKey(), String.valueOf(tdc.isSrcAclEnable()));
        keyValue.put(TaskConfigEnum.TASK_SOURCE_ACCESS_KEY.getKey(), tdc.getSrcAccessKey());
        keyValue.put(TaskConfigEnum.TASK_SOURCE_SECRET_KEY.getKey(), tdc.getSrcSecretKey());
        config.add(keyValue);
    }
    return config;
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class ConnectKeyValueTest method testKeyValueOperations.

@Test
public void testKeyValueOperations() {
    KeyValue keyValue = new ConnectKeyValue();
    keyValue.put("StringKey", "StringValue");
    keyValue.put("IntegerKey", 0);
    keyValue.put("LongKey", 1L);
    keyValue.put("DoubleKey", 5.2);
    assertEquals("StringValue", keyValue.getString("StringKey"));
    assertEquals(0, keyValue.getInt("IntegerKey"));
    assertEquals(1L, keyValue.getLong("LongKey"));
    assertEquals(5.2, keyValue.getDouble("DoubleKey"), 0.0);
    assertEquals("StringValue1", keyValue.getString("StringKey1", "StringValue1"));
    assertEquals(2, keyValue.getInt("IntegerKey1", 2));
    assertEquals(2L, keyValue.getLong("LongKey1", 2L));
    assertEquals(5.0, keyValue.getDouble("DoubleKey1", 5.0), 0.0);
    Set<String> keySet = keyValue.keySet();
    Set<String> compareKeySet = new HashSet<>();
    compareKeySet.add("StringKey");
    compareKeySet.add("IntegerKey");
    compareKeySet.add("LongKey");
    compareKeySet.add("DoubleKey");
    assertEquals(keySet, compareKeySet);
    assertTrue(keyValue.containsKey("StringKey"));
    assertTrue(keyValue.containsKey("IntegerKey"));
    assertTrue(keyValue.containsKey("LongKey"));
    assertTrue(keyValue.containsKey("DoubleKey"));
}
Also used : KeyValue(io.openmessaging.KeyValue) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class RedisSourceConnectorTest method testConnector.

@Test
public void testConnector() {
    RedisSourceConnector connector = new RedisSourceConnector();
    connector.verifyAndSetConfig(this.keyValue);
    Class cl = connector.taskClass();
    Assert.assertNotNull(cl);
    List<KeyValue> keyValues = connector.taskConfigs();
    Assert.assertNotNull(keyValues);
    connector.start();
    connector.pause();
    connector.resume();
    connector.stop();
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) RedisSourceConnector(org.apache.rocketmq.connect.redis.connector.RedisSourceConnector) Test(org.junit.Test)

Example 24 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class HudiSinkConnector method taskConfigs.

@Override
public List<KeyValue> taskConfigs() {
    log.info("List.start");
    if (!configValid) {
        return new ArrayList<KeyValue>();
    }
    startMQAdminTools();
    buildRoute();
    DefaultKeyValue defaultKeyValue = new DefaultKeyValue();
    defaultKeyValue.put(HudiConnectConfig.CONN_HUDI_TABLE_PATH, sinkConnectConfig.getTablePath());
    defaultKeyValue.put(HudiConnectConfig.CONN_HUDI_TABLE_NAME, sinkConnectConfig.getTableName());
    defaultKeyValue.put(HudiConnectConfig.CONN_HUDI_INSERT_SHUFFLE_PARALLELISM, sinkConnectConfig.getInsertShuffleParallelism());
    defaultKeyValue.put(HudiConnectConfig.CONN_HUDI_UPSERT_SHUFFLE_PARALLELISM, sinkConnectConfig.getUpsertShuffleParallelism());
    defaultKeyValue.put(HudiConnectConfig.CONN_HUDI_DELETE_PARALLELISM, sinkConnectConfig.getDeleteParallelism());
    defaultKeyValue.put(HudiConnectConfig.CONN_SOURCE_RECORD_CONVERTER, sinkConnectConfig.getSrcRecordConverter());
    defaultKeyValue.put(HudiConnectConfig.CONN_TOPIC_NAMES, sinkConnectConfig.getTopicNames());
    defaultKeyValue.put(HudiConnectConfig.CONN_SCHEMA_PATH, sinkConnectConfig.getSchemaPath());
    defaultKeyValue.put(HudiConnectConfig.CONN_TASK_PARALLELISM, sinkConnectConfig.getTaskParallelism());
    defaultKeyValue.put(HudiConnectConfig.CONN_TASK_DIVIDE_STRATEGY, sinkConnectConfig.getTaskDivideStrategy());
    defaultKeyValue.put(HudiConnectConfig.CONN_WHITE_LIST, JSONObject.toJSONString(sinkConnectConfig.getWhiteList()));
    defaultKeyValue.put(HudiConnectConfig.CONN_SCHEMA_PATH, sinkConnectConfig.getSchemaPath());
    defaultKeyValue.put(HudiConnectConfig.CONN_TOPIC_ROUTE_INFO, JSONObject.toJSONString(sinkConnectConfig.getTopicRouteMap()));
    log.info("taskConfig : " + defaultKeyValue + ", sinkConnectConfig : " + sinkConnectConfig);
    ITaskDivideStrategy strategy = TaskDivideStrategyFactory.getInstance();
    List<KeyValue> taskConfigs = strategy.divide(defaultKeyValue);
    return taskConfigs;
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) ITaskDivideStrategy(org.apache.rocketmq.connect.hudi.strategy.ITaskDivideStrategy) ArrayList(java.util.ArrayList)

Example 25 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class TaskDivideByQueueStrategy method divide.

@Override
public List<KeyValue> divide(KeyValue source) {
    List<KeyValue> config = new ArrayList<KeyValue>();
    int parallelism = source.getInt(HudiConnectConfig.CONN_TASK_PARALLELISM);
    Map<String, MessageQueue> topicRouteInfos = (Map<String, MessageQueue>) JSONObject.parse(source.getString(HudiConnectConfig.CONN_TOPIC_ROUTE_INFO));
    int id = 0;
    List<List<String>> taskTopicQueues = new ArrayList<>(parallelism);
    for (Map.Entry<String, MessageQueue> topicQueue : topicRouteInfos.entrySet()) {
        MessageQueue messageQueue = topicQueue.getValue();
        String topicQueueStr = messageQueue.getTopic() + "," + messageQueue.getBrokerName() + "," + messageQueue.getQueueId();
        int ind = ++id % parallelism;
        if (taskTopicQueues.get(ind) != null) {
            List<String> taskTopicQueue = new LinkedList<>();
            taskTopicQueue.add(topicQueueStr);
            taskTopicQueues.add(ind, taskTopicQueue);
        } else {
            List<String> taskTopicQueue = taskTopicQueues.get(ind);
            taskTopicQueue.add(topicQueueStr);
        }
    }
    for (int i = 0; i < parallelism; i++) {
        // build single task queue config; format is topicName1,brokerName1,queueId1;topicName1,brokerName1,queueId2
        String singleTaskTopicQueueStr = "";
        List<String> singleTaskTopicQueues = taskTopicQueues.get(i);
        for (String singleTopicQueue : singleTaskTopicQueues) {
            singleTaskTopicQueueStr += singleTopicQueue + ";";
        }
        singleTaskTopicQueueStr = singleTaskTopicQueueStr.substring(0, singleTaskTopicQueueStr.length() - 1);
        // fill connect config;
        KeyValue keyValue = new DefaultKeyValue();
        keyValue.put(HudiConnectConfig.CONN_TOPIC_QUEUES, singleTaskTopicQueueStr);
        keyValue.put(HudiConnectConfig.CONN_HUDI_TABLE_PATH, source.getString(HudiConnectConfig.CONN_HUDI_TABLE_PATH));
        keyValue.put(HudiConnectConfig.CONN_HUDI_TABLE_NAME, source.getString(HudiConnectConfig.CONN_HUDI_TABLE_NAME));
        keyValue.put(HudiConnectConfig.CONN_HUDI_INSERT_SHUFFLE_PARALLELISM, source.getInt(HudiConnectConfig.CONN_HUDI_INSERT_SHUFFLE_PARALLELISM));
        keyValue.put(HudiConnectConfig.CONN_HUDI_UPSERT_SHUFFLE_PARALLELISM, source.getInt(HudiConnectConfig.CONN_HUDI_UPSERT_SHUFFLE_PARALLELISM));
        keyValue.put(HudiConnectConfig.CONN_HUDI_DELETE_PARALLELISM, source.getInt(HudiConnectConfig.CONN_HUDI_DELETE_PARALLELISM));
        keyValue.put(HudiConnectConfig.CONN_SOURCE_RECORD_CONVERTER, source.getString(HudiConnectConfig.CONN_SOURCE_RECORD_CONVERTER));
        keyValue.put(HudiConnectConfig.CONN_SCHEMA_PATH, source.getString(HudiConnectConfig.CONN_SCHEMA_PATH));
        keyValue.put(HudiConnectConfig.CONN_TASK_PARALLELISM, source.getInt(HudiConnectConfig.CONN_TASK_PARALLELISM));
        keyValue.put(HudiConnectConfig.CONN_SCHEMA_PATH, source.getString(HudiConnectConfig.CONN_SCHEMA_PATH));
        config.add(keyValue);
    }
    return config;
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

KeyValue (io.openmessaging.KeyValue)39 DefaultKeyValue (io.openmessaging.internal.DefaultKeyValue)29 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)9 Map (java.util.Map)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ConnectKeyValue (org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)5 BytesMessage (io.openmessaging.BytesMessage)4 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)4 PositionStorageReader (io.openmessaging.connector.api.PositionStorageReader)3 SourceTaskContext (io.openmessaging.connector.api.source.SourceTaskContext)3 ByteBuffer (java.nio.ByteBuffer)3 QueueMetaData (io.openmessaging.connector.api.common.QueueMetaData)2 SinkTaskContext (io.openmessaging.connector.api.sink.SinkTaskContext)2 BytesMessageImpl (io.openmessaging.rocketmq.domain.BytesMessageImpl)2 Set (java.util.Set)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)2 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)2