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 29, 2024
2 parents 1cda706 + 861a29b commit de61206
Show file tree
Hide file tree
Showing 29 changed files with 317 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.rm.RMProject;
import org.jkiss.dbeaver.model.rm.RMUtils;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceEvent;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.runtime.jobs.DisconnectJob;

Expand Down Expand Up @@ -189,9 +189,9 @@ public List<WebConnectionInfo> getConnections() {
* updates data sources based on event in web session
*
* @param dataSourceIds list of updated connections
* @param type type of event
* @param eventId id of event
*/
public synchronized boolean updateProjectDataSources(@NotNull List<String> dataSourceIds, @NotNull WSEventType type) {
public synchronized boolean updateProjectDataSources(@NotNull List<String> dataSourceIds, @NotNull String eventId) {
var sendDataSourceUpdatedEvent = false;
DBPDataSourceRegistry registry = getDataSourceRegistry();
// save old connections
Expand All @@ -202,22 +202,22 @@ public synchronized boolean updateProjectDataSources(@NotNull List<String> dataS
DBPDataSourceContainer::getId,
Function.identity())
);
if (type == WSEventType.DATASOURCE_CREATED || type == WSEventType.DATASOURCE_UPDATED) {
if (WSDataSourceEvent.CREATED.equals(eventId) || WSDataSourceEvent.UPDATED.equals(eventId)) {
registry.refreshConfig(dataSourceIds);
}
for (String dsId : dataSourceIds) {
DataSourceDescriptor ds = (DataSourceDescriptor) registry.getDataSource(dsId);
if (ds == null) {
continue;
}
switch (type) {
case DATASOURCE_CREATED -> {
switch (eventId) {
case WSDataSourceEvent.CREATED -> {
addConnection(ds);
sendDataSourceUpdatedEvent = true;
}
case DATASOURCE_UPDATED -> // if settings were changed we need to send event
case WSDataSourceEvent.UPDATED -> // if settings were changed we need to send event
sendDataSourceUpdatedEvent |= !ds.equalSettings(oldDataSources.get(dsId));
case DATASOURCE_DELETED -> {
case WSDataSourceEvent.DELETED -> {
WebDataSourceUtils.disconnectDataSource(webSession, ds);
if (registry instanceof DBPDataSourceRegistryCache dsrc) {
dsrc.removeDataSourceFromList(ds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
public class LocalAuthProviderConstants {
public static final String PROVIDER_ID = "local";
public static final String CRED_USER = "user";
public static final String CRED_DISPLAY_NAME = "displayName";
public static final String CRED_PASSWORD = "password";
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.jkiss.dbeaver.model.security.SMObjectType;
import org.jkiss.dbeaver.model.sql.DBQuotaException;
import org.jkiss.dbeaver.model.websocket.event.MessageType;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent;
import org.jkiss.dbeaver.registry.ResourceTypeDescriptor;
import org.jkiss.dbeaver.registry.ResourceTypeRegistry;
Expand Down Expand Up @@ -777,7 +776,6 @@ protected <T> T doProjectOperation(String projectId, RMFileOperation<T> operatio
if (credentialsProvider.getActiveUserCredentials() != null) {
ServletAppUtils.getServletApplication().getEventController().addEvent(
new WSSessionLogUpdatedEvent(
WSEventType.SESSION_LOG_UPDATED,
credentialsProvider.getActiveUserCredentials().getSmSessionId(),
credentialsProvider.getActiveUserCredentials().getUserId(),
MessageType.ERROR,
Expand All @@ -796,7 +794,6 @@ protected <T> T doFileReadOperation(String projectId, Path file, RMFileOperation
if (credentialsProvider.getActiveUserCredentials() != null) {
ServletAppUtils.getServletApplication().getEventController().addEvent(
new WSSessionLogUpdatedEvent(
WSEventType.SESSION_LOG_UPDATED,
credentialsProvider.getActiveUserCredentials().getSmSessionId(),
credentialsProvider.getActiveUserCredentials().getUserId(),
MessageType.ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.jkiss.dbeaver.model.security.SMController;
import org.jkiss.dbeaver.model.sql.DBQuotaException;
import org.jkiss.dbeaver.model.websocket.event.MessageType;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.CommonUtils;
Expand Down Expand Up @@ -602,7 +601,6 @@ public void addSessionMessage(WebServerMessage message) {
sessionMessages.add(message);
}
addSessionEvent(new WSSessionLogUpdatedEvent(
WSEventType.SESSION_LOG_UPDATED,
this.userContext.getSmSessionId(),
this.userContext.getUserId(),
MessageType.ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPDriverLibrary;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class WebDriverRegistry {

Expand All @@ -42,6 +51,7 @@ public synchronized static WebDriverRegistry getInstance() {
return instance;
}

private final List<DBPDriver> applicableDrivers = new ArrayList<>();
private final Set<String> webDrivers = new HashSet<>();

protected WebDriverRegistry() {
Expand All @@ -59,13 +69,45 @@ private void loadExtensions(IExtensionRegistry registry) {
}
}

public boolean isDriverEnabled(DBPDriver driver) {
return webDrivers.contains(driver.getFullId());
public List<DBPDriver> getApplicableDrivers() {
return applicableDrivers;
}

public void refreshApplicableDrivers() {

Check warning on line 76 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/registry/WebDriverRegistry.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/registry/WebDriverRegistry.java:76:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)

Check warning on line 76 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/registry/WebDriverRegistry.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/registry/WebDriverRegistry.java#L76

Missing a Javadoc comment.
this.applicableDrivers.clear();
this.applicableDrivers.addAll(
DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders().stream()
.map(DBPDataSourceProviderDescriptor::getEnabledDrivers)
.flatMap(List::stream)
.filter(this::isDriverApplicable)
.toList());
log.info("Available drivers: " + applicableDrivers.stream().map(DBPDriver::getFullName).collect(Collectors.joining(",")));
}

public boolean validateDriverFilesAvailability() {
return true;
protected boolean isDriverApplicable(@NotNull DBPDriver driver) {
List<? extends DBPDriverLibrary> libraries = driver.getDriverLibraries();
if (!webDrivers.contains(driver.getFullId())) {
return false;
}
boolean hasAllFiles = true;
for (DBPDriverLibrary lib : libraries) {
if (!isDriverLibraryFilePresent(lib)) {
hasAllFiles = false;
log.error("\tDriver '" + driver.getId() + "' is missing library '" + lib.getDisplayName() + "'");
} else {
if (lib.getType() == DBPDriverLibrary.FileType.jar) {
return true;
}
}
}
return hasAllFiles;
}

private boolean isDriverLibraryFilePresent(@NotNull DBPDriverLibrary lib) {
if (lib.getType() == DBPDriverLibrary.FileType.license) {
return true;
}
Path localFile = lib.getLocalFile();
return localFile != null && Files.exists(localFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,10 @@ protected void sendConfigChangedEvent(SMCredentialsProvider credentialsProvider)
public abstract CBServerConfigurationController<T> getServerConfigurationController();

private void refreshDisabledDriversConfig() {
CBPlatform.getInstance().refreshApplicableDrivers();
getDriverRegistry().refreshApplicableDrivers();
CBAppConfig config = getAppConfiguration();
Set<String> disabledDrivers = new LinkedHashSet<>(Arrays.asList(config.getDisabledDrivers()));
for (DBPDriver driver : CBPlatform.getInstance().getApplicableDrivers()) {
for (DBPDriver driver : getDriverRegistry().getApplicableDrivers()) {
if (!driver.isEmbedded() || config.isDriverForceEnabled(driver.getFullId())) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package io.cloudbeaver.server;

import io.cloudbeaver.auth.NoAuthCredentialsProvider;
import io.cloudbeaver.registry.WebDriverRegistry;
import io.cloudbeaver.server.jobs.SessionStateJob;
import io.cloudbeaver.server.jobs.WebDataSourceMonitorJob;
import io.cloudbeaver.server.jobs.WebSessionMonitorJob;
Expand All @@ -27,23 +25,13 @@
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBFileController;
import org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPDriverLibrary;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.runtime.AbstractJob;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.IOUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* CBPlatform
Expand All @@ -59,7 +47,6 @@ public class CBPlatform extends BaseWebPlatform {
private static CBApplication<?> application = null;

private WebServerPreferenceStore preferenceStore;
protected final List<DBPDriver> applicableDrivers = new ArrayList<>();

public static CBPlatform getInstance() {
return (CBPlatform) DBWorkbench.getPlatform();
Expand Down Expand Up @@ -124,10 +111,6 @@ public CBApplication<?> getApplication() {
return application;
}

public List<DBPDriver> getApplicableDrivers() {
return applicableDrivers;
}


@NotNull
@Override
Expand All @@ -140,50 +123,4 @@ public boolean isShuttingDown() {
return false;
}

public void refreshApplicableDrivers() {
this.applicableDrivers.clear();
assert application != null;
WebDriverRegistry driverRegistry = application.getDriverRegistry();

for (DBPDataSourceProviderDescriptor dspd : DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders()) {
for (DBPDriver driver : dspd.getEnabledDrivers()) {
List<? extends DBPDriverLibrary> libraries = driver.getDriverLibraries();
{
if (!driverRegistry.isDriverEnabled(driver)) {
continue;
}
boolean hasAllFiles = true, hasJars = false;
for (DBPDriverLibrary lib : libraries) {
if (driverRegistry.validateDriverFilesAvailability() && !isDriverLibraryFilePresent(lib))
{
hasAllFiles = false;
log.error("\tDriver '" + driver.getId() + "' is missing library '" + lib.getDisplayName() + "'");
} else {
if (lib.getType() == DBPDriverLibrary.FileType.jar) {
hasJars = true;
}
}
}
if (hasAllFiles || hasJars) {
applicableDrivers.add(driver);
}
}
}
}
log.info("Available drivers: " + applicableDrivers.stream().map(DBPDriver::getFullName).collect(Collectors.joining(",")));
}

private boolean isDriverLibraryFilePresent(@NotNull DBPDriverLibrary lib) {
if (lib.getType() == DBPDriverLibrary.FileType.license) {
return true;
}
Path localFile = lib.getLocalFile();
return localFile != null && Files.exists(localFile);
}

@NotNull
@Override
public DBFileController createFileController() {
return getApplication().createFileController(new NoAuthCredentialsProvider());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.security.SMAdminController;
import org.jkiss.dbeaver.model.security.SMObjectPermissionsGrant;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.WSProjectUpdateEvent;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceEvent;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceProperty;
Expand Down Expand Up @@ -108,7 +106,7 @@ private Consumer<BaseWebSession> getUpdateUserDataSourcesInfoConsumer(
return;
}
boolean isAccessibleNow = project.findWebConnectionInfo(dataSourceId) != null;
if (WSEventType.OBJECT_PERMISSIONS_UPDATED.getEventId().equals(event.getId())) {
if (WSObjectPermissionEvent.UPDATED.equals(event.getId())) {
if (isAccessibleNow || !shouldBeAccessible) {
return;
}
Expand All @@ -122,7 +120,7 @@ private Consumer<BaseWebSession> getUpdateUserDataSourcesInfoConsumer(
WSDataSourceProperty.CONFIGURATION
)
);
} else if (WSEventType.OBJECT_PERMISSIONS_DELETED.getEventId().equals(event.getId())) {
} else if (WSObjectPermissionEvent.DELETED.equals(event.getId())) {
if (!isAccessibleNow || shouldBeAccessible) {
return;
}
Expand All @@ -147,7 +145,7 @@ private Consumer<BaseWebSession> getUpdateUserProjectsInfoConsumer(
) {
return (activeUserSession) -> {
try {
if (WSEventType.OBJECT_PERMISSIONS_UPDATED.getEventId().equals(event.getId())) {
if (WSObjectPermissionEvent.UPDATED.equals(event.getId())) {
var accessibleProjectIds = activeUserSession.getUserContext().getAccessibleProjectIds();
if (accessibleProjectIds.contains(event.getObjectId())) {
return;
Expand All @@ -160,7 +158,7 @@ private Consumer<BaseWebSession> getUpdateUserProjectsInfoConsumer(
projectId
)
);
} else if (WSEventType.OBJECT_PERMISSIONS_DELETED.getEventId().equals(event.getId())) {
} else if (WSObjectPermissionEvent.DELETED.equals(event.getId())) {
activeUserSession.removeSessionProject(projectId);
activeUserSession.addSessionEvent(
WSProjectUpdateEvent.delete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.rm.RMEvent;
import org.jkiss.dbeaver.model.rm.RMEventManager;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.resource.WSResourceUpdatedEvent;

/**
Expand All @@ -41,22 +40,22 @@ protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @Not
if (activeUserSession instanceof WebSession) {
var webSession = (WebSession) activeUserSession;
acceptChangesInNavigatorTree(
WSEventType.valueById(event.getId()),
event.getId(),
event.getResourcePath(),
webSession.getProjectById(event.getProjectId())
);
}
activeUserSession.addSessionEvent(event);
}

private void acceptChangesInNavigatorTree(WSEventType eventType, String resourcePath, WebProjectImpl project) {
if (eventType == WSEventType.RM_RESOURCE_CREATED) {
private void acceptChangesInNavigatorTree(@NotNull String eventId, String resourcePath, WebProjectImpl project) {
if (WSResourceUpdatedEvent.CREATED.equals(eventId)) {
RMEventManager.fireEvent(
new RMEvent(RMEvent.Action.RESOURCE_ADD,
project.getRMProject(),
resourcePath)
);
} else if (eventType == WSEventType.RM_RESOURCE_DELETED) {
} else if (WSResourceUpdatedEvent.DELETED.equals(eventId)) {
RMEventManager.fireEvent(
new RMEvent(RMEvent.Action.RESOURCE_DELETE,
project.getRMProject(),
Expand Down
Loading

0 comments on commit de61206

Please sign in to comment.