incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r995954 - in /sling/trunk/installer/osgi: installer/src/main/java/org/apache/sling/osgi/installer/impl/ installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/...
Date Fri, 10 Sep 2010 19:45:21 GMT
Author: cziegeler
Date: Fri Sep 10 19:45:20 2010
New Revision: 995954

URL: http://svn.apache.org/viewvc?rev=995954&view=rev
Log:
SLING-1737 : Add state management for resources
SLING-1738 : Add kind of audit log

Modified:
    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/PersistentResourceList.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.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/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=995954&r1=995953&r2=995954&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
Fri Sep 10 19:45:20 2010
@@ -62,6 +62,9 @@ public class OsgiInstallerImpl
     /** The logger */
     private final Logger logger =  LoggerFactory.getLogger(this.getClass());
 
+    /** The audit logger */
+    private final Logger auditLogger =  LoggerFactory.getLogger("org.apache.sling.audit.osgi.installer");
+
     /** The bundle context. */
     private final BundleContext ctx;
 
@@ -311,7 +314,8 @@ public class OsgiInstallerImpl
                             }
                             if ( !found) {
                                 logger.debug("Resource {} seems to be removed.", r);
-                                if ( r.getState() == RegisteredResource.State.INSTALLED &&
first ) {
+                                if ( first && (r.getState() == RegisteredResource.State.INSTALLED
+                                           ||  r.getState() == RegisteredResource.State.INSTALL))
{
                                      r.setState(RegisteredResource.State.UNINSTALL);
                                 } else {
                                     toRemove.add(r);
@@ -346,6 +350,7 @@ public class OsgiInstallerImpl
 
             // if we have changes we have to process the resources per entity to update states
             if ( changed ) {
+                printResources("Merged");
                 for(final String entityId : this.persistentList.getEntityIds()) {
                     final Collection<RegisteredResource> group = this.persistentList.getResources(entityId);
                     if ( !group.isEmpty() ) {
@@ -381,12 +386,38 @@ public class OsgiInstallerImpl
                         }
                     }
                 }
+                printResources("Prepared");
                 // persist list
                 this.persistentList.save();
             }
         }
     }
 
+    private void printResources(String hint) {
+        if ( !logger.isDebugEnabled() ) {
+            return;
+        }
+        final StringBuilder sb = new StringBuilder();
+        sb.append(hint);
+        sb.append(" Resources={\n");
+        for(final String id : this.persistentList.getEntityIds() ) {
+            sb.append("- ");
+            sb.append(id);
+            sb.append(" : [");
+            boolean first = true;
+            for(final RegisteredResource rr : this.persistentList.getResources(id)) {
+                if ( !first) {
+                    sb.append(", ");
+                }
+                first = false;
+                sb.append(rr);
+            }
+            sb.append("]\n");
+        }
+        sb.append("}\n");
+        logger.debug(sb.toString());
+    }
+
     /**
      * Compute OSGi tasks based on our resources, and add to supplied list of tasks.
      */
