You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by GitBox <gi...@apache.org> on 2020/03/24 01:30:57 UTC
[GitHub] [beam] robertwb opened a new pull request #11203: [BEAM-9577]
Define and implement dependency-aware artifact staging service.
robertwb opened a new pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203
This is not yet used anywhere (and even the legacy service is not yet used in Dataflow) but it is good to define what we want this service to look like.
R: @lukecwik
CC: @ihji
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
- [ ] Format the pull request title like `[BEAM-XXX] Fixes bug in ApproximateQuantiles`, where you replace `BEAM-XXX` with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/#make-reviewers-job-easier).
Post-Commit Tests Status (on master branch)
------------------------------------------------------------------------------------------------
Lang | SDK | Apex | Dataflow | Flink | Gearpump | Samza | Spark
--- | --- | --- | --- | --- | --- | --- | ---
Go | [](https://builds.apache.org/job/beam_PostCommit_Go/lastCompletedBuild/) | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_Go_VR_Flink/lastCompletedBuild/) | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_Go_VR_Spark/lastCompletedBuild/)
Java | [](https://builds.apache.org/job/beam_PostCommit_Java/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Apex/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow_Java11/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_PVR_Flink_Batch/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_PVR_Flink_Streaming/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Gearpump/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Samza/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Spark/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_PVR_Spark_Batch/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_SparkStructuredStreaming/lastCompletedBuild/)
Python | [](https://builds.apache.org/job/beam_PostCommit_Python2/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python35/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python36/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python37/lastCompletedBuild/) | --- | [](https://builds.apache.org/job/beam_PostCommit_Py_VR_Dataflow/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Py_VR_Dataflow_V2/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Py_ValCont/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Python2_PVR_Flink_Cron/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python35_VR_Flink/lastCompletedBuild/) | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_Python_VR_Spark/lastCompletedBuild/)
XLang | --- | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_XVR_Flink/lastCompletedBuild/) | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_XVR_Spark/lastCompletedBuild/)
Pre-Commit Tests Status (on master branch)
------------------------------------------------------------------------------------------------
--- |Java | Python | Go | Website
--- | --- | --- | --- | ---
Non-portable | [](https://builds.apache.org/job/beam_PreCommit_Java_Cron/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Python_Cron/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PreCommit_PythonLint_Cron/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Go_Cron/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Website_Cron/lastCompletedBuild/)
Portable | --- | [](https://builds.apache.org/job/beam_PreCommit_Portable_Python_Cron/lastCompletedBuild/) | --- | ---
See [.test-infra/jenkins/README](https://github.com/apache/beam/blob/master/.test-infra/jenkins/README.md) for trigger phrase, status and link of all Jenkins jobs.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400467966
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
Review comment:
It is important to point out that the artifact information / ordering is important in both the request and the response since in Java this would represent the classpath. So artifacts should be passed in the expected order of usage and returned in an expected order of usage.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606101284
Run JavaPortabilityApi PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399501260
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
Review comment:
I can see that your trying to set this up so that the staging service can make calls to the SDK so that this way it can get artifacts that are created by the expansion service.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400478381
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
+ def ResolveArtifacts(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(
+ resolve_artifact=request))
+ return next(responses).resolve_artifact_response
+
+ def GetArtifact(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(get_artifact=request))
+ while True:
+ response = next(responses)
+ yield response.get_artifact_response
+ if response.is_last:
+ break
+
+ def resolve():
+ file_deps = resolve_as_files(
+ FakeRetrievalService(),
+ lambda name: self._file_writer(os.path.join(staging_token, name)),
+ dependencies)
+ dependencies[:] = file_deps
+ requests.put(None)
+ event.set()
+
+ t = threading.Thread(target=resolve)
+ t.daemon = True
+ t.start()
+
+ return _queue_iter(requests, None)
+
+
+def resolve_as_files(retrieval_service, file_writer, dependencies):
+ """Translates a set of dependencies into file-based dependencies."""
+ # Resolve until nothing changes. This ensures that they can be fetched.
+ resolution = retrieval_service.ResolveArtifacts(
+ beam_artifact_api_pb2.ResolveArtifactRequest(
+ artifacts=dependencies,
+ # Anything fetchable will do.
+ # TODO(robertwb): Take advantage of shared filesystems, urls.
+ preferred_urns=[],
Review comment:
preferred_urns = FILE
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400585676
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
+ def ResolveArtifacts(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(
+ resolve_artifact=request))
+ return next(responses).resolve_artifact_response
+
+ def GetArtifact(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(get_artifact=request))
+ while True:
+ response = next(responses)
+ yield response.get_artifact_response
+ if response.is_last:
+ break
+
+ def resolve():
+ file_deps = resolve_as_files(
+ FakeRetrievalService(),
+ lambda name: self._file_writer(os.path.join(staging_token, name)),
+ dependencies)
+ dependencies[:] = file_deps
+ requests.put(None)
+ event.set()
+
+ t = threading.Thread(target=resolve)
+ t.daemon = True
+ t.start()
+
+ return _queue_iter(requests, None)
+
+
+def resolve_as_files(retrieval_service, file_writer, dependencies):
+ """Translates a set of dependencies into file-based dependencies."""
+ # Resolve until nothing changes. This ensures that they can be fetched.
+ resolution = retrieval_service.ResolveArtifacts(
+ beam_artifact_api_pb2.ResolveArtifactRequest(
+ artifacts=dependencies,
+ # Anything fetchable will do.
+ # TODO(robertwb): Take advantage of shared filesystems, urls.
+ preferred_urns=[],
+ ))
+ if resolution.error:
+ raise RuntimeError(resolution)
+ dependencies = resolution.replacements
+
+ # Fetch each of the dependencies, using file_writer to store them as
+ # file-based artifacts.
+ # TODO(robertwb): Consider parallelizing the actual writes.
+ for dep in dependencies:
+ if dep.role_urn == common_urns.artifact_roles.STAGING_TO.urn:
+ base_name = os.path.basename(
+ proto_utils.parse_Bytes(
+ dep.role_payload,
+ beam_runner_api_pb2.ArtifactStagingToRolePayload).staged_name)
+ else:
+ base_name = None
+ unique_name = '-'.join(
+ filter(
+ None,
+ [hashlib.sha256(dep.SerializeToString()).hexdigest(), base_name]))
Review comment:
The full file path will already be prefixed by the staging token (line ~413 where this is called). This does make me wonder whether every artifact should have a name (even non-file based ones). Especially if roles become more specific (like classpath or pip package rather than just stage_to).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400470967
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
+}
+
+// A response for artifact resolution.
+message ResolveArtifactResponse {
+ // A full set of replacements for the set of requested artifacts, preferably
+ // in terms of the requested type URNs. If there is no better resolution,
+ // the original list is returned.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation replacements = 1;
+
+ // (Optional) If set, used to indicate the artifacts are mutually inconsistent
+ // (e.g. due to a diamond dependency problem) or could otherwise not be
+ // resolved (e.g. due to invalid specifications).
+ string error = 2;
+}
+
+// A request to get an artifact.
+message GetArtifactRequest {
+ org.apache.beam.model.pipeline.v1.ArtifactInformation artifact = 1;
Review comment:
Should we have a resume_offset field?
Whenever we need to stage a large amount of data, it seems as though the SDK would reconnect so a "retry" would be possible and should be able to pass in a point to resume from for a large stream.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399466963
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
Review comment:
```suggestion
//
// A client calls the service with an ArtifactResponseWrapper that has the
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400583972
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
+ def ResolveArtifacts(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(
+ resolve_artifact=request))
+ return next(responses).resolve_artifact_response
Review comment:
Good call. Done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400583853
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
Review comment:
Done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399580804
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
Review comment:
Yes, updated the documentation.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400603582
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
+ def ResolveArtifacts(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(
+ resolve_artifact=request))
+ return next(responses).resolve_artifact_response
+
+ def GetArtifact(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(get_artifact=request))
+ while True:
+ response = next(responses)
+ yield response.get_artifact_response
+ if response.is_last:
+ break
+
+ def resolve():
+ file_deps = resolve_as_files(
+ FakeRetrievalService(),
+ lambda name: self._file_writer(os.path.join(staging_token, name)),
+ dependencies)
+ dependencies[:] = file_deps
+ requests.put(None)
+ event.set()
+
+ t = threading.Thread(target=resolve)
+ t.daemon = True
+ t.start()
+
+ return _queue_iter(requests, None)
+
+
+def resolve_as_files(retrieval_service, file_writer, dependencies):
+ """Translates a set of dependencies into file-based dependencies."""
+ # Resolve until nothing changes. This ensures that they can be fetched.
+ resolution = retrieval_service.ResolveArtifacts(
+ beam_artifact_api_pb2.ResolveArtifactRequest(
+ artifacts=dependencies,
+ # Anything fetchable will do.
+ # TODO(robertwb): Take advantage of shared filesystems, urls.
+ preferred_urns=[],
+ ))
+ if resolution.error:
+ raise RuntimeError(resolution)
+ dependencies = resolution.replacements
+
+ # Fetch each of the dependencies, using file_writer to store them as
+ # file-based artifacts.
+ # TODO(robertwb): Consider parallelizing the actual writes.
+ for dep in dependencies:
+ if dep.role_urn == common_urns.artifact_roles.STAGING_TO.urn:
+ base_name = os.path.basename(
+ proto_utils.parse_Bytes(
+ dep.role_payload,
+ beam_runner_api_pb2.ArtifactStagingToRolePayload).staged_name)
+ else:
+ base_name = None
+ unique_name = '-'.join(
+ filter(
+ None,
+ [hashlib.sha256(dep.SerializeToString()).hexdigest(), base_name]))
Review comment:
Its typically pretty easy to figure out the name of a path component so no need.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399467517
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+}
+
+// A response for artifact resolution.
+message ResolveArtifactResponse {
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation replacements = 1;
+}
+
+// A request to get an artifact.
+message GetArtifactRequest {
+ org.apache.beam.model.pipeline.v1.ArtifactInformation artifact = 2;
Review comment:
```suggestion
org.apache.beam.model.pipeline.v1.ArtifactInformation artifact = 1;
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400490551
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
+ def ResolveArtifacts(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(
+ resolve_artifact=request))
+ return next(responses).resolve_artifact_response
Review comment:
It doesn't look like we are passing any of the failures through the queue meaning the daemon thread below will get stuck forever, it would be great if we could pass through the status/error we got from the call we forwarded and stop.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400604546
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -284,12 +284,38 @@ def _open(self, path, mode='r'):
# The dependency-aware artifact staging and retrieval services.
-def _queue_iter(queue, end_token):
- while True:
- item = queue.get()
- if item is end_token:
- break
- yield item
+class _QueueIter(object):
+
+ _END = object()
+
+ def __init__(self):
+ self._queue = queue.Queue()
+
+ def put(self, item):
+ self._queue.put(item)
+
+ def done(self):
+ self._queue.put(self._END)
+ self._queue.put(StopIteration)
+
+ def abort(self, exn=None):
+ if exn is None:
+ exn = sys.exc_info()[1]
+ self._queue.put(self._END)
+ self._queue.put(exn)
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ item = self._queue.get()
Review comment:
so clever
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399469457
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
Review comment:
Some documentation questions:
Is this meant to completely replace the artifacts supplied in replacements?
What if a user doesn't pass in all the original artifacts?
If something can't be "resolved" to something simpler, does it still appear in the output?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606845984
Run JavaPortabilityApi PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb merged pull request #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb merged pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400467076
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
Review comment:
Is this an ordered list, things that appear first are *more* preferred then things that appear later?
If so, we should make that clear.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400572321
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
Review comment:
Yes, done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399582853
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
Review comment:
The documentation has been expanded.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-604678086
Run JavaPortabilityApi PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-604160723
CC: @ihji
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400584277
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
+ def ResolveArtifacts(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(
+ resolve_artifact=request))
+ return next(responses).resolve_artifact_response
+
+ def GetArtifact(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(get_artifact=request))
+ while True:
+ response = next(responses)
+ yield response.get_artifact_response
+ if response.is_last:
+ break
+
+ def resolve():
+ file_deps = resolve_as_files(
+ FakeRetrievalService(),
+ lambda name: self._file_writer(os.path.join(staging_token, name)),
+ dependencies)
+ dependencies[:] = file_deps
+ requests.put(None)
+ event.set()
+
+ t = threading.Thread(target=resolve)
+ t.daemon = True
+ t.start()
+
+ return _queue_iter(requests, None)
+
+
+def resolve_as_files(retrieval_service, file_writer, dependencies):
+ """Translates a set of dependencies into file-based dependencies."""
+ # Resolve until nothing changes. This ensures that they can be fetched.
+ resolution = retrieval_service.ResolveArtifacts(
+ beam_artifact_api_pb2.ResolveArtifactRequest(
+ artifacts=dependencies,
+ # Anything fetchable will do.
+ # TODO(robertwb): Take advantage of shared filesystems, urls.
+ preferred_urns=[],
Review comment:
There is no preference here, it always fetches them.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399581813
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
Review comment:
Good question. As discussed offline, multiple requests can be pushed before waiting for a response, so we should be able to fill the network buffer. Either the server or client can choose to parallelize on its backend store as needed.
I added an error field to the resolve_artifacts field as a runner may attempt to opportunistically consolidate environments, and then fall back to doing each separately.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-605204144
Run PythonDocker PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-605204087
Run JavaPortabilityApi PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-604679288
FYI, this may be easier to review filtering commits. The main changes are in the second (proto) and third (Python) commits. The first is an automatic rename with sed, and the last is a required go proto regeneration.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399501830
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
Review comment:
What does simpler mean?, should the request contain a supported set of urns for types and roles?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-604267552
Run JavaPortabilityApi PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400566768
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
Review comment:
Done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606217331
Run JavaPortabilityApi PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400566563
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
Review comment:
Resolution may expand a dependency into multiple distinct blobs. Also, it may be possible (likely?) that artifacts can be resolved into form the client can recognize (or at least deduplicate) obviating the need for a fetch.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400606909
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
Review comment:
We don't have to answer this question as part of this PR as it involves a much smaller subset so if you address the other parts then LGTM.
Imagine we added the **deferred** artifact, would resolving be allowed to return the **deferred** artifact again?
What would **Get** do for a **deferred** artifact?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606217265
Run Portable_Python PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-604678032
Run Python PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-604267447
Run Python PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400480966
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
+ def ResolveArtifacts(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(
+ resolve_artifact=request))
+ return next(responses).resolve_artifact_response
+
+ def GetArtifact(self, request):
+ requests.put(
+ beam_artifact_api_pb2.ArtifactRequestWrapper(get_artifact=request))
+ while True:
+ response = next(responses)
+ yield response.get_artifact_response
+ if response.is_last:
+ break
+
+ def resolve():
+ file_deps = resolve_as_files(
+ FakeRetrievalService(),
+ lambda name: self._file_writer(os.path.join(staging_token, name)),
+ dependencies)
+ dependencies[:] = file_deps
+ requests.put(None)
+ event.set()
+
+ t = threading.Thread(target=resolve)
+ t.daemon = True
+ t.start()
+
+ return _queue_iter(requests, None)
+
+
+def resolve_as_files(retrieval_service, file_writer, dependencies):
+ """Translates a set of dependencies into file-based dependencies."""
+ # Resolve until nothing changes. This ensures that they can be fetched.
+ resolution = retrieval_service.ResolveArtifacts(
+ beam_artifact_api_pb2.ResolveArtifactRequest(
+ artifacts=dependencies,
+ # Anything fetchable will do.
+ # TODO(robertwb): Take advantage of shared filesystems, urls.
+ preferred_urns=[],
+ ))
+ if resolution.error:
+ raise RuntimeError(resolution)
+ dependencies = resolution.replacements
+
+ # Fetch each of the dependencies, using file_writer to store them as
+ # file-based artifacts.
+ # TODO(robertwb): Consider parallelizing the actual writes.
+ for dep in dependencies:
+ if dep.role_urn == common_urns.artifact_roles.STAGING_TO.urn:
+ base_name = os.path.basename(
+ proto_utils.parse_Bytes(
+ dep.role_payload,
+ beam_runner_api_pb2.ArtifactStagingToRolePayload).staged_name)
+ else:
+ base_name = None
+ unique_name = '-'.join(
+ filter(
+ None,
+ [hashlib.sha256(dep.SerializeToString()).hexdigest(), base_name]))
Review comment:
Any reason to not use the staging token to prevent collisions instead of relying on the sha256 of a proto which may not be unique (note that nobody populates the sha256 for the File type, I mentioned this on #11205)?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606845864
Run Java PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400476127
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
+
+ def resolved_deps(self, staging_token, timeout=None):
+ dependencies_list, event = self._jobs_to_stage[staging_token]
+ try:
+ if not event.wait(timeout):
+ raise concurrent.futures.TimeoutError()
+ return dependencies_list
+ finally:
+ del self._jobs_to_stage[staging_token]
+
+ def ReverseArtifactRetrievalService(self, responses, context=None):
+ staging_token = next(responses).staging_token
+ dependencies, event = self._jobs_to_stage[staging_token]
+
+ requests = queue.Queue()
+
+ class FakeRetrievalService(object):
Review comment:
nit: FakeRetrievalService -> ForwardingRetrievalService
or ProxyingRetrievalService
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399475366
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
Review comment:
Why do you not want the resolving to happen as part of GetArtifact?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-604267505
Run Java PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400489288
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
Review comment:
Its probably best to raise an error if the staging token is already in the dict.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400604009
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -67,15 +70,10 @@ message ResolveArtifactRequest {
// A response for artifact resolution.
message ResolveArtifactResponse {
- // A full set of replacements for the set of requested artifacts, preferably
- // in terms of the requested type URNs. If there is no better resolution,
- // the original list is returned.
+ // A full (ordered) set of replacements for the set of requested artifacts,
Review comment:
```suggestion
// A fully (ordered) set of replacements for the set of requested artifacts,
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400571617
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
+}
+
+// A response for artifact resolution.
+message ResolveArtifactResponse {
+ // A full set of replacements for the set of requested artifacts, preferably
+ // in terms of the requested type URNs. If there is no better resolution,
+ // the original list is returned.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation replacements = 1;
+
+ // (Optional) If set, used to indicate the artifacts are mutually inconsistent
+ // (e.g. due to a diamond dependency problem) or could otherwise not be
+ // resolved (e.g. due to invalid specifications).
+ string error = 2;
+}
+
+// A request to get an artifact.
+message GetArtifactRequest {
+ org.apache.beam.model.pipeline.v1.ArtifactInformation artifact = 1;
Review comment:
Let's not for now; this could be difficult to implement in practice (for non-seekable resources). We could add this capability in the future if needed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606925303
The Java PreCommit has a different (unrelated) flake each time it's run.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399583281
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
Review comment:
Clarified in the docs.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400604823
##########
File path: sdks/python/apache_beam/runners/portability/artifact_service.py
##########
@@ -263,3 +279,205 @@ def _open(self, path, mode='r'):
return filesystems.FileSystems.create(path)
else:
return filesystems.FileSystems.open(path)
+
+
+# The dependency-aware artifact staging and retrieval services.
+
+
+def _queue_iter(queue, end_token):
+ while True:
+ item = queue.get()
+ if item is end_token:
+ break
+ yield item
+
+
+class ArtifactRetrievalService(
+ beam_artifact_api_pb2_grpc.ArtifactRetrievalServiceServicer):
+
+ _DEFAULT_CHUNK_SIZE = 2 << 20
+
+ def __init__(
+ self,
+ file_reader, # type: Callable[[str], BinaryIO],
+ chunk_size=None,
+ ):
+ self._file_reader = file_reader
+ self._chunk_size = chunk_size or self._DEFAULT_CHUNK_SIZE
+
+ def ResolveArtifact(self, request, context=None):
+ return beam_artifact_api_pb2.ResolveArtifactResponse(
+ replacements=request.artifacts)
+
+ def GetArtifact(self, request, context=None):
+ if request.artifact.type_urn == common_urns.artifact_types.FILE.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.ArtifactFilePayload)
+ read_handle = self._file_reader(payload.path)
+ elif request.artifact.type_urn == common_urns.artifact_types.URL.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload, beam_runner_api_pb2.ArtifactUrlPayload)
+ # TODO(Py3): Remove the unneeded contextlib wrapper.
+ read_handle = contextlib.closing(urlopen(payload.path))
+ elif request.artifact.type_urn == common_urns.artifact_types.EMBEDDED.urn:
+ payload = proto_utils.parse_Bytes(
+ request.artifact.type_payload,
+ beam_runner_api_pb2.EmbeddedFilePayload)
+ read_handle = BytesIO(payload.data)
+ else:
+ raise NotImplementedError(request.artifact.type_urn)
+
+ with read_handle as fin:
+ while True:
+ chunk = fin.read(self._chunk_size)
+ if not chunk:
+ break
+ yield beam_artifact_api_pb2.GetArtifactResponse(data=chunk)
+
+
+class ArtifactStagingService(
+ beam_artifact_api_pb2_grpc.ArtifactStagingServiceServicer):
+ def __init__(
+ self,
+ file_writer, # type: Callable[[str, Optional[str]], Tuple[BinaryIO, str]]
+ ):
+ self._lock = threading.Lock()
+ self._jobs_to_stage = {}
+ self._file_writer = file_writer
+
+ def register_job(self, staging_token, dependencies):
+ self._jobs_to_stage[staging_token] = list(dependencies), threading.Event()
Review comment:
I think we need to hold _lock everywhere for access/mutation of `_jobs_to_stage`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606744041
Regarding resolving a deferred artifact, the returned artifacts not in the list are required to be fetchable (so it would have to be resolved to actual concrete artifacts at that point, unless "deferred artifact" was actually in the preferred list.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606101109
Run Java PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r399499164
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,77 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact reference into one or more simpler artifact
+ // references (e.g. a Maven dependency into a (transitive) set of jars.
+ // If no further simplification is possible, returns the original artifacts,
+ // at which point, all artifacts must be gettable.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
Review comment:
The style of this stream won't allow for parallel *requests* to be send to the client since there is no *id* mechanism to diffentiate the responses since every request will have to have wait for the *is_last* to be set before the next *request* is sent out. If you want to support parallel *requests*, you also need to have a place to provide errors outside of the gRPC status that can be returned since you'll want to identify which *request* had a problem.
Also, if there are any errors for a single *request*, the whole RPC needs to be terminated since there is no way to say which *request* failed.
Since Java has typically a lot of jars, it is likely that we'll want to be able to parallelize this.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606872418
Run Java PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400567481
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
Review comment:
I was not intending for this to be an ordered list; I think the choice of artifact will governed more by the existing placement of the artifact.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400468512
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
+}
+
+// A response for artifact resolution.
+message ResolveArtifactResponse {
+ // A full set of replacements for the set of requested artifacts, preferably
+ // in terms of the requested type URNs. If there is no better resolution,
+ // the original list is returned.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation replacements = 1;
+
+ // (Optional) If set, used to indicate the artifacts are mutually inconsistent
+ // (e.g. due to a diamond dependency problem) or could otherwise not be
+ // resolved (e.g. due to invalid specifications).
+ string error = 2;
Review comment:
I don't believe this error message will be actionable.
A runner makes a request to resolve A -> B. If it doesn't understand what A is then an error during resolution won't really be actionable to the runner and I don't believe will be significantly better then terminating the whole streaming RPC with the failure. Lets say the runner could also try A -> C, then it should have listed in the preferred URNs B and C and the resolver would choose a valid combination.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on issue #11203: [BEAM-9577] Define and
implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on issue #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#issuecomment-606101217
Run Portable_Python PreCommit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] lukecwik commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
lukecwik commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400606139
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
+}
+
+// A response for artifact resolution.
+message ResolveArtifactResponse {
+ // A full set of replacements for the set of requested artifacts, preferably
+ // in terms of the requested type URNs. If there is no better resolution,
+ // the original list is returned.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation replacements = 1;
+
+ // (Optional) If set, used to indicate the artifacts are mutually inconsistent
+ // (e.g. due to a diamond dependency problem) or could otherwise not be
+ // resolved (e.g. due to invalid specifications).
+ string error = 2;
+}
+
+// A request to get an artifact.
+message GetArtifactRequest {
+ org.apache.beam.model.pipeline.v1.ArtifactInformation artifact = 1;
Review comment:
I'm fine with adding it later, just pointing out that adding it later will require producing GetArtifactRequest V2 as adding the field would be backwards incompatible unless an *actual* resumed_offset was added to the response.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [beam] robertwb commented on a change in pull request #11203:
[BEAM-9577] Define and implement dependency-aware artifact staging service.
Posted by GitBox <gi...@apache.org>.
robertwb commented on a change in pull request #11203: [BEAM-9577] Define and implement dependency-aware artifact staging service.
URL: https://github.com/apache/beam/pull/11203#discussion_r400570316
##########
File path: model/job-management/src/main/proto/beam_artifact_api.proto
##########
@@ -31,8 +31,92 @@ option java_outer_classname = "ArtifactApi";
import "beam_runner_api.proto";
-// A service to stage artifacts for use in a Job.
+// A service to retrieve artifacts for use in a Job.
+service ArtifactRetrievalService {
+ // Resolves the given artifact references into one or more replacement
+ // artifact references (e.g. a Maven dependency into a (transitive) set
+ // of jars.
+ rpc ResolveArtifact(ResolveArtifactRequest) returns (ResolveArtifactResponse);
+
+ // Retrieves the given artifact as a stream of bytes.
+ rpc GetArtifact(GetArtifactRequest) returns (stream GetArtifactResponse);
+}
+
+// A service that allows the client to act as an ArtifactRetrievalService,
+// for a particular job with the server initiating requests and receiving
+// responses.
+//
+// A client calls the service with an ArtifactResponseWrapper that has the
+// staging token set, and thereafter responds to the server's requests.
service ArtifactStagingService {
+ rpc ReverseArtifactRetrievalService(stream ArtifactResponseWrapper)
+ returns (stream ArtifactRequestWrapper);
+}
+
+// A request for artifact resolution.
+message ResolveArtifactRequest {
+ // A set of artifacts to (jointly) resolve.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation artifacts = 1;
+
+ // A set of artifact type urns that are understood by the requester.
+ // An attempt should be made to resolve the artifacts in terms of these URNs,
+ // but other URNs may be used as well with the understanding that they must
+ // be fetch-able as bytes via GetArtifact.
+ repeated string preferred_urns = 2;
+}
+
+// A response for artifact resolution.
+message ResolveArtifactResponse {
+ // A full set of replacements for the set of requested artifacts, preferably
+ // in terms of the requested type URNs. If there is no better resolution,
+ // the original list is returned.
+ repeated org.apache.beam.model.pipeline.v1.ArtifactInformation replacements = 1;
+
+ // (Optional) If set, used to indicate the artifacts are mutually inconsistent
+ // (e.g. due to a diamond dependency problem) or could otherwise not be
+ // resolved (e.g. due to invalid specifications).
+ string error = 2;
Review comment:
This was intended to be used for the merging of environments. Suppose one environment requires A and another requires B. It may be possible to provide a set of artifacts that satisfy both (e.g. if they were maven dependencies), or possibly not (if there was a diamond dependency problem, or they were opaque).
I am now realizing that this probably needs to be a separate protocol, which can be introduced at a future date.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services