You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2014/10/10 18:12:45 UTC

svn commit: r1630931 - /sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/

Author: cziegeler
Date: Fri Oct 10 16:12:45 2014
New Revision: 1630931

URL: http://svn.apache.org/r1630931
Log:
Separate install from start task

Added:
    sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java   (with props)
Modified:
    sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/InstallSubsystemTask.java
    sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/SubsystemInstaller.java
    sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UninstallSubsystemTask.java
    sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UpdateSubsystemTask.java

Modified: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/InstallSubsystemTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/InstallSubsystemTask.java?rev=1630931&r1=1630930&r2=1630931&view=diff
==============================================================================
--- sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/InstallSubsystemTask.java (original)
+++ sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/InstallSubsystemTask.java Fri Oct 10 16:12:45 2014
@@ -28,6 +28,9 @@ import org.apache.sling.installer.api.ta
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
 import org.osgi.service.subsystem.Subsystem;
 
+/**
+ * This is the subsystem install task.
+ */
 public class InstallSubsystemTask extends InstallTask {
 
     private static final String INSTALL_ORDER = "53-";
@@ -46,8 +49,8 @@ public class InstallSubsystemTask extend
 
         try {
             final Subsystem sub = this.rootSubsystem.install(tr.getURL(), tr.getInputStream());
-            sub.start();
-            ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.INSTALLED));
+            ctx.addTaskToCurrentCycle(new StartSubsystemTask(this.getResourceGroup(), sub));
+            ctx.log("Installed new subsystem {}", sub);
         } catch (final IOException e) {
             ctx.log("Unable to install subsystem {} : {}", tr, e);
             ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.IGNORED));

Added: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java?rev=1630931&view=auto
==============================================================================
--- sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java (added)
+++ sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java Fri Oct 10 16:12:45 2014
@@ -0,0 +1,57 @@
+/*
+ * 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.sling.installer.factories.subsystems.impl;
+
+import org.apache.sling.installer.api.tasks.ChangeStateTask;
+import org.apache.sling.installer.api.tasks.InstallTask;
+import org.apache.sling.installer.api.tasks.InstallationContext;
+import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.TaskResource;
+import org.apache.sling.installer.api.tasks.TaskResourceGroup;
+import org.osgi.service.subsystem.Subsystem;
+
+/**
+ * This is the subsystem start task.
+ */
+public class StartSubsystemTask extends InstallTask {
+
+    private static final String INSTALL_ORDER = "55-";
+
+    private final Subsystem subsystem;
+
+    public StartSubsystemTask(final TaskResourceGroup grp, final Subsystem system) {
+        super(grp);
+        this.subsystem = system;
+    }
+
+    @Override
+    public void execute(final InstallationContext ctx) {
+        final TaskResource tr = this.getResource();
+        ctx.log("Starting subsystem from {}", tr);
+
+        this.subsystem.start();
+        ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.INSTALLED));
+        ctx.log("Started subsystem {}", this.subsystem);
+    }
+
+    @Override
+    public String getSortKey() {
+        return INSTALL_ORDER + getResource().getURL();
+    }
+}

Propchange: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/StartSubsystemTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/SubsystemInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/SubsystemInstaller.java?rev=1630931&r1=1630930&r2=1630931&view=diff
==============================================================================
--- sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/SubsystemInstaller.java (original)
+++ sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/SubsystemInstaller.java Fri Oct 10 16:12:45 2014
@@ -42,15 +42,19 @@ import org.osgi.framework.InvalidSyntaxE
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.Subsystem.State;
 import org.osgi.service.subsystem.SubsystemConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * This is an extension for the OSGi installer
