Skip to content

Commit

Permalink
Cb 4280 refactor cb application configuration logic (#2242)
Browse files Browse the repository at this point in the history
* CB-4280 prettify reading configuration file

* CB-4280 serialize db config, remove it from te

* CB-4280 extract configs from app classes

* CB-4280 resolve conflicts

* CB-4280 fixes after review

* CB-4280 fix copyrights

* CB-4280 add comments

* CB-4280 resolve conflicts

---------

Co-authored-by: mr-anton-t <[email protected]>
  • Loading branch information
yagudin10 and mr-anton-t authored Mar 26, 2024
1 parent d915018 commit cae7699
Show file tree
Hide file tree
Showing 20 changed files with 1,176 additions and 739 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.app;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
* Abstract class that contains methods for loading configuration with gson.
*/
public abstract class BaseServerConfigurationController<T extends WebServerConfiguration> implements WebServerConfigurationController<T> {

protected Gson getGson() {
return getGsonBuilder().create();
}

protected abstract GsonBuilder getGsonBuilder();

public abstract T getServerConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package io.cloudbeaver.model.app;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.cloudbeaver.DataSourceFilter;
import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.WebSessionProjectImpl;
Expand Down Expand Up @@ -102,8 +100,7 @@ public boolean isMultiuser() {
return true;
}

@Nullable
protected Path loadServerConfiguration() throws DBException {
protected boolean loadServerConfiguration() throws DBException {
Path configFilePath = getMainConfigurationFilePath().toAbsolutePath();
Path configFolder = configFilePath.getParent();

Expand All @@ -120,13 +117,13 @@ protected Path loadServerConfiguration() throws DBException {
// Load config file
log.debug("Loading configuration from " + configFilePath);
try {
loadConfiguration(configFilePath);
getServerConfigurationController().loadServerConfiguration(configFilePath);
} catch (Exception e) {
log.error("Error parsing configuration", e);
return null;
return false;
}

return configFilePath;
return true;
}

@Nullable
Expand All @@ -153,7 +150,7 @@ public Path getLogbackConfigPath() {
return getLogbackConfigPath(configFolder);
}

private Path getMainConfigurationFilePath() {
protected Path getMainConfigurationFilePath() {
String configPath = DEFAULT_CONFIG_FILE_PATH;

String[] args = Platform.getCommandLineArgs();
Expand All @@ -179,8 +176,6 @@ private Path getCustomConfigPath(Path configPath, String fileName) {
return Files.exists(customConfigPath) ? customConfigPath : configPath.resolve(fileName);
}

protected abstract void loadConfiguration(Path configPath) throws DBException;

@Override
public WebProjectImpl createProjectImpl(
@NotNull WebSession webSession,
Expand All @@ -207,7 +202,7 @@ public DBSSecretController getSecretController(
return VoidSecretController.INSTANCE;
}

protected static Map<String, Object> getServerConfigProps(Map<String, Object> configProps) {
public static Map<String, Object> getServerConfigProps(Map<String, Object> configProps) {
return JSONUtils.getObject(configProps, "server");
}

Expand Down Expand Up @@ -270,11 +265,7 @@ public WSEventController getEventController() {
return null;
}

protected Gson getGson() {
return getGsonBuilder().create();
}

protected abstract GsonBuilder getGsonBuilder();
public abstract WebServerConfigurationController getServerConfigurationController();

@Override
public boolean isEnvironmentVariablesAccessible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public interface WebApplication extends DBPApplication {

WebAppConfiguration getAppConfiguration();

WebServerConfiguration getServerConfiguration();

Path getDataDirectory(boolean create);

Path getWorkspaceDirectory();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.app;

/**
* Web server configuration.
* Contains only server configuration properties.
*/
public interface WebServerConfiguration {
boolean isDevelMode();

default String getRootURI() {
return "";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.app;

import org.jkiss.dbeaver.DBException;

import java.nio.file.Path;

/**
* Server configuration controller.
* Works with app server configuration (loads, updates)
*/
public interface WebServerConfigurationController<T extends WebServerConfiguration> {

/**
* Loads server configuration.
*/
void loadServerConfiguration(Path configPath) throws DBException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static void addResponseCookie(HttpServletRequest request, HttpServletResp
sessionCookie.setMaxAge((int) (maxSessionIdleTime / 1000));
}

String path = getWebApplication().getRootURI();
String path = getWebApplication().getServerConfiguration().getRootURI();

if (sameSite != null) {
if (!request.isSecure()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public WebServerConfig(CBApplication application) {

@Property
public String getName() {
return CommonUtils.notEmpty(application.getServerName());
return CommonUtils.notEmpty(application.getServerConfiguration().getServerName());
}

@Property
Expand All @@ -61,12 +61,12 @@ public String getWorkspaceId() {

@Property
public String getServerURL() {
return CommonUtils.notEmpty(application.getServerURL());
return CommonUtils.notEmpty(application.getServerConfiguration().getServerURL());
}

@Property
public String getRootURI() {
return CommonUtils.notEmpty(application.getRootURI());
return CommonUtils.notEmpty(application.getServerConfiguration().getRootURI());
}

@Deprecated
Expand Down Expand Up @@ -127,7 +127,7 @@ public boolean isConfigurationMode() {

@Property
public boolean isDevelopmentMode() {
return application.isDevelMode();
return application.getServerConfiguration().isDevelMode();
}

@Property
Expand All @@ -142,7 +142,7 @@ public boolean isResourceManagerEnabled() {

@Property
public long getSessionExpireTime() {
return application.getConfiguredMaxSessionIdleTime();
return application.getServerConfiguration().getMaxSessionIdleTime();
}

@Property
Expand Down
Loading

0 comments on commit cae7699

Please sign in to comment.