Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 70154 invoked from network); 17 Feb 2010 09:13:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Feb 2010 09:13:04 -0000 Received: (qmail 6105 invoked by uid 500); 17 Feb 2010 09:13:04 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 6047 invoked by uid 500); 17 Feb 2010 09:13:04 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 6038 invoked by uid 99); 17 Feb 2010 09:13:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Feb 2010 09:13:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Feb 2010 09:12:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E814823888E8; Wed, 17 Feb 2010 09:12:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r910873 - in /felix/trunk/webconsole/src/main: java/org/apache/felix/webconsole/ java/org/apache/felix/webconsole/internal/system/ resources/OSGI-INF/l10n/ resources/res/ui/ resources/templates/ Date: Wed, 17 Feb 2010 09:12:34 -0000 To: commits@felix.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100217091234.E814823888E8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmeschbe Date: Wed Feb 17 09:12:34 2010 New Revision: 910873 URL: http://svn.apache.org/viewvc?rev=910873&view=rev Log: FELIX-1988 Apply 6.vmstat.patch by Valentin Valchev (thanks) with the following change: The WebConsoleUtil.getVariableResolver now presets the default resolver created with the appRoot and pluginRoot properties from the respective request attributes Added: felix/trunk/webconsole/src/main/resources/res/ui/vmstat.js (with props) felix/trunk/webconsole/src/main/resources/templates/vmstat.html (with props) felix/trunk/webconsole/src/main/resources/templates/vmstat_restart.html (with props) felix/trunk/webconsole/src/main/resources/templates/vmstat_stop.html (with props) Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java felix/trunk/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java?rev=910873&r1=910872&r2=910873&view=diff ============================================================================== --- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java (original) +++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java Wed Feb 17 09:12:34 2010 @@ -54,10 +54,13 @@ /** * Returns the {@link VariableResolver} for the given request. *

