Search in sources :

Example 1 with StandaloneHerder

use of org.apache.kafka.connect.runtime.standalone.StandaloneHerder in project kafka by apache.

the class ConnectStandalone method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        log.info("Usage: ConnectStandalone worker.properties connector1.properties [connector2.properties ...]");
        Exit.exit(1);
    }
    String workerPropsFile = args[0];
    Map<String, String> workerProps = !workerPropsFile.isEmpty() ? Utils.propsToStringMap(Utils.loadProps(workerPropsFile)) : Collections.<String, String>emptyMap();
    Time time = Time.SYSTEM;
    ConnectorFactory connectorFactory = new ConnectorFactory();
    StandaloneConfig config = new StandaloneConfig(workerProps);
    RestServer rest = new RestServer(config);
    URI advertisedUrl = rest.advertisedUrl();
    String workerId = advertisedUrl.getHost() + ":" + advertisedUrl.getPort();
    Worker worker = new Worker(workerId, time, connectorFactory, config, new FileOffsetBackingStore());
    Herder herder = new StandaloneHerder(worker);
    final Connect connect = new Connect(herder, rest);
    try {
        connect.start();
        for (final String connectorPropsFile : Arrays.copyOfRange(args, 1, args.length)) {
            Map<String, String> connectorProps = Utils.propsToStringMap(Utils.loadProps(connectorPropsFile));
            FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>(new Callback<Herder.Created<ConnectorInfo>>() {

                @Override
                public void onCompletion(Throwable error, Herder.Created<ConnectorInfo> info) {
                    if (error != null)
                        log.error("Failed to create job for {}", connectorPropsFile);
                    else
                        log.info("Created connector {}", info.result().name());
                }
            });
            herder.putConnectorConfig(connectorProps.get(ConnectorConfig.NAME_CONFIG), connectorProps, false, cb);
            cb.get();
        }
    } catch (Throwable t) {
        log.error("Stopping after connector error", t);
        connect.stop();
    }
    // Shutdown will be triggered by Ctrl-C or via HTTP shutdown request
    connect.awaitStop();
}
Also used : ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Connect(org.apache.kafka.connect.runtime.Connect) Time(org.apache.kafka.common.utils.Time) URI(java.net.URI) FileOffsetBackingStore(org.apache.kafka.connect.storage.FileOffsetBackingStore) RestServer(org.apache.kafka.connect.runtime.rest.RestServer) ConnectorFactory(org.apache.kafka.connect.runtime.ConnectorFactory) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) Worker(org.apache.kafka.connect.runtime.Worker) StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) Herder(org.apache.kafka.connect.runtime.Herder) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) FutureCallback(org.apache.kafka.connect.util.FutureCallback)

Example 2 with StandaloneHerder

use of org.apache.kafka.connect.runtime.standalone.StandaloneHerder in project ignite by apache.

the class IgniteSourceConnectorTest method beforeTest.

/** {@inheritDoc} */
@Override
protected void beforeTest() throws Exception {
    kafkaBroker = new TestKafkaBroker();
    WorkerConfig workerCfg = new StandaloneConfig(makeWorkerProps());
    MemoryOffsetBackingStore offBackingStore = new MemoryOffsetBackingStore();
    offBackingStore.configure(workerCfg);
    worker = new Worker(WORKER_ID, new SystemTime(), workerCfg, offBackingStore);
    worker.start();
    herder = new StandaloneHerder(worker);
    herder.start();
}
Also used : StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) Worker(org.apache.kafka.connect.runtime.Worker) TestKafkaBroker(org.apache.ignite.stream.kafka.TestKafkaBroker) StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) MemoryOffsetBackingStore(org.apache.kafka.connect.storage.MemoryOffsetBackingStore) SystemTime(org.apache.kafka.common.utils.SystemTime)

Example 3 with StandaloneHerder

use of org.apache.kafka.connect.runtime.standalone.StandaloneHerder in project ignite by apache.

the class IgniteSinkConnectorTest method beforeTest.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected void beforeTest() throws Exception {
    kafkaBroker = new TestKafkaBroker();
    for (String topic : TOPICS) kafkaBroker.createTopic(topic, PARTITIONS, REPLICATION_FACTOR);
    WorkerConfig workerCfg = new StandaloneConfig(makeWorkerProps());
    OffsetBackingStore offBackingStore = mock(OffsetBackingStore.class);
    offBackingStore.configure(workerCfg);
    worker = new Worker(WORKER_ID, new SystemTime(), workerCfg, offBackingStore);
    worker.start();
    herder = new StandaloneHerder(worker);
    herder.start();
}
Also used : OffsetBackingStore(org.apache.kafka.connect.storage.OffsetBackingStore) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) Worker(org.apache.kafka.connect.runtime.Worker) TestKafkaBroker(org.apache.ignite.stream.kafka.TestKafkaBroker) StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) SystemTime(org.apache.kafka.common.utils.SystemTime)

Aggregations

Worker (org.apache.kafka.connect.runtime.Worker)3 StandaloneConfig (org.apache.kafka.connect.runtime.standalone.StandaloneConfig)3 StandaloneHerder (org.apache.kafka.connect.runtime.standalone.StandaloneHerder)3 TestKafkaBroker (org.apache.ignite.stream.kafka.TestKafkaBroker)2 SystemTime (org.apache.kafka.common.utils.SystemTime)2 WorkerConfig (org.apache.kafka.connect.runtime.WorkerConfig)2 URI (java.net.URI)1 Time (org.apache.kafka.common.utils.Time)1 Connect (org.apache.kafka.connect.runtime.Connect)1 ConnectorFactory (org.apache.kafka.connect.runtime.ConnectorFactory)1 Herder (org.apache.kafka.connect.runtime.Herder)1 RestServer (org.apache.kafka.connect.runtime.rest.RestServer)1 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)1 FileOffsetBackingStore (org.apache.kafka.connect.storage.FileOffsetBackingStore)1 MemoryOffsetBackingStore (org.apache.kafka.connect.storage.MemoryOffsetBackingStore)1 OffsetBackingStore (org.apache.kafka.connect.storage.OffsetBackingStore)1 FutureCallback (org.apache.kafka.connect.util.FutureCallback)1