From bd8c5005694f485b3038e660dfdf5488d15d2b92 Mon Sep 17 00:00:00 2001 From: Aleksandr Skoblikov Date: Wed, 9 Oct 2024 17:22:42 +0400 Subject: [PATCH 1/2] CB-5424 QM cleanup job --- .../model/app/BaseWebApplication.java | 8 +++ .../model/app/WebServerConfiguration.java | 9 +++ .../server/WebServerPreferenceStore.java} | 13 ++-- .../src/io/cloudbeaver/server/CBPlatform.java | 4 +- .../server/jobs/PeriodicSystemJob.java | 62 ------------------- .../server/jobs/SessionStateJob.java | 1 + .../server/jobs/WebSessionMonitorJob.java | 1 + 7 files changed, 26 insertions(+), 72 deletions(-) rename server/bundles/{io.cloudbeaver.server/src/io/cloudbeaver/server/CBPreferenceStore.java => io.cloudbeaver.model/src/io/cloudbeaver/server/WebServerPreferenceStore.java} (93%) delete mode 100644 server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/PeriodicSystemJob.java diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java index 810c387d47..87f9b85409 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java @@ -258,4 +258,12 @@ public WSEventController getEventController() { public boolean isEnvironmentVariablesAccessible() { return false; } + + protected void closeResource(String name, Runnable closeFunction) { + try { + closeFunction.run(); + } catch (Exception e) { + log.error("Failed close " + name, e); + } + } } diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java index 1c8fa96c2c..eef17a03fc 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java @@ -16,6 +16,10 @@ */ package io.cloudbeaver.model.app; +import org.jkiss.code.NotNull; + +import java.util.Map; + /** * Web server configuration. * Contains only server configuration properties. @@ -27,4 +31,9 @@ default String getRootURI() { return ""; } + @NotNull + default Map getProductSettings() { + return Map.of(); + } + } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBPreferenceStore.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebServerPreferenceStore.java similarity index 93% rename from server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBPreferenceStore.java rename to server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebServerPreferenceStore.java index a40bf64584..681262bf36 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBPreferenceStore.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebServerPreferenceStore.java @@ -16,6 +16,7 @@ */ package io.cloudbeaver.server; +import io.cloudbeaver.utils.WebAppUtils; import org.jkiss.code.NotNull; import org.jkiss.dbeaver.model.impl.preferences.AbstractPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; @@ -23,16 +24,12 @@ import java.io.IOException; import java.util.Map; -public class CBPreferenceStore extends AbstractPreferenceStore { - @NotNull - private final CBPlatform cbPlatform; +public class WebServerPreferenceStore extends AbstractPreferenceStore { private final DBPPreferenceStore parentStore; - public CBPreferenceStore( - @NotNull CBPlatform cbPlatform, + public WebServerPreferenceStore( @NotNull DBPPreferenceStore parentStore ) { - this.cbPlatform = cbPlatform; this.parentStore = parentStore; } @@ -188,7 +185,7 @@ public void save() throws IOException { } private Map productConf() { - var app = cbPlatform.getApplication(); - return app.getProductConfiguration(); + var app = WebAppUtils.getWebApplication(); + return app.getServerConfiguration().getProductSettings(); } } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBPlatform.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBPlatform.java index 1c4e0fadd5..0cc1833109 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBPlatform.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBPlatform.java @@ -59,7 +59,7 @@ public class CBPlatform extends BaseGQLPlatform { @Nullable private static GQLApplicationAdapter application = null; - private CBPreferenceStore preferenceStore; + private WebServerPreferenceStore preferenceStore; protected final List applicableDrivers = new ArrayList<>(); public static CBPlatform getInstance() { @@ -77,7 +77,7 @@ public static void setApplication(@NotNull GQLApplicationAdapter application) { protected synchronized void initialize() { long startTime = System.currentTimeMillis(); log.info("Initialize web platform...: "); - this.preferenceStore = new CBPreferenceStore(this, WebPlatformActivator.getInstance().getPreferences()); + this.preferenceStore = new WebServerPreferenceStore(WebPlatformActivator.getInstance().getPreferences()); super.initialize(); refreshApplicableDrivers(); diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/PeriodicSystemJob.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/PeriodicSystemJob.java deleted file mode 100644 index 15d4de80d8..0000000000 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/PeriodicSystemJob.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.server.jobs; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.jkiss.code.NotNull; -import org.jkiss.dbeaver.model.app.DBPPlatform; -import org.jkiss.dbeaver.model.runtime.AbstractJob; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; - -public abstract class PeriodicSystemJob extends AbstractJob { - - @NotNull - protected final DBPPlatform platform; - private final long periodMs; - - public PeriodicSystemJob(@NotNull String name, @NotNull DBPPlatform platform, long periodMs) { - super(name); - this.platform = platform; - this.periodMs = periodMs; - - setUser(false); - setSystem(true); - } - - @Override - protected IStatus run(@NotNull DBRProgressMonitor monitor) { - if (platform.isShuttingDown()) { - return Status.OK_STATUS; - } - - doJob(monitor); - - // If the platform is still running after the job is completed, reschedule the job - if (!platform.isShuttingDown()) { - scheduleMonitor(); - } - - return Status.OK_STATUS; - } - - protected abstract void doJob(@NotNull DBRProgressMonitor monitor); - - public void scheduleMonitor() { - schedule(periodMs); - } -} diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java index 354934ebc4..82a100cf59 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java @@ -21,6 +21,7 @@ import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.model.app.DBPPlatform; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; +import org.jkiss.dbeaver.model.runtime.PeriodicSystemJob; public class SessionStateJob extends PeriodicSystemJob { private static final Log log = Log.getLog(SessionStateJob.class); diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java index c17dc270f4..184280fe12 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java @@ -21,6 +21,7 @@ import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.model.app.DBPPlatform; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; +import org.jkiss.dbeaver.model.runtime.PeriodicSystemJob; /** * WebSessionMonitorJob From dbc33b10e678719162d150f2d6380947acbb8144 Mon Sep 17 00:00:00 2001 From: Aleksandr Skoblikov Date: Wed, 9 Oct 2024 18:37:02 +0400 Subject: [PATCH 2/2] CB-5424 review fix --- .../src/io/cloudbeaver/model/app/WebServerConfiguration.java | 4 ++++ .../src/io/cloudbeaver/server/jobs/SessionStateJob.java | 4 ++-- .../src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java index eef17a03fc..82cbfeb05a 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebServerConfiguration.java @@ -16,6 +16,7 @@ */ package io.cloudbeaver.model.app; +import io.cloudbeaver.server.WebServerPreferenceStore; import org.jkiss.code.NotNull; import java.util.Map; @@ -31,6 +32,9 @@ default String getRootURI() { return ""; } + /** + * @return the setting values that will be used in {@link WebServerPreferenceStore} + */ @NotNull default Map getProductSettings() { return Map.of(); diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java index 82a100cf59..01aaffb15a 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/SessionStateJob.java @@ -21,9 +21,9 @@ import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.model.app.DBPPlatform; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; -import org.jkiss.dbeaver.model.runtime.PeriodicSystemJob; +import org.jkiss.dbeaver.model.runtime.PeriodicJob; -public class SessionStateJob extends PeriodicSystemJob { +public class SessionStateJob extends PeriodicJob { private static final Log log = Log.getLog(SessionStateJob.class); private static final int PERIOD_MS = 30_000; // once per 30 seconds private final WebSessionManager sessionManager; diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java index 184280fe12..e73dacdf62 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jobs/WebSessionMonitorJob.java @@ -21,12 +21,12 @@ import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.model.app.DBPPlatform; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; -import org.jkiss.dbeaver.model.runtime.PeriodicSystemJob; +import org.jkiss.dbeaver.model.runtime.PeriodicJob; /** * WebSessionMonitorJob */ -public class WebSessionMonitorJob extends PeriodicSystemJob { +public class WebSessionMonitorJob extends PeriodicJob { private static final Log log = Log.getLog(WebSessionMonitorJob.class); private static final int MONITOR_INTERVAL = 10000; // once per 10 seconds private final WebSessionManager sessionManager;