use of org.apache.samza.coordinator.stream.messages.Delete in project samza by apache.
the class TaskAssignmentManager method writeTaskContainerMapping.
/**
* Method to write task container info to coordinator stream.
*
* @param taskName the task name
* @param containerId the SamzaContainer ID or {@code null} to delete the mapping
*/
public void writeTaskContainerMapping(String taskName, String containerId) {
String existingContainerId = taskNameToContainerId.get(taskName);
if (existingContainerId != null && !existingContainerId.equals(containerId)) {
log.info("Task \"{}\" moved from container {} to container {}", new Object[] { taskName, existingContainerId, containerId });
} else {
log.debug("Task \"{}\" assigned to container {}", taskName, containerId);
}
if (containerId == null) {
send(new Delete(getSource(), taskName, SetTaskContainerMapping.TYPE));
taskNameToContainerId.remove(taskName);
} else {
send(new SetTaskContainerMapping(getSource(), taskName, String.valueOf(containerId)));
taskNameToContainerId.put(taskName, containerId);
}
}
use of org.apache.samza.coordinator.stream.messages.Delete in project samza by apache.
the class TestCoordinatorStreamMessage method testDelete.
@Test
public void testDelete() {
Delete delete = new Delete("source2", "key", "delete-type");
assertEquals("delete-type", delete.getType());
assertEquals("key", delete.getKey());
assertNull(delete.getMessageMap());
assertTrue(delete.isDelete());
assertEquals(CoordinatorStreamMessage.VERSION, delete.getVersion());
}
use of org.apache.samza.coordinator.stream.messages.Delete in project samza by apache.
the class TestCoordinatorStreamSystemProducer method testCoordinatorStreamSystemProducer.
@Test
public void testCoordinatorStreamSystemProducer() {
String source = "source";
SystemStream systemStream = new SystemStream("system", "stream");
MockCoordinatorSystemProducer systemProducer = new MockCoordinatorSystemProducer(source);
MockSystemAdmin systemAdmin = new MockSystemAdmin();
CoordinatorStreamSystemProducer producer = new CoordinatorStreamSystemProducer(systemStream, systemProducer, systemAdmin);
SetConfig setConfig1 = new SetConfig(source, "job.name", "my-job-name");
SetConfig setConfig2 = new SetConfig(source, "job.id", "1234");
Delete delete = new Delete(source, "job.name", SetConfig.TYPE);
assertFalse(systemProducer.isRegistered());
producer.register(source);
assertTrue(systemProducer.isRegistered());
assertFalse(systemProducer.isStarted());
producer.start();
assertTrue(systemProducer.isStarted());
producer.send(setConfig1);
producer.send(setConfig2);
producer.send(delete);
assertFalse(systemProducer.isStopped());
producer.stop();
assertTrue(systemProducer.isStopped());
List<OutgoingMessageEnvelope> envelopes = systemProducer.getEnvelopes();
OutgoingMessageEnvelope envelope0 = envelopes.get(0);
OutgoingMessageEnvelope envelope1 = envelopes.get(1);
OutgoingMessageEnvelope envelope2 = envelopes.get(2);
TypeReference<Object[]> keyRef = new TypeReference<Object[]>() {
};
TypeReference<Map<String, Object>> msgRef = new TypeReference<Map<String, Object>>() {
};
assertEquals(3, envelopes.size());
assertEquals(new CoordinatorStreamMessage(setConfig1), new CoordinatorStreamMessage(deserialize((byte[]) envelope0.getKey(), keyRef), deserialize((byte[]) envelope0.getMessage(), msgRef)));
assertEquals(new CoordinatorStreamMessage(setConfig2), new CoordinatorStreamMessage(deserialize((byte[]) envelope1.getKey(), keyRef), deserialize((byte[]) envelope1.getMessage(), msgRef)));
assertEquals(new CoordinatorStreamMessage(delete), new CoordinatorStreamMessage(deserialize((byte[]) envelope2.getKey(), keyRef), deserialize((byte[]) envelope2.getMessage(), msgRef)));
}
Aggregations