Skip to content

Commit

Permalink
Merge branch 'CB-6051-ability-to-download-driver-from-the-maven-repos…
Browse files Browse the repository at this point in the history
…itory' of https://github.com/dbeaver/cloudbeaver into CB-6051-ability-to-download-driver-from-the-maven-repository
  • Loading branch information
devnaumov committed Dec 24, 2024
2 parents 85baf9c + e297174 commit b6c9d9e
Show file tree
Hide file tree
Showing 43 changed files with 883 additions and 199 deletions.
8 changes: 8 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@
"options": {
"cwd": "${workspaceFolder}/webapp"
}
},
{
"label": "Add Custom Plugin",
"type": "shell",
"command": "yarn run add-plugin",
"options": {
"cwd": "${workspaceFolder}/webapp/packages"
}
}
],
"inputs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,41 @@
*/
package io.cloudbeaver.model;

import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.runtime.AbstractJob;

/**
* Web connection info
* Web async task info
*/
public class WebAsyncTaskInfo {

private String id;
private String name;
private boolean running;
@NotNull
private final String id;
@NotNull
private final String name;
private boolean running = false;
private Object result;
private Object extendedResult;
private String status;
private Throwable jobError;

private AbstractJob job;

public WebAsyncTaskInfo(String id, String name) {
public WebAsyncTaskInfo(@NotNull String id, @NotNull String name) {
this.id = id;
this.name = name;
}

@NotNull
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@NotNull
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isRunning() {
return running;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import io.cloudbeaver.model.session.monitor.TaskProgressMonitor;
import io.cloudbeaver.model.user.WebUser;
import io.cloudbeaver.service.DBWSessionHandler;
import io.cloudbeaver.service.sql.WebSQLConstants;
import io.cloudbeaver.utils.CBModelConstants;
import io.cloudbeaver.utils.WebDataSourceUtils;
import io.cloudbeaver.utils.WebEventUtils;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand All @@ -57,7 +59,6 @@
import org.jkiss.dbeaver.model.runtime.AbstractJob;
import org.jkiss.dbeaver.model.runtime.BaseProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.ProxyProgressMonitor;
import org.jkiss.dbeaver.model.security.SMAdminController;
import org.jkiss.dbeaver.model.security.SMConstants;
import org.jkiss.dbeaver.model.security.SMController;
Expand Down Expand Up @@ -511,7 +512,7 @@ public DBRProgressMonitor getProgressMonitor() {
///////////////////////////////////////////////////////
// Async model

public WebAsyncTaskInfo getAsyncTask(String taskId, String taskName, boolean create) {
public WebAsyncTaskInfo getAsyncTask(@NotNull String taskId, @NotNull String taskName, boolean create) {
synchronized (asyncTasks) {
WebAsyncTaskInfo taskInfo = asyncTasks.get(taskId);
if (taskInfo == null && create) {
Expand All @@ -528,7 +529,6 @@ public WebAsyncTaskInfo asyncTaskStatus(String taskId, boolean removeOnFinish) t
if (taskInfo == null) {
throw new DBWebException("Task '" + taskId + "' not found");
}
taskInfo.setRunning(taskInfo.getJob() != null && !taskInfo.getJob().isFinished());
if (removeOnFinish && !taskInfo.isRunning()) {
asyncTasks.remove(taskId);
}
Expand All @@ -551,7 +551,7 @@ public boolean asyncTaskCancel(String taskId) throws DBWebException {
return true;
}

public WebAsyncTaskInfo createAndRunAsyncTask(String taskName, WebAsyncTaskProcessor<?> runnable) {
public WebAsyncTaskInfo createAndRunAsyncTask(@NotNull String taskName, @NotNull WebAsyncTaskProcessor<?> runnable) {
int taskId = TASK_ID.incrementAndGet();
WebAsyncTaskInfo asyncTask = getAsyncTask(String.valueOf(taskId), taskName, true);

Expand All @@ -560,7 +560,8 @@ public WebAsyncTaskInfo createAndRunAsyncTask(String taskName, WebAsyncTaskProce
protected IStatus run(DBRProgressMonitor monitor) {
int curTaskCount = taskCount.incrementAndGet();

TaskProgressMonitor taskMonitor = new TaskProgressMonitor(monitor, asyncTask);
DBRProgressMonitor taskMonitor = new TaskProgressMonitor(monitor, WebSession.this, asyncTask);

try {
Number queryLimit = application.getAppConfiguration().getResourceQuota(WebSQLConstants.QUOTA_PROP_QUERY_LIMIT);
if (queryLimit != null && curTaskCount > queryLimit.intValue()) {
Expand All @@ -572,14 +573,15 @@ protected IStatus run(DBRProgressMonitor monitor) {
asyncTask.setResult(runnable.getResult());
asyncTask.setExtendedResult(runnable.getExtendedResults());
asyncTask.setStatus("Finished");
asyncTask.setRunning(false);
} catch (InvocationTargetException e) {
addSessionError(e.getTargetException());
asyncTask.setJobError(e.getTargetException());
} catch (Exception e) {
asyncTask.setJobError(e);
} finally {
taskCount.decrementAndGet();
asyncTask.setRunning(false);
WebEventUtils.sendAsyncTaskEvent(WebSession.this, asyncTask);
}
return Status.OK_STATUS;
}
Expand Down Expand Up @@ -989,27 +991,6 @@ public void subTask(String name) {
}
}

private static class TaskProgressMonitor extends ProxyProgressMonitor {

private final WebAsyncTaskInfo asyncTask;

public TaskProgressMonitor(DBRProgressMonitor original, WebAsyncTaskInfo asyncTask) {
super(original);
this.asyncTask = asyncTask;
}

@Override
public void beginTask(String name, int totalWork) {
super.beginTask(name, totalWork);
asyncTask.setStatus(name);
}

@Override
public void subTask(String name) {
super.subTask(name);
asyncTask.setStatus(name);
}
}

private record PersistentAttribute(Object value) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.model.session.monitor;

import io.cloudbeaver.model.WebAsyncTaskInfo;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.utils.WebEventUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.ProxyProgressMonitor;

/**
* Task progress monitor.
* Used by async GQL requests.
*/
public class TaskProgressMonitor extends ProxyProgressMonitor {

@NotNull
private final WebAsyncTaskInfo asyncTask;
private final WebSession webSession;

public TaskProgressMonitor(DBRProgressMonitor original, @NotNull WebSession webSession, @NotNull WebAsyncTaskInfo asyncTask) {
super(original);
this.webSession = webSession;
this.asyncTask = asyncTask;
}

@Override
public void beginTask(String name, int totalWork) {
super.beginTask(name, totalWork);
asyncTask.setStatus(name);
WebEventUtils.sendAsyncTaskEvent(webSession, asyncTask);
}

@Override
public void subTask(String name) {
super.subTask(name);
asyncTask.setStatus(name);
WebEventUtils.sendAsyncTaskEvent(webSession, asyncTask);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package io.cloudbeaver.utils;

import io.cloudbeaver.model.WebAsyncTaskInfo;
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.websocket.WSConstants;
import org.jkiss.dbeaver.model.websocket.event.WSEvent;
Expand All @@ -25,6 +27,7 @@
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDatasourceFolderEvent;
import org.jkiss.dbeaver.model.websocket.event.resource.WSResourceProperty;
import org.jkiss.dbeaver.model.websocket.event.resource.WSResourceUpdatedEvent;
import org.jkiss.dbeaver.model.websocket.event.session.WSSessionTaskInfoEvent;

import java.util.List;

Expand Down Expand Up @@ -182,4 +185,14 @@ public static void addRmResourceUpdatedEvent(
ServletAppUtils.getServletApplication().getEventController().addEvent(event);
}

public static void sendAsyncTaskEvent(@NotNull WebSession webSession, @NotNull WebAsyncTaskInfo taskInfo) {
webSession.addSessionEvent(
new WSSessionTaskInfoEvent(
taskInfo.getId(),
taskInfo.getStatus(),
taskInfo.isRunning()
)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ type DriverLibraryInfo {
id: ID!
name: String!
icon: String
libraryFiles: [DriverFileInfo!]
}

type DriverFileInfo @since(version: "24.3.2") {
id: ID!
fileName: String!
icon: String
}

enum ResultDataFormat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ enum CBServerEventId {
cb_object_permissions_updated,
cb_subject_permissions_updated,

cb_database_output_log_updated
cb_database_output_log_updated,

cb_session_task_info_updated @since(version: "24.3.1")
}

# Events sent by client
Expand All @@ -56,6 +58,9 @@ enum CBEventTopic {
cb_object_permissions,
cb_subject_permissions,
cb_database_output_log,

cb_session_task, @since(version: "24.3.1")

cb_datasource_connection,
cb_delete_temp_folder
}
Expand Down Expand Up @@ -182,6 +187,14 @@ type WSOutputLogInfo {
# Add more fields as needed
}

# Async task info status event
type WSAsyncTaskInfo @since(version: "24.3.1") {
id: CBServerEventId!
taskId: ID!
statusName: String
running: Boolean!
}

# Datasource disconnect event
type WSDataSourceDisconnectEvent implements CBServerEvent {
id: CBServerEventId!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.model;

import io.cloudbeaver.WebServiceUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.connection.DBPDriverLibrary;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.registry.driver.DriverDescriptor;

public class WebDriverLibraryFileInfo {

@NotNull
private final DriverDescriptor.DriverFileInfo fileInfo;

public WebDriverLibraryFileInfo(@NotNull DriverDescriptor.DriverFileInfo fileInfo) {
this.fileInfo = fileInfo;
}


@Property
public String getId() {
return fileInfo.getId();
}

@Property
public String getFileName() {
return fileInfo.toString();
}

@Property
public String getIcon() {
if (fileInfo.getType() == DBPDriverLibrary.FileType.license) {
return WebServiceUtils.makeIconId(DBIcon.TYPE_TEXT);
}
return WebServiceUtils.makeIconId(DBIcon.JAR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.cloudbeaver.WebServiceUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPDriverLibrary;
import org.jkiss.dbeaver.model.meta.Property;
Expand Down Expand Up @@ -49,9 +50,14 @@ public String getName() {
}

@Property
public List<String> getLibraryFiles() {
return ((DriverDescriptor) driver).getLibraryFiles(driverLibrary).stream()
.map(f -> f.getFile().getFileName().toString())
@Nullable
public List<WebDriverLibraryFileInfo> getLibraryFiles() {
var libraryFiles = ((DriverDescriptor) driver).getLibraryFiles(driverLibrary);
if (libraryFiles == null) {
return null;
}
return libraryFiles.stream()
.map(WebDriverLibraryFileInfo::new)
.toList();
}

Expand Down
Loading

0 comments on commit b6c9d9e

Please sign in to comment.