Search in sources :

Example 1 with Delete

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);
    }
}
Also used : Delete(org.apache.samza.coordinator.stream.messages.Delete) SetTaskContainerMapping(org.apache.samza.coordinator.stream.messages.SetTaskContainerMapping)

Example 2 with Delete

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());
}
Also used : Delete(org.apache.samza.coordinator.stream.messages.Delete) Test(org.junit.Test)

Example 3 with Delete

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)));
}
Also used : Delete(org.apache.samza.coordinator.stream.messages.Delete) SystemStream(org.apache.samza.system.SystemStream) CoordinatorStreamMessage(org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage) SetConfig(org.apache.samza.coordinator.stream.messages.SetConfig) TypeReference(org.codehaus.jackson.type.TypeReference) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Delete (org.apache.samza.coordinator.stream.messages.Delete)3 Test (org.junit.Test)2 Map (java.util.Map)1 CoordinatorStreamMessage (org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage)1 SetConfig (org.apache.samza.coordinator.stream.messages.SetConfig)1 SetTaskContainerMapping (org.apache.samza.coordinator.stream.messages.SetTaskContainerMapping)1 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)1 SystemStream (org.apache.samza.system.SystemStream)1 TypeReference (org.codehaus.jackson.type.TypeReference)1