- * If not resolver - * has yet be created for the requests, an instance of the - * {@link DefaultVariableResolver} is created, placed into the request and - * returned. + * If no resolver has yet be created for the requests, an instance of the + * {@link DefaultVariableResolver} is created with preset properties, + * placed into the request and returned. The preset properties are + * appRoot set to the value of the + * {@link WebConsoleConstants#ATTR_APP_ROOT} request attribute and + * pluginRoot set to the value of the + * {@link WebConsoleConstants#ATTR_PLUGIN_ROOT} request attribute. *

* Note: An object not implementing the {@link VariableResolver} * interface already stored as the @@ -77,7 +80,9 @@ return ( VariableResolver ) resolverObj; } - final VariableResolver resolver = new DefaultVariableResolver(); + final DefaultVariableResolver resolver = new DefaultVariableResolver(); + resolver.put( "appRoot", request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT ) ); + resolver.put( "pluginRoot", request.getAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT ) ); setVariableResolver( request, resolver ); return resolver; } @@ -101,8 +106,8 @@ /** * An utility method, that is used to filter out simple parameter from file * parameter when multipart transfer encoding is used. - * - * This method processes the request and sets a request attribute + * + * This method processes the request and sets a request attribute * {@link AbstractWebConsolePlugin#ATTR_FILEUPLOAD}. The attribute value is a {@link Map} * where the key is a String specifying the field name and the value * is a {@link org.apache.commons.fileupload.FileItem}. @@ -186,12 +191,12 @@ * Utility method to handle relative redirects. * Some application servers like Web Sphere handle relative redirects differently * therefore we should make an absolute URL before invoking send redirect. - * + * * @param request the HTTP request coming from the user * @param response the HTTP response, where data is rendered * @param redirectUrl the redirect URI. * @throws IOException If an input or output exception occurs - * @throws IllegalStateException If the response was committed or if a partial + * @throws IllegalStateException If the response was committed or if a partial * URL is given and cannot be converted into a valid URL */ public static final void sendRedirect(final HttpServletRequest request, @@ -218,8 +223,8 @@ /** * Escapes HTML special chars like: <>&\r\n and space - * - * + * + * * @param text the text to escape * @return the escaped text */ @@ -262,7 +267,7 @@ /** * Retrieves a request parameter and converts it to int. - * + * * @param request the HTTP request * @param name the name of the request parameter * @param _default the default value returned if the parameter is not set or is not a valid integer. @@ -287,9 +292,9 @@ } /** - * Writes a key-value pair in a JSON writer. Write is performed only if both key and + * Writes a key-value pair in a JSON writer. Write is performed only if both key and * value are not null. - * + * * @param jw the writer, where to write the data * @param key the key value, stored under 'key' * @param value the value stored under 'value' Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java?rev=910873&r1=910872&r2=910873&view=diff ============================================================================== --- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java (original) +++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java Wed Feb 17 09:12:34 2010 @@ -20,51 +20,75 @@ import java.io.IOException; -import java.io.PrintWriter; import java.util.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.felix.webconsole.internal.BaseWebConsolePlugin; -import org.apache.felix.webconsole.internal.Util; -import org.apache.felix.webconsole.internal.core.SetStartLevelAction; +import org.apache.commons.io.IOUtils; +import org.apache.felix.webconsole.DefaultVariableResolver; +import org.apache.felix.webconsole.SimpleWebConsolePlugin; +import org.apache.felix.webconsole.WebConsoleUtil; +import org.apache.felix.webconsole.internal.OsgiManagerPlugin; +import org.json.JSONException; +import org.json.JSONObject; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; -import org.osgi.service.log.LogService; +import org.osgi.service.startlevel.StartLevel; -public class VMStatPlugin extends BaseWebConsolePlugin +/** + * VMStatPlugin provides the System Information tab. This particular plugin uses + * more than one templates. + */ +public class VMStatPlugin extends SimpleWebConsolePlugin implements OsgiManagerPlugin { - public static final String LABEL = "vmstat"; - - public static final String TITLE = "System Information"; + private static final String LABEL = "vmstat"; + private static final String TITLE = "System Information"; + private static final String CSS[] = null; private static final String ATTR_TERMINATED = "terminated"; private static final String PARAM_SHUTDOWN_TIMER = "shutdown_timer"; private static final String PARAM_SHUTDOWN_TYPE = "shutdown_type"; - private static final String PARAM_SHUTDOWN_TYPE_RESTART = "Restart"; - private static final String PARAM_SHUTDOWN_TYPE_STOP = "Stop"; + //private static final String PARAM_SHUTDOWN_TYPE_STOP = "Stop"; private static final long startDate = ( new Date() ).getTime(); + // from BaseWebConsolePlugin + private static String START_LEVEL_NAME = StartLevel.class.getName(); - public String getLabel() - { - return LABEL; - } + // templates + private final String TPL_VM_MAIN; + private final String TPL_VM_STOP; + private final String TPL_VM_RESTART; - public String getTitle() + /** Default constructor */ + public VMStatPlugin() { - return TITLE; + super( LABEL, TITLE, CSS ); + // load templates + try + { + TPL_VM_MAIN = IOUtils.toString( getClass().getResourceAsStream( "/templates/vmstat.html" ), "UTF-8" ); + TPL_VM_STOP = IOUtils.toString( getClass().getResourceAsStream( "/templates/vmstat_stop.html" ), "UTF-8" ); + TPL_VM_RESTART = IOUtils.toString( getClass().getResourceAsStream( "/templates/vmstat_restart.html" ), + "UTF-8" ); + } + catch ( IOException e ) + { + throw new RuntimeException( e.toString() ); + } } + /** + * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { @@ -75,6 +99,7 @@ final boolean restart = PARAM_SHUTDOWN_TYPE_RESTART.equals( request.getParameter( PARAM_SHUTDOWN_TYPE ) ); // simply terminate VM in case of shutdown :-) + final Bundle systemBundle = getBundleContext().getBundle( 0 ); Thread t = new Thread( "Stopper" ) { public void run() @@ -88,12 +113,11 @@ // ignore } - getLog().log( LogService.LOG_INFO, "Shutting down server now!" ); + log( "Shutting down server now!" ); // stopping bundle 0 (system bundle) stops the framework try { - Bundle systemBundle = getBundleContext().getBundle( 0 ); if ( restart ) { systemBundle.update(); @@ -105,7 +129,7 @@ } catch ( BundleException be ) { - getLog().log( LogService.LOG_ERROR, "Problem stopping or restarting the Framework", be ); + log( "Problem stopping or restarting the Framework", be ); } } }; @@ -120,178 +144,70 @@ } + /** + * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { - PrintWriter pw = response.getWriter(); - - pw.println( "" ); + String body; if ( request.getAttribute( ATTR_TERMINATED ) != null ) { - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - Object restart = request.getAttribute( PARAM_SHUTDOWN_TYPE ); if ( ( restart instanceof Boolean ) && ( ( Boolean ) restart ).booleanValue() ) { - pw.println( "" ); - - pw.println( "" ); - pw.println( "
Framework is restarting. stand by ..." ); - pw.println( "
" ); - pw.println( " " ); - pw.println( "Reloading in  " ); - pw.println( "" ); - - pw.println( "
" ); - pw.println( "Framework has been stopped." ); + body = TPL_VM_STOP; } - - pw.println( "
" ); - pw.println( "" ); - pw.println( "" ); + response.getWriter().print( body ); return; } - boolean shutdownTimer = false; - String target = request.getRequestURI(); - if ( request.getParameter( PARAM_SHUTDOWN_TIMER ) != null ) - { - target = getLabel(); // ShutdownRender.NAME; - shutdownTimer = true; - } + body = TPL_VM_MAIN; - pw.println( "" ); + long freeMem = Runtime.getRuntime().freeMemory() / 1024; + long totalMem = Runtime.getRuntime().totalMemory() / 1024; + long usedMem = totalMem - freeMem; - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - - pw.println( "" ); - pw.println( "" ); - - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - - pw.println( "" ); - pw.println( "" ); - - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); + DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) ); + vars.put( "startData", json.toString() ); - long freeMem = Runtime.getRuntime().freeMemory() / 1024; - long totalMem = Runtime.getRuntime().totalMemory() / 1024; - long usedMem = totalMem - freeMem; - - this.infoLine( pw, "Java Runtime", System.getProperty( "java.runtime.name" ) + "(build " - + System.getProperty( "java.runtime.version" ) + ")" ); - this.infoLine( pw, "Java Virtual Machine", System.getProperty( "java.vm.name" ) + "(build " - + System.getProperty( "java.vm.version" ) + ", " + System.getProperty( "java.vm.info" ) + ")" ); - this.infoLine( pw, "Total Memory", totalMem + " KB" ); - this.infoLine( pw, "Used Memory", usedMem + " KB" ); - this.infoLine( pw, "Free Memory", freeMem + " KB" ); - - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "" ); - - pw.println( "
Start Level Information:
System Start Level" ); - pw.println( "
" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "  " ); - pw.println( "
" ); - pw.println( "
Default Bundle Start Level" ); - pw.println( "
" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "  " ); - pw.println( "
" ); - pw.println( "
 " ); - pw.println( "
Server Information:
Last Started" ); - pw.println( "" ); - pw.println( "
Framework" ); + boolean shutdownTimer = request.getParameter( PARAM_SHUTDOWN_TIMER ) != null; + String shutdownType = request.getParameter( PARAM_SHUTDOWN_TYPE ); + if ( shutdownType == null ) + shutdownType = ""; - if ( !shutdownTimer ) + JSONObject json = new JSONObject(); + try { - pw.println( "" ); - pw - .println( "" ); - pw - .println( "" ); + json.put( "systemStartLevel", getStartLevel().getStartLevel() ); + json.put( "bundleStartLevel", getStartLevel().getInitialBundleStartLevel() ); + json.put( "lastStarted", startDate ); + json.put( "runtime", System.getProperty( "java.runtime.name" ) + "(build " + + System.getProperty( "java.runtime.version" ) + ")" ); + json.put( "jvm", System.getProperty( "java.vm.name" ) + "(build " + System.getProperty( "java.vm.version" ) + + ", " + System.getProperty( "java.vm.info" ) + ")" ); + json.put( "shutdownTimer", shutdownTimer ); + json.put( "mem_total", totalMem ); + json.put( "mem_free", freeMem ); + json.put( "mem_used", usedMem ); + json.put( "shutdownType", shutdownType ); } - else + catch ( JSONException e ) { - pw.println( "" ); - pw.println( " " ); - pw.println( "Shutdown in  " ); - pw.println( "" ); + throw new IOException( e.toString() ); } - pw.println( "
 " ); - pw.println( "
Java Information:
Garbage Collection" ); - pw.println( "" ); - pw.println( "" ); - pw.println( "
" ); + response.getWriter().print( body ); } - private void infoLine( PrintWriter pw, String label, String value ) + private final StartLevel getStartLevel() { - pw.println( "" ); - pw.println( "" + label + "" ); - pw.println( "" ); - pw.println( value ); - pw.println( "" ); + return ( StartLevel ) getService( START_LEVEL_NAME ); } - } Modified: felix/trunk/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties?rev=910873&r1=910872&r2=910873&view=diff ============================================================================== --- felix/trunk/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties (original) +++ felix/trunk/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties Wed Feb 17 09:12:34 2010 @@ -23,9 +23,31 @@ # to translate the natively encoded files to ISO-8859-1 during bundle build # -# -# There are no resources currently. -# -# In the future, this file will list the keys used in the Web Console bundle, -# which may be translated by localization fragments. -# + +# Common UI +reload=Reload +change=Change +abort=Abort + +# VMStat plugin +vmstat.stopped=Framework has been stopped. +vmstat.restarting=Framework is restarting. stand by ... +vmstat.reloading.in=Reloading in +vmstat.running=System is up and running! +vmstat.sl.title=Start Level Information: +vmstat.sl.system=System Start Level +vmstat.sl.bundle=Default Bundle Start Level +vmstat.info.title=Server Information: +vmstat.lastStarted=Last Started +vmstat.framework=Framework +vmstat.shutdown.in=Shutdown in +vmstat.java.title=Java Information: +vmstat.java.runtime=Java Runtime +vmstat.java.jvm=Java Virtual Machine +vmstat.mem.total=Total Memory +vmstat.mem.used=Used Memory +vmstat.mem.free=Free Memory +vmstat.gc.title=Garbage Collection +vmstat.gc.button=Run + + Added: felix/trunk/webconsole/src/main/resources/res/ui/vmstat.js URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/vmstat.js?rev=910873&view=auto ============================================================================== --- felix/trunk/webconsole/src/main/resources/res/ui/vmstat.js (added) +++ felix/trunk/webconsole/src/main/resources/res/ui/vmstat.js Wed Feb 17 09:12:34 2010 @@ -0,0 +1,42 @@ +/* shuts down server after [num] seconds */ +function shutdown(num, formname, elemid) { + var elem = $('#' + elemid); + var secs=" second"; + var ellipsis="..."; + if (num > 0) { + if (num != 1) { + secs+="s"; + } + elem.html(num+secs+ellipsis); + setTimeout('shutdown('+(--num)+', "'+formname+'", "'+elemid+'")',1000); + } else { + $('#' + formname).submit(); + } +} + +/* aborts server shutdown and redirects to [target] */ +function abort(target) { + top.location.href=target; +} + +/* displays a date in the user's local timezone */ +function localTm(time) { + return (time ? new Date(time) : new Date()).toLocaleString(); +} +/* fill in the data */ +$(document).ready(function() { + if(typeof statData == 'undefined') return; + for(i in statData) { + var target = $('#' + i); + if (target.val()) { + target.val(statData[i]); + } else { + target.text(statData[i]); + } + } + $('#lastStarted').text(localTm(statData.lastStarted)); + var st = statData.shutdownTimer; + $('#shutdownform').css('display', st ? 'none' : 'block'); + $('#shutdownform2').css('display', st ? 'block' : 'none'); + $('#shutdown_type').val(statData.shutdownType); +}); \ No newline at end of file Propchange: felix/trunk/webconsole/src/main/resources/res/ui/vmstat.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/webconsole/src/main/resources/res/ui/vmstat.js ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev Url Added: felix/trunk/webconsole/src/main/resources/templates/vmstat.html URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/templates/vmstat.html?rev=910873&view=auto ============================================================================== --- felix/trunk/webconsole/src/main/resources/templates/vmstat.html (added) +++ felix/trunk/webconsole/src/main/resources/templates/vmstat.html [UTF-8] Wed Feb 17 09:12:34 2010 @@ -0,0 +1,108 @@ + + + + +

${vmstat.running}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
${vmstat.sl.title}
${vmstat.sl.system} +
+
+ + +    +
+
+
${vmstat.sl.bundle} +
+
+ + +    +
+
+
 
${vmstat.info.title}
${vmstat.lastStarted}---
${vmstat.framework} +
+
+ + + + +
+
+
+
+ + + ${vmstat.shutdown.in}   + +
+
+
 
${vmstat.java.title}
${vmstat.java.runtime}-
${vmstat.java.jvm}-
${vmstat.mem.total}-
${vmstat.mem.used}-
${vmstat.mem.free}-
${vmstat.gc.title} +
+
+ + +
+
+
Propchange: felix/trunk/webconsole/src/main/resources/templates/vmstat.html ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/webconsole/src/main/resources/templates/vmstat.html ------------------------------------------------------------------------------ svn:mime-type = text/html; charset=UTF-8 Added: felix/trunk/webconsole/src/main/resources/templates/vmstat_restart.html URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/templates/vmstat_restart.html?rev=910873&view=auto ============================================================================== --- felix/trunk/webconsole/src/main/resources/templates/vmstat_restart.html (added) +++ felix/trunk/webconsole/src/main/resources/templates/vmstat_restart.html [UTF-8] Wed Feb 17 09:12:34 2010 @@ -0,0 +1,13 @@ + + + +

${vmstat.restarting}

+ +
+
+ + ${vmstat.reloading.in}   + +
+
+ Propchange: felix/trunk/webconsole/src/main/resources/templates/vmstat_restart.html ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/webconsole/src/main/resources/templates/vmstat_restart.html ------------------------------------------------------------------------------ svn:mime-type = text/html; charset=UTF-8 Added: felix/trunk/webconsole/src/main/resources/templates/vmstat_stop.html URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/templates/vmstat_stop.html?rev=910873&view=auto ============================================================================== --- felix/trunk/webconsole/src/main/resources/templates/vmstat_stop.html (added) +++ felix/trunk/webconsole/src/main/resources/templates/vmstat_stop.html [UTF-8] Wed Feb 17 09:12:34 2010 @@ -0,0 +1,5 @@ + + + +

${vmstat.stopped}

+ Propchange: felix/trunk/webconsole/src/main/resources/templates/vmstat_stop.html ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/webconsole/src/main/resources/templates/vmstat_stop.html ------------------------------------------------------------------------------ svn:mime-type = text/html; charset=UTF-8