use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.
the class RestHandler method handleCreateConnector.
private void handleCreateConnector(Context context) {
String connectorName = context.pathParam("connectorName");
String arg = context.req.getParameter("config");
if (arg == null) {
context.result("failed! query param 'config' is required ");
return;
}
log.info("config: {}", arg);
Map keyValue = JSON.parseObject(arg, Map.class);
ConnectKeyValue configs = new ConnectKeyValue();
for (Object key : keyValue.keySet()) {
configs.put((String) key, keyValue.get(key).toString());
}
try {
String result = connectController.getConfigManagementService().putConnectorConfig(connectorName, configs);
if (result != null && result.length() > 0) {
context.result(result);
} else {
context.result("success");
}
} catch (Exception e) {
log.error("Handle createConnector error .", e);
context.result("failed");
}
}
use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.
the class ConfigManagementServiceImpl method getConnectorConfigs.
@Override
public Map<String, ConnectKeyValue> getConnectorConfigs() {
Map<String, ConnectKeyValue> result = new HashMap<>();
Map<String, ConnectKeyValue> connectorConfigs = connectorKeyValueStore.getKVMap();
for (String connectorName : connectorConfigs.keySet()) {
ConnectKeyValue config = connectorConfigs.get(connectorName);
if (0 != config.getInt(RuntimeConfigDefine.CONFIG_DELETED)) {
continue;
}
result.put(connectorName, config);
}
return result;
}
use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue 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();
}
use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.
the class ConfigManagementServiceImpl method getConnectorConfigsIncludeDeleted.
@Override
public Map<String, ConnectKeyValue> getConnectorConfigsIncludeDeleted() {
Map<String, ConnectKeyValue> result = new HashMap<>();
Map<String, ConnectKeyValue> connectorConfigs = connectorKeyValueStore.getKVMap();
for (String connectorName : connectorConfigs.keySet()) {
ConnectKeyValue config = connectorConfigs.get(connectorName);
result.put(connectorName, config);
}
return result;
}
use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.
the class ConfigManagementServiceImpl method mergeConfig.
/**
* Merge new received configs with the configs in memory.
*
* @param newConnAndTaskConfig
* @return
*/
private boolean mergeConfig(ConnAndTaskConfigs newConnAndTaskConfig) {
boolean changed = false;
for (String connectorName : newConnAndTaskConfig.getConnectorConfigs().keySet()) {
ConnectKeyValue newConfig = newConnAndTaskConfig.getConnectorConfigs().get(connectorName);
ConnectKeyValue oldConfig = getConnectorConfigsIncludeDeleted().get(connectorName);
if (null == oldConfig) {
changed = true;
connectorKeyValueStore.put(connectorName, newConfig);
taskKeyValueStore.put(connectorName, newConnAndTaskConfig.getTaskConfigs().get(connectorName));
} else {
Long oldUpdateTime = oldConfig.getLong(RuntimeConfigDefine.UPDATE_TIMESTAMP);
Long newUpdateTime = newConfig.getLong(RuntimeConfigDefine.UPDATE_TIMESTAMP);
if (newUpdateTime > oldUpdateTime) {
changed = true;
connectorKeyValueStore.put(connectorName, newConfig);
taskKeyValueStore.put(connectorName, newConnAndTaskConfig.getTaskConfigs().get(connectorName));
}
}
}
return changed;
}
Aggregations