incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1585871 - in /sling/trunk/bundles/extensions/event/src/main: java/org/apache/sling/event/impl/jobs/ java/org/apache/sling/event/impl/jobs/config/ java/org/apache/sling/event/jobs/ resources/OSGI-INF/metatype/
Date Wed, 09 Apr 2014 01:30:20 GMT
Author: cziegeler
Date: Wed Apr  9 01:30:20 2014
New Revision: 1585871

URL: http://svn.apache.org/r1585871
Log:
SLING-3497 : Provide option to run jobs on same instance where job was created

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/ConfigurationConstants.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfiguration.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/package-info.java
    sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java?rev=1585871&r1=1585870&r2=1585871&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
Wed Apr  9 01:30:20 2014
@@ -169,6 +169,7 @@ public class MaintenanceTask {
             if ( potentialTargets != null && potentialTargets.size() > 0 ) {
                 final QueueInfo info = queueManager.getQueueInfo(topicName);
                 logger.debug("Found queue {} for {}", info.queueConfiguration, topicName);
+
                 // if queue is configured to drop, we drop
                 if ( info.queueConfiguration.getType() ==  QueueConfiguration.Type.DROP)
{
                     final Iterator<Resource> i = topicResource.listChildren();

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java?rev=1585871&r1=1585870&r2=1585871&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java
Wed Apr  9 01:30:20 2014
@@ -240,6 +240,21 @@ public class TopologyCapabilities {
                     logger.debug("Potential targets filtered for {} : {}", jobTopic, potentialTargets);
                 }
             }
+            // check prefer run on creation instance
+            if ( queueInfo.queueConfiguration.isPreferRunOnCreationInstance() ) {
+                InstanceDescription creationDesc = null;
+                for(final InstanceDescription desc : potentialTargets) {
+                    if ( desc.getSlingId().equals(createdOn) ) {
+                        creationDesc = desc;
+                        break;
+                    }
+                }
+                if ( creationDesc != null ) {
+                    potentialTargets.clear();
+                    potentialTargets.add(creationDesc);
+                    logger.debug("Potential targets reduced to creation instance for {} :
{}", jobTopic, potentialTargets);
+                }
+            }
             if ( queueInfo.queueConfiguration.getType() == QueueConfiguration.Type.ORDERED
) {
                 // for ordered queues we always pick the first as we have to pick the same
target on each cluster view
                 // on all instances (TODO - we could try to do some round robin of the whole
queue)

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/ConfigurationConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/ConfigurationConstants.java?rev=1585871&r1=1585870&r2=1585871&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/ConfigurationConstants.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/ConfigurationConstants.java
Wed Apr  9 01:30:20 2014
@@ -32,6 +32,7 @@ public abstract class ConfigurationConst
     public static final int DEFAULT_MAX_PARALLEL = 15;
     public static final boolean DEFAULT_KEEP_JOBS = false;
     public static final int DEFAULT_THREAD_POOL_SIZE = 0;
+    public static final boolean DEFAULT_PREFER_RUN_ON_CREATION_INSTANCE = false;
 
     public static final String PROP_NAME = "queue.name";
     public static final String PROP_TYPE = "queue.type";
@@ -42,5 +43,6 @@ public abstract class ConfigurationConst
     public static final String PROP_PRIORITY = "queue.priority";
     public static final String PROP_KEEP_JOBS = "queue.keepJobs";
     public static final String PROP_THREAD_POOL_SIZE = "queue.threadPoolSize";
+    public static final String PROP_PREFER_RUN_ON_CREATION_INSTANCE = "queue.preferRunOnCreationInstance";
 
 }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfiguration.java?rev=1585871&r1=1585870&r2=1585871&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfiguration.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfiguration.java
Wed Apr  9 01:30:20 2014
@@ -64,6 +64,8 @@ import org.osgi.framework.Constants;
                      @PropertyOption(name="MAX",value="Max")}),
     @Property(name=ConfigurationConstants.PROP_KEEP_JOBS,
               boolValue=ConfigurationConstants.DEFAULT_KEEP_JOBS),
