CB-2371 project connections add exceptions (#983)

* CB-2371 project connections add exceptions

* CB-2371 check for errors in data source registry
This commit is contained in:
Ainur
2022-07-27 15:30:18 +03:00
committed by GitHub
parent 15599bc29b
commit 7104dbe034
3 changed files with 34 additions and 3 deletions
@@ -21,6 +21,7 @@ import io.cloudbeaver.VirtualProjectImpl;
import io.cloudbeaver.model.rm.RMUtils;
import io.cloudbeaver.service.sql.WebSQLConstants;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.WebDataSourceUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
@@ -253,9 +254,10 @@ public class LocalResourceController implements RMController {
public String getProjectsDataSources(@NotNull String projectId) throws DBException {
DBPProject projectMetadata = getProjectMetadata(projectId);
DBPDataSourceRegistry registry = projectMetadata.getDataSourceRegistry();
registry.checkForErrors();
DataSourceConfigurationManagerBuffer buffer = new DataSourceConfigurationManagerBuffer();
((DataSourceRegistry)registry).saveConfigurationToManager(new VoidProgressMonitor(), buffer, null);
registry.checkForErrors();
return new String(buffer.getData(), StandardCharsets.UTF_8);
}
@@ -266,7 +268,9 @@ public class LocalResourceController implements RMController {
final DBPDataSourceConfigurationStorage storage = new DataSourceMemoryStorage(configuration.getBytes(StandardCharsets.UTF_8));
final DataSourceConfigurationManager manager = new DataSourceConfigurationManagerBuffer();
registry.loadDataSources(List.of(storage), manager, true, false);
registry.checkForErrors();
registry.saveDataSources();
registry.checkForErrors();
}
@Override
@@ -283,6 +287,7 @@ public class LocalResourceController implements RMController {
log.warn("Could not find datasource " + dataSourceId + " for deletion");
}
}
registry.checkForErrors();
}
@NotNull
@@ -362,6 +362,11 @@ public class WebSession extends AbstractSessionPersistent implements SMSession,
WebConnectionInfo connectionInfo = new WebConnectionInfo(this, ds);
connList.add(connectionInfo);
}
Throwable lastError = registry.getLastError();
if (lastError != null) {
addSessionError(lastError);
log.error("Error refreshing connections from project '" + project.getId() + "'", lastError);
}
}
// Add all provided datasources to the session
@@ -317,6 +317,11 @@ public class WebServiceCore implements DBWServiceCore {
}
sessionRegistry.addDataSource(newDataSource);
try {
sessionRegistry.checkForErrors();
} catch (DBException e) {
throw new DBWebException(e.getMessage(), e.getCause());
}
WebConnectionInfo connectionInfo = new WebConnectionInfo(webSession, newDataSource);
webSession.addConnection(connectionInfo);
@@ -354,6 +359,11 @@ public class WebServiceCore implements DBWServiceCore {
WebServiceUtils.saveAuthProperties(dataSource, dataSource.getConnectionConfiguration(), config.getCredentials(), config.isSaveCredentials());
sessionRegistry.updateDataSource(dataSource);
try {
sessionRegistry.checkForErrors();
} catch (DBException e) {
throw new DBWebException(e.getMessage(), e.getCause());
}
return connectionInfo;
}
@@ -392,6 +402,11 @@ public class WebServiceCore implements DBWServiceCore {
newDataSource.setName(connectionName);
}
projectRegistry.addDataSource(newDataSource);
try {
projectRegistry.checkForErrors();
} catch (DBException e) {
throw new DBWebException(e.getMessage(), e.getCause());
}
WebConnectionInfo connectionInfo = new WebConnectionInfo(webSession, newDataSource);
webSession.addConnection(connectionInfo);
@@ -434,7 +449,7 @@ public class WebServiceCore implements DBWServiceCore {
WebConnectionInfo connectionInfo = new WebConnectionInfo(webSession, newDataSource);
webSession.addConnection(connectionInfo);
dataSourceRegistry.checkForErrors();
return connectionInfo;
} catch (DBException e) {
throw new DBWebException("Error copying connection", e);
@@ -554,7 +569,13 @@ public class WebServiceCore implements DBWServiceCore {
//new DisconnectJob(connectionInfo.getDataSource()).schedule();
}
if (forceDelete) {
webSession.getProjectById(projectId).getDataSourceRegistry().removeDataSource(dataSourceContainer);
DBPDataSourceRegistry registry = webSession.getProjectById(projectId).getDataSourceRegistry();
registry.removeDataSource(dataSourceContainer);
try {
registry.checkForErrors();
} catch (DBException e) {
throw new DBWebException(e.getMessage(), e.getCause());
}
webSession.removeConnection(connectionInfo);
} else {
// Just reset saved credentials