You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by al...@apache.org on 2017/10/10 17:27:31 UTC
[1/2] beam git commit: Pin runner harness container image for
Dataflow distributions of BEAM Python SDK
Repository: beam
Updated Branches:
refs/heads/master 1001cf1ab -> b0030aeb3
Pin runner harness container image for Dataflow distributions of BEAM Python SDK
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/fe889404
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/fe889404
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/fe889404
Branch: refs/heads/master
Commit: fe889404682f8ea072f9af526696ab6df4185bd8
Parents: 1001cf1
Author: Valentyn Tymofieiev <va...@google.com>
Authored: Mon Oct 9 15:07:56 2017 -0700
Committer: Valentyn Tymofieiev <va...@google.com>
Committed: Tue Oct 10 09:41:31 2017 -0700
----------------------------------------------------------------------
.../runners/dataflow/internal/apiclient.py | 8 ++++
.../runners/dataflow/internal/apiclient_test.py | 35 +++++++++++++++--
.../runners/dataflow/internal/dependency.py | 40 ++++++++++++++------
3 files changed, 68 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/beam/blob/fe889404/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py b/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py
index d010065..e48b58c 100644
--- a/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py
+++ b/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py
@@ -162,6 +162,14 @@ class Environment(object):
value=to_json_value(job_type)),
dataflow.Environment.VersionValue.AdditionalProperty(
key='major', value=to_json_value(environment_version))])
+ # TODO: Use enumerated type instead of strings for job types.
+ if job_type.startswith('FNAPI_'):
+ runner_harness_override = (
+ dependency.get_runner_harness_container_image())
+ if runner_harness_override:
+ self.debug_options.experiments = self.debug_options.experiments or []
+ self.debug_options.experiments.append(
+ 'runner_harness_container_image=' + runner_harness_override)
# Experiments
if self.debug_options.experiments:
for experiment in self.debug_options.experiments:
http://git-wip-us.apache.org/repos/asf/beam/blob/fe889404/sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py b/sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py
index e7cced7..ce28928 100644
--- a/sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py
+++ b/sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py
@@ -16,11 +16,11 @@
#
"""Unit tests for the apiclient module."""
import unittest
-
-from mock import Mock
+import mock
from apache_beam.metrics.cells import DistributionData
from apache_beam.options.pipeline_options import PipelineOptions
+from apache_beam.runners.dataflow.internal import dependency
from apache_beam.runners.dataflow.internal.clients import dataflow
# Protect against environments where apitools library is not available.
@@ -31,6 +31,7 @@ except ImportError:
apiclient = None
# pylint: enable=wrong-import-order, wrong-import-position
+import pkg_resources
@unittest.skipIf(apiclient is None, 'GCP dependencies are not installed')
class UtilTest(unittest.TestCase):
@@ -102,7 +103,7 @@ class UtilTest(unittest.TestCase):
def test_translate_means(self):
metric_update = dataflow.CounterUpdate()
- accumulator = Mock()
+ accumulator = mock.Mock()
accumulator.sum = 16
accumulator.count = 2
apiclient.MetricUpdateTranslators.translate_scalar_mean_int(accumulator,
@@ -142,6 +143,34 @@ class UtilTest(unittest.TestCase):
env.proto.workerPools[0].ipConfiguration,
dataflow.WorkerPool.IpConfigurationValueValuesEnum.WORKER_IP_PRIVATE)
+ def test_harness_override_present_in_dataflow_distributions(self):
+ pipeline_options = PipelineOptions(
+ ['--temp_location', 'gs://any-location/temp', '--streaming'])
+ override = ''.join(
+ ['runner_harness_container_image=',
+ dependency.DATAFLOW_CONTAINER_IMAGE_REPOSITORY,
+ '/harness:2.2.0'])
+ distribution = pkg_resources.Distribution(version='2.2.0')
+ with mock.patch(
+ 'apache_beam.runners.dataflow.internal.dependency.pkg_resources'
+ '.get_distribution',
+ mock.MagicMock(return_value=distribution)):
+ env = apiclient.Environment([], pipeline_options, '2.2.0')
+ self.assertIn(override, env.proto.experiments)
+
+ def test_harness_override_absent_in_unreleased_sdk(self):
+ pipeline_options = PipelineOptions(
+ ['--temp_location', 'gs://any-location/temp', '--streaming'])
+ override = ''.join(
+ ['runner_harness_container_image=',
+ dependency.DATAFLOW_CONTAINER_IMAGE_REPOSITORY,
+ '/harness:2.2.0'])
+ with mock.patch(
+ 'apache_beam.runners.dataflow.internal.dependency.pkg_resources'
+ '.get_distribution',
+ mock.Mock(side_effect=pkg_resources.DistributionNotFound())):
+ env = apiclient.Environment([], pipeline_options, '2.2.0')
+ self.assertNotIn(override, env.proto.experiments)
if __name__ == '__main__':
unittest.main()
http://git-wip-us.apache.org/repos/asf/beam/blob/fe889404/sdks/python/apache_beam/runners/dataflow/internal/dependency.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/runners/dataflow/internal/dependency.py b/sdks/python/apache_beam/runners/dataflow/internal/dependency.py
index 383f8e9..4988dab 100644
--- a/sdks/python/apache_beam/runners/dataflow/internal/dependency.py
+++ b/sdks/python/apache_beam/runners/dataflow/internal/dependency.py
@@ -1,5 +1,3 @@
-
-#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -69,6 +67,8 @@ from apache_beam.options.pipeline_options import SetupOptions
from apache_beam.runners.dataflow.internal import names
from apache_beam.utils import processes
+import pkg_resources
+
# All constants are for internal use only; no backwards-compatibility
# guarantees.
@@ -97,6 +97,8 @@ BEAM_PACKAGE_NAME = 'apache-beam'
GOOGLE_SDK_NAME = 'Google Cloud Dataflow SDK for Python'
BEAM_SDK_NAME = 'Apache Beam SDK for Python'
+DATAFLOW_CONTAINER_IMAGE_REPOSITORY = 'dataflow.gcr.io/v1beta3'
+
def _dependency_file_copy(from_path, to_path):
"""Copies a local file to a GCS file or vice versa."""
@@ -488,6 +490,22 @@ def _stage_beam_sdk_tarball(sdk_remote_location, staged_path, temp_dir):
'type of location: %s' % sdk_remote_location)
+def get_runner_harness_container_image():
+ """For internal use only; no backwards-compatibility guarantees.
+
+ Returns:
+ str: Runner harness container image that shall be used by default
+ for current SDK version or None if the runner harness container image
+ bundled with the service shall be used.
+ """
+ try:
+ version = pkg_resources.get_distribution(GOOGLE_PACKAGE_NAME).version
+ return (DATAFLOW_CONTAINER_IMAGE_REPOSITORY + '/' + 'harness' + ':' +
+ version)
+ except pkg_resources.DistributionNotFound:
+ return None
+
+
def get_default_container_image_for_current_sdk(job_type):
"""For internal use only; no backwards-compatibility guarantees.
@@ -517,17 +535,17 @@ def _get_required_container_version(job_type=None):
current version of the SDK.
"""
# TODO(silviuc): Handle apache-beam versions when we have official releases.
- import pkg_resources as pkg
try:
- version = pkg.get_distribution(GOOGLE_PACKAGE_NAME).version
+ version = pkg_resources.get_distribution(GOOGLE_PACKAGE_NAME).version
# We drop any pre/post parts of the version and we keep only the X.Y.Z
# format. For instance the 0.3.0rc2 SDK version translates into 0.3.0.
- container_version = '%s.%s.%s' % pkg.parse_version(version)._version.release
+ container_version = (
+ '%s.%s.%s' % pkg_resources.parse_version(version)._version.release)
# We do, however, keep the ".dev" suffix if it is present.
if re.match(r'.*\.dev[0-9]*$', version):
container_version += '.dev'
return container_version
- except pkg.DistributionNotFound:
+ except pkg_resources.DistributionNotFound:
# This case covers Apache Beam end-to-end testing scenarios. All these tests
# will run with a special container version.
if job_type == 'FNAPI_BATCH' or job_type == 'FNAPI_STREAMING':
@@ -540,12 +558,11 @@ def get_sdk_name_and_version():
"""For internal use only; no backwards-compatibility guarantees.
Returns name and version of SDK reported to Google Cloud Dataflow."""
- import pkg_resources as pkg
container_version = _get_required_container_version()
try:
- pkg.get_distribution(GOOGLE_PACKAGE_NAME)
+ pkg_resources.get_distribution(GOOGLE_PACKAGE_NAME)
return (GOOGLE_SDK_NAME, container_version)
- except pkg.DistributionNotFound:
+ except pkg_resources.DistributionNotFound:
return (BEAM_SDK_NAME, beam_version.__version__)
@@ -563,10 +580,9 @@ def get_sdk_package_name():
def _download_pypi_sdk_package(temp_dir):
"""Downloads SDK package from PyPI and returns path to local path."""
package_name = get_sdk_package_name()
- import pkg_resources as pkg
try:
- version = pkg.get_distribution(package_name).version
- except pkg.DistributionNotFound:
+ version = pkg_resources.get_distribution(package_name).version
+ except pkg_resources.DistributionNotFound:
raise RuntimeError('Please set --sdk_location command-line option '
'or install a valid {} distribution.'
.format(package_name))
[2/2] beam git commit: This closes #3966
Posted by al...@apache.org.
This closes #3966
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/b0030aeb
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/b0030aeb
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/b0030aeb
Branch: refs/heads/master
Commit: b0030aeb3a9459cf78621a4eba2be8f6e86e7829
Parents: 1001cf1 fe88940
Author: Ahmet Altay <al...@google.com>
Authored: Tue Oct 10 10:27:23 2017 -0700
Committer: Ahmet Altay <al...@google.com>
Committed: Tue Oct 10 10:27:23 2017 -0700
----------------------------------------------------------------------
.../runners/dataflow/internal/apiclient.py | 8 ++++
.../runners/dataflow/internal/apiclient_test.py | 35 +++++++++++++++--
.../runners/dataflow/internal/dependency.py | 40 ++++++++++++++------
3 files changed, 68 insertions(+), 15 deletions(-)
----------------------------------------------------------------------