felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r667270 - in /felix/trunk/webconsole/src/main: java/org/apache/felix/webconsole/internal/core/ java/org/apache/felix/webconsole/internal/misc/ java/org/apache/felix/webconsole/internal/servlet/ resources/res/ui/
Date Thu, 12 Jun 2008 22:18:04 GMT
Author: fmeschbe
Date: Thu Jun 12 15:18:03 2008
New Revision: 667270

URL: http://svn.apache.org/viewvc?rev=667270&view=rev
Log:
FELIX-566 next step in making bundle display more REST-ful:

    requesting ..../bundles lists all bundles
    requesting ..../bundles/<id> just lists the bundle with the given <id> and
its details

bundle actions (start, stop, uninstall, refreshPackages) is now
integrated with the single BundlesServlet handling the bundles
requests

The BundlesServlet is the default start page

Added:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
      - copied, changed from r662438, felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleListRender.java
Removed:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/AjaxBundleDetailsAction.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleListRender.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/RefreshPackagesAction.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/StartAction.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/StopAction.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UninstallAction.java
Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleAction.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/AssemblyListRender.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
    felix/trunk/webconsole/src/main/resources/res/ui/bundles.js

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleAction.java?rev=667270&r1=667269&r2=667270&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleAction.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleAction.java
Thu Jun 12 15:18:03 2008
@@ -28,7 +28,7 @@
 
     protected long getBundleId( HttpServletRequest request )
     {
-        String bundleIdPar = request.getParameter( BundleListRender.BUNDLE_ID );
+        String bundleIdPar = request.getParameter( BundlesServlet.BUNDLE_ID );
         if ( bundleIdPar != null )
         {
             try

Copied: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
(from r662438, felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleListRender.java)
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java?p2=felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java&p1=felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleListRender.java&r1=662438&r2=667270&rev=667270&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleListRender.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
Thu Jun 12 15:18:03 2008
@@ -32,8 +32,6 @@
 import java.util.TreeMap;
 
 import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -43,7 +41,6 @@
 import org.apache.felix.bundlerepository.R4Package;
 import org.apache.felix.webconsole.internal.BaseWebConsolePlugin;
 import org.apache.felix.webconsole.internal.Util;
-import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONWriter;
 import org.osgi.framework.Bundle;
@@ -54,19 +51,19 @@
 import org.osgi.framework.Version;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentConstants;
+import org.osgi.service.log.LogService;
 import org.osgi.service.obr.Repository;
 import org.osgi.service.obr.RepositoryAdmin;
 import org.osgi.service.obr.Resource;
 import org.osgi.service.packageadmin.ExportedPackage;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
-import org.osgi.util.tracker.ServiceTracker;
 
 
 /**
- * The <code>BundleListRender</code> TODO
+ * The <code>BundlesServlet</code> TODO
  */
-public class BundleListRender extends BaseWebConsolePlugin
+public class BundlesServlet extends BaseWebConsolePlugin
 {
 
     public static final String NAME = "bundles";
@@ -169,12 +166,18 @@
 
     protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,
IOException
     {
+        String action = req.getParameter( "action" );
+        if ( "refreshPackages".equals( action ) )
+        {
+            getPackageAdmin().refreshPackages( null );
+        }
+
         boolean success = false;
         Bundle bundle = getBundle( req.getPathInfo() );
         long bundleId = bundle.getBundleId();
+
         if ( bundle != null )
         {
-            String action = req.getParameter( "action" );
             if ( "start".equals( action ) )
             {
                 // start bundle
@@ -185,7 +188,7 @@
                 }
                 catch ( BundleException be )
                 {
-                    // log
+                    getLog().log( LogService.LOG_ERROR, "Cannot start", be );
                 }
             }
             else if ( "stop".equals( action ) )
@@ -198,7 +201,7 @@
                 }
                 catch ( BundleException be )
                 {
-                    // log
+                    getLog().log( LogService.LOG_ERROR, "Cannot stop", be );
                 }
             }
             else if ( "update".equals( action ) )
@@ -217,11 +220,21 @@
                 }
                 catch ( BundleException be )
                 {
-                    // log
+                    getLog().log( LogService.LOG_ERROR, "Cannot uninstall", be );
                 }
             }
         }
 
