Skip to content
代码片段 群组 项目
未验证 提交 e44d8a72 编辑于 作者: Milan Patel's avatar Milan Patel 提交者: GitHub
浏览文件

BEAM-13939: Restructure Protos to fix namespace conflicts (#16961)

* Updates the Beam model protos to be housed in a namespaced directory structure. This is so that the proto files require usage of a org/apache/beam/model namespace in their imports and so that the generated files also include this namespace in their source file metadata.

* Updates session.proto to use the new namespaced import

* Adds a generic proto generated script that can be used to correctly generate all proto files for the go sdk. This new tool will add any necessary options to the proto compiler and generate the proto files relative to the go sdk root to ensure that the generated files have a namespaced file path in their metadata. If you want to generate a proto file in the go sdk, simply use this script in the go:generate directive, the rest will be taken care of by the script.

* Updates the go sdk to use the new genproto script to correctly generate proto bindings. Updates the README for how to generate the model proto bindings into the SDK

* Regenerates all go sdk proto bindings

* Updates to the python build system. gen_protos.py now supports the new namespaced structure of the Beam model. It does this by supporting arbitrary directory structures of proto files by calculating and replacing the generated imports with relative imports with the generated source. Additionally, it will generate bindings that allow for imports of the form `from apache_beam.portability.api import beam_runner_api_pb2` so that the SDK is not dependent on the potentially changing structure of the generated bindings within `api`. Imports of the form `from apache_beam.portability.api.org.apache.beam.model import beam_runner_api_pb2` are still supported. setup.py now attempts to generate the proto bindings on invocation since the package structure must exist before the wheel can be created.

* Updates to various build, ignore, and linting tooling for python in order to support the new python output structure

* Updates to the python SDK to use the new import structure created by gen_protos
上级 9e4c2886
No related branches found
No related tags found
无相关合并请求
显示
482 个添加480 个删除
...@@ -51,8 +51,7 @@ sdks/python/**/*.egg ...@@ -51,8 +51,7 @@ sdks/python/**/*.egg
sdks/python/LICENSE sdks/python/LICENSE
sdks/python/NOTICE sdks/python/NOTICE
sdks/python/README.md sdks/python/README.md
sdks/python/apache_beam/portability/api/*pb2*.* sdks/python/apache_beam/portability/api/*
sdks/python/apache_beam/portability/api/*.yaml
sdks/python/nosetests*.xml sdks/python/nosetests*.xml
sdks/python/pytest*.xml sdks/python/pytest*.xml
sdks/python/postcommit_requirements.txt sdks/python/postcommit_requirements.txt
......
...@@ -57,7 +57,7 @@ tasks.rat { ...@@ -57,7 +57,7 @@ tasks.rat {
// Default eclipse excludes neglect subprojects // Default eclipse excludes neglect subprojects
// Proto/grpc generated wrappers // Proto/grpc generated wrappers
"**/apache_beam/portability/api/*_pb2*.py", "**/apache_beam/portability/api/**/*_pb2*.py",
"**/go/pkg/beam/**/*.pb.go", "**/go/pkg/beam/**/*.pb.go",
// Ignore go.sum files, which don't permit headers // Ignore go.sum files, which don't permit headers
......
...@@ -38,12 +38,12 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/fnexecutio ...@@ -38,12 +38,12 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/fnexecutio
option java_package = "org.apache.beam.model.fnexecution.v1"; option java_package = "org.apache.beam.model.fnexecution.v1";
option java_outer_classname = "BeamFnApi"; option java_outer_classname = "BeamFnApi";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
import "endpoints.proto"; import "org/apache/beam/model/pipeline/v1/endpoints.proto";
import "org/apache/beam/model/pipeline/v1/metrics.proto";
import "google/protobuf/descriptor.proto"; import "google/protobuf/descriptor.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto"; import "google/protobuf/duration.proto";
import "metrics.proto";
// A descriptor for connecting to a remote port using the Beam Fn Data API. // A descriptor for connecting to a remote port using the Beam Fn Data API.
// Allows for communication between two environments (for example between the // Allows for communication between two environments (for example between the
......
...@@ -29,8 +29,8 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/fnexecutio ...@@ -29,8 +29,8 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/fnexecutio
option java_package = "org.apache.beam.model.fnexecution.v1"; option java_package = "org.apache.beam.model.fnexecution.v1";
option java_outer_classname = "ProvisionApi"; option java_outer_classname = "ProvisionApi";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
import "endpoints.proto"; import "org/apache/beam/model/pipeline/v1/endpoints.proto";
import "google/protobuf/struct.proto"; import "google/protobuf/struct.proto";
// A service to provide runtime provisioning information to the SDK harness // A service to provide runtime provisioning information to the SDK harness
......
...@@ -32,7 +32,7 @@ option go_package = "interactive_v1"; ...@@ -32,7 +32,7 @@ option go_package = "interactive_v1";
option java_package = "org.apache.beam.model.interactive.v1"; option java_package = "org.apache.beam.model.interactive.v1";
option java_outer_classname = "InteractiveApi"; option java_outer_classname = "InteractiveApi";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
// The first record. This contains metadata about the stream and how to // The first record. This contains metadata about the stream and how to
......
...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagem ...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagem
option java_package = "org.apache.beam.model.jobmanagement.v1"; option java_package = "org.apache.beam.model.jobmanagement.v1";
option java_outer_classname = "ArtifactApi"; option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
// A service to retrieve artifacts for use in a Job. // A service to retrieve artifacts for use in a Job.
service ArtifactRetrievalService { service ArtifactRetrievalService {
......
...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagem ...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagem
option java_package = "org.apache.beam.model.expansion.v1"; option java_package = "org.apache.beam.model.expansion.v1";
option java_outer_classname = "ExpansionApi"; option java_outer_classname = "ExpansionApi";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
message ExpansionRequest { message ExpansionRequest {
// Set of components needed to interpret the transform, or which // Set of components needed to interpret the transform, or which
......
...@@ -29,11 +29,11 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagem ...@@ -29,11 +29,11 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagem
option java_package = "org.apache.beam.model.jobmanagement.v1"; option java_package = "org.apache.beam.model.jobmanagement.v1";
option java_outer_classname = "JobApi"; option java_outer_classname = "JobApi";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
import "endpoints.proto"; import "org/apache/beam/model/pipeline/v1/endpoints.proto";
import "org/apache/beam/model/pipeline/v1/metrics.proto";
import "google/protobuf/struct.proto"; import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
import "metrics.proto";
// Job Service for running RunnerAPI pipelines // Job Service for running RunnerAPI pipelines
service JobService { service JobService {
......
...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v ...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v
option java_package = "org.apache.beam.model.pipeline.v1"; option java_package = "org.apache.beam.model.pipeline.v1";
option java_outer_classname = "RunnerApi"; option java_outer_classname = "RunnerApi";
import "endpoints.proto"; import "org/apache/beam/model/pipeline/v1/endpoints.proto";
import "google/protobuf/descriptor.proto"; import "google/protobuf/descriptor.proto";
message BeamConstants { message BeamConstants {
......
...@@ -28,8 +28,8 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v ...@@ -28,8 +28,8 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v
option java_package = "org.apache.beam.model.pipeline.v1"; option java_package = "org.apache.beam.model.pipeline.v1";
option java_outer_classname = "ExternalTransforms"; option java_outer_classname = "ExternalTransforms";
import "schema.proto"; import "org/apache/beam/model/pipeline/v1/schema.proto";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
// A configuration payload for an external transform. // A configuration payload for an external transform.
// Used as the payload of ExternalTransform as part of an ExpansionRequest. // Used as the payload of ExternalTransform as part of an ExpansionRequest.
......
...@@ -29,7 +29,7 @@ option java_package = "org.apache.beam.model.pipeline.v1"; ...@@ -29,7 +29,7 @@ option java_package = "org.apache.beam.model.pipeline.v1";
option java_outer_classname = "MetricsApi"; option java_outer_classname = "MetricsApi";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
import "google/protobuf/descriptor.proto"; import "google/protobuf/descriptor.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
......
...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v ...@@ -29,7 +29,7 @@ option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v
option java_package = "org.apache.beam.model.pipeline.v1"; option java_package = "org.apache.beam.model.pipeline.v1";
option java_outer_classname = "StandardWindowFns"; option java_outer_classname = "StandardWindowFns";
import "beam_runner_api.proto"; import "org/apache/beam/model/pipeline/v1/beam_runner_api.proto";
import "google/protobuf/duration.proto"; import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
......
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
package v1 package v1
//go:generate protoc -I . v1.proto --go_out=../../../../../../../../../../../ //go:generate ../../../../../../scripts/genproto.sh
此差异已折叠。
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
package harness package harness
//go:generate protoc -I. -I../../../../../../../model/fn-execution/src/main/proto -I../../../../../../../model/pipeline/src/main/proto session.proto --go_out=Mbeam_fn_api.proto=github.com/apache/beam/sdks/go/pkg/beam/model/fnexecution_v1:../../../../../../../../../../ //go:generate ../../../../../scripts/genproto.sh
...@@ -26,7 +26,7 @@ package org.apache.beam.sdks.go.pkg.beam.core.runtime.harness.session; ...@@ -26,7 +26,7 @@ package org.apache.beam.sdks.go.pkg.beam.core.runtime.harness.session;
option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/harness/session;session"; option go_package = "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/harness/session;session";
import "beam_fn_api.proto"; import "org/apache/beam/model/fn_execution/v1/beam_fn_api.proto";
message Header { message Header {
string version = 1; // version identifier of the session schema string version = 1; // version identifier of the session schema
......
...@@ -30,19 +30,15 @@ First, follow this one-time setup: ...@@ -30,19 +30,15 @@ First, follow this one-time setup:
1. Download [the protobuf compiler](https://github.com/google/protobuf/releases). 1. Download [the protobuf compiler](https://github.com/google/protobuf/releases).
The simplest approach is to download one of the prebuilt binaries (named The simplest approach is to download one of the prebuilt binaries (named
`protoc`) and extract it somewhere in your machine's `$PATH`. `protoc`) and extract it somewhere in your machine's `$PATH`.
1. Add `$GOBIN` to your `$PATH`. (Note: If `$GOBIN` is not set, add `$GOPATH/bin`
instead.)
To generate the code: To generate the code:
1. Navigate to this directory (`pkg/beam/model`). 1. Navigate to this directory (`pkg/beam/model`).
1. Check [go.mod](https://github.com/apache/beam/blob/master/sdks/go.mod) and 2. Check [go.mod](https://github.com/apache/beam/blob/master/sdks/go.mod) and
make note of which versions of [google.golang.org/protobuf](https://github.com/protocolbuffers/protobuf-go) make note of which versions of [google.golang.org/protobuf](https://github.com/protocolbuffers/protobuf-go)
and [google.golang.org/grpc](https://github.com/grpc/grpc-go) are required. and [google.golang.org/grpc](https://github.com/grpc/grpc-go) are required.
1. Install the compiler executables at the corresponding versions. 3. Verify the versions in ../../../scripts/genproto.sh are correct
1. `go install google.golang.org/protobuf/cmd/protoc-gen-go@<protobuf_version>` 4. `go generate`
1. `go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@<grpc_version>`
1. `go generate`
## Generated Go code fails to build ## Generated Go code fails to build
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册