Skip to content

Commit

Permalink
CB-3839. Added async error events messages for te
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisSinelnikov committed Sep 18, 2023
1 parent 9d99075 commit 7c1b4fc
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.jkiss.dbeaver.model.security.SMController;
import org.jkiss.dbeaver.model.security.SMObjectType;
import org.jkiss.dbeaver.model.sql.DBQuotaException;
import org.jkiss.dbeaver.model.websocket.event.WSErrorEvent;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.registry.*;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.ArrayUtils;
Expand Down Expand Up @@ -959,12 +961,25 @@ protected <T> T doProjectOperation(String projectId, RMFileOperation<T> operatio

protected <T> T doFileReadOperation(String projectId, Path file, RMFileOperation<T> operation) throws DBException {
for (RMFileOperationHandler fileHandler : fileHandlers) {
try {
fileHandler.beforeFileRead(projectId, file);
} catch (Exception e) {
log.error("Error before file reading", e);
// try {
// fileHandler.beforeFileRead(projectId, file);
// } catch (Exception e) {
if (credentialsProvider.getActiveUserCredentials() != null) {
WebAppUtils.getWebApplication().getEventController().addEvent(
new WSErrorEvent(
WSEventType.SESSION_LOG_MESSAGE_ADDED,
credentialsProvider.getActiveUserCredentials().getSmSessionId(),
credentialsProvider.getActiveUserCredentials().getUserId(),
"123")); //e.getMessage()));
} else {
WebAppUtils.getWebApplication().getEventController().addEvent(
new WSErrorEvent(
WSEventType.SESSION_LOG_MESSAGE_ADDED,
"123")); //e.getMessage()));
}
}
// log.error("Error before file reading", e);
// }
return operation.doOperation();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package io.cloudbeaver.model.session;

import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.websocket.CBWebSessionEventHandler;
Expand Down Expand Up @@ -201,6 +202,8 @@ public void removeSessionProject(@Nullable String projectId) throws DBException
userContext.getAccessibleProjectIds().remove(projectId);
}

public abstract void addSessionMessage(WebServerMessage message);

@Property
public boolean isValid() {
return getRemainingTime() > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package io.cloudbeaver.model.session;

import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.app.WebAuthApplication;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
Expand All @@ -37,6 +38,11 @@ public void addSessionError(Throwable exception) {

}

@Override
public void addSessionMessage(WebServerMessage message) {

}

@Override
public SMSessionPrincipal getSessionPrincipal() {
return null;
Expand Down
3 changes: 3 additions & 0 deletions server/bundles/io.cloudbeaver.server/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<eventHandler class="io.cloudbeaver.server.events.WSUserSecretEventHandlerImpl">
<topic id="cb_user_secret"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.EventHandlerLogSend">
<topic id="cb_session_log"/>
</eventHandler>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2023 DBeaver Corp
*
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of DBeaver Corp and its suppliers, if any.
* The intellectual and technical concepts contained
* herein are proprietary to DBeaver Corp and its suppliers
* and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from DBeaver Corp.
*/
package io.cloudbeaver.server.events;

import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.server.CBPlatform;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.websocket.WSEventHandler;
import org.jkiss.dbeaver.model.websocket.event.WSErrorEvent;

import java.util.Collection;

public class EventHandlerLogSend extends WSDefaultEventHandler<WSErrorEvent> {

protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @NotNull WSErrorEvent event) {
activeUserSession.addSessionMessage(new WebServerMessage(WebServerMessage.MessageType.ERROR, event.getErrorMessage()));
}

protected boolean isAcceptableInSession(@NotNull BaseWebSession activeUserSession, @NotNull WSErrorEvent event) {
return WSWebUtils.isSessionIdEquals(activeUserSession, event.getSessionId()); // skip events from current session
}
}

0 comments on commit 7c1b4fc

Please sign in to comment.