Skip to content

Commit

Permalink
Merge branch 'main' into iam-integration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlamz committed Jun 5, 2024
2 parents b6d4702 + 85507b1 commit 00374ac
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 245 deletions.
16 changes: 4 additions & 12 deletions common/lib/authentication/aws_secrets_manager_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,12 @@ export class SecretCacheKey {
}

export class Secret {
private readonly _username: string;
private readonly _password: string;
readonly username: string;
readonly password: string;

constructor(username: string, password: string) {
this._username = username;
this._password = password;
}

get username(): string {
return this._username;
}

get password(): string | null {
return this._password;
this.username = username;
this.password = password;
}
}

Expand Down
1 change: 0 additions & 1 deletion common/lib/authentication/iam_authentication_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { Messages } from "../utils/messages";
import { logger } from "../../logutils";
import { AwsWrapperError } from "../utils/errors";
import { HostInfo } from "../host_info";
import { Signer } from "@aws-sdk/rds-signer";
import { AwsCredentialsManager } from "./aws_credentials_manager";
import { AbstractConnectionPlugin } from "../abstract_connection_plugin";
import { WrapperProperties } from "../wrapper_property";
Expand Down
41 changes: 10 additions & 31 deletions common/lib/aws_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { PluginServiceManagerContainer } from "./plugin_service_manager_container";
import { PluginService } from "./plugin_service";
import { HostInfo } from "./host_info";
import { WrapperProperties } from "./wrapper_property";
import { ErrorHandler } from "./error_handler";
import { DatabaseDialect, DatabaseType } from "./database_dialect/database_dialect";
import { ConnectionUrlParser } from "./utils/connection_url_parser";
Expand All @@ -27,22 +26,22 @@ import { EventEmitter } from "stream";
import { DriverConnectionProvider } from "./driver_connection_provider";

