Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: connection provider and connection provider manager #41

Merged
merged 1 commit into from
May 8, 2024

Conversation

crystall-bitquill
Copy link
Contributor

Summary

Description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@crystall-bitquill crystall-bitquill added the ready for review Pull requests that are ready to be reviewed label Apr 29, 2024
const availableHost = new HostInfoBuilder({
hostAvailabilityStrategy: new SimpleHostAvailabilityStrategy()
})
.withHost("someAvailableHost")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "someAvailableHost"/"someUnavailableHost" could be const variable

Comment on lines 35 to 37
if (ConnectionProviderManager.connProvider) {
if (ConnectionProviderManager.connProvider.acceptsUrl(hostInfo, props)) {
return ConnectionProviderManager.connProvider;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (ConnectionProviderManager.connProvider) {
if (ConnectionProviderManager.connProvider.acceptsUrl(hostInfo, props)) {
return ConnectionProviderManager.connProvider;
}
}
if (ConnectionProviderManager.connProvider?.acceptsUrl(hostInfo, props)) {
return ConnectionProviderManager.connProvider;
}

acceptsStrategy(role: HostRole, strategy: string) {
let acceptsStrategy = false;
if (ConnectionProviderManager.connProvider) {
acceptsStrategy = ConnectionProviderManager.connProvider.acceptsStrategy(role, strategy);
}

if (!acceptsStrategy) {
acceptsStrategy = this.defaultProvider.acceptsStrategy(role, strategy);
}

return acceptsStrategy;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this?

Suggested change
acceptsStrategy(role: HostRole, strategy: string) {
let acceptsStrategy = false;
if (ConnectionProviderManager.connProvider) {
acceptsStrategy = ConnectionProviderManager.connProvider.acceptsStrategy(role, strategy);
}
if (!acceptsStrategy) {
acceptsStrategy = this.defaultProvider.acceptsStrategy(role, strategy);
}
return acceptsStrategy;
}
acceptsStrategy(role: HostRole, strategy: string) {
return ConnectionProviderManager.connProvider?.acceptsStrategy(role, strategy) || this.defaultProvider.acceptsStrategy(role, strategy);
}


getHostInfoByStrategy(hosts: HostInfo[], role: HostRole, strategy: string, props: Map<string, any>) {
let host;
if (ConnectionProviderManager.connProvider && ConnectionProviderManager.connProvider.acceptsStrategy(role, strategy)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these equivalent?

if (ConnectionProviderManager.connProvider && ConnectionProviderManager.connProvider.acceptsStrategy(role, strategy)) {

and

if (ConnectionProviderManager.connProvider?.acceptsStrategy(role, strategy)) {

@crystall-bitquill crystall-bitquill force-pushed the connection-provider branch 2 times, most recently from 87c3b95 to e78fce6 Compare May 3, 2024 19:04
@@ -57,7 +80,30 @@ export class DefaultPlugin extends AbstractConnectionPlugin {
connectFunc: () => Promise<Type>
): Promise<Type> {
logger.debug(`Start connect for test plugin: ${this.id}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove this log?

getHost(hosts: HostInfo[], role: HostRole, props?: Map<string, any>): HostInfo {
const eligibleHosts = hosts.filter((hostInfo: HostInfo) => hostInfo.role === role && hostInfo.getAvailability() === HostAvailability.AVAILABLE);
if (eligibleHosts.length === 0) {
throw new AwsWrapperError(Messages.get("HostSelector.noHostsMatchingRole", role.toString()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will print No hosts were found matching the requested '1' role. Need to update the HostRole class to

export enum HostRole {
  UNKNOWN = "unknown",
  WRITER = "writer",
  READER = "reader"
}

then you can just

Suggested change
throw new AwsWrapperError(Messages.get("HostSelector.noHostsMatchingRole", role.toString()));
throw new AwsWrapperError(Messages.get("HostSelector.noHostsMatchingRole", role));

props: Map<string, any>,
defaultConnProvider: ConnectionProvider,
effectiveConnProvider: ConnectionProvider | null
): ConnectionPlugin[] {
const plugins: ConnectionPlugin[] = [];
let pluginCodes: string = props.get(WrapperProperties.PLUGINS.name);
if (pluginCodes === null || pluginCodes === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be simplified to pluginCodes == null? Or do you think it is better practice to be explicit as you've done here?

@@ -1,9 +1,11 @@
{
"ConnectionPluginManager.unknownPluginCode": "Unknown plugin code: '%s'",
"ConnectionPluginManager.failedToConnectWithNewTargetClient": "Failed to connect with a new target for host: '%s'",
"ConnectionProvider.unsupportedHostSpecSelectorStrategy": "Unsupported host selection strategy '%s' specified for this connection provider '%s'. Please visit the documentation for all supported strategies.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"ConnectionProvider.unsupportedHostSpecSelectorStrategy": "Unsupported host selection strategy '%s' specified for this connection provider '%s'. Please visit the documentation for all supported strategies.",
"ConnectionProvider.unsupportedHostInfoSelectorStrategy": "Unsupported host selection strategy '%s' specified for this connection provider '%s'. Please visit the documentation for all supported strategies.",

@joyc-bq
Copy link
Contributor

joyc-bq commented May 7, 2024

lgtm just a couple small comments

const container = new PluginServiceManagerContainer();
this.pluginService = new PluginService(container, this);
this.pluginManager = new PluginManager(container, this.properties);
this.pluginService = new PluginService(container, this, this._properties);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
this._properties - the member is used directly.
However, the call below uses this.properties (which is a getter for this._properties)
The result is the same, but should we choose the same in both cases, either properties or _properties?

@crystall-bitquill crystall-bitquill merged commit 77ea4d0 into main May 8, 2024
2 checks passed
@crystall-bitquill crystall-bitquill deleted the connection-provider branch May 8, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Pull requests that are ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants