-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
const availableHost = new HostInfoBuilder({ | ||
hostAvailabilityStrategy: new SimpleHostAvailabilityStrategy() | ||
}) | ||
.withHost("someAvailableHost") |
There was a problem hiding this comment.
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
if (ConnectionProviderManager.connProvider) { | ||
if (ConnectionProviderManager.connProvider.acceptsUrl(hostInfo, props)) { | ||
return ConnectionProviderManager.connProvider; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
} |
There was a problem hiding this comment.
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?
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)) { |
There was a problem hiding this comment.
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)) {
87c3b95
to
e78fce6
Compare
common/lib/plugins/default_plugin.ts
Outdated
@@ -57,7 +80,30 @@ export class DefaultPlugin extends AbstractConnectionPlugin { | |||
connectFunc: () => Promise<Type> | |||
): Promise<Type> { | |||
logger.debug(`Start connect for test plugin: ${this.id}`); |
There was a problem hiding this comment.
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?
common/lib/random_host_selector.ts
Outdated
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())); |
There was a problem hiding this comment.
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
throw new AwsWrapperError(Messages.get("HostSelector.noHostsMatchingRole", role.toString())); | |
throw new AwsWrapperError(Messages.get("HostSelector.noHostsMatchingRole", role)); |
e78fce6
to
9937cb2
Compare
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) { |
There was a problem hiding this comment.
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?
common/lib/utils/locales/en.json
Outdated
@@ -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.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.", |
lgtm just a couple small comments |
9937cb2
to
dfb0a93
Compare
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); |
There was a problem hiding this comment.
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?
dfb0a93
to
b374878
Compare
Summary
Description
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.