+    @Property(name=ConfigurationConstants.PROP_PREFER_RUN_ON_CREATION_INSTANCE,
+              boolValue=ConfigurationConstants.DEFAULT_PREFER_RUN_ON_CREATION_INSTANCE),
     @Property(name=ConfigurationConstants.PROP_THREAD_POOL_SIZE,
               intValue=ConfigurationConstants.DEFAULT_THREAD_POOL_SIZE),
     @Property(name=Constants.SERVICE_RANKING, intValue=0, propertyPrivate=false,
@@ -108,6 +110,9 @@ public class InternalQueueConfiguration
     /** Optional thread pool size. */
     private int ownThreadPoolSize;
 
+    /** Prefer creation instance. */
+    private boolean preferCreationInstance;
+
     private String pid;
 
     /**
@@ -145,6 +150,7 @@ public class InternalQueueConfiguration
         this.keepJobs = PropertiesUtil.toBoolean(params.get(ConfigurationConstants.PROP_KEEP_JOBS),
ConfigurationConstants.DEFAULT_KEEP_JOBS);
         this.serviceRanking = PropertiesUtil.toInteger(params.get(Constants.SERVICE_RANKING),
0);
         this.ownThreadPoolSize = PropertiesUtil.toInteger(params.get(ConfigurationConstants.PROP_THREAD_POOL_SIZE),
ConfigurationConstants.DEFAULT_THREAD_POOL_SIZE);
+        this.preferCreationInstance = PropertiesUtil.toBoolean(params.get(ConfigurationConstants.PROP_PREFER_RUN_ON_CREATION_INSTANCE),
ConfigurationConstants.DEFAULT_PREFER_RUN_ON_CREATION_INSTANCE);
         this.pid = (String)params.get(Constants.SERVICE_PID);
         this.valid = this.checkIsValid();
     }
@@ -293,6 +299,11 @@ public class InternalQueueConfiguration
     }
 
     @Override
+    public boolean isPreferRunOnCreationInstance() {
+        return this.preferCreationInstance;
+    }
+
+    @Override
     public String toString() {
         return "Queue-Configuration(" + this.hashCode() + ") : {" +
             "name=" + this.name +
@@ -302,6 +313,7 @@ public class InternalQueueConfiguration
             ", retries=" + this.retries +
             ", retryDelayInMs=" + this.retryDelay +
             ", keepJobs=" + this.keepJobs +
+            ", preferRunOnCreationInstance=" + this.preferCreationInstance +
             ", ownThreadPoolSize=" + this.ownThreadPoolSize +
             ", serviceRanking=" + this.serviceRanking +
             ", pid=" + this.pid +

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java?rev=1585871&r1=1585870&r2=1585871&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java
Wed Apr  9 01:30:20 2014
@@ -115,4 +115,10 @@ public interface QueueConfiguration {
      * Get the ranking of this configuration.
      */
     int getRanking();
+
+    /**
+     * Prefer to run the job on the same instance it was created on.
+     * @since 1.4
+     */
+    boolean isPreferRunOnCreationInstance();
 }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/package-info.java?rev=1585871&r1=1585870&r2=1585871&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/package-info.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/package-info.java
Wed Apr  9 01:30:20 2014
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("1.3.0")
+@Version("1.4.0")
 package org.apache.sling.event.jobs;
 
 import aQute.bnd.annotation.Version;

Modified: sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1585871&r1=1585870&r2=1585871&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
Wed Apr  9 01:30:20 2014
@@ -74,6 +74,10 @@ queue.threadPoolSize.description = Optio
  this queue. If this is value has a positive number of threads configuration, this queue
uses \
  an own thread pool with the configured number of threads.
 
+queue.preferRunOnCreationInstance.name = Prefer Creation Instance
+queue.preferRunOnCreationInstance.description = If this option is enabled, the jobs are tried
to \
+ be run on the instance where the job was created.
+
 #
 # Job Event Handler
 job.events.name = Apache Sling Job Default Queue 



Mime
View raw message