-
Notifications
You must be signed in to change notification settings - Fork 392
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
CB-5933 Connection state is not synchronized with other resources triggering connection state #3119
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5f1ca66
CB-5933. Added event for disconnect datasource
DenisSinelnikov 865d4c5
CB-5933. Added to gql
DenisSinelnikov ed3f056
CB-5933 adds handlers for disconnected/connected events
sergeyteleshev 4f17237
CB-5933. Rename topic
DenisSinelnikov 3e89677
CB-5933. Rename topic
DenisSinelnikov 77db2de
CB-5933. Added event for connect to database
DenisSinelnikov ba6f64c
СB-5933 adds ConnectionDisconnectEventHandler
sergeyteleshev 24939a0
CB-5933. Fixed typo
DenisSinelnikov cd7cf32
Merge remote-tracking branch 'origin/CB-5933-sync-datasource-connecti…
DenisSinelnikov 5643b9a
CB-5933 fixes disconnect handler + adds connect handler for connections
sergeyteleshev 1580432
CB-5933 fix for connected event
sergeyteleshev a85114e
СB-5933 marks outdated connected/disconnected connections on event ha…
sergeyteleshev 1a2aba2
Merge branch 'devel' into CB-5933-sync-datasource-connection
sergeyteleshev 69a7a99
CB-5933 cleanup
sergeyteleshev 2e6d168
CB-5933 pr fixes
sergeyteleshev c8b5567
CB-5933 pr fixes
sergeyteleshev 89baa40
CB-5933. Refactor after review
DenisSinelnikov 76edd39
Merge branch 'devel' into CB-5933-sync-datasource-connection
EvgeniaBzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ import { schemaValidationError } from '@cloudbeaver/core-utils'; | |
|
||
import { CONNECTION_INFO_PARAM_SCHEMA, type IConnectionInfoParams } from './CONNECTION_INFO_PARAM_SCHEMA.js'; | ||
import { ConnectionInfoEventHandler, type IConnectionInfoEvent } from './ConnectionInfoEventHandler.js'; | ||
import { ConnectionStateEventHandler, type IWsDataSourceConnectEvent, type IWsDataSourceDisconnectEvent } from './ConnectionStateEventHandler.js'; | ||
import type { DatabaseConnection } from './DatabaseConnection.js'; | ||
import { DBDriverResource } from './DBDriverResource.js'; | ||
import { parseConnectionKey } from './parseConnectionKey.js'; | ||
|
@@ -97,6 +98,7 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar | |
sessionDataResource: SessionDataResource, | ||
appAuthService: AppAuthService, | ||
connectionInfoEventHandler: ConnectionInfoEventHandler, | ||
connectionStateEventHandler: ConnectionStateEventHandler, | ||
userInfoResource: UserInfoResource, | ||
) { | ||
super(); | ||
|
@@ -163,6 +165,49 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar | |
this, | ||
); | ||
|
||
connectionStateEventHandler.onEvent<IWsDataSourceDisconnectEvent>( | ||
ServerEventId.CbDatasourceDisconnected, | ||
async data => { | ||
const key: IConnectionInfoParams = { | ||
projectId: data.projectId, | ||
connectionId: data.connectionId, | ||
}; | ||
const metadata = this.metadata.get(key); | ||
|
||
if (metadata?.connecting) { | ||
return; | ||
} | ||
|
||
if (this.isConnected(key)) { | ||
this.markOutdated(key); | ||
} | ||
}, | ||
undefined, | ||
this, | ||
); | ||
|
||
connectionStateEventHandler.onEvent<IWsDataSourceConnectEvent>( | ||
ServerEventId.CbDatasourceConnected, | ||
async data => { | ||
const key: IConnectionInfoParams = { | ||
projectId: data.projectId, | ||
connectionId: data.connectionId, | ||
}; | ||
|
||
const metadata = this.metadata.get(key); | ||
|
||
if (metadata?.connecting) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
|
||
if (!this.isConnected(key)) { | ||
this.markOutdated(key); | ||
} | ||
}, | ||
undefined, | ||
this, | ||
); | ||
|
||
connectionInfoEventHandler.onEvent<ResourceKeyList<IConnectionInfoParams>>( | ||
ServerEventId.CbDatasourceUpdated, | ||
key => { | ||
|
26 changes: 26 additions & 0 deletions
26
webapp/packages/core-connections/src/ConnectionStateEventHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { injectable } from '@cloudbeaver/core-di'; | ||
import { type ISessionEvent, type SessionEventId, SessionEventSource, SessionEventTopic, TopicEventHandler } from '@cloudbeaver/core-root'; | ||
import type { WsDataSourceConnectEvent, WsDataSourceDisconnectEvent } from '@cloudbeaver/core-sdk'; | ||
|
||
export type IWsDataSourceDisconnectEvent = WsDataSourceDisconnectEvent; | ||
export type IWsDataSourceConnectEvent = WsDataSourceConnectEvent; | ||
|
||
type ConnectionStateEvent = IWsDataSourceConnectEvent | IWsDataSourceDisconnectEvent; | ||
|
||
@injectable() | ||
export class ConnectionStateEventHandler extends TopicEventHandler<ConnectionStateEvent, ISessionEvent, SessionEventId, SessionEventTopic> { | ||
constructor(sessionEventSource: SessionEventSource) { | ||
super(SessionEventTopic.CbDatasourceConnection, sessionEventSource); | ||
} | ||
|
||
map(event: any): ConnectionStateEvent { | ||
return event; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please use isConnecting (you then can make only one if)