Search in sources :

Example 31 with KeyValue

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

the class ActivemqConnectorTest method verifyAndSetConfigTest.

@Test
public void verifyAndSetConfigTest() {
    KeyValue keyValue = new DefaultKeyValue();
    for (String requestKey : Config.REQUEST_CONFIG) {
        assertEquals(connector.verifyAndSetConfig(keyValue), "Request config key: " + requestKey);
        keyValue.put(requestKey, requestKey);
    }
    assertEquals(connector.verifyAndSetConfig(keyValue), "");
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) Test(org.junit.Test)

Example 32 with KeyValue

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

the class DivideTaskByQueue method divide.

@Override
public List<KeyValue> divide(Map<String, Set<TaskTopicInfo>> topicRouteMap, TaskDivideConfig tdc) {
    List<KeyValue> config = new ArrayList<KeyValue>();
    int parallelism = tdc.getTaskParallelism();
    Map<Integer, List<TaskTopicInfo>> queueTopicList = new HashMap<Integer, List<TaskTopicInfo>>();
    int id = -1;
    for (String t : topicRouteMap.keySet()) {
        for (TaskTopicInfo taskTopicInfo : topicRouteMap.get(t)) {
            int ind = ++id % parallelism;
            if (!queueTopicList.containsKey(ind)) {
                queueTopicList.put(ind, new ArrayList<TaskTopicInfo>());
            }
            queueTopicList.get(ind).add(taskTopicInfo);
        }
    }
    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(queueTopicList.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) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) HashMap(java.util.HashMap) TaskTopicInfo(org.apache.rocketmq.replicator.config.TaskTopicInfo) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 33 with KeyValue

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

the class RmqSourceReplicatorTest method testGenerateTopic.

@Test
public void testGenerateTopic() throws NoSuchFieldException {
    RmqSourceReplicator rmqSourceReplicator = Mockito.spy(RmqSourceReplicator.class);
    RmqConnectorConfig config = new RmqConnectorConfig();
    KeyValue kv = new DefaultKeyValue();
    kv.put(ConfigDefine.CONN_TOPIC_RENAME_FMT, "${topic}.replica");
    config.validate(kv);
    Field field = RmqSourceReplicator.class.getDeclaredField("replicatorConfig");
    FieldSetter.setField(rmqSourceReplicator, field, config);
    String dstTopic = rmqSourceReplicator.generateTargetTopic("dest");
    assertThat(dstTopic).isEqualTo("dest.replica");
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) Field(java.lang.reflect.Field) RmqConnectorConfig(org.apache.rocketmq.replicator.config.RmqConnectorConfig) KeyValue(io.openmessaging.KeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) Test(org.junit.Test)

Example 34 with KeyValue

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

the class WorkerDirectTask method startSourceTask.

private void startSourceTask() {
    state.compareAndSet(WorkerTaskState.NEW, WorkerTaskState.PENDING);
    sourceTask.initialize(new SourceTaskContext() {

        @Override
        public PositionStorageReader positionStorageReader() {
            return positionStorageReader;
        }

        @Override
        public KeyValue configs() {
            return taskConfig;
        }
    });
    sourceTask.start(taskConfig);
    state.compareAndSet(WorkerTaskState.PENDING, WorkerTaskState.RUNNING);
    log.info("Source task start, config:{}", JSON.toJSONString(taskConfig));
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) KeyValue(io.openmessaging.KeyValue) SourceTaskContext(io.openmessaging.connector.api.source.SourceTaskContext) PositionStorageReader(io.openmessaging.connector.api.PositionStorageReader)

Example 35 with KeyValue

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

the class ConfigManagementServiceImpl method recomputeTaskConfigs.

@Override
public void recomputeTaskConfigs(String connectorName, Connector connector, Long currentTimestamp) {
    ConnectKeyValue connectConfig = connectorKeyValueStore.get(connectorName);
    boolean directEnable = Boolean.parseBoolean(connectConfig.getString(RuntimeConfigDefine.CONNECTOR_DIRECT_ENABLE));
    List<KeyValue> taskConfigs = connector.taskConfigs();
    List<ConnectKeyValue> converterdConfigs = new ArrayList<>();
    for (KeyValue keyValue : taskConfigs) {
        ConnectKeyValue newKeyValue = new ConnectKeyValue();
        for (String key : keyValue.keySet()) {
            newKeyValue.put(key, keyValue.getString(key));
        }
        if (directEnable) {
            newKeyValue.put(RuntimeConfigDefine.TASK_TYPE, Worker.TaskType.DIRECT.name());
            newKeyValue.put(RuntimeConfigDefine.SOURCE_TASK_CLASS, connectConfig.getString(RuntimeConfigDefine.SOURCE_TASK_CLASS));
            newKeyValue.put(RuntimeConfigDefine.SINK_TASK_CLASS, connectConfig.getString(RuntimeConfigDefine.SINK_TASK_CLASS));
        }
        newKeyValue.put(RuntimeConfigDefine.TASK_CLASS, connector.taskClass().getName());
        newKeyValue.put(RuntimeConfigDefine.UPDATE_TIMESTAMP, currentTimestamp);
        converterdConfigs.add(newKeyValue);
    }
    putTaskConfigs(connectorName, converterdConfigs);
    sendSynchronizeConfig();
    triggerListener();
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) KeyValue(io.openmessaging.KeyValue) ArrayList(java.util.ArrayList)

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