export abstract class AwsClient extends EventEmitter {
private _defaultPort: number = -1;
protected pluginManager: PluginManager;
protected pluginService: PluginService;
private _defaultPort: number = -1;
private _config: any;
protected isConnected: boolean = false;
protected _isReadOnly: boolean = false;
protected _isAutoCommit: boolean = true;
protected _catalog: string = "";
protected _schema: string = "";
protected _isolationLevel: number = 0;
private readonly _properties: Map<string, any>;
private _targetClient: any = null;
protected _errorHandler: ErrorHandler;
protected _createClientFunc?: (config: any) => any;
protected _connectFunc?: () => Promise<any>;
protected _connectionUrlParser: ConnectionUrlParser;
readonly properties: Map<string, any>;
config: any;
targetClient: any;

protected constructor(
config: any,
Expand All @@ -55,27 +54,27 @@ export abstract class AwsClient extends EventEmitter {
this._errorHandler = errorHandler;
this._connectionUrlParser = parser;

this._properties = new Map<string, any>(Object.entries(config));
this.properties = new Map<string, any>(Object.entries(config));

const defaultConnProvider = new DriverConnectionProvider();
const effectiveConnProvider = null;
// TODO: check for configuration profile to update the effectiveConnProvider

const container = new PluginServiceManagerContainer();
this.pluginService = new PluginService(container, this, dbType, knownDialectsByCode, this.properties);
this.pluginManager = new PluginManager(container, this._properties, defaultConnProvider, effectiveConnProvider);
this.pluginManager = new PluginManager(container, this.properties, defaultConnProvider, effectiveConnProvider);

// TODO: properly set up host info
const host: string = this._properties.get("host");
const port: number = this._properties.get("port");
const host: string = this.properties.get("host");
const port: number = this.properties.get("port");

this.pluginService.setCurrentHostInfo(new HostInfo(host, port));
}

protected async internalConnect() {
const hostListProvider: HostListProvider = this.pluginService
.getDialect()
.getHostListProvider(this._properties, this._properties.get("host"), this.pluginService);
.getHostListProvider(this.properties, this.properties.get("host"), this.pluginService);
this.pluginService.setHostListProvider(hostListProvider);
const info = this.pluginService.getCurrentHostInfo();
if (info != null) {
Expand All @@ -91,26 +90,6 @@ export abstract class AwsClient extends EventEmitter {
this.isConnected = true;
}

get properties(): Map<string, any> {
return this._properties;
}

get config(): any {
return this._config;
}

set config(value: any) {
this._config = value;
}

get targetClient(): any {
return this._targetClient;
}

set targetClient(value: any) {
this._targetClient = value;
}

get defaultPort(): number {
return this._defaultPort;
}
Expand Down Expand Up @@ -159,6 +138,6 @@ export abstract class AwsClient extends EventEmitter {
if (!this.targetClient) {
return Promise.resolve(false);
}
return await this.pluginService.getDialect().isClientValid(this.targetClient);
return await this.pluginService.isClientValid(this.targetClient);
}
}
2 changes: 1 addition & 1 deletion common/lib/database_dialect/database_dialect_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

import { DatabaseDialect, DatabaseType } from "./database_dialect";
import { DatabaseDialect } from "./database_dialect";

export interface DatabaseDialectProvider {
getDialect(props: Map<string, any>): DatabaseDialect;
Expand Down
98 changes: 25 additions & 73 deletions common/lib/host_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ export class HostInfo {
public static readonly NO_PORT: number = -1;
public static readonly DEFAULT_WEIGHT: number = 100;

private readonly _host: string;
private readonly _port: number;
private _availability: HostAvailability;
private readonly _role: HostRole;
readonly host: string;
readonly port: number;
readonly role: HostRole;
readonly weight: number; // Greater or equal 0. Lesser the weight, the healthier node.
readonly lastUpdateTime: number;
availability: HostAvailability;
allAliases: Set<string> = new Set<string>();
hostId?: string;
hostAvailabilityStrategy: HostAvailabilityStrategy;
protected aliases: Set<string> = new Set<string>();
private _allAliases: Set<string> = new Set<string>();
private readonly _weight: number; // Greater or equal 0. Lesser the weight, the healthier node.
private _hostId?: string;
private readonly _lastUpdateTime: number;
private _hostAvailabilityStrategy: HostAvailabilityStrategy;

constructor(
host: string,
Expand All @@ -43,33 +43,17 @@ export class HostInfo {
lastUpdateTime: number = Date.now(),
hostAvailabilityStrategy: HostAvailabilityStrategy = new SimpleHostAvailabilityStrategy()
) {
this._host = host;
this._port = port;
this._availability = availability;
this._role = role;
this._weight = weight;
this._lastUpdateTime = lastUpdateTime;
this._hostAvailabilityStrategy = hostAvailabilityStrategy;
}

get host(): string {
return this._host;
}

get port(): number {
return this._port;
}

get hostId(): string | undefined {
return this._hostId;
}

set hostId(id: string | undefined) {
this._hostId = id;
this.host = host;
this.port = port;
this.availability = availability;
this.role = role;
this.weight = weight;
this.lastUpdateTime = lastUpdateTime;
this.hostAvailabilityStrategy = hostAvailabilityStrategy;
}

isPortSpecified(): boolean {
return this._port != HostInfo.NO_PORT;
return this.port != HostInfo.NO_PORT;
}

addAlias(...alias: string[]) {
Expand All @@ -79,7 +63,7 @@ export class HostInfo {

alias.forEach((x) => {
this.aliases.add(x);
this._allAliases.add(x);
this.allAliases.add(x);
});
}

Expand All @@ -90,7 +74,7 @@ export class HostInfo {

aliases.forEach((x) => {
this.aliases.delete(x);
this._allAliases.delete(x);
this.allAliases.delete(x);
});
}

Expand All @@ -101,64 +85,32 @@ export class HostInfo {
}

get asAlias() {
return this.isPortSpecified() ? `${this._host}:${this.port}` : this.host;
return this.isPortSpecified() ? `${this.host}:${this.port}` : this.host;
}

get url() {
let url = this.isPortSpecified() ? `${this._host}:${this.port}` : this.host;
let url = this.isPortSpecified() ? `${this.host}:${this.port}` : this.host;
if (!url.endsWith("/")) {
url += "/";
}

return url;
}

get availability(): HostAvailability {
return this._availability;
}

set availability(availability: HostAvailability) {
this._availability = availability;
}

set hostAvailabilityStrategy(value: HostAvailabilityStrategy) {
this._hostAvailabilityStrategy = value;
}

get role(): HostRole {
return this._role;
}

get allAliases(): Set<string> {
return this._allAliases;
}

get weight(): number {
return this._weight;
}

get lastUpdateTime(): number {
return this._lastUpdateTime;
}

get hostAvailabilityStrategy(): HostAvailabilityStrategy {
return this._hostAvailabilityStrategy;
}

equals(other: HostInfo): boolean {
return this.port === other.port && this.availability === other.availability && this.role === other.role && this.weight === other.weight;
}

getAvailability(): HostAvailability {
if (this._hostAvailabilityStrategy) {
return this._hostAvailabilityStrategy.getHostAvailability(this._availability);
if (this.hostAvailabilityStrategy) {
return this.hostAvailabilityStrategy.getHostAvailability(this.availability);
}

return this._availability;
return this.availability;
}

getRawAvailability(): HostAvailability {
return this._availability;
return this.availability;
}

setAvailability(availability: HostAvailability) {}
Expand Down
2 changes: 0 additions & 2 deletions common/lib/plugin_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { AwsWrapperError } from "./utils/errors";
import { Messages } from "./utils/messages";
import { PluginServiceManagerContainer } from "./plugin_service_manager_container";
import { HostListProviderService } from "./host_list_provider_service";
import { AwsClient } from "./aws_client";
import { PluginService } from "./plugin_service";
import { HostChangeOptions } from "./host_change_options";
import { OldConnectionSuggestionAction } from "./old_connection_suggestion_action";
import { HostRole } from "./host_role";
Expand Down
18 changes: 7 additions & 11 deletions common/lib/plugin_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export class PluginService implements ErrorHandler, HostListProviderService {
private _hostListProvider?: HostListProvider;
private _initialConnectionHostInfo?: HostInfo;
private _isInTransaction: boolean = false;
private readonly _props: Map<string, any>;
private pluginServiceManagerContainer: PluginServiceManagerContainer;
protected hosts: HostInfo[] = [];
private dbDialectProvider: DatabaseDialectProvider;
private initialHost: string;
private dialect: DatabaseDialect;
protected readonly sessionStateService: SessionStateService;
protected static readonly hostAvailabilityExpiringCache: CacheMap<string, HostAvailability> = new CacheMap<string, HostAvailability>();
readonly props: Map<string, any>;

constructor(
container: PluginServiceManagerContainer,
Expand All @@ -61,17 +61,13 @@ export class PluginService implements ErrorHandler, HostListProviderService {
) {
this._currentClient = client;
this.pluginServiceManagerContainer = container;
this._props = props;
this.dbDialectProvider = new DatabaseDialectManager(knownDialectsByCode, dbType, this._props);
this.props = props;
this.dbDialectProvider = new DatabaseDialectManager(knownDialectsByCode, dbType, this.props);
this.initialHost = props.get(WrapperProperties.HOST.name);
this.sessionStateService = new SessionStateServiceImpl(this, this._props);
this.sessionStateService = new SessionStateServiceImpl(this, this.props);
container.pluginService = this;

this.dialect = this.dbDialectProvider.getDialect(this._props);
}

get props(): Map<string, any> {
return this._props;
this.dialect = this.dbDialectProvider.getDialect(this.props);
}

isInTransaction(): boolean {
Expand Down Expand Up @@ -343,13 +339,13 @@ export class PluginService implements ErrorHandler, HostListProviderService {

async updateDialect(targetClient: any) {
const originalDialect = this.dialect;
this.dialect = await this.dbDialectProvider.getDialectForUpdate(targetClient, this.initialHost, this._props.get(WrapperProperties.HOST.name));
this.dialect = await this.dbDialectProvider.getDialectForUpdate(targetClient, this.initialHost, this.props.get(WrapperProperties.HOST.name));

if (originalDialect === this.dialect) {
return;
}

this._hostListProvider = this.dialect.getHostListProvider(this._props, this._props.get(WrapperProperties.HOST.name), this);
this._hostListProvider = this.dialect.getHostListProvider(this.props, this.props.get(WrapperProperties.HOST.name), this);
}

private async updateReadOnly(statements: string[]) {
Expand Down
Loading

0 comments on commit 00374ac

Please sign in to comment.