Search in sources :

Example 26 with ConnectKeyValue

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");
    }
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with ConnectKeyValue

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;
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap)

Example 28 with ConnectKeyValue

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

Example 29 with ConnectKeyValue

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;
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap)

Example 30 with ConnectKeyValue

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;
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)

Aggregations

ConnectKeyValue (org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)33 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)13 List (java.util.List)12 Test (org.junit.Test)12 Map (java.util.Map)9 ConnAndTaskConfigs (org.apache.rocketmq.connect.runtime.common.ConnAndTaskConfigs)8 Before (org.junit.Before)4 HashSet (java.util.HashSet)3 WorkerConnector (org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector)3 JSONObject (com.alibaba.fastjson.JSONObject)2 Connector (io.openmessaging.connector.api.Connector)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConnectConfig (org.apache.rocketmq.connect.runtime.config.ConnectConfig)2 DefaultConnectorContext (org.apache.rocketmq.connect.runtime.service.DefaultConnectorContext)2 PluginClassLoader (org.apache.rocketmq.connect.runtime.utils.PluginClassLoader)2 KeyValue (io.openmessaging.KeyValue)1 Task (io.openmessaging.connector.api.Task)1 Converter (io.openmessaging.connector.api.data.Converter)1 SinkTask (io.openmessaging.connector.api.sink.SinkTask)1