+        if ( "refreshPackages".equals( action ) )
+        {
+            success = true;
+            getPackageAdmin().refreshPackages( null );
+
+            // refresh completely
+            bundle = null;
+            bundleId = -1;
+        }
+
         if ( success )
         {
             // redirect or 200
@@ -233,13 +246,20 @@
                 {
                     bundleInfo( jw, bundle, true );
                 }
-                else
+                else if ( bundleId >= 0 )
                 {
                     jw.object();
                     jw.key( "bundleId" );
                     jw.value( bundleId );
                     jw.endObject();
                 }
+                else
+                {
+                    jw.object();
+                    jw.key( "reload" );
+                    jw.value( true );
+                    jw.endObject();
+                }
             }
             catch ( JSONException je )
             {
@@ -303,7 +323,7 @@
 
             if ( bundles != null && bundles.length > 0 )
             {
-                sort( bundles );
+                Util.sort( bundles );
 
                 jw.key( "bundles" );
 
@@ -338,7 +358,7 @@
         jw.key( "bundleId" );
         jw.value( bundle.getBundleId() );
         jw.key( "name" );
-        jw.value( getName( bundle ) );
+        jw.value( Util.getName( bundle ) );
         jw.key( "state" );
         jw.value( toStateString( bundle.getState() ) );
         jw.key( "hasStart" );
@@ -448,32 +468,7 @@
     }
 
 
-    private void sort( Bundle[] bundles )
-    {
-        Arrays.sort( bundles, BUNDLE_NAME_COMPARATOR );
-    }
-
-
-    private static String getName( Bundle bundle )
-    {
-        String name = ( String ) bundle.getHeaders().get( Constants.BUNDLE_NAME );
-        if ( name == null || name.length() == 0 )
-        {
-            name = bundle.getSymbolicName();
-            if ( name == null )
-            {
-                name = bundle.getLocation();
-                if ( name == null )
-                {
-                    name = String.valueOf( bundle.getBundleId() );
-                }
-            }
-        }
-        return name;
-    }
-
-
-    public void performAction( JSONWriter jw, Bundle bundle ) throws JSONException
+    private void performAction( JSONWriter jw, Bundle bundle ) throws JSONException
     {
         jw.object();
         jw.key( BUNDLE_ID );
@@ -485,7 +480,7 @@
     }
 
 
-    public void bundleDetails( JSONWriter jw, Bundle bundle ) throws JSONException
+    private void bundleDetails( JSONWriter jw, Bundle bundle ) throws JSONException
     {
         Dictionary headers = bundle.getHeaders();
 
@@ -942,59 +937,4 @@
         return val.toString();
     }
 
-    // ---------- inner classes ------------------------------------------------
-
-    private static final Comparator BUNDLE_NAME_COMPARATOR = new Comparator()
-    {
-        public int compare( Object o1, Object o2 )
-        {
-            return compare( ( Bundle ) o1, ( Bundle ) o2 );
-        }
-
-
-        public int compare( Bundle b1, Bundle b2 )
-        {
-
-            // the same bundles
-            if ( b1 == b2 || b1.getBundleId() == b2.getBundleId() )
-            {
-                return 0;
-            }
-
-            // special case for system bundle, which always is first
-            if ( b1.getBundleId() == 0 )
-            {
-                return -1;
-            }
-            else if ( b2.getBundleId() == 0 )
-            {
-                return 1;
-            }
-
-            // compare the symbolic names
-            int snComp = getName( b1 ).compareToIgnoreCase( getName( b2 ) );
-            if ( snComp != 0 )
-            {
-                return snComp;
-            }
-
-            // same names, compare versions
-            Version v1 = Version.parseVersion( ( String ) b1.getHeaders().get( Constants.BUNDLE_VERSION
) );
-            Version v2 = Version.parseVersion( ( String ) b2.getHeaders().get( Constants.BUNDLE_VERSION
) );
-            int vComp = v1.compareTo( v2 );
-            if ( vComp != 0 )
-            {
-                return vComp;
-            }
-
-            // same version ? Not really, but then, we compare by bundle id
-            if ( b1.getBundleId() < b2.getBundleId() )
-            {
-                return -1;
-            }
-
-            // b1 id must be > b2 id because equality is already checked
-            return 1;
-        }
-    };
 }

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/AssemblyListRender.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/AssemblyListRender.java?rev=667270&r1=667269&r2=667270&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/AssemblyListRender.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/AssemblyListRender.java
Thu Jun 12 15:18:03 2008
@@ -20,11 +20,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.felix.webconsole.internal.core.BundleListRender;
+import org.apache.felix.webconsole.internal.core.BundlesServlet;
 import org.osgi.framework.Bundle;
 
 
