You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by da...@apache.org on 2023/04/05 13:47:56 UTC

[beam] branch users/damccorm/go-nits created (now bb77d6a1978)

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

damccorm pushed a change to branch users/damccorm/go-nits
in repository https://gitbox.apache.org/repos/asf/beam.git


      at bb77d6a1978 Clean up some unneccessarily nested ifs in stage.go

This branch includes the following new commits:

     new bb77d6a1978 Clean up some unneccessarily nested ifs in stage.go

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[beam] 01/01: Clean up some unneccessarily nested ifs in stage.go

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

damccorm pushed a commit to branch users/damccorm/go-nits
in repository https://gitbox.apache.org/repos/asf/beam.git

commit bb77d6a197882eff49146f3ded7f0d81810497b6
Author: Danny McCormick <da...@google.com>
AuthorDate: Wed Apr 5 09:47:44 2023 -0400

    Clean up some unneccessarily nested ifs in stage.go
---
 .../playground_components/assets/symbols/go.g.yaml    |  4 ++--
 sdks/go/pkg/beam/runners/universal/runnerlib/stage.go | 19 ++++++++++---------
 .../beam/runners/universal/runnerlib/stage_test.go    |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/playground/frontend/playground_components/assets/symbols/go.g.yaml b/playground/frontend/playground_components/assets/symbols/go.g.yaml
index cf3b2a0c9c9..2c156f4d2d7 100644
--- a/playground/frontend/playground_components/assets/symbols/go.g.yaml
+++ b/playground/frontend/playground_components/assets/symbols/go.g.yaml
@@ -762,8 +762,8 @@
   - StageDir
   - StageFile
   - StageModel
-  - StageViaLegacyApi
-  - StageViaPortableApi
+  - StageViaLegacyAPI
+  - StageViaPortableAPI
   - StartLoopback
   - StartReadTimestamp
   - Step
diff --git a/sdks/go/pkg/beam/runners/universal/runnerlib/stage.go b/sdks/go/pkg/beam/runners/universal/runnerlib/stage.go
index bb1f51c13c7..3cbc3343683 100644
--- a/sdks/go/pkg/beam/runners/universal/runnerlib/stage.go
+++ b/sdks/go/pkg/beam/runners/universal/runnerlib/stage.go
@@ -43,16 +43,17 @@ func Stage(ctx context.Context, id, endpoint, binary, st string) (retrievalToken
 	}
 	defer cc.Close()
 
-	if err := StageViaPortableApi(ctx, cc, binary, st); err == nil {
+	if err := StageViaPortableAPI(ctx, cc, binary, st); err == nil {
 		return "", nil
-	} else {
-		log.Warnf(ctx, "unable to stage with PortableAPI: %v; falling back to legacy", err)
 	}
+	log.Warnf(ctx, "unable to stage with PortableAPI: %v; falling back to legacy", err)
 
-	return StageViaLegacyApi(ctx, cc, binary, st)
+	return StageViaLegacyAPI(ctx, cc, binary, st)
 }
 
-func StageViaPortableApi(ctx context.Context, cc *grpc.ClientConn, binary, st string) (retErr error) {
+// StageViaPortableAPI stages the worker binary and any additional files
+// using the given grpc connection for the Portable API.
+func StageViaPortableAPI(ctx context.Context, cc *grpc.ClientConn, binary, st string) (retErr error) {
 	const attempts = 3
 	var failures []string
 	for {
@@ -60,9 +61,7 @@ func StageViaPortableApi(ctx context.Context, cc *grpc.ClientConn, binary, st st
 		if err == nil {
 			return nil // success!
 		}
-		if err != nil {
-			failures = append(failures, err.Error())
-		}
+		failures = append(failures, err.Error())
 		if len(failures) > attempts {
 			return errors.Errorf("failed to stage artifacts for token %v in %v attempts: %v", st, attempts, strings.Join(failures, ";\n"))
 		}
@@ -180,7 +179,9 @@ func stageFile(filename string, stream jobpb.ArtifactStagingService_ReverseArtif
 	}
 }
 
-func StageViaLegacyApi(ctx context.Context, cc *grpc.ClientConn, binary, st string) (retrievalToken string, err error) {
+// StageViaLegacyAPI stages the worker binary and any additional files using the
+// given grpc connection for the Legacy API. It returns the retrieval token if successful.
+func StageViaLegacyAPI(ctx context.Context, cc *grpc.ClientConn, binary, st string) (retrievalToken string, err error) {
 	client := jobpb.NewLegacyArtifactStagingServiceClient(cc)
 
 	files := []artifact.KeyedFile{{Key: "worker", Filename: binary}}
diff --git a/sdks/go/pkg/beam/runners/universal/runnerlib/stage_test.go b/sdks/go/pkg/beam/runners/universal/runnerlib/stage_test.go
index 2a1d784d4e7..81e4402fcbd 100644
--- a/sdks/go/pkg/beam/runners/universal/runnerlib/stage_test.go
+++ b/sdks/go/pkg/beam/runners/universal/runnerlib/stage_test.go
@@ -73,7 +73,7 @@ func TestPortableArtifactStaging(t *testing.T) {
 	das.wantToken = "token"
 	das.reqFile = "stage.go"
 
-	err := StageViaPortableApi(ctx, cc, "reqFile", das.wantToken)
+	err := StageViaPortableAPI(ctx, cc, "reqFile", das.wantToken)
 	if err != nil {
 		t.Fatal(err)
 	}