use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.
the class KafkaStatusBackingStoreTest method putSafeConnectorIgnoresStaleStatus.
@Test
public void putSafeConnectorIgnoresStaleStatus() {
byte[] value = new byte[0];
String otherWorkerId = "anotherhost:8083";
KafkaBasedLog<String, byte[]> kafkaBasedLog = mock(KafkaBasedLog.class);
Converter converter = mock(Converter.class);
KafkaStatusBackingStore store = new KafkaStatusBackingStore(new MockTime(), converter, STATUS_TOPIC, kafkaBasedLog);
// the persisted came from a different host and has a newer generation
Map<String, Object> statusMap = new HashMap<>();
statusMap.put("worker_id", otherWorkerId);
statusMap.put("state", "RUNNING");
statusMap.put("generation", 1L);
expect(converter.toConnectData(STATUS_TOPIC, value)).andReturn(new SchemaAndValue(null, statusMap));
// we're verifying that there is no call to KafkaBasedLog.send
replayAll();
store.read(consumerRecord(0, "status-connector-conn", value));
store.putSafe(new ConnectorStatus(CONNECTOR, ConnectorStatus.State.UNASSIGNED, WORKER_ID, 0));
ConnectorStatus status = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.RUNNING, otherWorkerId, 1);
assertEquals(status, store.get(CONNECTOR));
verifyAll();
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.
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"));
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.
the class MemoryStatusBackingStoreTest method putAndGetConnectorStatus.
@Test
public void putAndGetConnectorStatus() {
MemoryStatusBackingStore store = new MemoryStatusBackingStore();
ConnectorStatus status = new ConnectorStatus("connector", ConnectorStatus.State.RUNNING, "localhost:8083", 0);
store.put(status);
assertEquals(status, store.get("connector"));
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project kafka by apache.
the class KafkaStatusBackingStore method parseConnectorStatus.
private ConnectorStatus parseConnectorStatus(String connector, byte[] data) {
try {
SchemaAndValue schemaAndValue = converter.toConnectData(statusTopic, data);
if (!(schemaAndValue.value() instanceof Map)) {
log.error("Invalid connector status type {}", schemaAndValue.value().getClass());
return null;
}
@SuppressWarnings("unchecked") Map<String, Object> statusMap = (Map<String, Object>) schemaAndValue.value();
TaskStatus.State state = TaskStatus.State.valueOf((String) statusMap.get(STATE_KEY_NAME));
String trace = (String) statusMap.get(TRACE_KEY_NAME);
String workerUrl = (String) statusMap.get(WORKER_ID_KEY_NAME);
int generation = ((Long) statusMap.get(GENERATION_KEY_NAME)).intValue();
return new ConnectorStatus(connector, state, trace, workerUrl, generation);
} catch (Exception e) {
log.error("Failed to deserialize connector status", e);
return null;
}
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project kafka by apache.
the class KafkaStatusBackingStoreTest method deleteConnectorState.
@Test
public void deleteConnectorState() {
final byte[] value = new byte[0];
Map<String, Object> statusMap = new HashMap<>();
statusMap.put("worker_id", WORKER_ID);
statusMap.put("state", "RUNNING");
statusMap.put("generation", 0L);
when(converter.fromConnectData(eq(STATUS_TOPIC), any(Schema.class), any(Struct.class))).thenReturn(value);
when(converter.fromConnectData(eq(STATUS_TOPIC), any(Schema.class), any(Struct.class))).thenReturn(value);
when(converter.toConnectData(STATUS_TOPIC, value)).thenReturn(new SchemaAndValue(null, statusMap));
ConnectorStatus connectorStatus = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.RUNNING, WORKER_ID, 0);
store.put(connectorStatus);
TaskStatus taskStatus = new TaskStatus(TASK, TaskStatus.State.RUNNING, WORKER_ID, 0);
store.put(taskStatus);
store.read(consumerRecord(0, "status-task-conn-0", value));
verify(kafkaBasedLog).send(eq("status-connector-" + CONNECTOR), eq(value), any(Callback.class));
verify(kafkaBasedLog).send(eq("status-task-conn-0"), eq(value), any(Callback.class));
assertEquals(new HashSet<>(Collections.singletonList(CONNECTOR)), store.connectors());
assertEquals(new HashSet<>(Collections.singletonList(taskStatus)), new HashSet<>(store.getAll(CONNECTOR)));
store.read(consumerRecord(0, "status-connector-conn", null));
assertTrue(store.connectors().isEmpty());
assertTrue(store.getAll(CONNECTOR).isEmpty());
}
Aggregations