FELIX-747 Implement OBR installation/update again
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@700067 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java
index af5bf3f..eed0725 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java
@@ -128,7 +128,6 @@
pw.println( "<tr class='content'>" );
pw.println( "<td class='content'>" + repo.getName() + "</td>" );
- pw.println( "<td class='content'>" + repo.getURL() + "</td>" );
pw.print ( "<td class='content'>" );
pw.print ( "<a href='" + repo.getURL() + "' target='_blank' title='Show Repository " + repo.getURL()
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/DeployerThread.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/DeployerThread.java
new file mode 100644
index 0000000..8646187
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/DeployerThread.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.felix.webconsole.internal.obr;
+
+
+import org.apache.felix.webconsole.internal.Logger;
+import org.osgi.service.log.LogService;
+import org.osgi.service.obr.Requirement;
+import org.osgi.service.obr.Resolver;
+import org.osgi.service.obr.Resource;
+
+
+public class DeployerThread extends Thread
+{
+
+ private final Resolver obrResolver;
+
+ private final Logger logger;
+
+ private final boolean startBundles;
+
+
+ public DeployerThread( Resolver obrResolver, Logger logger, boolean startBundles )
+ {
+ this( obrResolver, logger, startBundles, "OBR Bundle Deployer" );
+ }
+
+
+ public DeployerThread( Resolver obrResolver, Logger logger, boolean startBundles, String name )
+ {
+ super( name );
+ this.obrResolver = obrResolver;
+ this.logger = logger;
+ this.startBundles = startBundles;
+ }
+
+
+ public void run()
+ {
+ try
+ {
+ if ( obrResolver.resolve() )
+ {
+
+ logResource( "Installing Requested Resources", obrResolver.getAddedResources() );
+ logResource( "Installing Required Resources", obrResolver.getRequiredResources() );
+ logResource( "Installing Optional Resources", obrResolver.getOptionalResources() );
+
+ obrResolver.deploy( startBundles );
+ }
+ else
+ {
+ logRequirements( "Cannot Install requested bundles due to unsatisfied requirements", obrResolver
+ .getUnsatisfiedRequirements() );
+ }
+ }
+ catch ( Exception ie )
+ {
+ Throwable cause = ( ie.getCause() != null ) ? ie.getCause() : ie;
+ logger.log( LogService.LOG_ERROR, "Cannot install bundles", cause );
+ }
+ }
+
+
+ private void logResource( String message, Resource[] res )
+ {
+ if ( res != null && res.length > 0 )
+ {
+ logger.log( LogService.LOG_INFO, message );
+ for ( int i = 0; i < res.length; i++ )
+ {
+ logger.log( LogService.LOG_INFO, " " + i + ": " + res[i].getSymbolicName() + ", "
+ + res[i].getVersion() );
+ }
+ }
+ }
+
+
+ private void logRequirements( String message, Requirement[] req )
+ {
+ logger.log( LogService.LOG_ERROR, message );
+ for ( int i = 0; req != null && i < req.length; i++ )
+ {
+ logger.log( LogService.LOG_ERROR, " " + i + ": " + req[i].getName() + " (" + req[i].getComment() + ")" );
+ }
+ }
+
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/InstallFromRepoAction.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/InstallFromRepoAction.java
index 109f095..f58c46d 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/InstallFromRepoAction.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/InstallFromRepoAction.java
@@ -17,10 +17,17 @@
package org.apache.felix.webconsole.internal.obr;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.felix.webconsole.Action;
+import org.osgi.service.log.LogService;
+import org.osgi.service.obr.RepositoryAdmin;
+import org.osgi.service.obr.Resolver;
+import org.osgi.service.obr.Resource;
-public abstract class InstallFromRepoAction extends AbstractObrPlugin implements Action
+public class InstallFromRepoAction extends AbstractObrPlugin implements Action
{
public static final String NAME = "installFromOBR";
@@ -37,58 +44,64 @@
return NAME;
}
+
/*
* (non-Javadoc)
*
* @see org.apache.sling.manager.web.internal.Action#performAction(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
- public boolean performAction(HttpServletRequest request,
- HttpServletResponse response) {
+ */
+ public boolean performAction( HttpServletRequest request, HttpServletResponse response )
+ {
// check whether we have to do something
- String[] bundles = request.getParameterValues("bundle");
- if (bundles == null || bundles.length == 0) {
- getLog().log(LogService.LOG_INFO, "No resources to deploy");
+ String[] bundles = request.getParameterValues( "bundle" );
+ if ( bundles == null || bundles.length == 0 )
+ {
+ getLog().log( LogService.LOG_INFO, "No resources to deploy" );
return true;
}
- InstallerService installerService = getInstallerService();
- if (installerService != null) {
- Installer installer = installerService.getInstaller();
+ RepositoryAdmin repoAdmin = getRepositoryAdmin();
+ if ( repoAdmin != null )
+ {
+
+ Resolver resolver = repoAdmin.resolver();
// prepare the deployment
- for (int i = 0; i < bundles.length; i++) {
+ for ( int i = 0; i < bundles.length; i++ )
+ {
String bundle = bundles[i];
- int comma = bundle.indexOf(',');
- String name = (comma > 0) ? bundle.substring(0, comma) : bundle;
- String version = (comma < bundle.length() - 1)
- ? bundle.substring(comma + 1)
- : null;
+ int comma = bundle.indexOf( ',' );
+ String name = ( comma > 0 ) ? bundle.substring( 0, comma ) : bundle;
+ String version = ( comma < bundle.length() - 1 ) ? bundle.substring( comma + 1 ) : null;
- if (name.length() > 0) {
+ if ( name.length() > 0 )
+ {
// no name, ignore this one
- VersionRange versionRange = new VersionRange(version);
- installer.addBundle(name, versionRange, -1);
+ if ( version == null )
+ {
+ version = "*";
+ }
+
+ String filter = "(&(symbolicname=" + name + ")(version=" + version + "))";
+ Resource[] resources = repoAdmin.discoverResources( filter );
+ if ( resources != null && resources.length > 0 )
+ {
+ resolver.add( resources[0] );
+ }
}
+
}
// check whether the "deploystart" button was clicked
- boolean start = request.getParameter("deploystart") != null;
+ boolean start = request.getParameter( "deploystart" ) != null;
- try {
- installer.install(start);
- } catch (InstallerException ie) {
- Throwable cause = (ie.getCause() != null) ? ie.getCause() : ie;
- getLog().log(LogService.LOG_ERROR, "Cannot install bundles",
- cause);
- } finally {
- installer.dispose();
- }
+ DeployerThread dt = new DeployerThread( resolver, getLog(), start );
+ dt.start();
}
// redirect to bundle list
return true;
}
- */
-
}
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 99983b6..5c4e28d 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
@@ -30,6 +30,7 @@
import org.apache.felix.webconsole.internal.core.*;
import org.apache.felix.webconsole.internal.misc.*;
import org.apache.felix.webconsole.internal.obr.BundleRepositoryRender;
+import org.apache.felix.webconsole.internal.obr.InstallFromRepoAction;
import org.apache.felix.webconsole.internal.obr.RefreshRepoAction;
import org.apache.felix.webconsole.internal.system.*;
import org.osgi.framework.*;
@@ -105,7 +106,7 @@
{ ComponentConfigurationPrinter.class, ComponentsServlet.class, ConfigManager.class, BundlesServlet.class,
InstallAction.class, SetStartLevelAction.class, ConfigurationRender.class, GCAction.class,
ShutdownAction.class, ShutdownRender.class, VMStatRender.class, BundleRepositoryRender.class,
- LicenseServlet.class, RefreshRepoAction.class, ShellServlet.class };
+ LicenseServlet.class, RefreshRepoAction.class, InstallFromRepoAction.class, ShellServlet.class };
private BundleContext bundleContext;