usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [2/3] git commit: Implements USERGRID-205
Date Tue, 29 Jul 2014 21:47:37 GMT
Implements USERGRID-205

Added dead event to the job interface


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/6d29163b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/6d29163b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/6d29163b

Branch: refs/heads/add-metrics
Commit: 6d29163bfc9a6398d169100571786034dc2f446d
Parents: 00a5032
Author: Todd Nine <toddnine@apache.org>
Authored: Tue Jul 29 15:47:05 2014 -0600
Committer: Todd Nine <toddnine@apache.org>
Committed: Tue Jul 29 15:47:05 2014 -0600

----------------------------------------------------------------------
 .../java/org/apache/usergrid/batch/Job.java     | 12 ++-
 .../batch/service/JobSchedulerService.java      | 10 +++
 .../apache/usergrid/batch/BulkTestUtils.java    |  6 ++
 .../usergrid/batch/job/CountdownLatchJob.java   |  6 ++
 .../usergrid/batch/job/DelayExecution.java      |  6 ++
 .../usergrid/batch/job/DelayHeartbeat.java      |  6 ++
 .../batch/job/FailureJobExceuction.java         | 74 -----------------
 .../usergrid/batch/job/FailureJobExecution.java | 87 ++++++++++++++++++++
 .../usergrid/batch/job/OnlyOnceExceution.java   |  6 ++
 .../job/OnlyOnceUnlockOnFailExceution.java      |  6 ++
 .../usergrid/batch/job/SchedulerRuntime3IT.java | 32 +++++--
 .../usergrid/management/export/ExportJob.java   |  6 ++
 12 files changed, 174 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/main/java/org/apache/usergrid/batch/Job.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/batch/Job.java b/stack/core/src/main/java/org/apache/usergrid/batch/Job.java
