Java Code Examples for org.apache.beam.model.pipeline.v1.RunnerApi#MessageWithComponents

The following examples show how to use org.apache.beam.model.pipeline.v1.RunnerApi#MessageWithComponents . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowingStrategyTranslation.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link WindowingStrategy} into a {@link RunnerApi.MessageWithComponents} where
 * {@link RunnerApi.MessageWithComponents#getWindowingStrategy()} ()} is a {@link
 * RunnerApi.WindowingStrategy RunnerApi.WindowingStrategy (proto)} for the input {@link
 * WindowingStrategy}.
 */
public static RunnerApi.MessageWithComponents toMessageProto(
    WindowingStrategy<?, ?> windowingStrategy, SdkComponents components) throws IOException {
  RunnerApi.WindowingStrategy windowingStrategyProto = toProto(windowingStrategy, components);

  return RunnerApi.MessageWithComponents.newBuilder()
      .setWindowingStrategy(windowingStrategyProto)
      .setComponents(components.toComponents())
      .build();
}
 
Example 2
Source File: WindowingStrategyTranslation.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Converts from a {@link RunnerApi.WindowingStrategy} accompanied by {@link Components} to the
 * SDK's {@link WindowingStrategy}.
 */
public static WindowingStrategy<?, ?> fromProto(RunnerApi.MessageWithComponents proto)
    throws InvalidProtocolBufferException {
  switch (proto.getRootCase()) {
    case WINDOWING_STRATEGY:
      return fromProto(
          proto.getWindowingStrategy(),
          RehydratedComponents.forComponents(proto.getComponents()));
    default:
      throw new IllegalArgumentException(
          String.format(
              "Expected a %s with components but received %s",
              RunnerApi.WindowingStrategy.class.getCanonicalName(), proto));
  }
}
 
Example 3
Source File: CoderTranslation.java    From beam with Apache License 2.0 5 votes vote down vote up
public static RunnerApi.MessageWithComponents toProto(Coder<?> coder) throws IOException {
  SdkComponents components = SdkComponents.create();
  RunnerApi.Coder coderProto = toProto(coder, components);
  return RunnerApi.MessageWithComponents.newBuilder()
      .setCoder(coderProto)
      .setComponents(components.toComponents())
      .build();
}
 
Example 4
Source File: GroupAlsoByWindowParDoFnFactory.java    From beam with Apache License 2.0 5 votes vote down vote up
static WindowingStrategy deserializeWindowingStrategy(byte[] encodedWindowingStrategy)
    throws InvalidProtocolBufferException {
  RunnerApi.MessageWithComponents strategyProto =
      RunnerApi.MessageWithComponents.parseFrom(encodedWindowingStrategy);
  checkArgument(
      strategyProto.getRootCase() == RootCase.WINDOWING_STRATEGY,
      "Invalid windowing strategy: %s",
      strategyProto);
  return WindowingStrategyTranslation.fromProto(
      strategyProto.getWindowingStrategy(),
      RehydratedComponents.forComponents(strategyProto.getComponents()));
}
 
Example 5
Source File: CreateExecutableStageNodeFunction.java    From beam with Apache License 2.0 5 votes vote down vote up
private void registerWindowingStrategy(
    String windowingStrategyId,
    WindowingStrategy<?, ?> windowingStrategy,
    RunnerApi.Components.Builder componentsBuilder,
    SdkComponents sdkComponents)
    throws IOException {
  RunnerApi.MessageWithComponents fakeWindowingStrategyProto =
      WindowingStrategyTranslation.toMessageProto(windowingStrategy, sdkComponents);
  componentsBuilder.putWindowingStrategies(
      windowingStrategyId, fakeWindowingStrategyProto.getWindowingStrategy());
  componentsBuilder.putAllCoders(fakeWindowingStrategyProto.getComponents().getCodersMap());
  componentsBuilder.putAllEnvironments(
      fakeWindowingStrategyProto.getComponents().getEnvironmentsMap());
}