sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1617254 - in /sling/trunk/installer/providers/jcr/src: main/java/org/apache/sling/installer/provider/jcr/impl/ main/resources/OSGI-INF/metatype/ test/java/org/apache/sling/installer/provider/jcr/impl/
Date Mon, 11 Aug 2014 11:21:59 GMT
Author: chetanm
Date: Mon Aug 11 11:21:58 2014
New Revision: 1617254

URL: http://svn.apache.org/r1617254
Log:
SLING-3747 - Provide a way to signal Jcr Installer to pause and resume scanning

Modified:
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
    sling/trunk/installer/providers/jcr/src/main/resources/OSGI-INF/metatype/metatype.properties
    sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ContentHelper.java
    sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ScanningLoopTest.java

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java?rev=1617254&r1=1617253&r2=1617254&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
(original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
Mon Aug 11 11:21:58 2014
@@ -178,6 +178,15 @@ public class JcrInstaller implements Eve
     /** The path for new configurations. */
     private String newConfigPath;
 
+    public static final String PAUSE_SCAN_NODE_PATH = "/system/sling/installer/jcr/pauseInstallation";
+    @Property(value= PAUSE_SCAN_NODE_PATH)
+    private static final String PROP_SCAN_PROP_PATH = "sling.jcrinstall.signal.path";
+
+    /** The path for pauseInstallation property */
+    private String pauseScanNodePath;
+
+    private volatile boolean pauseMessageLogged = false;
+
     private static final boolean DEFAULT_ENABLE_WRITEBACK = true;
     @Property(boolValue=DEFAULT_ENABLE_WRITEBACK)
     private static final String PROP_ENABLE_WRITEBACK = "sling.jcrinstall.enable.writeback";
@@ -360,6 +369,8 @@ public class JcrInstaller implements Eve
             this.newConfigPath = this.folderNameFilter.getRootPaths()[0] + '/' + this.newConfigPath;
         }
 
+        this.pauseScanNodePath = PropertiesUtil.toString(getPropertyValue(PROP_SCAN_PROP_PATH),
PAUSE_SCAN_NODE_PATH);
+
         backgroundThread = new StoppableThread();
         backgroundThread.start();
     }
