jrmccluskey commented on a change in pull request #16470:
URL: https://github.com/apache/beam/pull/16470#discussion_r781398709
##########
File path: sdks/go/pkg/beam/core/runtime/xlangx/expansionx/process.go
##########
@@ -30,20 +31,40 @@ type ExpansionServiceRunner struct {
serviceCommand *exec.Cmd
}
+func findOpenPort() (int, error) {
+ listener, err := net.Listen("tcp", ":0")
+ if err != nil {
+ return 0, err
+ }
+ defer listener.Close()
+ return listener.Addr().(*net.TCPAddr).Port, nil
+}
+
// NewExpansionServiceRunner builds an ExpansionServiceRunner struct for a
given gradle target and
-// Beam version and returns a pointer to it.
-func NewExpansionServiceRunner(jarPath, servicePort string)
*ExpansionServiceRunner {
+// Beam version and returns a pointer to it. Passing an empty string as
servicePort will request an
+// open port to be assigned to the service.
+func NewExpansionServiceRunner(jarPath, servicePort string)
(*ExpansionServiceRunner, error) {
if servicePort == "" {
- servicePort = "8097"
+ port, err := findOpenPort()
+ if err != nil {
+ return nil, fmt.Errorf("failed to find open port for
service, got %v", err)
+ }
+ servicePort = fmt.Sprintf("%d", port)
}
serviceCommand := exec.Command("java", "-jar", jarPath, servicePort)
- return &ExpansionServiceRunner{jarPath: jarPath, servicePort:
servicePort, serviceCommand: serviceCommand}
+ return &ExpansionServiceRunner{jarPath: jarPath, servicePort:
servicePort, serviceCommand: serviceCommand}, nil
}
func (e *ExpansionServiceRunner) String() string {
return fmt.Sprintf("JAR: %v, Port: %v, Process: %v", e.jarPath,
e.servicePort, e.serviceCommand.Process)
}
+// GetPort returns the formatted port the ExpansionServiceRunner is set to
start the expansion
Review comment:
Missed that one, whoops
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]