Search in sources :

Example 1 with SourceConnectorConfig

use of org.apache.kafka.connect.runtime.SourceConnectorConfig in project kafka by apache.

the class StandaloneHerder method recomputeTaskConfigs.

private List<Map<String, String>> recomputeTaskConfigs(String connName) {
    Map<String, String> config = configState.connectorConfig(connName);
    ConnectorConfig connConfig;
    if (worker.isSinkConnector(connName)) {
        connConfig = new SinkConnectorConfig(config);
        return worker.connectorTaskConfigs(connName, connConfig.getInt(ConnectorConfig.TASKS_MAX_CONFIG), connConfig.getList(SinkConnectorConfig.TOPICS_CONFIG));
    } else {
        connConfig = new SourceConnectorConfig(config);
        return worker.connectorTaskConfigs(connName, connConfig.getInt(ConnectorConfig.TASKS_MAX_CONFIG), null);
    }
}
Also used : SourceConnectorConfig(org.apache.kafka.connect.runtime.SourceConnectorConfig) SinkConnectorConfig(org.apache.kafka.connect.runtime.SinkConnectorConfig) SourceConnectorConfig(org.apache.kafka.connect.runtime.SourceConnectorConfig) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) SinkConnectorConfig(org.apache.kafka.connect.runtime.SinkConnectorConfig)

Example 2 with SourceConnectorConfig

use of org.apache.kafka.connect.runtime.SourceConnectorConfig in project kafka by apache.

the class DistributedHerder method reconfigureConnector.

// Updates configurations for a connector by requesting them from the connector, filling in parameters provided
// by the system, then checks whether any configs have actually changed before submitting the new configs to storage
private void reconfigureConnector(final String connName, final Callback<Void> cb) {
    try {
        if (!worker.isRunning(connName)) {
            log.info("Skipping reconfiguration of connector {} since it is not running", connName);
            return;
        }
        Map<String, String> configs = configState.connectorConfig(connName);
        ConnectorConfig connConfig;
        List<String> sinkTopics = null;
        if (worker.isSinkConnector(connName)) {
            connConfig = new SinkConnectorConfig(configs);
            sinkTopics = connConfig.getList(SinkConnectorConfig.TOPICS_CONFIG);
        } else {
            connConfig = new SourceConnectorConfig(configs);
        }
        final List<Map<String, String>> taskProps = worker.connectorTaskConfigs(connName, connConfig.getInt(ConnectorConfig.TASKS_MAX_CONFIG), sinkTopics);
        boolean changed = false;
        int currentNumTasks = configState.taskCount(connName);
        if (taskProps.size() != currentNumTasks) {
            log.debug("Change in connector task count from {} to {}, writing updated task configurations", currentNumTasks, taskProps.size());
            changed = true;
        } else {
            int index = 0;
            for (Map<String, String> taskConfig : taskProps) {
                if (!taskConfig.equals(configState.taskConfig(new ConnectorTaskId(connName, index)))) {
                    log.debug("Change in task configurations, writing updated task configurations");
                    changed = true;
                    break;
                }
                index++;
            }
        }
        if (changed) {
            if (isLeader()) {
                configBackingStore.putTaskConfigs(connName, taskProps);
                cb.onCompletion(null, null);
            } else {
                // We cannot forward the request on the same thread because this reconfiguration can happen as a result of connector
                // addition or removal. If we blocked waiting for the response from leader, we may be kicked out of the worker group.
                forwardRequestExecutor.submit(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            String reconfigUrl = RestServer.urlJoin(leaderUrl(), "/connectors/" + connName + "/tasks");
                            RestServer.httpRequest(reconfigUrl, "POST", taskProps, null);
                            cb.onCompletion(null, null);
                        } catch (ConnectException e) {
                            log.error("Request to leader to reconfigure connector tasks failed", e);
                            cb.onCompletion(e, null);
                        }
                    }
                });
            }
        }
    } catch (Throwable t) {
        cb.onCompletion(t, null);
    }
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) SourceConnectorConfig(org.apache.kafka.connect.runtime.SourceConnectorConfig) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) SinkConnectorConfig(org.apache.kafka.connect.runtime.SinkConnectorConfig) SinkConnectorConfig(org.apache.kafka.connect.runtime.SinkConnectorConfig) SourceConnectorConfig(org.apache.kafka.connect.runtime.SourceConnectorConfig) Map(java.util.Map) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)2 SinkConnectorConfig (org.apache.kafka.connect.runtime.SinkConnectorConfig)2 SourceConnectorConfig (org.apache.kafka.connect.runtime.SourceConnectorConfig)2 Map (java.util.Map)1 ConnectException (org.apache.kafka.connect.errors.ConnectException)1 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)1