incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1076199 - in /sling/trunk/installer: core/src/main/java/org/apache/sling/installer/core/impl/ factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/
Date Wed, 02 Mar 2011 12:51:20 GMT
Author: cziegeler
Date: Wed Mar  2 12:51:19 2011
New Revision: 1076199

URL: http://svn.apache.org/viewvc?rev=1076199&view=rev
Log:
SLING-1971 : Persist configuration (and bundle) changes not made through the installer

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/FileDataStore.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigRemoveTask.java
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/FileDataStore.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/FileDataStore.java?rev=1076199&r1=1076198&r2=1076199&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/FileDataStore.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/FileDataStore.java
Wed Mar  2 12:51:19 2011
@@ -37,7 +37,6 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.osgi.framework.BundleContext;
-import org.slf4j.LoggerFactory;
 
 /**
  * Utility class for all file handling.
@@ -146,7 +145,7 @@ public class FileDataStore {
                 }
             }
         }
-        final String filename = hint + "-resource-" + getNextSerialNumber() + ".ser";
+        final String filename = (hint == null ? "unknown" : hint) + "-resource-" + getNextSerialNumber()
+ ".ser";
         final File file = this.getDataFile(filename);
 
         this.copyToLocalStorage(stream, file);
@@ -185,7 +184,7 @@ public class FileDataStore {
 
     public File createNewDataFile(final String hint, final InputStream stream)
     throws IOException {
-        final String filename = hint + "-resource-" + getNextSerialNumber() + ".ser";
+        final String filename = (hint == null ? "unknown" : hint) + "-resource-" + getNextSerialNumber()
+ ".ser";
         final File file = this.getDataFile(filename);
 
         this.copyToLocalStorage(stream, file);
@@ -197,7 +196,6 @@ public class FileDataStore {
         synchronized ( this.digestCache ) {
             final String storedDigest = this.digestCache.get(url);
             if ( storedDigest != null && storedDigest.equals(digest) ) {
-                LoggerFactory.getLogger(this.getClass()).warn("Remove {} : {}", url, digest);
                 this.digestCache.remove(url);
             }
         }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1076199&r1=1076198&r2=1076199&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
Wed Mar  2 12:51:19 2011
@@ -175,22 +175,17 @@ public class OsgiInstallerImpl
 
             this.mergeNewlyRegisteredResources();
 
-            // invoke transformers - sync as we change state
-            synchronized ( this.resourcesLock ) {
-                this.transformResources();
-            }
+            // invoke transformers
+            this.transformResources();
 
             // execute tasks
             final SortedSet<InstallTask> tasks = this.computeTasks();
             final boolean tasksCreated = !tasks.isEmpty();
 
-            // sync as we might change state
-            synchronized ( this.resourcesLock ) {
-                this.executeTasks(tasks);
+            this.executeTasks(tasks);
 
-                // clean up and save
-                this.cleanupInstallableResources();
-            }
+            // clean up and save
+            this.cleanupInstallableResources();
 
             // if we don't have any tasks, we go to sleep
             if (!tasksCreated) {

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java?rev=1076199&r1=1076198&r2=1076199&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
(original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
Wed Mar  2 12:51:19 2011
@@ -43,42 +43,44 @@ public class ConfigInstallTask extends A
     @SuppressWarnings("unchecked")
 	@Override
     public void execute(final InstallationContext ctx) {
-        final ConfigurationAdmin ca = this.getConfigurationAdmin();
+        synchronized ( ConfigTaskCreator.getLock() ) {
+            final ConfigurationAdmin ca = this.getConfigurationAdmin();
 
-        // Get or create configuration, but do not
-        // update if the new one has the same values.
-        boolean created = false;
-        try {
-            Configuration config = getConfiguration(ca, false);
-            if (config == null) {
-                created = true;
-                config = getConfiguration(ca, true);
-            } else {
-    			if (ConfigUtil.isSameData(config.getProperties(), getResource().getDictionary()))
{
-    			    this.getLogger().debug("Configuration {} already installed with same data, update
request ignored: {}",
-    	                        config.getPid(), getResource());
-    				config = null;
-    			}
-            }
-
-            if (config != null) {
-                if (config.getBundleLocation() != null) {
-                    config.setBundleLocation(null);
+            // Get or create configuration, but do not
+            // update if the new one has the same values.
+            boolean created = false;
+            try {
+                Configuration config = getConfiguration(ca, false);
+                if (config == null) {
+                    created = true;
+                    config = getConfiguration(ca, true);
+                } else {
+        			if (ConfigUtil.isSameData(config.getProperties(), getResource().getDictionary()))
{
+        			    this.getLogger().debug("Configuration {} already installed with same data,
update request ignored: {}",
+        	                        config.getPid(), getResource());
+        				config = null;
+        			}
                 }
-                config.update(getDictionary());
-                ctx.log("Installed configuration {} from resource {}", config.getPid(), getResource());
-                if ( this.factoryPid != null ) {
-                    this.aliasPid = config.getPid();
+
+                if (config != null) {
+                    if (config.getBundleLocation() != null) {
+                        config.setBundleLocation(null);
+                    }
+                    config.update(getDictionary());
+                    ctx.log("Installed configuration {} from resource {}", config.getPid(),
getResource());
+                    if ( this.factoryPid != null ) {
+                        this.aliasPid = config.getPid();
+                    }
+                    this.setFinishedState(ResourceState.INSTALLED, this.getCompositeAliasPid());
+                    this.getLogger().debug("Configuration " + config.getPid()
+                                + " " + (created ? "created" : "updated")
+                                + " from " + getResource());
+                } else {
+                    this.setFinishedState(ResourceState.IGNORED, this.getCompositeAliasPid());
                 }
-                this.setFinishedState(ResourceState.INSTALLED, this.getCompositeAliasPid());
-                this.getLogger().debug("Configuration " + config.getPid()
-                            + " " + (created ? "created" : "updated")
-                            + " from " + getResource());
-            } else {
-                this.setFinishedState(ResourceState.IGNORED, this.getCompositeAliasPid());
+            } catch (Exception e) {
+                this.getLogger().debug("Exception during installation of config " + this.getResource()
+ " : " + e.getMessage() + ". Retrying later.", e);
             }
-        } catch (Exception e) {
-            this.getLogger().debug("Exception during installation of config " + this.getResource()
+ " : " + e.getMessage() + ". Retrying later.", e);
         }
     }
 }
\ No newline at end of file

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigRemoveTask.java?rev=1076199&r1=1076198&r2=1076199&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigRemoveTask.java
(original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigRemoveTask.java
Wed Mar  2 12:51:19 2011
@@ -44,26 +44,28 @@ public class ConfigRemoveTask extends Ab
      */
     @SuppressWarnings("unchecked")
     public void execute(final InstallationContext ctx) {
-        final ConfigurationAdmin ca = this.getConfigurationAdmin();
+        synchronized ( ConfigTaskCreator.getLock() ) {
+            final ConfigurationAdmin ca = this.getConfigurationAdmin();
 
-        try {
-            final Configuration cfg = getConfiguration(ca, false);
-            if (cfg == null) {
-                this.getLogger().debug("Cannot delete config , pid={} not found, ignored
({})", getCompositePid(), getResource());
-                this.setFinishedState(ResourceState.IGNORED);
-            } else {
-                if ( !ConfigUtil.isSameData(cfg.getProperties(), this.getResource().getDictionary())
) {
-                    this.getLogger().debug("Configuration has changed after it has been installed.
Not removing!");
+            try {
+                final Configuration cfg = getConfiguration(ca, false);
+                if (cfg == null) {
+                    this.getLogger().debug("Cannot delete config , pid={} not found, ignored
({})", getCompositePid(), getResource());
                     this.setFinishedState(ResourceState.IGNORED);
                 } else {
-                    this.getLogger().debug("Deleting config {} ({})", getCompositePid(),
getResource());
-                    cfg.delete();
-                    ctx.log("Deleted configuration {} from resource {}", getCompositePid(),
getResource());
-                    this.setFinishedState(ResourceState.UNINSTALLED);
+                    if ( !ConfigUtil.isSameData(cfg.getProperties(), this.getResource().getDictionary())
) {
+                        this.getLogger().debug("Configuration has changed after it has been
installed. Not removing!");
+                        this.setFinishedState(ResourceState.IGNORED);
+                    } else {
+                        this.getLogger().debug("Deleting config {} ({})", getCompositePid(),
getResource());
+                        cfg.delete();
+                        ctx.log("Deleted configuration {} from resource {}", getCompositePid(),
getResource());
+                        this.setFinishedState(ResourceState.UNINSTALLED);
+                    }
                 }
+            } catch (Exception e) {
+                this.getLogger().debug("Exception during removal of config " + this.getResource()
+ " : " + e.getMessage() + ". Retrying later.", e);
             }
-        } catch (Exception e) {
-            this.getLogger().debug("Exception during removal of config " + this.getResource()
+ " : " + e.getMessage() + ". Retrying later.", e);
         }
     }
 }
\ No newline at end of file

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java?rev=1076199&r1=1076198&r2=1076199&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
(original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
Wed Mar  2 12:51:19 2011
@@ -80,21 +80,23 @@ public class ConfigTaskCreator
      */
     @SuppressWarnings("unchecked")
     public void configurationEvent(final ConfigurationEvent event) {
-        final String id = (event.getFactoryPid() == null ? "" : event.getFactoryPid() + ".")
+ event.getPid();
-        if ( event.getType() == ConfigurationEvent.CM_DELETED ) {
-            this.changeListener.resourceRemoved(InstallableResource.TYPE_CONFIG, id);
-        } else {
-            try {
-                final Configuration config = ConfigUtil.getConfiguration(configAdmin,
-                        event.getFactoryPid(),
-                        event.getPid(),
-                        false);
-                if ( config != null ) {
-                    final Dictionary<String, Object> dict = ConfigUtil.cleanConfiguration(config.getProperties());
-                    this.changeListener.resourceAddedOrUpdated(InstallableResource.TYPE_CONFIG,
id, null, dict);
+        synchronized ( ConfigTaskCreator.getLock() ) {
+            final String id = (event.getFactoryPid() == null ? "" : event.getFactoryPid()
+ ".") + event.getPid();
+            if ( event.getType() == ConfigurationEvent.CM_DELETED ) {
+                this.changeListener.resourceRemoved(InstallableResource.TYPE_CONFIG, id);
+            } else {
+                try {
+                    final Configuration config = ConfigUtil.getConfiguration(configAdmin,
+                            event.getFactoryPid(),
+                            event.getPid(),
+                            false);
+                    if ( config != null ) {
+                        final Dictionary<String, Object> dict = ConfigUtil.cleanConfiguration(config.getProperties());
+                        this.changeListener.resourceAddedOrUpdated(InstallableResource.TYPE_CONFIG,
id, null, dict);
+                    }
+                } catch ( final Exception ignore) {
+                    // ignore for now (TODO)
                 }
-            } catch ( final Exception ignore) {
-                // ignore for now (TODO)
             }
         }
     }
@@ -176,4 +178,10 @@ public class ConfigTaskCreator
         }
         return false;
     }
+
+    private static final Object LOCK = new Object();
+
+    public static Object getLock() {
+        return LOCK;
+    }
 }



Mime
View raw message