-public class AssemblyListRender extends BundleListRender
+public class AssemblyListRender extends BundlesServlet
 {
 
     public static final String NAME = "assemblyList";

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java?rev=667270&r1=667269&r2=667270&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
Thu Jun 12 15:18:03 2008
@@ -44,9 +44,8 @@
 import org.apache.felix.webconsole.internal.compendium.ComponentConfigurationPrinter;
 import org.apache.felix.webconsole.internal.compendium.ComponentRenderAction;
 import org.apache.felix.webconsole.internal.compendium.ConfigManager;
-import org.apache.felix.webconsole.internal.core.BundleListRender;
+import org.apache.felix.webconsole.internal.core.BundlesServlet;
 import org.apache.felix.webconsole.internal.core.InstallAction;
-import org.apache.felix.webconsole.internal.core.RefreshPackagesAction;
 import org.apache.felix.webconsole.internal.core.SetStartLevelAction;
 import org.apache.felix.webconsole.internal.misc.ConfigurationRender;
 import org.apache.felix.webconsole.internal.obr.BundleRepositoryRender;
@@ -90,42 +89,44 @@
     private static final String PROP_MANAGER_ROOT = "manager.root";
 
     /**
-     * @scr.property value="list"
+     * @scr.property valueRef="DEFAULT_PAGE"
      */
     private static final String PROP_DEFAULT_RENDER = "default.render";
 
     /**
-     * @scr.property value="OSGi Management Console"
+     * @scr.property valueRef="DEFAULT_REALM"
      */
     private static final String PROP_REALM = "realm";
 
     /**
-     * @scr.property value="admin"
+     * @scr.property valueRef="DEFAULT_USER_NAME"
      */
     private static final String PROP_USER_NAME = "username";
 
     /**
-     * @scr.property value="admin"
+     * @scr.property valueRef="DEFAULT_PASSWORD"
      */
     private static final String PROP_PASSWORD = "password";
 
+    private static final String DEFAULT_PAGE = BundlesServlet.NAME;
+
+    private static final String DEFAULT_REALM = "OSGi Management Console";
+
+    private static final String DEFAULT_USER_NAME = "admin";
+
+    private static final String DEFAULT_PASSWORD = "admin";
+
     /**
      * The default value for the {@link #PROP_MANAGER_ROOT} configuration
      * property (value is "/system/console").
      */
     private static final String DEFAULT_MANAGER_ROOT = "/system/console";
 
-    //    private static final Class[] PLUGIN_CLASSES =
-    //        { AjaxConfigManagerAction.class, ComponentConfigurationPrinter.class, ComponentRenderAction.class,
-    //        ConfigManager.class, AjaxBundleDetailsAction.class, BundleListRender.class,
InstallAction.class,
-    //        RefreshPackagesAction.class, SetStartLevelAction.class, StartAction.class,
StopAction.class,
-    //        UninstallAction.class, UpdateAction.class, ConfigurationRender.class, GCAction.class,
ShutdownAction.class,
-    //        ShutdownRender.class, VMStatRender.class };
     private static final Class[] PLUGIN_CLASSES =
         { AjaxConfigManagerAction.class, ComponentConfigurationPrinter.class, ComponentRenderAction.class,
-            ConfigManager.class, BundleListRender.class, InstallAction.class, RefreshPackagesAction.class,
-            SetStartLevelAction.class, ConfigurationRender.class, GCAction.class, ShutdownAction.class,
-            ShutdownRender.class, VMStatRender.class, BundleRepositoryRender.class };
+            ConfigManager.class, BundlesServlet.class, InstallAction.class, SetStartLevelAction.class,
+            ConfigurationRender.class, GCAction.class, ShutdownAction.class, ShutdownRender.class,
VMStatRender.class,
+            BundleRepositoryRender.class };
 
     private BundleContext bundleContext;
 
