incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r806248 - in /sling/trunk/installer/osgi: installer/src/main/java/org/apache/sling/osgi/installer/ installer/src/main/java/org/apache/sling/osgi/installer/impl/ installer/src/test/java/org/apache/sling/osgi/installer/impl/ it/src/test/java/...
Date Thu, 20 Aug 2009 16:47:14 GMT
Author: bdelacretaz
Date: Thu Aug 20 16:47:14 2009
New Revision: 806248

URL: http://svn.apache.org/viewvc?rev=806248&view=rev
Log:
SLING-1078 - purge uninstallable resources and groups

Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
Thu Aug 20 16:47:14 2009
@@ -64,6 +64,13 @@
     /** Counter index: number of installer cycles */
     int INSTALLER_CYCLES_COUNTER = 1;
     
+    /** Counter index: number of currently registered resources */
+    int REGISTERED_RESOURCES_COUNTER = 2;
+    
+    /** Counter index: number of currently registered resource groups 
+     *  of resources having the same OSGi entity ID */
+    int REGISTERED_GROUPS_COUNTER = 3;
+    
 	/** Size of the counters array */
-	int COUNTERS_SIZE = 2;
+	int COUNTERS_SIZE = 4;
 }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
Thu Aug 20 16:47:14 2009
@@ -31,6 +31,7 @@
 	ConfigurationAdmin getConfigurationAdmin();
 	LogService getLogService();
 	void incrementCounter(int index);
+    void setCounter(int index, long value);
 	
 	/** Schedule a task for execution in the current OsgiController cycle */
 	void addTaskToCurrentCycle(OsgiInstallerTask t);

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
Thu Aug 20 16:47:14 2009
@@ -49,12 +49,7 @@
         this.packageAdmin = pa;
         this.logServiceTracker = logServiceTracker;
         
-        installerThread = new OsgiInstallerThread(this) {
-            @Override
-            protected void cycleDone() {
-                incrementCounter(INSTALLER_CYCLES_COUNTER);
-            }
-        };
+        installerThread = new OsgiInstallerThread(this);
         installerThread.setDaemon(true);
         installerThread.start();
     }
@@ -132,4 +127,8 @@
 	public void incrementCounter(int index) {
 	    counters[index]++;
 	}
+
+    public void setCounter(int index, long value) {
+        counters[index] = value;
+    }
 }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
Thu Aug 20 16:47:14 2009
@@ -25,7 +25,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -210,6 +209,9 @@
         // TODO do nothing for a group that's "stable" - i.e. one where no tasks were
         // created in the last cycle??
         for(SortedSet<RegisteredResource> group : registeredResources.values()) {
+            if(group.isEmpty()) {
+                continue;
+            }
             if(group.first().getResourceType().equals(RegisteredResource.ResourceType.BUNDLE))
{
                 bundleTaskCreator.createTasks(ctx, group, tasks);
             } else {
@@ -231,12 +233,46 @@
         }
     }
     
-    protected void cycleDone() {
+    private void cycleDone() {
+        // Cleanup resources that are not marked installable,
+        // they have been processed by now
+        int resourceCount = 0;
+        final List<RegisteredResource> toDelete = new ArrayList<RegisteredResource>();
+        final List<String> groupKeysToRemove = new ArrayList<String>();
+        for(SortedSet<RegisteredResource> group : registeredResources.values()) {
+            toDelete.clear();
+            String key = null;
+            for(RegisteredResource r : group) {
+                key = r.getEntityId();
+                resourceCount++;
+                if(!r.isInstallable()) {
+                    toDelete.add(r);
+                }
+            }
+            for(RegisteredResource r : toDelete) {
+                group.remove(r);
+                if(ctx.getLogService() != null) {
+                    ctx.getLogService().log(LogService.LOG_DEBUG,
+                            "Resource deleted, not installable and has been processed: "
+ r);
+                }
+            }
+            if(group.isEmpty() && key != null) {
+                groupKeysToRemove.add(key);
+            }
+        }
+        
+        for(String key : groupKeysToRemove) {
+            registeredResources.remove(key);
+        }
+        
+        ctx.setCounter(OsgiInstaller.REGISTERED_RESOURCES_COUNTER, resourceCount);
+        ctx.setCounter(OsgiInstaller.REGISTERED_GROUPS_COUNTER, registeredResources.size());
+        ctx.incrementCounter(OsgiInstaller.INSTALLER_CYCLES_COUNTER);
     }
     
     private void debug(String str) {
         if(ctx.getLogService() != null) {
             ctx.getLogService().log(LogService.LOG_DEBUG, str);
-        }
+       }
     }
 }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