@@ -456,8 +487,7 @@ public class OsgiInstallerImpl
             }
 
             public void log(String message, Object... args) {
-                // TODO Auto-generated method stub
-
+                auditLogger.info(message, args);
             }
         };
         while (this.active && !tasks.isEmpty()) {
@@ -478,6 +508,7 @@ public class OsgiInstallerImpl
         if ( this.persistentList.compact() ) {
             persistentList.save();
         }
+        printResources("Compacted");
     }
 
     /** If we have any tasks waiting to be retried, schedule their execution */

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
Fri Sep 10 19:45:20 2010
@@ -136,7 +136,8 @@ public class PersistentResourceList {
             while ( i.hasNext() ) {
                 final RegisteredResource r = i.next();
                 if ( r.getURL().equals(url) ) {
-                    if ( first && r.getState() == RegisteredResource.State.INSTALLED
) {
+                    if ( first && (r.getState() == RegisteredResource.State.INSTALLED
+                            || r.getState() == RegisteredResource.State.INSTALL)) {
                         logger.debug("Marking for uninstalling: {}", r);
                         r.setState(RegisteredResource.State.UNINSTALL);
                     } else {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
Fri Sep 10 19:45:20 2010
@@ -177,10 +177,10 @@ public class RegisteredResourceImpl
 
 	@Override
 	public String toString() {
-	    return getClass().getSimpleName() + " " + this.getURL() +
+	    return "RegisteredResource(url=" + this.getURL() +
 	        ", entity=" + this.getEntityId() +
 	        ", state=" + this.state +
-	        ", digest=" + this.getDigest() + ", serialNumber=" + this.getSerialNumber();
+	        ", digest=" + this.getDigest() + ", serialNumber=" + this.getSerialNumber() + ")";
 	}
 
 	protected File getDataFile(final BundleContext bundleContext) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
Fri Sep 10 19:45:20 2010
@@ -96,6 +96,7 @@ public class ConfigInstallTask extends A
                     config.setBundleLocation(null);
                 }
                 config.update(dict);
+                ctx.log("Installed configuration {} from resource {}", config.getPid(), getResource());
                 this.getResource().setState(RegisteredResource.State.INSTALLED);
                 this.getLogger().debug("Configuration " + config.getPid()
                             + " " + (created ? "created" : "updated")

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
Fri Sep 10 19:45:20 2010
@@ -62,6 +62,7 @@ public class ConfigRemoveTask extends Ab
             } else {
                 this.getLogger().debug("Deleting config {} ({})", pid, getResource());
                 cfg.delete();
+                ctx.log("Deleted configuration {} from resource {}", pid, getResource());
                 this.getResource().setState(RegisteredResource.State.UNINSTALLED);
             }
         } catch (Exception e) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
Fri Sep 10 19:45:20 2010
@@ -59,6 +59,7 @@ public class BundleInstallTask extends O
         final StartLevel startLevelService = this.creator.getStartLevel();
         try {
             final Bundle b = this.creator.getBundleContext().installBundle(getResource().getURL(),
getResource().getInputStream());
+            ctx.log("Installed bundle {} from resource {}", b, getResource());
             // optionally set the start level
             if ( startLevel > 0 ) {
                 if (startLevelService != null) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
Fri Sep 10 19:45:20 2010
@@ -49,7 +49,7 @@ public class BundleRemoveTask extends Os
         final Bundle b = this.creator.getMatchingBundle(symbolicName);
         if (b == null) {
             // nothing to do, so just stop
-            this.getResource().setState(RegisteredResource.State.IGNORED);
+            this.getResource().setState(RegisteredResource.State.UNINSTALLED);
             return;
         }
         final int state = b.getState();
@@ -58,6 +58,7 @@ public class BundleRemoveTask extends Os
             	b.stop();
             }
             b.uninstall();
+            ctx.log("Uninstalled bundle {} from resource {}", b, getResource());
             this.getResource().setState(RegisteredResource.State.UNINSTALLED);
             ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.creator));
         } catch (final BundleException be) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
Fri Sep 10 19:45:20 2010
@@ -64,12 +64,12 @@ public class BundleStartTask extends Osg
 	 * @see org.apache.sling.osgi.installer.impl.OsgiInstallerTask#execute(org.apache.sling.osgi.installer.impl.OsgiInstallerContext)
 	 */
 	public void execute(final OsgiInstallerContext ctx) {
-	    if ( this.getResource() != null ) {
-	        this.getResource().setState(RegisteredResource.State.INSTALLED);
-	    }
 	    // this is just a sanity check which should never be reached
         if (bundleId == 0) {
             this.getLogger().debug("Bundle 0 is the framework bundle, ignoring request to
start it");
+            if ( this.getResource() != null ) {
+                this.getResource().setState(RegisteredResource.State.INSTALLED);
+            }
             return;
         }
 
@@ -78,7 +78,9 @@ public class BundleStartTask extends Osg
         if (eventsCount < eventsCountForRetrying) {
             this.getLogger().debug("Task is not executable at this time, counters={}/{}",
                     eventsCountForRetrying, eventsCount);
-            ctx.addTaskToNextCycle(this);
+            if ( this.getResource() == null ) {
+                ctx.addTaskToNextCycle(this);
+            }
             return;
         }
 
@@ -90,11 +92,17 @@ public class BundleStartTask extends Osg
 
         if (b.getState() == Bundle.ACTIVE) {
             this.getLogger().debug("Bundle already started, no action taken: {}/{}", bundleId,
b.getSymbolicName());
+            if ( this.getResource() != null ) {
+                this.getResource().setState(RegisteredResource.State.INSTALLED);
+            }
             return;
         }
         // Try to start bundle, and if that doesn't work we'll need to retry
         try {
             b.start();
+            if ( this.getResource() != null ) {
+                this.getResource().setState(RegisteredResource.State.INSTALLED);
+            }
             this.getLogger().info("Bundle started (retry count={}, bundle ID={}) : {}",
                     new Object[] {retryCount, bundleId, b.getSymbolicName()});
         } catch(BundleException e) {
@@ -110,9 +118,9 @@ public class BundleStartTask extends Osg
                 eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount() + 1;
             }
             retryCount++;
-            ctx.addTaskToNextCycle(this);
+            if ( this.getResource() == null ) {
+                ctx.addTaskToNextCycle(this);
+            }
         }
-
-        return;
 	}
 }

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
Fri Sep 10 19:45:20 2010
@@ -100,6 +100,7 @@ public class BundleUpdateTask extends Os
                         + getResource());
             }
             b.update(is);