@@ -537,9 +538,9 @@
         Dictionary config = getConfiguration();
 
         // get authentication details
-        String realm = this.getProperty( config, PROP_REALM, "OSGi Management Console" );
-        String userId = this.getProperty( config, PROP_USER_NAME, null );
-        String password = this.getProperty( config, PROP_PASSWORD, null );
+        String realm = this.getProperty( config, PROP_REALM, DEFAULT_REALM );
+        String userId = this.getProperty( config, PROP_USER_NAME, DEFAULT_USER_NAME );
+        String password = this.getProperty( config, PROP_PASSWORD, DEFAULT_PASSWORD );
 
         // register the servlet and resources
         try
@@ -670,7 +671,7 @@
 
         configuration = config;
 
-        defaultRenderName = ( String ) config.get( PROP_DEFAULT_RENDER );
+        defaultRenderName = getProperty( config, PROP_DEFAULT_RENDER, DEFAULT_PAGE );
         if ( defaultRenderName != null && plugins.get( defaultRenderName ) != null
)
         {
             defaultRender = ( Servlet ) plugins.get( defaultRenderName );

Modified: felix/trunk/webconsole/src/main/resources/res/ui/bundles.js
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/bundles.js?rev=667270&r1=667269&r2=667270&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/bundles.js (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/bundles.js Thu Jun 12 15:18:03 2008
@@ -135,7 +135,7 @@
     document.write( "<td class='content' align='right' colspan='5' noWrap>" );
     document.write( "<input class='submit' style='width:auto' type='submit' value='Install
or Update'>" );
     document.write( "&nbsp;" );
-    document.write( "<input class='submit' style='width:auto' type='submit' value='Refresh
Packages' onClick='this.form.action.value=\"refreshPackages\"; return true;'>" );
+    document.write( "<input class='submit' style='width:auto' type='button' value='Refresh
Packages' onClick='changeBundle(0, \"refreshPackages\");'>" );
     document.write( "</td>" );
     document.write( "</tr>" );
     document.write( "</form>" );
@@ -151,43 +151,47 @@
     
 function bundleChanged(obj)
 {
-    var bundleId = obj.bundleId;
-    if (obj.state)
+    if (obj.reload)
     {
-        // has status, so draw the line
-        var span = document.getElementById('bundle' + bundleId);
-        if (span)
-        {
-            span.innerHTML = bundleInternal( obj );
-        }
-        
-        if (obj.props)
-        {
-            var span = document.getElementById('bundle' + bundleId + '_details');
-            if (span && span.innerHTML)
-            {
-                span.innerHTML = bundleDetails( obj.props );
-            }
-        }
-        
+        document.location = document.location;
     }
     else
     {
-        // no status, bundle has been uninstalled
-        var span = document.getElementById('bundle' + bundleId);
-        if (span)
+        var bundleId = obj.bundleId;
+        if (obj.state)
         {
-            span.parentNode.removeChild(span);
+            // has status, so draw the line
+            var span = document.getElementById('bundle' + bundleId);
+            if (span)
+            {
+                span.innerHTML = bundleInternal( obj );
+            }
+            
+            if (obj.props)
+            {
+                var span = document.getElementById('bundle' + bundleId + '_details');
+                if (span && span.innerHTML)
+                {
+                    span.innerHTML = bundleDetails( obj.props );
+                }
+            }
+            
         }
-        var span = document.getElementById('bundle' + bundleId + '_details');
-        if (span)
+        else
         {
-            span.parentNode.removeChild(span);
+            // no status, bundle has been uninstalled
+            var span = document.getElementById('bundle' + bundleId);
+            if (span)
+            {
+                span.parentNode.removeChild(span);
+            }
+            var span = document.getElementById('bundle' + bundleId + '_details');
+            if (span)
+            {
+                span.parentNode.removeChild(span);
+            }
         }
-    }
-    
-    // reload --- should do better and only update the bundle
-    // document.location = document.location;
+    }    
 }
 
     



Mime
View raw message