Thu Aug 20 16:47:14 2009
@@ -53,4 +53,7 @@
 
     public void incrementCounter(int index) {
     }
+    
+    public void setCounter(int index, long value) {
+    }
 }

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
Thu Aug 20 16:47:14 2009
@@ -95,6 +95,10 @@
     	
     	assertNoOsgiTasks("After test " + testIndex++);
     	
+    	// Verify number of registered resources and groups
+        assertCounter(OsgiInstaller.REGISTERED_RESOURCES_COUNTER, 3);
+        assertCounter(OsgiInstaller.REGISTERED_GROUPS_COUNTER, 1);
+        
     	// Uninstall
     	{
             resetCounters();
@@ -114,6 +118,10 @@
             waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 2);
     	}
     	
+    	// No resources must be registered anymore
+        assertCounter(OsgiInstaller.REGISTERED_RESOURCES_COUNTER, 0);
+    	assertCounter(OsgiInstaller.REGISTERED_GROUPS_COUNTER, 0);
+    	
     	assertNoOsgiTasks("After test " + testIndex++);
     	
     	// Reinstall lower version, must work

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
Thu Aug 20 16:47:14 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.sling.osgi.installer.it;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
@@ -28,7 +27,6 @@
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
 
 @RunWith(JUnit4TestRunner.class)
 public class BundleStatePreservedTest extends OsgiInstallerTestBase {
@@ -78,17 +76,18 @@
         installer.addResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
         waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
         
-        final String symbolicName = "osgi-installer-testbundle";
-    	final Bundle b = findBundle(symbolicName);
-    	assertNotNull("Installed bundle must be found", b);
-    	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
-    	assertEquals("Version must be 1.2", "1.2", b.getHeaders().get(Constants.BUNDLE_VERSION));
+        assertBundle("After installing testbundle", "osgi-installer-testbundle", "1.2", Bundle.ACTIVE);
+    	
+        // Verify number of registered resources and groups
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
+        assertCounter(OsgiInstaller.REGISTERED_RESOURCES_COUNTER, 5);
+        assertCounter(OsgiInstaller.REGISTERED_GROUPS_COUNTER, 3);
     	
         installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-testbundle-1.0.jar")));
         installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-testbundle-1.1.jar")));
         installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-testbundle-1.2.jar")));
         waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 2);
-        assertNull("testbundle must be gone at end of test", findBundle(symbolicName));
+        assertNull("testbundle must be gone at end of test", findBundle("osgi-installer-testbundle"));
         
     	// Now check that bundles A and B have kept their states
         assertBundle("Bundle A must still be started", "osgi-installer-testA", null, Bundle.ACTIVE);

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java?rev=806248&r1=806247&r2=806248&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
Thu Aug 20 16:47:14 2009
@@ -268,6 +268,10 @@
     			actionsCounter, installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER]);
     }
     
+    public void assertCounter(int index, long value) {
+        assertEquals("Expected value matches for counter " + index, value, installer.getCounters()[index]);
+    }
+    
     public static Option[] defaultConfiguration() {
     	String vmOpt = "-Dosgi.installer.testing";
     	



Mime
View raw message