Search in sources :

Example 16 with ConnectorStatus

use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.

the class KafkaStatusBackingStore method readConnectorStatus.

private void readConnectorStatus(String key, byte[] value) {
    String connector = parseConnectorStatusKey(key);
    if (connector == null || connector.isEmpty()) {
        log.warn("Discarding record with invalid connector status key {}", key);
        return;
    }
    if (value == null) {
        log.trace("Removing status for connector {}", connector);
        remove(connector);
        return;
    }
    ConnectorStatus status = parseConnectorStatus(connector, value);
    if (status == null)
        return;
    synchronized (this) {
        log.trace("Received connector {} status update {}", connector, status);
        CacheEntry<ConnectorStatus> entry = getOrAdd(connector);
        entry.put(status);
    }
}
Also used : ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus)

Example 17 with ConnectorStatus

use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.

the class StandaloneHerderTest method testDestroyConnector.

@Test
public void testDestroyConnector() throws Exception {
    connector = PowerMock.createMock(BogusSourceConnector.class);
    expectAdd(SourceSink.SOURCE);
    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    Connector connectorMock = PowerMock.createMock(SourceConnector.class);
    expectConfigValidation(connectorMock, true, config);
    EasyMock.expect(statusBackingStore.getAll(CONNECTOR_NAME)).andReturn(Collections.<TaskStatus>emptyList());
    statusBackingStore.put(new ConnectorStatus(CONNECTOR_NAME, AbstractStatus.State.DESTROYED, WORKER_ID, 0));
    expectDestroy();
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
    FutureCallback<Herder.Created<ConnectorInfo>> futureCb = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, futureCb);
    futureCb.get(1000L, TimeUnit.MILLISECONDS);
    // Second deletion should fail since the connector is gone
    futureCb = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, futureCb);
    try {
        futureCb.get(1000L, TimeUnit.MILLISECONDS);
        fail("Should have thrown NotFoundException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotFoundException);
    }
    PowerMock.verifyAll();
}
Also used : SourceConnector(org.apache.kafka.connect.source.SourceConnector) WorkerConnector(org.apache.kafka.connect.runtime.WorkerConnector) Connector(org.apache.kafka.connect.connector.Connector) SinkConnector(org.apache.kafka.connect.sink.SinkConnector) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with ConnectorStatus

use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.

the class KafkaStatusBackingStoreTest method putSafeWithNoPreviousValueIsPropagated.

@Test
public void putSafeWithNoPreviousValueIsPropagated() {
    final Converter converter = mock(Converter.class);
    final KafkaBasedLog<String, byte[]> kafkaBasedLog = mock(KafkaBasedLog.class);
    final KafkaStatusBackingStore store = new KafkaStatusBackingStore(new MockTime(), converter, STATUS_TOPIC, kafkaBasedLog);
    final byte[] value = new byte[0];
    final Capture<Struct> statusValueStruct = newCapture();
    converter.fromConnectData(eq(STATUS_TOPIC), anyObject(Schema.class), capture(statusValueStruct));
    EasyMock.expectLastCall().andReturn(value);
    kafkaBasedLog.send(eq("status-connector-" + CONNECTOR), eq(value), anyObject(Callback.class));
    expectLastCall();
    replayAll();
    final ConnectorStatus status = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.FAILED, WORKER_ID, 0);
    store.putSafe(status);
    verifyAll();
    assertEquals(status.state().toString(), statusValueStruct.getValue().get(KafkaStatusBackingStore.STATE_KEY_NAME));
    assertEquals(status.workerId(), statusValueStruct.getValue().get(KafkaStatusBackingStore.WORKER_ID_KEY_NAME));
    assertEquals(status.generation(), statusValueStruct.getValue().get(KafkaStatusBackingStore.GENERATION_KEY_NAME));
}
Also used : Callback(org.apache.kafka.clients.producer.Callback) Schema(org.apache.kafka.connect.data.Schema) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) MockTime(org.apache.kafka.common.utils.MockTime) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Example 19 with ConnectorStatus

use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.

the class KafkaStatusBackingStoreTest method readConnectorState.

@Test
public void readConnectorState() {
    byte[] value = new byte[0];
    KafkaBasedLog<String, byte[]> kafkaBasedLog = mock(KafkaBasedLog.class);
    Converter converter = mock(Converter.class);
    KafkaStatusBackingStore store = new KafkaStatusBackingStore(new MockTime(), converter, STATUS_TOPIC, kafkaBasedLog);
    Map<String, Object> statusMap = new HashMap<>();
    statusMap.put("worker_id", WORKER_ID);
    statusMap.put("state", "RUNNING");
    statusMap.put("generation", 0L);
    expect(converter.toConnectData(STATUS_TOPIC, value)).andReturn(new SchemaAndValue(null, statusMap));
    replayAll();
    store.read(consumerRecord(0, "status-connector-conn", value));
    ConnectorStatus status = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.RUNNING, WORKER_ID, 0);
    assertEquals(status, store.get(CONNECTOR));
    verifyAll();
}
Also used : HashMap(java.util.HashMap) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) EasyMock.anyObject(org.easymock.EasyMock.anyObject) MockTime(org.apache.kafka.common.utils.MockTime) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.Test)

Example 20 with ConnectorStatus

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

the class MemoryStatusBackingStoreTest method deleteConnectorStatus.

@Test
public void deleteConnectorStatus() {
    MemoryStatusBackingStore store = new MemoryStatusBackingStore();
    store.put(new ConnectorStatus("connector", ConnectorStatus.State.RUNNING, "localhost:8083", 0));
    store.put(new ConnectorStatus("connector", ConnectorStatus.State.DESTROYED, "localhost:8083", 0));
    assertNull(store.get("connector"));
}
Also used : ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) Test(org.junit.Test)

Aggregations

ConnectorStatus (org.apache.kafka.connect.runtime.ConnectorStatus)27 Test (org.junit.Test)23 Callback (org.apache.kafka.clients.producer.Callback)14 Schema (org.apache.kafka.connect.data.Schema)13 Struct (org.apache.kafka.connect.data.Struct)13 HashMap (java.util.HashMap)12 SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)12 MockTime (org.apache.kafka.common.utils.MockTime)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)5 EasyMock.anyObject (org.easymock.EasyMock.anyObject)4 Map (java.util.Map)3 ConfigException (org.apache.kafka.common.config.ConfigException)3 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)3 ExecutionException (java.util.concurrent.ExecutionException)2 RetriableException (org.apache.kafka.common.errors.RetriableException)2 TimeoutException (org.apache.kafka.common.errors.TimeoutException)2 Connector (org.apache.kafka.connect.connector.Connector)2 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)2 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)2