From 3642b6879dcea78e6bed443c7651e0796ccc84ba Mon Sep 17 00:00:00 2001 From: Karen Chen <64801825+karenc-bq@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:17:45 -0800 Subject: [PATCH] refactor: remove duplicated getHostAndPort method --- common/lib/host_info.ts | 4 ---- .../monitoring/cluster_topology_monitor.ts | 4 ++-- common/lib/plugins/bluegreen/blue_green_interim_status.ts | 4 ++-- common/lib/plugins/bluegreen/blue_green_status_provider.ts | 2 +- .../lib/plugins/bluegreen/routing/base_connect_routing.ts | 2 +- .../lib/plugins/bluegreen/routing/base_execute_routing.ts | 2 +- .../plugins/bluegreen/routing/substitute_connect_routing.ts | 6 +++--- .../plugins/connection_tracker/opened_connection_tracker.ts | 2 +- common/lib/plugins/failover2/failover2_plugin.ts | 2 +- 9 files changed, 12 insertions(+), 16 deletions(-) diff --git a/common/lib/host_info.ts b/common/lib/host_info.ts index 566f5cfaa..3ac577518 100644 --- a/common/lib/host_info.ts +++ b/common/lib/host_info.ts @@ -65,10 +65,6 @@ export class HostInfo { return this.port != HostInfo.NO_PORT; } - getHostAndPort(): string { - return this.isPortSpecified() ? this.host + ":" + this.port : this.host; - } - addAlias(...alias: string[]) { if (!alias || alias.length < 1) { return; diff --git a/common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts b/common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts index a5a3e2f09..958f4046c 100644 --- a/common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts +++ b/common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts @@ -528,9 +528,9 @@ export class HostMonitor { } const latestWriterHostInfo: HostInfo = hosts.find((x) => x.role === HostRole.WRITER); - if (latestWriterHostInfo && writerHostInfo && latestWriterHostInfo.getHostAndPort() !== writerHostInfo.getHostAndPort()) { + if (latestWriterHostInfo && writerHostInfo && latestWriterHostInfo.hostAndPort !== writerHostInfo.hostAndPort) { this.writerChanged = true; - logger.debug(Messages.get("HostMonitor.writerHostChanged", writerHostInfo.getHostAndPort(), latestWriterHostInfo.getHostAndPort())); + logger.debug(Messages.get("HostMonitor.writerHostChanged", writerHostInfo.hostAndPort, latestWriterHostInfo.hostAndPort)); this.monitor.updateTopologyCache(hosts); logger.debug(logTopology(hosts, `[hostMonitor ${this.hostInfo.hostId}] `)); } diff --git a/common/lib/plugins/bluegreen/blue_green_interim_status.ts b/common/lib/plugins/bluegreen/blue_green_interim_status.ts index c2c979317..4cf7bb3fa 100644 --- a/common/lib/plugins/bluegreen/blue_green_interim_status.ts +++ b/common/lib/plugins/bluegreen/blue_green_interim_status.ts @@ -104,7 +104,7 @@ export class BlueGreenInterimStatus { this.startTopology == null ? "" : this.startTopology - .map((x) => x.getHostAndPort() + x.role) + .map((x) => x.hostAndPort + x.role) .sort() .join(",") ); @@ -114,7 +114,7 @@ export class BlueGreenInterimStatus { this.currentTopology == null ? "" : this.currentTopology - .map((x) => x.getHostAndPort() + x.role) + .map((x) => x.hostAndPort + x.role) .sort() .join(",") ); diff --git a/common/lib/plugins/bluegreen/blue_green_status_provider.ts b/common/lib/plugins/bluegreen/blue_green_status_provider.ts index c503f133d..0919fc781 100644 --- a/common/lib/plugins/bluegreen/blue_green_status_provider.ts +++ b/common/lib/plugins/bluegreen/blue_green_status_provider.ts @@ -874,7 +874,7 @@ export class BlueGreenStatusProvider { logger.debug( "Corresponding hosts:\n" + Array.from(this.correspondingHosts.entries()) - .map(([key, value]) => ` ${key} -> ${value.right == null ? "" : value.right.getHostAndPort()}`) + .map(([key, value]) => ` ${key} -> ${value.right == null ? "" : value.right.hostAndPort}`) .join("\n") ); diff --git a/common/lib/plugins/bluegreen/routing/base_connect_routing.ts b/common/lib/plugins/bluegreen/routing/base_connect_routing.ts index 5dfdd25cc..9a0deeccc 100644 --- a/common/lib/plugins/bluegreen/routing/base_connect_routing.ts +++ b/common/lib/plugins/bluegreen/routing/base_connect_routing.ts @@ -25,7 +25,7 @@ import { PluginService } from "../../../plugin_service"; export abstract class BaseConnectRouting extends BaseRouting implements ConnectRouting { isMatch(hostInfo: HostInfo, hostRole: BlueGreenRole): boolean { return ( - (this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.getHostAndPort().toLowerCase())) && + (this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.hostAndPort.toLowerCase())) && (this.role === null || this.role === hostRole) ); } diff --git a/common/lib/plugins/bluegreen/routing/base_execute_routing.ts b/common/lib/plugins/bluegreen/routing/base_execute_routing.ts index 80d7d50e5..e631442ba 100644 --- a/common/lib/plugins/bluegreen/routing/base_execute_routing.ts +++ b/common/lib/plugins/bluegreen/routing/base_execute_routing.ts @@ -24,7 +24,7 @@ import { ConnectionPlugin } from "../../../connection_plugin"; export abstract class BaseExecuteRouting extends BaseRouting implements ExecuteRouting { isMatch(hostInfo: HostInfo, hostRole: BlueGreenRole): boolean { return ( - (this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.getHostAndPort().toLowerCase())) && + (this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.hostAndPort.toLowerCase())) && (this.role === null || this.role === hostRole) ); } diff --git a/common/lib/plugins/bluegreen/routing/substitute_connect_routing.ts b/common/lib/plugins/bluegreen/routing/substitute_connect_routing.ts index 1d453e461..94f356770 100644 --- a/common/lib/plugins/bluegreen/routing/substitute_connect_routing.ts +++ b/common/lib/plugins/bluegreen/routing/substitute_connect_routing.ts @@ -99,12 +99,12 @@ export class SubstituteConnectRouting extends BaseConnectRouting { // try with another IAM host } } - throw new AwsWrapperError(Messages.get("Bgd.inProgressCantOpenConnection", this.substituteHost.getHostAndPort())); + throw new AwsWrapperError(Messages.get("Bgd.inProgressCantOpenConnection", this.substituteHost.hostAndPort)); } toString(): string { - return `${this.constructor.name} [${this.hostAndPort ?? ""}, ${this.role?.name ?? ""}, substitute: ${this.substituteHost?.getHostAndPort() ?? ""}, iamHosts: ${ - this.iamHosts?.map((host) => host.getHostAndPort()).join(", ") ?? "" + return `${this.constructor.name} [${this.hostAndPort ?? ""}, ${this.role?.name ?? ""}, substitute: ${this.substituteHost?.hostAndPort ?? ""}, iamHosts: ${ + this.iamHosts?.map((host) => host.hostAndPort).join(", ") ?? "" }]`; } } diff --git a/common/lib/plugins/connection_tracker/opened_connection_tracker.ts b/common/lib/plugins/connection_tracker/opened_connection_tracker.ts index 364a123be..6c8b6a580 100644 --- a/common/lib/plugins/connection_tracker/opened_connection_tracker.ts +++ b/common/lib/plugins/connection_tracker/opened_connection_tracker.ts @@ -36,7 +36,7 @@ export class OpenedConnectionTracker { // Check if the connection was established using an instance endpoint if (OpenedConnectionTracker.rdsUtils.isRdsInstance(hostInfo.host)) { - this.trackConnection(hostInfo.getHostAndPort(), client); + this.trackConnection(hostInfo.hostAndPort, client); return; } diff --git a/common/lib/plugins/failover2/failover2_plugin.ts b/common/lib/plugins/failover2/failover2_plugin.ts index 5d7060d03..3b4a7f044 100644 --- a/common/lib/plugins/failover2/failover2_plugin.ts +++ b/common/lib/plugins/failover2/failover2_plugin.ts @@ -138,7 +138,7 @@ export class Failover2Plugin extends AbstractConnectionPlugin implements CanRele return await this._staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService!, props, connectFunc); } - const hostInfoWithAvailability: HostInfo = this.pluginService.getHosts().find((x) => x.getHostAndPort() === hostInfo.getHostAndPort()); + const hostInfoWithAvailability: HostInfo = this.pluginService.getHosts().find((x) => x.hostAndPort === hostInfo.hostAndPort); let client: ClientWrapper = null; if (!hostInfoWithAvailability || hostInfoWithAvailability.getAvailability() != HostAvailability.NOT_AVAILABLE) {