diff --git a/yb-voyager/src/dbzm/config.go b/yb-voyager/src/dbzm/config.go index 9a12d484eb..b8b2909e6f 100644 --- a/yb-voyager/src/dbzm/config.go +++ b/yb-voyager/src/dbzm/config.go @@ -81,6 +81,7 @@ type Config struct { var baseConfigTemplate = ` debezium.format.value=connect debezium.format.key=connect +quarkus.http.port=%d quarkus.log.console.json=false quarkus.log.level=%s ` @@ -295,10 +296,19 @@ func (c *Config) String() string { } else { log.Infof("QUEUE_SEGMENT_MAX_BYTES: %d", queueSegmentMaxBytes) } + + quarkusLogPort, err := utils.GetFreePort() + if err != nil { + log.Warnf("failed to get a free port for quarkus http server, falling back to 8080: %v", err) + quarkusLogPort = 8080 + } + log.Infof("using port number %d for quarkus http server", quarkusLogPort) + var conf string switch c.SourceDBType { case "postgresql": conf = fmt.Sprintf(postgresConfigTemplate, + quarkusLogPort, c.LogLevel, c.Username, c.SnapshotMode, @@ -332,6 +342,7 @@ func (c *Config) String() string { case "yugabytedb": if !c.UseYBgRPCConnector { conf = fmt.Sprintf(yugabyteLogicalReplicationConfigTemplate, + quarkusLogPort, c.LogLevel, c.Username, "never", @@ -359,6 +370,7 @@ func (c *Config) String() string { } } else { conf = fmt.Sprintf(yugabyteConfigTemplate, + quarkusLogPort, c.LogLevel, c.Username, "never", @@ -391,6 +403,7 @@ func (c *Config) String() string { } case "oracle": conf = fmt.Sprintf(oracleConfigTemplate, + quarkusLogPort, c.LogLevel, c.Username, c.SnapshotMode, @@ -422,6 +435,7 @@ func (c *Config) String() string { case "mysql": conf = fmt.Sprintf(mysqlConfigTemplate, + quarkusLogPort, c.LogLevel, c.Username, c.SnapshotMode, diff --git a/yb-voyager/src/utils/utils.go b/yb-voyager/src/utils/utils.go index 2bb1a9bd4c..0d105415c2 100644 --- a/yb-voyager/src/utils/utils.go +++ b/yb-voyager/src/utils/utils.go @@ -684,3 +684,17 @@ func ChangeFileExtension(filePath string, newExt string) string { return filePath + newExt } + +// Port 0 generally returns port number in range 30xxx - 60xxx but it also depends on OS and network configuration +func GetFreePort() (int, error) { + // Listen on port 0, which tells the OS to assign an available port + listener, err := net.Listen("tcp", ":0") + if err != nil { + return 0, fmt.Errorf("failed to listen on a port: %v", err) + } + defer listener.Close() + + // Retrieve the assigned port + addr := listener.Addr().(*net.TCPAddr) + return addr.Port, nil +}