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), "");
}
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;
}
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");
}
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));
}
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();
}
Aggregations