- * It listens for files ending with ".esa" and a proper manifest. Though subsystems does
- * not require a complete manifest, the installer supports only subsystems with the
- * basic info.
+ * It listens for files ending with ".esa" and a proper subsystem manifest.
+ * Though subsystems does not require a complete manifest, the installer supports
+ * only subsystems with the basic info (name and version).
+ *
+ * As subsystems currently do not support an update, an uninstall/install is done
+ * instead - which will lose bundle private data, bound configurations etc.
  */
 public class SubsystemInstaller
     implements ResourceTransformer, InstallTaskFactory {
@@ -175,45 +179,55 @@ public class SubsystemInstaller
                 // search a subsystem with the symbolic name
                 final ServiceReference<Subsystem> ref = this.getSubsystemReference(info.symbolicName);
 
-                final Version newVersion = new Version(info.version);
-                final Version oldVersion = (ref == null ? null : (Version)ref.getProperty("subsystem.version"));
+                final Subsystem currentSubsystem = (ref != null ? this.bundleContext.getService(ref) : null);
+                try {
+                    final Version newVersion = new Version(info.version);
+                    final Version oldVersion = (ref == null ? null : (Version)ref.getProperty("subsystem.version"));
 
-                // Install
-                if ( rsrc.getState() == ResourceState.INSTALL ) {
-                    if ( oldVersion != null ) {
-
-                        final int compare = oldVersion.compareTo(newVersion);
-                        if (compare < 0) {
-                            // installed version is lower -> update
-                            result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
-                        } else if ( compare == 0 && isSnapshot(newVersion) ) {
-                            // same version but snapshot -> update
-                            result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
+                    // Install
+                    if ( rsrc.getState() == ResourceState.INSTALL ) {
+                        if ( oldVersion != null ) {
+
+                            final int compare = oldVersion.compareTo(newVersion);
+                            if (compare < 0) {
+                                // installed version is lower -> update
+                                result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
+                            } else if ( compare == 0 && isSnapshot(newVersion) ) {
+                                // same version but snapshot -> update
+                                result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
+                            } else if ( compare == 0 && currentSubsystem != null && currentSubsystem.getState() != State.ACTIVE ) {
+                                // try to start the version
+                                result = new StartSubsystemTask(toActivate, currentSubsystem);
+                            } else {
+                                logger.info("{} is not installed, subsystem with same or higher version is already installed: {}", info, newVersion);
+                                result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
+                            }
                         } else {
-                            logger.debug("{} is not installed, subsystem with same or higher version is already installed: {}", info, newVersion);
-                            result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
+                            result = new InstallSubsystemTask(toActivate, this.rootSubsystem);
                         }
-                    } else {
-                        result = new InstallSubsystemTask(toActivate, this.rootSubsystem);
-                    }
-
-                // Uninstall
-                } else if ( rsrc.getState() == ResourceState.UNINSTALL ) {
-                    if ( oldVersion == null ) {
-                        logger.error("Nothing to uninstall. {} is currently not installed.", info);
-                        result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
-                    } else {
 
-                        final int compare = oldVersion.compareTo(newVersion);
-                        if ( compare == 0 ) {
-                            result = new UninstallSubsystemTask(toActivate, this.bundleContext, ref);
-                        } else {
-                            logger.error("Nothing to uninstall. {} is currently not installed, different version is installed {}", info, oldVersion);
+                    // Uninstall
+                    } else if ( rsrc.getState() == ResourceState.UNINSTALL ) {
+                        if ( oldVersion == null ) {
+                            logger.error("Nothing to uninstall. {} is currently not installed.", info);
                             result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
+                        } else {
+
+                            final int compare = oldVersion.compareTo(newVersion);
+                            if ( compare == 0 ) {
+                                result = new UninstallSubsystemTask(toActivate, this.bundleContext, ref);
+                            } else {
+                                logger.error("Nothing to uninstall. {} is currently not installed, different version is installed {}", info, oldVersion);
+                                result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
+                            }
                         }
+                    } else {
+                        result = null;
+                    }
+                } finally {
+                    if ( currentSubsystem != null ) {
+                        this.bundleContext.ungetService(ref);
                     }
-                } else {
-                    result = null;
                 }
             }
         } else {

Modified: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UninstallSubsystemTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UninstallSubsystemTask.java?rev=1630931&r1=1630930&r2=1630931&view=diff
==============================================================================
--- sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UninstallSubsystemTask.java (original)
+++ sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UninstallSubsystemTask.java Fri Oct 10 16:12:45 2014
@@ -28,6 +28,9 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.subsystem.Subsystem;
 
+/**
+ * Uninstall a subsystem
+ */
 public class UninstallSubsystemTask extends InstallTask {
 
     private static final String INSTALL_ORDER = "52-";
@@ -55,6 +58,7 @@ public class UninstallSubsystemTask exte
             if ( subsystem != null ) {
                 subsystem.uninstall();
                 ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.UNINSTALLED));
+                ctx.log("Uninstalled subsystem {}", subsystem);
             } else {
                 ctx.log("Unable to uninstall subsystem {}.", tr);
                 ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.IGNORED));

Modified: sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UpdateSubsystemTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UpdateSubsystemTask.java?rev=1630931&r1=1630930&r2=1630931&view=diff
==============================================================================
--- sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UpdateSubsystemTask.java (original)
+++ sling/trunk/installer/factories/subsystems/src/main/java/org/apache/sling/installer/factories/subsystems/impl/UpdateSubsystemTask.java Fri Oct 10 16:12:45 2014
@@ -28,6 +28,9 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.subsystem.Subsystem;
 
+/**
+ * Update subsystem by uninstalling and installing it.
+ */
 public class UpdateSubsystemTask extends InstallTask {
 
     private static final String INSTALL_ORDER = "54-";