use of com.google.api.services.dataflow.model.StreamingConfigTask in project beam by apache.
the class StreamingDataflowWorkerTest method testBasic.
@Test
public void testBasic() throws Exception {
List<ParallelInstruction> instructions = Arrays.asList(makeSourceInstruction(StringUtf8Coder.of()), makeSinkInstruction(StringUtf8Coder.of(), 0));
FakeWindmillServer server = new FakeWindmillServer(errorCollector);
server.setIsReady(false);
StreamingConfigTask streamingConfig = new StreamingConfigTask();
streamingConfig.setStreamingComputationConfigs(ImmutableList.of(makeDefaultStreamingComputationConfig(instructions)));
streamingConfig.setWindmillServiceEndpoint("foo");
WorkItem workItem = new WorkItem();
workItem.setStreamingConfigTask(streamingConfig);
when(mockWorkUnitClient.getGlobalStreamingConfigWorkItem()).thenReturn(Optional.of(workItem));
StreamingDataflowWorkerOptions options = createTestingPipelineOptions(server);
StreamingDataflowWorker worker = makeWorker(instructions, options, true);
worker.start();
final int numIters = 2000;
for (int i = 0; i < numIters; ++i) {
server.addWorkToOffer(makeInput(i, TimeUnit.MILLISECONDS.toMicros(i)));
}
Map<Long, Windmill.WorkItemCommitRequest> result = server.waitForAndGetCommits(numIters);
worker.stop();
for (int i = 0; i < numIters; ++i) {
assertTrue(result.containsKey((long) i));
assertEquals(makeExpectedOutput(i, TimeUnit.MILLISECONDS.toMicros(i)).build(), result.get((long) i));
}
verify(hotKeyLogger, atLeastOnce()).logHotKeyDetection(nullable(String.class), any());
}
use of com.google.api.services.dataflow.model.StreamingConfigTask in project beam by apache.
the class StreamingDataflowWorkerTest method testHotKeyLogging.
@Test
public void testHotKeyLogging() throws Exception {
// This is to test that the worker can correctly log the key from a hot key.
List<ParallelInstruction> instructions = Arrays.asList(makeSourceInstruction(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of())), makeSinkInstruction(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of()), 0));
FakeWindmillServer server = new FakeWindmillServer(errorCollector);
server.setIsReady(false);
StreamingConfigTask streamingConfig = new StreamingConfigTask();
streamingConfig.setStreamingComputationConfigs(ImmutableList.of(makeDefaultStreamingComputationConfig(instructions)));
streamingConfig.setWindmillServiceEndpoint("foo");
WorkItem workItem = new WorkItem();
workItem.setStreamingConfigTask(streamingConfig);
when(mockWorkUnitClient.getGlobalStreamingConfigWorkItem()).thenReturn(Optional.of(workItem));
StreamingDataflowWorkerOptions options = createTestingPipelineOptions(server, "--hotKeyLoggingEnabled=true");
StreamingDataflowWorker worker = makeWorker(instructions, options, true);
worker.start();
final int numIters = 2000;
for (int i = 0; i < numIters; ++i) {
server.addWorkToOffer(makeInput(i, TimeUnit.MILLISECONDS.toMicros(i), "key", DEFAULT_SHARDING_KEY));
}
server.waitForAndGetCommits(numIters);
worker.stop();
verify(hotKeyLogger, atLeastOnce()).logHotKeyDetection(nullable(String.class), any(), eq("key"));
}
use of com.google.api.services.dataflow.model.StreamingConfigTask in project beam by apache.
the class StreamingDataflowWorkerTest method testHotKeyLoggingNotEnabled.
@Test
public void testHotKeyLoggingNotEnabled() throws Exception {
// This is to test that the worker can correctly log the key from a hot key.
List<ParallelInstruction> instructions = Arrays.asList(makeSourceInstruction(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of())), makeSinkInstruction(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of()), 0));
FakeWindmillServer server = new FakeWindmillServer(errorCollector);
server.setIsReady(false);
StreamingConfigTask streamingConfig = new StreamingConfigTask();
streamingConfig.setStreamingComputationConfigs(ImmutableList.of(makeDefaultStreamingComputationConfig(instructions)));
streamingConfig.setWindmillServiceEndpoint("foo");
WorkItem workItem = new WorkItem();
workItem.setStreamingConfigTask(streamingConfig);
when(mockWorkUnitClient.getGlobalStreamingConfigWorkItem()).thenReturn(Optional.of(workItem));
StreamingDataflowWorkerOptions options = createTestingPipelineOptions(server);
StreamingDataflowWorker worker = makeWorker(instructions, options, true);
worker.start();
final int numIters = 2000;
for (int i = 0; i < numIters; ++i) {
server.addWorkToOffer(makeInput(i, TimeUnit.MILLISECONDS.toMicros(i), "key", DEFAULT_SHARDING_KEY));
}
server.waitForAndGetCommits(numIters);
worker.stop();
verify(hotKeyLogger, atLeastOnce()).logHotKeyDetection(nullable(String.class), any());
}
use of com.google.api.services.dataflow.model.StreamingConfigTask in project beam by apache.
the class StreamingDataflowWorker method getConfigFromDataflowService.
/**
* Sends a request to get configuration from Dataflow, either for a specific computation (if
* computation is not null) or global configuration (if computation is null).
*
* @throws IOException if the RPC fails.
*/
private void getConfigFromDataflowService(@Nullable String computation) throws IOException {
Optional<WorkItem> workItem;
if (computation != null) {
workItem = workUnitClient.getStreamingConfigWorkItem(computation);
} else {
workItem = workUnitClient.getGlobalStreamingConfigWorkItem();
}
if (workItem == null || !workItem.isPresent() || workItem.get() == null) {
return;
}
StreamingConfigTask config = workItem.get().getStreamingConfigTask();
Preconditions.checkState(config != null);
if (config.getUserStepToStateFamilyNameMap() != null) {
stateNameMap.putAll(config.getUserStepToStateFamilyNameMap());
}
if (computation == null) {
if (config.getMaxWorkItemCommitBytes() != null && config.getMaxWorkItemCommitBytes() > 0 && config.getMaxWorkItemCommitBytes() <= Integer.MAX_VALUE) {
setMaxWorkItemCommitBytes(config.getMaxWorkItemCommitBytes().intValue());
} else {
setMaxWorkItemCommitBytes(180 << 20);
}
}
List<StreamingComputationConfig> configs = config.getStreamingComputationConfigs();
if (configs != null) {
for (StreamingComputationConfig computationConfig : configs) {
MapTask mapTask = new MapTask();
mapTask.setSystemName(computationConfig.getSystemName());
mapTask.setStageName(computationConfig.getStageName());
mapTask.setInstructions(computationConfig.getInstructions());
addComputation(computationConfig.getComputationId(), mapTask, computationConfig.getTransformUserNameToStateFamily());
}
}
if (config.getWindmillServiceEndpoint() != null && !config.getWindmillServiceEndpoint().isEmpty()) {
int port = 443;
if (config.getWindmillServicePort() != null && config.getWindmillServicePort() != 0) {
port = config.getWindmillServicePort().intValue();
}
HashSet<HostAndPort> endpoints = new HashSet<>();
for (String endpoint : Splitter.on(',').split(config.getWindmillServiceEndpoint())) {
endpoints.add(HostAndPort.fromString(endpoint).withDefaultPort(port));
}
windmillServer.setWindmillServiceEndpoints(endpoints);
}
}
Aggregations