You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/10/12 04:27:56 UTC

[GitHub] [beam] lostluck commented on a change in pull request #15698: [BEAM-13013] Extend cross language expansion.

lostluck commented on a change in pull request #15698:
URL: https://github.com/apache/beam/pull/15698#discussion_r726750973



##########
File path: sdks/go/pkg/beam/core/runtime/xlangx/registry.go
##########
@@ -0,0 +1,317 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package xlangx
+
+import (
+	"context"
+	"fmt"
+	"net/url"
+	"strings"
+	"sync"
+
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/graphx"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/pipelinex"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
+	jobpb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagement_v1"
+	pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+)
+
+var defaultReg = newRegistry()
+
+// RegisterHandler associates a namespace with a HandlerFunc which can be used to
+// replace calls to a Beam ExpansionService.
+//
+// Then, expansion addresses of the forms
+//   "<namespace>" or
+//   "<namespace>:<configuration>"
+// can be used with beam.CrossLanguage. Any configuration after the separator is
+// provided to the HandlerFunc on call for the handler func to use at it's leisure.
+func RegisterHandler(namespace string, handler HandlerFunc) {
+	if err := defaultReg.RegisterHandler(namespace, handler); err != nil {
+		panic(err)
+	}
+}
+
+// RegisterExpansionForUrn overrides which expansion address is used to
+// expand a specific transform URN. The expansion address must be a URL
+// or be a namespaced handler registered with RegisterHandler.
+//
+// When the expansion address is for a handler, it may take the forms
+//  "<namespace>" or
+//  "<namespace>:<configuration>"
+func RegisterOverrideForUrn(urn, expansionAddr string) {
+	if err := defaultReg.RegisterOverrideForUrn(urn, expansionAddr); err != nil {
+		panic(err)
+	}
+}
+
+// HandlerParams is the parameter to an expansion service handler.
+type HandlerParams struct {
+	// Additional parameterization string, if any.
+	Config string
+
+	Req *jobpb.ExpansionRequest
+
+	// Additional pipeline graph information for custom handling
+	// Not exported to avoid mutation.
+	edge *graph.MultiEdge
+	ext  *graph.ExternalTransform

Review comment:
       Payload is already exposed via handlerParams.Req.GetTransform().GetSpec().GetPayload(), just like it would be for the RPC 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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org