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)));
}
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());
}
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));
}
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);
}
Aggregations