This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 57265da1e4 Introduce configuration options for setting felix shutdown
and reload timeout (#59)
57265da1e4 is described below
commit 57265da1e45f28d8bd48284a1a18d25e173c541f
Author: Luca Palano <[email protected]>
AuthorDate: Fri Aug 11 14:02:27 2023 +0200
Introduce configuration options for setting felix shutdown and reload
timeout (#59)
* Add FRAMEWORK_SHUTDOWN_TIMEOUT and FRAMEWORK_RELOAD_TIMEOUT
* Add reload and shutdown timeouts to the vmstat plugin
* Update vmstat html files introducing reload and shutdown timeouts
---
.../felix/webconsole/WebConsoleConstants.java | 22 ++++++
.../webconsole/internal/servlet/OsgiManager.java | 81 ++++++++++++++--------
.../webconsole/internal/system/VMStatPlugin.java | 19 +++++
.../src/main/resources/templates/vmstat.html | 2 +-
.../main/resources/templates/vmstat_restart.html | 7 +-
5 files changed, 99 insertions(+), 32 deletions(-)
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
index fd9064afc4..b2ad2b97ca 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
@@ -18,6 +18,9 @@
*/
package org.apache.felix.webconsole;
+import java.util.Dictionary;
+
+import org.apache.felix.webconsole.internal.servlet.OsgiManager;
/**
* WebConsoleConstants provides some common constants that are used by plugin
@@ -197,4 +200,23 @@ public interface WebConsoleConstants
* @since 3.1.2
*/
public static final String ATTR_LANG_MAP = "felix.webconsole.langMap";
//$NON-NLS-1$
+
+ /**
+ * The name of the request attribute holding the configuration params
{@link java.util.Map}
+ * for the request (value is "felix.webconsole.configuration").
+ * <p>
+ * The type of this request attribute is <code>Map<String,
Object></code>.
+ * <p>
+ * This map contains the web console configuration params managed by
{@link OsgiManager}.
+ * It can be used to access to the configuration values while processing
requests.
+ * e.g.: The VMStat plugin uses it in order to retrive the
"felix.webconsole.reload.timeout" ({@link OsgiManager#FRAMEWORK_RELOAD_TIMEOUT})
+ * and "felix.webconsole.shutdown.timeout" ({@link
OsgiManager#FRAMEWORK_SHUTDOWN_TIMEOUT}).
+ *
+ * @see OsgiManager
+ * @see OsgiManager#configuration
+ * @see OsgiManager#updateConfiguration( java.util.Dictionary )
+ *
+ * @since 4.8.13
+ */
+ public static final String ATTR_CONFIGURATION =
"felix.webconsole.configuration"; //$NON-NLS-1$
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index d52ede470a..b42633e1bd 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -64,6 +64,7 @@ import
org.apache.felix.webconsole.internal.core.BundlesServlet;
import org.apache.felix.webconsole.internal.filter.FilteringResponseWrapper;
import org.apache.felix.webconsole.internal.i18n.ResourceBundleManager;
import org.apache.felix.webconsole.internal.servlet.Plugin.InternalPlugin;
+import org.apache.felix.webconsole.internal.system.VMStatPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -142,6 +143,10 @@ public class OsgiManager extends GenericServlet
private static final String FRAMEWORK_PROP_LOCALE =
"felix.webconsole.locale"; //$NON-NLS-1$
+ private static final String FRAMEWORK_SHUTDOWN_TIMEOUT =
"felix.webconsole.shutdown.timeout"; //$NON-NLS-1$
+
+ private static final String FRAMEWORK_RELOAD_TIMEOUT =
"felix.webconsole.reload.timeout"; //$NON-NLS-1$
+
static final String FRAMEWORK_PROP_SECURITY_PROVIDERS =
"felix.webconsole.security.providers"; //$NON-NLS-1$
static final String SECURITY_PROVIDER_PROPERTY_NAME =
"webconsole.security.provider.id"; //$NON-NLS-1$
@@ -167,6 +172,12 @@ public class OsgiManager extends GenericServlet
static final String PROP_ENABLE_SECRET_HEURISTIC =
"secret.heuristic.enabled"; //$NON-NLS-1$
static final String PROP_HTTP_SERVICE_SELECTOR = "http.service.filter";
//$NON-NLS-1$
+
+ /** The framework shutdown timeout */
+ public static final String PROP_SHUTDOWN_TIMEOUT = "shutdown.timeout";
+
+ /** The timeout for VMStat plugin page reload */
+ public static final String PROP_RELOAD_TIMEOUT = "reload.timeout";
public static final int DEFAULT_LOG_LEVEL = LogService.LOG_WARNING;
@@ -182,6 +193,10 @@ public class OsgiManager extends GenericServlet
static final String DEFAULT_HTTP_SERVICE_SELECTOR = ""; //$NON-NLS-1$
+ static final int DEFAULT_SHUTDOWN_TIMEOUT = 5; //$NON-NLS-1$
+
+ static final int DEFAULT_RELOAD_TIMEOUT = 40; //$NON-NLS-1$
+
/** Default value for secret heuristics */
public static final boolean DEFAULT_ENABLE_SECRET_HEURISTIC = false;
@@ -361,7 +376,11 @@ public class OsgiManager extends GenericServlet
ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_PROP_LOG_LEVEL, DEFAULT_LOG_LEVEL ) );
this.defaultConfiguration.put( PROP_LOCALE,
ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_PROP_LOCALE, null ) );
-
+ this.defaultConfiguration.put( PROP_SHUTDOWN_TIMEOUT,
+ ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_SHUTDOWN_TIMEOUT, DEFAULT_SHUTDOWN_TIMEOUT ) );
+ this.defaultConfiguration.put( PROP_RELOAD_TIMEOUT,
+ ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_RELOAD_TIMEOUT, DEFAULT_RELOAD_TIMEOUT ) );
+
// configure and start listening for configuration
updateConfiguration(null);
@@ -578,35 +597,8 @@ public class OsgiManager extends GenericServlet
final Locale locale = getConfiguredLocale(request);
final String label = pathInfo.substring(1, slash);
AbstractWebConsolePlugin plugin = getConsolePlugin(label);
- if (plugin != null)
- {
- final Map labelMap = holder.getLocalizedLabelMap(
resourceBundleManager, locale, this.defaultCategory );
- final Object flatLabelMap = labelMap.remove(
WebConsoleConstants.ATTR_LABEL_MAP );
-
- // the official request attributes
- request.setAttribute(WebConsoleConstants.ATTR_LANG_MAP,
getLangMap());
- request.setAttribute(WebConsoleConstants.ATTR_LABEL_MAP,
flatLabelMap);
- request.setAttribute( ATTR_LABEL_MAP_CATEGORIZED, labelMap );
- request.setAttribute(WebConsoleConstants.ATTR_APP_ROOT,
- request.getContextPath() + request.getServletPath());
- request.setAttribute(WebConsoleConstants.ATTR_PLUGIN_ROOT,
- request.getContextPath() + request.getServletPath() + '/' +
label);
-
- // deprecated request attributes
- request.setAttribute(ATTR_LABEL_MAP_OLD, flatLabelMap);
- request.setAttribute(ATTR_APP_ROOT_OLD,
- request.getContextPath() + request.getServletPath());
-
- // fix for https://issues.apache.org/jira/browse/FELIX-3408
- ensureLocaleCookieSet(request, response, locale);
-
- // wrap the response for localization and template variable
replacement
- request = wrapRequest(request, locale);
- response = wrapResponse(request, response, plugin);
-
- plugin.service(request, response);
- }
- else
+
+ if (plugin == null)
{
final String body404 = MessageFormat.format(
resourceBundleManager.getResourceBundle(bundleContext.getBundle(),
locale).getString(
@@ -617,7 +609,36 @@ public class OsgiManager extends GenericServlet
response.setContentType("text/html"); //$NON-NLS-1$
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().println(body404);
+
+ return;
}
+
+ final Map labelMap = holder.getLocalizedLabelMap(
resourceBundleManager, locale, this.defaultCategory );
+ final Object flatLabelMap = labelMap.remove(
WebConsoleConstants.ATTR_LABEL_MAP );
+
+ // the official request attributes
+ request.setAttribute(WebConsoleConstants.ATTR_LANG_MAP, getLangMap());
+ request.setAttribute(WebConsoleConstants.ATTR_LABEL_MAP, flatLabelMap);
+ request.setAttribute( ATTR_LABEL_MAP_CATEGORIZED, labelMap );
+ request.setAttribute(WebConsoleConstants.ATTR_APP_ROOT,
+ request.getContextPath() + request.getServletPath());
+ request.setAttribute(WebConsoleConstants.ATTR_PLUGIN_ROOT,
+ request.getContextPath() + request.getServletPath() + '/' + label);
+ request.setAttribute(WebConsoleConstants.ATTR_CONFIGURATION,
configuration);
+
+ // deprecated request attributes
+ request.setAttribute(ATTR_LABEL_MAP_OLD, flatLabelMap);
+ request.setAttribute(ATTR_APP_ROOT_OLD,
+ request.getContextPath() + request.getServletPath());
+
+ // fix for https://issues.apache.org/jira/browse/FELIX-3408
+ ensureLocaleCookieSet(request, response, locale);
+
+ // wrap the response for localization and template variable replacement
+ request = wrapRequest(request, locale);
+ response = wrapResponse(request, response, plugin);
+
+ plugin.service(request, response);
}
private final void logout(HttpServletRequest request, HttpServletResponse
response)
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
index 336259fc09..1b7c2fba0b 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
@@ -24,6 +24,7 @@ import java.io.StringWriter;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.util.Date;
+import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -32,8 +33,10 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
+import org.apache.felix.webconsole.internal.servlet.OsgiManager;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.service.startlevel.StartLevel;
@@ -170,6 +173,7 @@ public class VMStatPlugin extends SimpleWebConsolePlugin
implements OsgiManagerP
*/
protected void renderContent( HttpServletRequest request,
HttpServletResponse response ) throws IOException
{
+ Map<String, Object> configuration = (Map<String, Object>)
request.getAttribute( WebConsoleConstants.ATTR_CONFIGURATION );
String body;
if ( request.getAttribute( ATTR_TERMINATED ) != null )
@@ -177,6 +181,18 @@ public class VMStatPlugin extends SimpleWebConsolePlugin
implements OsgiManagerP
Object restart = request.getAttribute( PARAM_SHUTDOWN_TYPE );
if ( ( restart instanceof Boolean ) && ( ( Boolean ) restart
).booleanValue() )
{
+ StringWriter json = new StringWriter();
+
+ int reloadTimeout = (int) configuration.get(
OsgiManager.PROP_RELOAD_TIMEOUT );
+ JSONWriter jw = new JSONWriter(json);
+ jw.object();
+ jw.key( "reloadTimeout").value( reloadTimeout );
+ jw.endObject();
+ jw.flush();
+
+ DefaultVariableResolver vars = ( ( DefaultVariableResolver )
WebConsoleUtil.getVariableResolver( request ) );
+ vars.put( "data", json.toString() );
+
body = TPL_VM_RESTART;
}
else
@@ -220,6 +236,9 @@ public class VMStatPlugin extends SimpleWebConsolePlugin
implements OsgiManagerP
jw.key( "mem_used").value(usedMem );
jw.key( "shutdownType").value(shutdownType );
+ int shutdownTimeout = (int) configuration.get(
OsgiManager.PROP_SHUTDOWN_TIMEOUT );
+ jw.key( "shutdownTimeout").value(shutdownTimeout );
+
// only add the processors if the number is available
final int processors = getAvailableProcessors();
if ( processors > 0 )
diff --git a/webconsole/src/main/resources/templates/vmstat.html
b/webconsole/src/main/resources/templates/vmstat.html
index 0c2ad551f0..71c7ee5889 100644
--- a/webconsole/src/main/resources/templates/vmstat.html
+++ b/webconsole/src/main/resources/templates/vmstat.html
@@ -68,7 +68,7 @@ var statData = ${startData};
<input type="hidden" name="shutdown_type"
id="shutdown_type" value="" />
<input class="ui-state-error" type="button"
value="${abort}" onclick="abort('${pluginRoot}')" />
${vmstat.shutdown.in} <span
id='countdowncell'> </span>
- <script
type="text/javascript">if(statData.shutdownTimer) shutdown(3, 'shutdownform2',
'countdowncell');</script>
+ <script
type="text/javascript">if(statData.shutdownTimer)
shutdown(statData.shutdownTimeout, 'shutdownform2', 'countdowncell');</script>
</div>
</form>
</td>
diff --git a/webconsole/src/main/resources/templates/vmstat_restart.html
b/webconsole/src/main/resources/templates/vmstat_restart.html
index 7eaaf60521..2aaf7467f2 100644
--- a/webconsole/src/main/resources/templates/vmstat_restart.html
+++ b/webconsole/src/main/resources/templates/vmstat_restart.html
@@ -1,4 +1,9 @@
<script type="text/javascript" src="${appRoot}/res/ui/vmstat.js"></script>
+<script type="text/javascript">
+// <![CDATA[
+var data = ${data};
+// ]]>
+</script>
<!-- status line -->
<p class="statline">${vmstat.restarting}</p>
@@ -7,7 +12,7 @@
<div style="width:100%; text-align: center">
<input class="ui-state-error" type="submit" value="${reload}" />
${vmstat.reloading.in} <span
id="reloadcountdowncell"> </span>
- <script type="text/javascript">shutdown(10, "reloadform",
"reloadcountdowncell");</script>
+ <script type="text/javascript">shutdown(${data.reloadTimeout},
"reloadform", "reloadcountdowncell");</script>
</div>
</form>