+            ctx.log("Updated bundle {} from resource {}", b, getResource());
             this.creator.getBundleDigestStorage().putInfo(b.getSymbolicName(), getResource().getDigest(),
newVersion.toString());
     	} catch (Exception e) {
             if ( canRetry ) {

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java?rev=995954&r1=995953&r2=995954&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java
Fri Sep 10 19:45:20 2010
@@ -32,7 +32,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.Bundle;
 import org.osgi.service.log.LogService;
 
 /** Repeatedly install/remove/reinstall semi-random sets
@@ -133,13 +132,10 @@ public class BundleInstallStressTest ext
 
     @Test
     public void testSemiRandomInstall() throws Exception {
-    	if(cycleCount < 1) {
+    	if (cycleCount < 1) {
     		fail("Cycle count (" + cycleCount + ") should be >= 1");
     	}
 
-    	// TODO TODO TODO - for now only one cycle works
-    	cycleCount = 1;
-
     	final int initialBundleCount = bundleContext.getBundles().length;
     	log(LogService.LOG_INFO,"Initial bundle count=" + initialBundleCount);
     	logInstalledBundles();
@@ -158,11 +154,18 @@ public class BundleInstallStressTest ext
     	// And run a number of cycles where randomly selected bundles are removed and reinstalled
     	final List<File> currentInstallation = new ArrayList<File>(testBundles);
     	for(int i=0; i < cycleCount; i++) {
-    		final long start = System.currentTimeMillis();
-    		log(LogService.LOG_DEBUG, "Test cycle " + i + ", semi-randomly selecting a subset of
our test bundles");
+            final long start = System.currentTimeMillis();
+            log(LogService.LOG_INFO, "Test cycle " + i + ", semi-randomly selecting a subset
of our test bundles");
+
+            for(final File f : currentInstallation) {
+    	        log(LogService.LOG_DEBUG, "Installed bundle: " + f);
+    	    }
 
     		final List<File> toInstall = selectRandomBundles();
         	log(LogService.LOG_INFO,"Re-registering " + toInstall.size() + " randomly selected
resources (other test bundles should be uninstalled)");
+            for(final File f : toInstall) {
+                log(LogService.LOG_DEBUG, "Re-Registering bundle: " + f);
+            }
         	int updates = 0;
         	int installs = 0;
         	for(final File f : toInstall ) {
@@ -181,6 +184,7 @@ public class BundleInstallStressTest ext
                     installedEvents[m] = new BundleEvent(null, null, org.osgi.framework.BundleEvent.INSTALLED);
                 }
             }
+            log(LogService.LOG_DEBUG, "Cycle results in " + removes + " removed bundles,
" + updates + " updated bundles, " + installs + " installed bundles");
 
             listener = this.startObservingBundleEvents();
     		install(toInstall);
@@ -252,10 +256,4 @@ public class BundleInstallStressTest ext
 
     	return result;
     }
-
-    private void logInstalledBundles() {
-		for(Bundle b : bundleContext.getBundles()) {
-			log(LogService.LOG_INFO, "Installed bundle: " + b.getSymbolicName());
-		}
-    }
 }

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=995954&r1=995953&r2=995954&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
Fri Sep 10 19:45:20 2010
@@ -294,8 +294,8 @@ class OsgiInstallerTestBase implements F
 
     protected InstallableResource[] getInstallableResource(File testBundle, String digest,
int priority) throws IOException {
         final String url = testBundle.getAbsolutePath();
-        if(digest == null) {
-            digest = testBundle.getAbsolutePath() + testBundle.lastModified();
+        if (digest == null) {
+            digest = String.valueOf(testBundle.lastModified());
         }
         final InstallableResource result = new MockInstallableResource(url, new FileInputStream(testBundle),
digest, null, priority);
         return new InstallableResource[] {result};
@@ -444,6 +444,12 @@ class OsgiInstallerTestBase implements F
         }
     }
 
+    public void logInstalledBundles() {
+        for(Bundle b : bundleContext.getBundles()) {
+            log(LogService.LOG_DEBUG, "Installed bundle: " + b.getSymbolicName());
+        }
+    }
+
     private final class BundleEventListener implements SynchronousBundleListener {
 
         private final List<BundleEvent> events = new ArrayList<BundleEvent>();
@@ -493,6 +499,7 @@ class OsgiInstallerTestBase implements F
                     Thread.sleep(100);
                 } catch (InterruptedException ignore) {}
             }
+            logInstalledBundles();
             final StringBuilder sb = new StringBuilder();
             sb.append(msg);
             sb.append(" : Expected events=[\n");



Mime
View raw message