Search in sources :

Example 6 with SetConfig

use of org.apache.samza.coordinator.stream.messages.SetConfig 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)

Example 7 with SetConfig

use of org.apache.samza.coordinator.stream.messages.SetConfig in project samza by apache.

the class TestCoordinatorStreamMessage method testSetConfig.

@Test
public void testSetConfig() {
    SetConfig setConfig = new SetConfig("source", "key", "value");
    assertEquals(SetConfig.TYPE, setConfig.getType());
    assertEquals("key", setConfig.getKey());
    assertEquals("value", setConfig.getConfigValue());
    assertFalse(setConfig.isDelete());
    assertEquals(CoordinatorStreamMessage.VERSION, setConfig.getVersion());
}
Also used : SetConfig(org.apache.samza.coordinator.stream.messages.SetConfig) Test(org.junit.Test)

Example 8 with SetConfig

use of org.apache.samza.coordinator.stream.messages.SetConfig in project samza by apache.

the class CoordinatorStreamWriter method sendSetConfigMessage.

/**
   * This method sends message of type "set-config" to the coordinator stream
   *
   * @param key   defines the name of the configuration being set. For example, for setting the number of yarn containers,
   *              the key is "yarn.container.count"
   * @param value defines the value associated with the key. For example, if the key is "yarn.container.count" the value
   *              is the new number of containers.
   */
private void sendSetConfigMessage(String key, String value) {
    log.info("sent SetConfig message with key = " + key + " and value = " + value);
    coordinatorStreamSystemProducer.send(new SetConfig(CoordinatorStreamWriter.SOURCE, key, value));
}
Also used : SetConfig(org.apache.samza.coordinator.stream.messages.SetConfig)

Example 9 with SetConfig

use of org.apache.samza.coordinator.stream.messages.SetConfig in project samza by apache.

the class CoordinatorStreamSystemProducer method writeConfig.

/**
   * Helper method that sends a series of SetConfig messages to the coordinator
   * stream.
   * 
   * @param source
   *          An identifier to denote which source is sending a message. This
   *          can be any arbitrary string.
   * @param config
   *          The config object to store in the coordinator stream.
   */
public void writeConfig(String source, Config config) {
    log.debug("Writing config: {}", config);
    for (Map.Entry<String, String> configPair : config.entrySet()) {
        send(new SetConfig(source, configPair.getKey(), configPair.getValue()));
    }
    systemProducer.flush(source);
}
Also used : SetConfig(org.apache.samza.coordinator.stream.messages.SetConfig) Map(java.util.Map)

Aggregations

SetConfig (org.apache.samza.coordinator.stream.messages.SetConfig)9 Map (java.util.Map)4 CoordinatorStreamMessage (org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage)4 Test (org.junit.Test)4 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)3 IOException (java.io.IOException)2 SamzaException (org.apache.samza.SamzaException)2 SystemStream (org.apache.samza.system.SystemStream)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 Partition (org.apache.samza.Partition)1 Delete (org.apache.samza.coordinator.stream.messages.Delete)1 SetChangelogMapping (org.apache.samza.coordinator.stream.messages.SetChangelogMapping)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)1 SystemConsumer (org.apache.samza.system.SystemConsumer)1