index 98c25db..3a35f49 100644
--- a/stack/core/src/main/java/org/apache/usergrid/batch/Job.java
+++ b/stack/core/src/main/java/org/apache/usergrid/batch/Job.java
@@ -30,7 +30,17 @@ public interface Job {
      * @param execution The execution information.  This will be the same from the last run.
 By default you should call
      * exeuction.start() once processing starts
      *
-     * @throws JobExecutionException If the job cannot be executed
+     * @throws Exception If the job cannot be executed
      */
     public void execute( JobExecution execution ) throws Exception;
+
+
+    /**
+     * Invoked when a job is marked as dead by the scheduler.  In some instances, jobs need
to know
+     * this information to handle this case appropriately
+     *
+     * @param execution
+     * @throws Exception
+     */
+    public void dead(JobExecution execution) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
b/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
index cd4d4d4..56d5704 100644
--- a/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
@@ -195,6 +195,16 @@ public class JobSchedulerService extends AbstractScheduledService {
 
                 //this job is dead, treat it as such
                 if ( execution.getStatus() == Status.DEAD ) {
+
+                    try {
+                        job.dead( execution );
+                    }
+                    catch ( Exception t ) {
+                        //we purposefully swallow all exceptions here, we don't want it to
effect the outcome
+                        //of finally popping this job from the queue
+                        LOG.error( "Unable to invoke dead event on job", t );
+                    }
+
                     return null;
                 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/BulkTestUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/BulkTestUtils.java b/stack/core/src/test/java/org/apache/usergrid/batch/BulkTestUtils.java
index 3b3347b..dad24a3 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/BulkTestUtils.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/BulkTestUtils.java
@@ -50,5 +50,11 @@ public class BulkTestUtils {
             // do some stuff
 
         }
+
+
+        @Override
+        public void dead( final JobExecution execution ) throws Exception {
+            //To change body of implemented methods use File | Settings | File Templates.
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/CountdownLatchJob.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/CountdownLatchJob.java
b/stack/core/src/test/java/org/apache/usergrid/batch/job/CountdownLatchJob.java
index 39ae01f..1b5a420 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/CountdownLatchJob.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/CountdownLatchJob.java
@@ -56,6 +56,12 @@ public class CountdownLatchJob implements Job {
     }
 
 
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+
     public void setLatch( int size ) {
         latch = new CountDownLatch( size );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayExecution.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayExecution.java b/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayExecution.java
index d17d762..af2974c 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayExecution.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayExecution.java
@@ -69,6 +69,12 @@ public class DelayExecution implements Job {
     }
 
 
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+
     public void setLatch( int calls ) {
         latch = new CountDownLatch( calls );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayHeartbeat.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayHeartbeat.java b/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayHeartbeat.java
index 0ddd5a6..90c2bf9 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayHeartbeat.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/DelayHeartbeat.java
@@ -71,6 +71,12 @@ public class DelayHeartbeat implements Job {
     }
 
 
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+
     public void setLatch( int calls ) {
         latch = new CountDownLatch( calls );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExceuction.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExceuction.java
b/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExceuction.java
deleted file mode 100644
index 348a825..0000000
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExceuction.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.batch.job;
-
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import org.junit.Ignore;
-import org.springframework.stereotype.Component;
-import org.apache.usergrid.batch.Job;
-import org.apache.usergrid.batch.JobExecution;
-
-
-/**
- * A simple job that does nothing but increment an atomic counter
- *
- * @author tnine
- */
-@Component("failureJobExceuction")
-@Ignore("Not a test")
-public class FailureJobExceuction implements Job {
-
-    private CountDownLatch latch = null;
-
-
-    /**
-     *
-     */
-    public FailureJobExceuction() {
-    }
-
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.usergrid.batch.Job#execute(org.apache.usergrid.batch.JobExecution)
-     */
-    @Override
-    public void execute( JobExecution execution ) throws Exception {
-        latch.countDown();
-
-        throw new RuntimeException( "Job Failed" );
-    }
-
-
-    public void setLatch( int calls ) {
-        latch = new CountDownLatch( calls );
-    }
-
-
-    public boolean waitForCount( long timeout, TimeUnit unit ) throws InterruptedException
{
-        return latch.await( timeout, unit );
-    }
-
-
-    public long getLatchCount() {
-        return latch.getCount();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExecution.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExecution.java
b/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExecution.java
new file mode 100644
index 0000000..c798194
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/FailureJobExecution.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.batch.job;
+
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Ignore;
+import org.springframework.stereotype.Component;
+import org.apache.usergrid.batch.Job;
+import org.apache.usergrid.batch.JobExecution;
+
+
+/**
+ * A simple job that does nothing but increment an atomic counter
+ *
+ * @author tnine
+ */
+@Component("failureJobExceuction")
+@Ignore("Not a test")
+public class FailureJobExecution implements Job {
+
+    private CountDownLatch latch = null;
+    private CountDownLatch deadLatch = null;
+
+
+    /**
+     *
+     */
+    public FailureJobExecution() {
+    }
+
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.usergrid.batch.Job#execute(org.apache.usergrid.batch.JobExecution)
+     */
+    @Override
+    public void execute( JobExecution execution ) throws Exception {
+        latch.countDown();
+
+        throw new RuntimeException( "Job Failed" );
+    }
+
+
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+        deadLatch.countDown();;
+    }
+
+
+    public void setLatch( int calls ) {
+        latch = new CountDownLatch( calls );
+        deadLatch = new CountDownLatch( 1 );
+    }
+
+
+
+    public boolean waitForCount( long timeout, TimeUnit unit ) throws InterruptedException
{
+        return latch.await( timeout, unit );
+    }
+
+    public boolean waitForDead(long timeout, TimeUnit unit) throws InterruptedException {
+        return deadLatch.await( timeout, unit );
+    }
+
+
+    public long getLatchCount() {
+        return latch.getCount();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceExceution.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceExceution.java
b/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceExceution.java
index bc5e1db..50b00db 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceExceution.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceExceution.java
@@ -113,4 +113,10 @@ public class OnlyOnceExceution extends OnlyOnceJob {
     public void setTimeout( long timeout ) {
         this.timeout = timeout;
     }
+
+
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceUnlockOnFailExceution.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceUnlockOnFailExceution.java
b/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceUnlockOnFailExceution.java
index 7c05043..86daaa0 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceUnlockOnFailExceution.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/OnlyOnceUnlockOnFailExceution.java
@@ -123,4 +123,10 @@ public class OnlyOnceUnlockOnFailExceution extends OnlyOnceJob {
     public void setTimeout( long timeout ) {
         this.timeout = timeout;
     }
+
+
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime3IT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime3IT.java
b/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime3IT.java
index a423729..5b3d519 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime3IT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime3IT.java
@@ -17,6 +17,8 @@
 package org.apache.usergrid.batch.job;
 
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.persistence.entities.JobData;
 import org.apache.usergrid.persistence.entities.JobStat;
@@ -25,6 +27,7 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 
 /**
@@ -41,33 +44,46 @@ public class SchedulerRuntime3IT extends AbstractSchedulerRuntimeIT {
         int failCount = Integer.parseInt( props.getProperty( FAIL_PROP ) );
         long sleepTime = Long.parseLong( props.getProperty( RUNLOOP_PROP ) );
 
-        FailureJobExceuction job = cassandraResource.getBean( "failureJobExceuction", FailureJobExceuction.class
);
+        FailureJobExecution job = cassandraResource.getBean( "failureJobExceuction", FailureJobExecution.class
);
 
-        int latchValue = failCount + 1;
+        int totalAttempts = failCount + 1;
 
-        job.setLatch( latchValue );
+        job.setLatch( failCount );
 
         getJobListener().setExpected( 3 );
 
         JobData returned = scheduler.createJob( "failureJobExceuction", System.currentTimeMillis(),
new JobData() );
 
+
+
+        final long waitTime = ( failCount + 2 ) * sleepTime + 5000L ;
+
+        boolean jobInvoked = job.waitForCount( waitTime, TimeUnit.MILLISECONDS);
+
+        assertTrue("Job invoked max times", jobInvoked);
+
+        boolean deadInvoked = job.waitForDead( waitTime, TimeUnit.MILLISECONDS );
+
+        assertTrue( "dead job signaled", deadInvoked );
+
+
         // sleep until the job should have failed. We sleep 1 extra cycle just to
         // make sure we're not racing the test
-        boolean waited = getJobListener().blockTilDone(( failCount + 2 ) * sleepTime + 5000L
);
+        boolean waited = getJobListener().blockTilDone(waitTime);
 
         //we shouldn't trip the latch.  It should fail failCount times, and not run again
         assertTrue( "Jobs ran", waited );
         assertTrue( failCount + " failures resulted", getJobListener().getFailureCount()
== failCount );
         assertTrue( 1 + " success resulted", getJobListener().getSuccessCount() == 1 );
 
-        //we shouldn't have run the last time, we should have counted down to it
-        assertEquals( 1, job.getLatchCount() );
 
         JobStat stat = scheduler.getStatsForJob( returned.getJobName(), returned.getUuid()
);
 
         // we should have only marked this as run fail+1 times
-        assertEquals( latchValue, stat.getTotalAttempts() );
-        assertEquals( latchValue, stat.getRunCount() );
+        assertEquals( totalAttempts, stat.getTotalAttempts() );
+        assertEquals( totalAttempts, stat.getRunCount() );
         assertEquals( 0, stat.getDelayCount() );
+
+
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6d29163b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java
b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java
index 5d6de63..55ed8cd 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java
@@ -79,4 +79,10 @@ public class ExportJob extends OnlyOnceJob {
     public void setExportService( final ExportService exportService ) {
         this.exportService = exportService;
     }
+
+
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
 }


Mime
View raw message