You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lo...@apache.org on 2022/10/18 22:02:27 UTC

[beam] branch master updated: add expansion service option (#23712)

This is an automated email from the ASF dual-hosted git repository.

lostluck pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new ae05c25854f add expansion service option (#23712)
ae05c25854f is described below

commit ae05c25854f1249f3cf9223f8db38fed4ba21575
Author: Ritesh Ghorse <ri...@gmail.com>
AuthorDate: Tue Oct 18 18:02:19 2022 -0400

    add expansion service option (#23712)
---
 sdks/go/pkg/beam/core/runtime/xlangx/expand.go   |  2 +-
 sdks/go/pkg/beam/core/runtime/xlangx/registry.go | 22 ++++++++++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/sdks/go/pkg/beam/core/runtime/xlangx/expand.go b/sdks/go/pkg/beam/core/runtime/xlangx/expand.go
index 51333b5cf02..5f04274d2bf 100644
--- a/sdks/go/pkg/beam/core/runtime/xlangx/expand.go
+++ b/sdks/go/pkg/beam/core/runtime/xlangx/expand.go
@@ -271,7 +271,7 @@ func QueryPythonExpansionService(ctx context.Context, p *HandlerParams) (*jobpb.
 	// Strip autoPython: tag to get actual python module
 	tag, module := parseAddr(p.Config)
 	// parse extra-packages from namespace if present
-	module, extraPackages := parseClasspath(module)
+	module, extraPackages := parseExtraPackages(module)
 
 	stopFunc, address, err := startPythonExpansionService(module, extraPackages)
 	if err != nil {
diff --git a/sdks/go/pkg/beam/core/runtime/xlangx/registry.go b/sdks/go/pkg/beam/core/runtime/xlangx/registry.go
index 425ed9aa8aa..47f98023695 100644
--- a/sdks/go/pkg/beam/core/runtime/xlangx/registry.go
+++ b/sdks/go/pkg/beam/core/runtime/xlangx/registry.go
@@ -283,6 +283,15 @@ func AddClasspaths(classpaths []string) ExpansionServiceOption {
 	}
 }
 
+// AddExtraPackages is an expansion service option for xlangx.UseAutomatedPythonExpansionService
+// that accepts a extra packages slice and creates a tagged  expansion address string
+// suffixed with classpath separator and service module provided.
+func AddExtraPackages(packages []string) ExpansionServiceOption {
+	return func(expansionAddress *string) {
+		*expansionAddress += ClasspathSeparator + strings.Join(packages, " ")
+	}
+}
+
 // UseAutomatedJavaExpansionService takes a gradle target and creates a
 // tagged string to indicate that it should be used to start up an
 // automated expansion service for a cross-language expansion.
@@ -306,8 +315,13 @@ func UseAutomatedJavaExpansionService(gradleTarget string, opts ...ExpansionServ
 // Intended for use by cross language wrappers to permit spinning
 // up an expansion service for a user if no expansion service address
 // is provided.
-func UseAutomatedPythonExpansionService(service string) string {
-	return autoPythonNamespace + Separator + service
+func UseAutomatedPythonExpansionService(service string, opts ...ExpansionServiceOption) string {
+	expansionAddress := autoPythonNamespace + Separator + service
+
+	for _, opt := range opts {
+		opt(&expansionAddress)
+	}
+	return expansionAddress
 }
 
 // restricted namespaces to prevent some awkward edge cases.
@@ -338,3 +352,7 @@ func parseClasspath(expansionAddr string) (string, string) {
 	}
 	return split[0], split[1]
 }
+
+func parseExtraPackages(expansionAddr string) (string, string) {
+	return parseClasspath(expansionAddr)
+}