@@ -593,6 +604,22 @@ public class JcrInstaller implements Eve
         try {
             boolean didRefresh = false;
 
+            if (anyWatchFolderNeedsScan()) {
+                session.refresh(false);
+                didRefresh = true;
+                if (scanningIsPaused()) {
+                    if (!pauseMessageLogged) {
+                        //Avoid flooding the logs every 500 msec so log at info level once
+                        logger.info("Detected signal for pausing the JCR Provider i.e. child
nodes found under path {}. " +
+                                "JCR Provider scanning would not be performed", pauseScanNodePath);
+                        pauseMessageLogged = true;
+                    }
+                    return;
+                } else if (pauseMessageLogged) {
+                    pauseMessageLogged = false;
+                }
+            }
+
             // Rescan WatchedFolders if needed
             boolean scanWf = false;
             for(WatchedFolder wf : watchedFolders) {
@@ -651,6 +678,32 @@ public class JcrInstaller implements Eve
         counters[RUN_LOOP_COUNTER]++;
     }
 
+    boolean scanningIsPaused() throws RepositoryException {
+        if (session.nodeExists(pauseScanNodePath)) {
+            Node node = session.getNode(pauseScanNodePath);
+            boolean result = node.hasNodes();
+            if (result && logger.isDebugEnabled()) {
+                List<String> nodeNames = new ArrayList<String>();
+                NodeIterator childItr = node.getNodes();
+                while (childItr.hasNext()) {
+                    nodeNames.add(childItr.nextNode().getName());
+                }
+                logger.debug("Found child nodes {} at path {}. Scanning would be paused",
nodeNames, pauseScanNodePath);
+            }
+            return result;
+        }
+        return false;
+    }
+
+    private boolean anyWatchFolderNeedsScan() {
+        for (WatchedFolder wf : watchedFolders) {
+            if (wf.needsScan()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     long [] getCounters() {
         return counters;
     }

Modified: sling/trunk/installer/providers/jcr/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1617254&r1=1617253&r2=1617254&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/installer/providers/jcr/src/main/resources/OSGI-INF/metatype/metatype.properties
Mon Aug 11 11:21:58 2014
@@ -33,7 +33,7 @@ sling.jcrinstall.folder.max.depth.descri
   
 sling.jcrinstall.folder.name.regexp.name = Installation folders name regexp
 sling.jcrinstall.folder.name.regexp.description = JCRInstall looks in repository folders
\
-  having a name that match this regular expression (under the root paths, which are defined
\  
+  having a name that match this regular expression (under the root paths, which are defined
\
   by the ResourceResolver search path) for resources to install. Folders having names \
   that match this expression, followed by dotted run mode selectors (like "install.author.production")
\
   are also included.   
@@ -58,4 +58,9 @@ handler.schemes.name = Schemes
 handler.schemes.description = For these schemes this installer writes back configurations.
 
 service.ranking.name = Ranking
-service.ranking.description = Ranking of this service.
\ No newline at end of file
+service.ranking.description = Ranking of this service.
+
+sling.jcrinstall.signal.path.name = Signal Node Path
+sling.jcrinstall.signal.path.description = Path of the node in repository whose children
would be \
+  watched for determining if the watch folder scanning has to be performed or not. If any
child node is found \
+  at this path then scanning would be paused.
\ No newline at end of file

Modified: sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ContentHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ContentHelper.java?rev=1617254&r1=1617253&r2=1617254&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ContentHelper.java
(original)
+++ sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ContentHelper.java
Mon Aug 11 11:21:58 2014
@@ -112,7 +112,7 @@ class ContentHelper {
         }
     }
 
-    void createFolder(String path) throws Exception {
+    Node createFolder(String path) throws Exception {
         final String [] parts = relPath(path).split("/");
         Node n = session.getRootNode();
         for(String part : parts) {
@@ -123,6 +123,7 @@ class ContentHelper {
             }
         }
         session.save();
+        return n;
     }
 
     void delete(String path) throws RepositoryException {

Modified: sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ScanningLoopTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ScanningLoopTest.java?rev=1617254&r1=1617253&r2=1617254&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ScanningLoopTest.java
(original)
+++ sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/ScanningLoopTest.java
Mon Aug 11 11:21:58 2014
@@ -18,11 +18,12 @@
  */
 package org.apache.sling.installer.provider.jcr.impl;
 
+
+import javax.jcr.Node;
 import javax.jcr.Session;
 
 import org.apache.sling.commons.testing.jcr.EventHelper;
 import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
-import org.apache.sling.installer.provider.jcr.impl.JcrInstaller;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.junit.Test;
 
@@ -56,6 +57,7 @@ public class ScanningLoopTest extends Re
         MiscUtil.waitForInstallerThread(installer, TIMEOUT);
         installer = null;
         contentHelper.cleanupContent();
+        contentHelper.deleteQuietly(JcrInstaller.PAUSE_SCAN_NODE_PATH);
         if(session != null) {
             session.logout();
             session = null;
@@ -85,6 +87,38 @@ public class ScanningLoopTest extends Re
         assertIdle();
     }
 
+    public void testDefaultScanPauseFalse() throws Exception{
+        assertFalse(installer.scanningIsPaused());
+    }
+
+    public void testPauseScan() throws Exception{
+        assertFalse(installer.scanningIsPaused());
+
+        Node n = contentHelper.createFolder(JcrInstaller.PAUSE_SCAN_NODE_PATH);
+        Node testNode = n.addNode("foo.example.pause");
+        session.save();
+
+        eventHelper.waitForEvents(TIMEOUT);
+
+        assertTrue(installer.scanningIsPaused());
+        final long sf = installer.getCounters()[JcrInstaller.SCAN_FOLDERS_COUNTER];
+        final long uc = installer.getCounters()[JcrInstaller.UPDATE_FOLDERS_LIST_COUNTER];
+
+        Thread.sleep(JcrInstaller.RUN_LOOP_DELAY_MSEC * 2);
+
+        //Counters should not have changed as no scanning being performed
+        assertEquals(sf, installer.getCounters()[JcrInstaller.SCAN_FOLDERS_COUNTER]);
+
+        //Now lets resume again
+        testNode.remove();
+        session.save();
+
+        Thread.sleep(JcrInstaller.RUN_LOOP_DELAY_MSEC * 2);
+
+        //Now counters should have changed
+        assertIdle();
+    }
+
     @Test
     public void testAddBundle() throws Exception {
         contentHelper.createOrUpdateFile(contentHelper.FAKE_RESOURCES[0]);
@@ -137,4 +171,9 @@ public class ScanningLoopTest extends Re
 
         assertIdle();
     }
+
+    private static String getParentPath(String absPath){
+        int pos = absPath.lastIndexOf('/');
+        return absPath.substring(0, pos);
+    }
 }
\ No newline at end of file



Mime
View raw message