Skip to content

Commit 557a378

Browse files
authored
refactor: remove duplicated getHostAndPort method (#613)
1 parent e117401 commit 557a378

9 files changed

Lines changed: 12 additions & 16 deletions

File tree

common/lib/host_info.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ export class HostInfo {
6565
return this.port != HostInfo.NO_PORT;
6666
}
6767

68-
getHostAndPort(): string {
69-
return this.isPortSpecified() ? this.host + ":" + this.port : this.host;
70-
}
71-
7268
addAlias(...alias: string[]) {
7369
if (!alias || alias.length < 1) {
7470
return;

common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ export class HostMonitor {
528528
}
529529

530530
const latestWriterHostInfo: HostInfo = hosts.find((x) => x.role === HostRole.WRITER);
531-
if (latestWriterHostInfo && writerHostInfo && latestWriterHostInfo.getHostAndPort() !== writerHostInfo.getHostAndPort()) {
531+
if (latestWriterHostInfo && writerHostInfo && latestWriterHostInfo.hostAndPort !== writerHostInfo.hostAndPort) {
532532
this.writerChanged = true;
533-
logger.debug(Messages.get("HostMonitor.writerHostChanged", writerHostInfo.getHostAndPort(), latestWriterHostInfo.getHostAndPort()));
533+
logger.debug(Messages.get("HostMonitor.writerHostChanged", writerHostInfo.hostAndPort, latestWriterHostInfo.hostAndPort));
534534
this.monitor.updateTopologyCache(hosts);
535535
logger.debug(logTopology(hosts, `[hostMonitor ${this.hostInfo.hostId}] `));
536536
}

common/lib/plugins/bluegreen/blue_green_interim_status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class BlueGreenInterimStatus {
104104
this.startTopology == null
105105
? ""
106106
: this.startTopology
107-
.map((x) => x.getHostAndPort() + x.role)
107+
.map((x) => x.hostAndPort + x.role)
108108
.sort()
109109
.join(",")
110110
);
@@ -114,7 +114,7 @@ export class BlueGreenInterimStatus {
114114
this.currentTopology == null
115115
? ""
116116
: this.currentTopology
117-
.map((x) => x.getHostAndPort() + x.role)
117+
.map((x) => x.hostAndPort + x.role)
118118
.sort()
119119
.join(",")
120120
);

common/lib/plugins/bluegreen/blue_green_status_provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ export class BlueGreenStatusProvider {
874874
logger.debug(
875875
"Corresponding hosts:\n" +
876876
Array.from(this.correspondingHosts.entries())
877-
.map(([key, value]) => ` ${key} -> ${value.right == null ? "<null>" : value.right.getHostAndPort()}`)
877+
.map(([key, value]) => ` ${key} -> ${value.right == null ? "<null>" : value.right.hostAndPort}`)
878878
.join("\n")
879879
);
880880

common/lib/plugins/bluegreen/routing/base_connect_routing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { PluginService } from "../../../plugin_service";
2525
export abstract class BaseConnectRouting extends BaseRouting implements ConnectRouting {
2626
isMatch(hostInfo: HostInfo, hostRole: BlueGreenRole): boolean {
2727
return (
28-
(this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.getHostAndPort().toLowerCase())) &&
28+
(this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.hostAndPort.toLowerCase())) &&
2929
(this.role === null || this.role === hostRole)
3030
);
3131
}

common/lib/plugins/bluegreen/routing/base_execute_routing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ConnectionPlugin } from "../../../connection_plugin";
2424
export abstract class BaseExecuteRouting extends BaseRouting implements ExecuteRouting {
2525
isMatch(hostInfo: HostInfo, hostRole: BlueGreenRole): boolean {
2626
return (
27-
(this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.getHostAndPort().toLowerCase())) &&
27+
(this.hostAndPort === null || this.hostAndPort === (hostInfo ?? hostInfo.hostAndPort.toLowerCase())) &&
2828
(this.role === null || this.role === hostRole)
2929
);
3030
}

common/lib/plugins/bluegreen/routing/substitute_connect_routing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ export class SubstituteConnectRouting extends BaseConnectRouting {
9999
// try with another IAM host
100100
}
101101
}
102-
throw new AwsWrapperError(Messages.get("Bgd.inProgressCantOpenConnection", this.substituteHost.getHostAndPort()));
102+
throw new AwsWrapperError(Messages.get("Bgd.inProgressCantOpenConnection", this.substituteHost.hostAndPort));
103103
}
104104

105105
toString(): string {
106-
return `${this.constructor.name} [${this.hostAndPort ?? "<null>"}, ${this.role?.name ?? "<null>"}, substitute: ${this.substituteHost?.getHostAndPort() ?? "<null>"}, iamHosts: ${
107-
this.iamHosts?.map((host) => host.getHostAndPort()).join(", ") ?? "<null>"
106+
return `${this.constructor.name} [${this.hostAndPort ?? "<null>"}, ${this.role?.name ?? "<null>"}, substitute: ${this.substituteHost?.hostAndPort ?? "<null>"}, iamHosts: ${
107+
this.iamHosts?.map((host) => host.hostAndPort).join(", ") ?? "<null>"
108108
}]`;
109109
}
110110
}

common/lib/plugins/connection_tracker/opened_connection_tracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class OpenedConnectionTracker {
3636

3737
// Check if the connection was established using an instance endpoint
3838
if (OpenedConnectionTracker.rdsUtils.isRdsInstance(hostInfo.host)) {
39-
this.trackConnection(hostInfo.getHostAndPort(), client);
39+
this.trackConnection(hostInfo.hostAndPort, client);
4040
return;
4141
}
4242

common/lib/plugins/failover2/failover2_plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class Failover2Plugin extends AbstractConnectionPlugin implements CanRele
138138
return await this._staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService!, props, connectFunc);
139139
}
140140

141-
const hostInfoWithAvailability: HostInfo = this.pluginService.getHosts().find((x) => x.getHostAndPort() === hostInfo.getHostAndPort());
141+
const hostInfoWithAvailability: HostInfo = this.pluginService.getHosts().find((x) => x.hostAndPort === hostInfo.hostAndPort);
142142

143143
let client: ClientWrapper = null;
144144
if (!hostInfoWithAvailability || hostInfoWithAvailability.getAvailability() != HostAvailability.NOT_AVAILABLE) {

0 commit comments

Comments
 (0)