You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by ro...@apache.org on 2013/07/29 18:57:44 UTC

svn commit: r1508134 - in /oozie/branches/branch-4.0: ./ client/src/main/java/org/apache/oozie/client/event/message/ core/src/main/java/org/apache/oozie/service/ core/src/main/java/org/apache/oozie/sla/ core/src/main/java/org/apache/oozie/sla/listener/...

Author: rohini
Date: Mon Jul 29 16:57:44 2013
New Revision: 1508134

URL: http://svn.apache.org/r1508134
Log:
OOZIE-1472 Confirm against database before generating start and duration miss events (rohini)

Modified:
    oozie/branches/branch-4.0/client/src/main/java/org/apache/oozie/client/event/message/SLAMessage.java
    oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/EventHandlerService.java
    oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculator.java
    oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculatorMemory.java
    oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLAOperations.java
    oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java
    oozie/branches/branch-4.0/core/src/main/resources/oozie-log4j.properties
    oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java
    oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestPartitionDependencyManagerEhcache.java
    oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLACalculatorMemory.java
    oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEmailEventListener.java
    oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEventGeneration.java
    oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAService.java
    oozie/branches/branch-4.0/core/src/test/resources/wf-job-sla.xml
    oozie/branches/branch-4.0/docs/src/site/twiki/DG_SLAMonitoring.twiki
    oozie/branches/branch-4.0/release-log.txt

Modified: oozie/branches/branch-4.0/client/src/main/java/org/apache/oozie/client/event/message/SLAMessage.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/client/src/main/java/org/apache/oozie/client/event/message/SLAMessage.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/client/src/main/java/org/apache/oozie/client/event/message/SLAMessage.java (original)
+++ oozie/branches/branch-4.0/client/src/main/java/org/apache/oozie/client/event/message/SLAMessage.java Mon Jul 29 16:57:44 2013
@@ -216,36 +216,36 @@ public class SLAMessage extends EventMes
     }
 
     /**
-     * Get expected duration time (in minutes)
+     * Get expected duration time (in milliseconds)
      *
-     * @return expectedDuration (in minutes)
+     * @return expectedDuration (in milliseconds)
      */
     public long getExpectedDuration() {
         return expectedDuration;
     }
 
     /**
-     * Set expected duration (in minutes) for message
+     * Set expected duration (in milliseconds) for message
      *
-     * @param expectedDuration (in minutes)
+     * @param expectedDuration (in milliseconds)
      */
     public void setExpectedDuration(long expectedDuration) {
         this.expectedDuration = expectedDuration;
     }
 
     /**
-     * Get actual duration (in minutes)
+     * Get actual duration (in milliseconds)
      *
-     * @return actual duration (in minutes)
+     * @return actual duration (in milliseconds)
      */
     public long getActualDuration() {
         return actualDuration;
     }
 
     /**
-     * Set actual duration (in minutes) for message
+     * Set actual duration (in milliseconds) for message
      *
-     * @param actualDuration (in minutes)
+     * @param actualDuration (in milliseconds)
      */
     public void setActualDuration(long actualDuration) {
         this.actualDuration = actualDuration;

Modified: oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/EventHandlerService.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/EventHandlerService.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/EventHandlerService.java (original)
+++ oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/EventHandlerService.java Mon Jul 29 16:57:44 2013
@@ -207,7 +207,8 @@ public class EventHandlerService impleme
     }
 
     public void queueEvent(Event event) {
-        LOG.trace("Stack trace while queueing event : " + event, new Throwable());
+        LOG.debug("Queueing event : {0}", event);
+        LOG.trace("Stack trace while queueing event : {0}", event, new Throwable());
         eventQueue.add(event);
     }
 
@@ -226,6 +227,7 @@ public class EventHandlerService impleme
                 if (!eventQueue.isEmpty()) {
                     List<Event> work = eventQueue.pollBatch();
                     for (Event event : work) {
+                        LOG.debug("Processing event : {0}", event);
                         MessageType msgType = event.getMsgType();
                         List<?> listeners = listenerMap.get(msgType);
                         if (listeners != null) {

Modified: oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculator.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculator.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculator.java (original)
+++ oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculator.java Mon Jul 29 16:57:44 2013
@@ -37,6 +37,8 @@ public interface SLACalculator {
 
     boolean addRegistration(String jobId, SLARegistrationBean reg) throws JPAExecutorException;
 
+    boolean updateRegistration(String jobId, SLARegistrationBean reg) throws JPAExecutorException;
+
     void removeRegistration(String jobId);
 
     boolean addJobStatus(String jobId, String jobStatus, EventStatus jobEventStatus, Date startTime, Date endTime)
@@ -48,6 +50,4 @@ public interface SLACalculator {
 
     SLACalcStatus get(String jobId) throws JPAExecutorException;
 
-    boolean updateRegistration(String jobId, SLARegistrationBean reg) throws JPAExecutorException;
-
 }

Modified: oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculatorMemory.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculatorMemory.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculatorMemory.java (original)
+++ oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLACalculatorMemory.java Mon Jul 29 16:57:44 2013
@@ -18,7 +18,6 @@
 package org.apache.oozie.sla;
 
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
@@ -26,7 +25,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TimeZone;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.hadoop.conf.Configuration;
@@ -65,6 +63,8 @@ import org.apache.oozie.util.XLog;
  * start/end/duration of jobs using a memory-based map
  */
 public class SLACalculatorMemory implements SLACalculator {
+
+    private static final XLog LOG = XLog.getLog(SLACalculatorMemory.class);
     // TODO optimization priority based insertion/processing/bumping up-down
     private static Map<String, SLACalcStatus> slaMap;
     private static Set<String> historySet;
@@ -91,6 +91,8 @@ public class SLACalculatorMemory impleme
     private void loadOnRestart() {
         boolean isJobModified = false;
         try {
+            long slaPendingCount = 0;
+            long statusPendingCount = 0;
             List<SLASummaryBean> summaryBeans = jpaService.execute(new SLASummaryGetRecordsOnRestartJPAExecutor(
                     modifiedAfter));
             for (SLASummaryBean summaryBean : summaryBeans) {
@@ -114,28 +116,31 @@ public class SLACalculatorMemory impleme
                     }
                 }
                 catch (Exception e) {
-                    XLog.getLog(SLAService.class).warn("Failed to load records for " + jobId, e);
+                    LOG.warn("Failed to load records for " + jobId, e);
                 }
                 try {
                     if (summaryBean.getEventProcessed() == 7) {
                         historySet.add(jobId);
+                        statusPendingCount++;
                     }
                     else if (summaryBean.getEventProcessed() <= 7) {
                         SLARegistrationBean slaRegBean = jpaService.execute(new SLARegistrationGetOnRestartJPAExecutor(
                                 jobId));
                         SLACalcStatus slaCalcStatus = new SLACalcStatus(summaryBean, slaRegBean);
                         slaMap.put(jobId, slaCalcStatus);
+                        slaPendingCount++;
                     }
                 }
                 catch (Exception e) {
-                    XLog.getLog(SLAService.class).warn("Failed to fetch/update records for " + jobId, e);
+                    LOG.warn("Failed to fetch/update records for " + jobId, e);
                 }
 
             }
+            LOG.info("Loaded SLASummary pendingSLA=" + slaPendingCount + ", pendingStatusUpdate=" + statusPendingCount);
 
         }
         catch (Exception e) {
-            XLog.getLog(SLAService.class).warn("Failed to retrieve SLASummary records on restart", e);
+            LOG.warn("Failed to retrieve SLASummary records on restart", e);
         }
     }
 
@@ -145,21 +150,20 @@ public class SLACalculatorMemory impleme
         CoordinatorActionBean coordAction = null;
         coordAction = jpaService.execute(new CoordActionGetForSLAJPAExecutor(jobId));
         if (!coordAction.getStatusStr().equals(summaryBean.getJobStatus())) {
-            XLog.getLog(SLAService.class).trace(
-                    "Coordinator action status is " + coordAction.getStatusStr() + " and summary bean status is "
-                            + summaryBean.getJobStatus());
+            LOG.trace("Coordinator action status is " + coordAction.getStatusStr() + " and summary bean status is "
+                    + summaryBean.getJobStatus());
             isJobModified = true;
             summaryBean.setJobStatus(coordAction.getStatusStr());
             if (coordAction.isTerminalStatus()) {
                 WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetForSLAJPAExecutor(coordAction
                         .getExternalId()));
-                setSLASummaryBean(summaryBean, wfJob.getStartTime(), coordAction.getLastModifiedTime(),
+                setEndForSLASummaryBean(summaryBean, wfJob.getStartTime(), coordAction.getLastModifiedTime(),
                         coordAction.getStatusStr());
             }
             else if (coordAction.getStatus() != CoordinatorAction.Status.WAITING) {
                 WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetForSLAJPAExecutor(coordAction
                         .getExternalId()));
-                setSLASummaryBean(summaryBean, summaryBean.getEventProcessed(), wfJob.getStartTime());
+                setStartForSLASummaryBean(summaryBean, summaryBean.getEventProcessed(), wfJob.getStartTime());
             }
         }
         return isJobModified;
@@ -171,16 +175,15 @@ public class SLACalculatorMemory impleme
         WorkflowActionBean wfAction = null;
         wfAction = jpaService.execute(new WorkflowActionGetForSLAJPAExecutor(jobId));
         if (!wfAction.getStatusStr().equals(summaryBean.getJobStatus())) {
-            XLog.getLog(SLAService.class).trace(
-                    "Workflow action status is " + wfAction.getStatusStr() + "and summary bean status is "
-                            + summaryBean.getJobStatus());
+            LOG.trace("Workflow action status is " + wfAction.getStatusStr() + "and summary bean status is "
+                    + summaryBean.getJobStatus());
             isJobModified = true;
             summaryBean.setJobStatus(wfAction.getStatusStr());
             if (wfAction.inTerminalState()) {
-                setSLASummaryBean(summaryBean, wfAction.getStartTime(), wfAction.getEndTime(), wfAction.getStatusStr());
+                setEndForSLASummaryBean(summaryBean, wfAction.getStartTime(), wfAction.getEndTime(), wfAction.getStatusStr());
             }
             else if (wfAction.getStatus() != WorkflowAction.Status.PREP) {
-                setSLASummaryBean(summaryBean, summaryBean.getEventProcessed(), wfAction.getStartTime());
+                setStartForSLASummaryBean(summaryBean, summaryBean.getEventProcessed(), wfAction.getStartTime());
             }
         }
         return isJobModified;
@@ -192,22 +195,21 @@ public class SLACalculatorMemory impleme
         WorkflowJobBean wfJob = null;
         wfJob = jpaService.execute(new WorkflowJobGetForSLAJPAExecutor(jobId));
         if (!wfJob.getStatusStr().equals(summaryBean.getJobStatus())) {
-            XLog.getLog(SLAService.class).trace(
-                    "Workflow job status is " + wfJob.getStatusStr() + "and summary bean status is "
-                            + summaryBean.getJobStatus());
+            LOG.trace("Workflow job status is " + wfJob.getStatusStr() + "and summary bean status is "
+                    + summaryBean.getJobStatus());
             isJobModified = true;
             summaryBean.setJobStatus(wfJob.getStatusStr());
             if (wfJob.inTerminalState()) {
-                setSLASummaryBean(summaryBean, wfJob.getStartTime(), wfJob.getEndTime(), wfJob.getStatusStr());
+                setEndForSLASummaryBean(summaryBean, wfJob.getStartTime(), wfJob.getEndTime(), wfJob.getStatusStr());
             }
             else if (wfJob.getStatus() != WorkflowJob.Status.PREP) {
-                setSLASummaryBean(summaryBean, summaryBean.getEventProcessed(), wfJob.getStartTime());
+                setStartForSLASummaryBean(summaryBean, summaryBean.getEventProcessed(), wfJob.getStartTime());
             }
         }
         return isJobModified;
     }
 
-    private void setSLASummaryBean(SLASummaryBean summaryBean, Date startTime, Date endTime, String status) {
+    private void setEndForSLASummaryBean(SLASummaryBean summaryBean, Date startTime, Date endTime, String status) {
         byte eventProc = summaryBean.getEventProcessed();
         summaryBean.setEventProcessed(8);
         summaryBean.setActualStart(startTime);
@@ -231,7 +233,7 @@ public class SLACalculatorMemory impleme
 
     }
 
-    private void setSLASummaryBean(SLASummaryBean summaryBean, byte eventProc, Date startTime) {
+    private void setStartForSLASummaryBean(SLASummaryBean summaryBean, byte eventProc, Date startTime) {
         if (((eventProc & 1) == 0)) {
             eventProc += 1;
             summaryBean.setEventProcessed(eventProc);
@@ -286,12 +288,18 @@ public class SLACalculatorMemory impleme
             // calculation w.r.t current time and status
             if ((eventProc & 1) == 0) { // first bit (start-processed) unset
                 if (reg.getExpectedStart() != null) {
-                    if (reg.getExpectedStart().getTime() + jobEventLatency < Calendar.getInstance(TimeZone.getTimeZone("UTC"))
-                            .getTimeInMillis()) {
-                        slaCalc.setEventStatus(EventStatus.START_MISS);
+                    if (reg.getExpectedStart().getTime() + jobEventLatency < System.currentTimeMillis()) {
+                        confirmWithDB(slaCalc);
+                        if ((slaCalc.getEventProcessed() & 1 ) == 0) {
+                            //Some DB exception
+                            slaCalc.setEventStatus(EventStatus.START_MISS);
+                            eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+                            eventProc++;
+                        }
+                        else {
+                            eventProc = slaCalc.getEventProcessed();
+                        }
                         change = true;
-                        eventHandler.queueEvent(new SLACalcStatus(slaCalc));
-                        eventProc++;
                     }
                 }
                 else {
@@ -305,22 +313,29 @@ public class SLACalculatorMemory impleme
                     change = true;
                 }
                 else if (slaCalc.getActualStart() != null) {
-                    if (reg.getExpectedDuration() + jobEventLatency < Calendar.getInstance(TimeZone.getTimeZone("UTC"))
-                            .getTimeInMillis() - slaCalc.getActualStart().getTime()) {
-                        slaCalc.setEventStatus(EventStatus.DURATION_MISS);
+                    if ((reg.getExpectedDuration() + jobEventLatency) < (System.currentTimeMillis() - slaCalc
+                            .getActualStart().getTime())) {
+                        slaCalc.setEventProcessed(eventProc);
+                        confirmWithDB(slaCalc);
+                        if (((slaCalc.getEventProcessed() >> 1) & 1 ) == 0) {
+                            //Some DB exception
+                            slaCalc.setEventStatus(EventStatus.DURATION_MISS);
+                            eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+                            eventProc += 2;
+                        }
+                        else {
+                            eventProc = slaCalc.getEventProcessed();
+                        }
                         change = true;
-                        eventHandler.queueEvent(new SLACalcStatus(slaCalc));
-                        eventProc += 2;
                     }
                 }
             }
             if (eventProc < 4) {
-                if (reg.getExpectedEnd().getTime() + jobEventLatency < Calendar
-                        .getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis()) {
+                if (reg.getExpectedEnd().getTime() + jobEventLatency < System.currentTimeMillis()) {
+                    slaCalc.setEventProcessed(eventProc);
                     confirmWithDB(slaCalc);
+                    eventProc = slaCalc.getEventProcessed();
                     change = true;
-                    eventHandler.queueEvent(new SLACalcStatus(slaCalc));
-                    eventProc += 4;
                 }
             }
             if (change) {
@@ -344,7 +359,7 @@ public class SLACalculatorMemory impleme
                 if (eventProc == 7) {
                     historySet.add(jobId);
                     slaMap.remove(jobId);
-                    XLog.getLog(SLAService.class).trace("Removed Job [{0}] from map after End-processed", jobId);
+                    LOG.trace("Removed Job [{0}] from map after End-processed", jobId);
                 }
 
             }
@@ -357,14 +372,16 @@ public class SLACalculatorMemory impleme
      */
     @Override
     public void updateAllSlaStatus() {
+        LOG.info("Running periodic SLA check");
         Iterator<String> iterator = slaMap.keySet().iterator();
         while (iterator.hasNext()) {
             String jobId = iterator.next();
             try {
+                LOG.trace("Processing SLA for jobid={0}", jobId);
                 updateJobSla(jobId);
             }
             catch (Exception e) {
-                XLog.getLog(SLAService.class).error("Exception in SLA processing for job [{0}]", jobId, e);
+                LOG.error("Exception in SLA processing for job [{0}]", jobId, e);
             }
         }
     }
@@ -384,13 +401,13 @@ public class SLACalculatorMemory impleme
                 insertList.add(reg);
                 insertList.add(new SLASummaryBean(slaCalc));
                 jpaService.execute(new SLACalculationInsertUpdateJPAExecutor(insertList, null));
-                XLog.getLog(SLAService.class).trace("SLA Registration Event - Job:" + jobId);
+                LOG.trace("SLA Registration Event - Job:" + jobId);
                 return true;
             }
             else {
-                XLog.getLog(SLAService.class)
-                .error("SLACalculator memory capacity reached. Cannot add or update new SLA Registration entry for job [{0}]",
-                reg.getId());
+                LOG.error(
+                        "SLACalculator memory capacity reached. Cannot add or update new SLA Registration entry for job [{0}]",
+                        reg.getId());
             }
         }
         catch (JPAExecutorException jpa) {
@@ -432,13 +449,13 @@ public class SLACalculatorMemory impleme
                 updateList.add(reg);
                 updateList.add(new SLASummaryBean(slaCalc));
                 jpaService.execute(new SLACalculationInsertUpdateJPAExecutor(null, updateList));
-                XLog.getLog(SLAService.class).trace("SLA Registration Event - Job:" + jobId);
+                LOG.trace("SLA Registration Event - Job:" + jobId);
                 return true;
             }
             else {
-                XLog.getLog(SLAService.class)
-                .error("SLACalculator memory capacity reached. Cannot add or update new SLA Registration entry for job [{0}]",
-                reg.getId());
+                LOG.error(
+                        "SLACalculator memory capacity reached. Cannot add or update new SLA Registration entry for job [{0}]",
+                        reg.getId());
             }
         }
         catch (JPAExecutorException jpa) {
@@ -481,7 +498,7 @@ public class SLACalculatorMemory impleme
                         slaInfo = processJobEndFailureSLA(slaCalc, startTime, endTime);
                         break;
                     default:
-                        XLog.getLog(SLAService.class).debug("Unknown Job Status for SLA purpose[{0}]", jobEventStatus);
+                        LOG.debug("Unknown Job Status for SLA purpose[{0}]", jobEventStatus);
                         slaInfo = getSLASummaryBean(slaCalc);
                 }
 
@@ -491,7 +508,7 @@ public class SLACalculatorMemory impleme
                 }
                 hasSla = true;
             }
-            XLog.getLog(SLAService.class).trace("SLA Status Event - Job:" + jobId + " Status:" + slaCalc.getSLAStatus());
+            LOG.trace("SLA Status Event - Job:" + jobId + " Status:" + slaCalc.getSLAStatus());
         }
         else if (historySet.contains(jobId)) {
             slaInfo = jpaService.execute(new SLASummaryGetJPAExecutor(jobId));
@@ -618,7 +635,10 @@ public class SLACalculatorMemory impleme
 
         byte eventProc = slaCalc.getEventProcessed();
         if (((eventProc >> 1) & 1) == 0) {
-            processDurationSLA(expectedDuration, actualDuration, slaCalc);
+            if (expectedDuration != -1) {
+                slaCalc.setEventStatus(EventStatus.DURATION_MISS);
+                eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+            }
             eventProc += 2;
             slaCalc.setEventProcessed(eventProc);
         }
@@ -627,7 +647,7 @@ public class SLACalculatorMemory impleme
             slaCalc.setSLAStatus(SLAStatus.MISS);
             eventProc += 4;
             slaCalc.setEventProcessed(eventProc);
-                eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+            eventHandler.queueEvent(new SLACalcStatus(slaCalc));
         }
         return getSLASummaryBean(slaCalc);
     }
@@ -657,22 +677,19 @@ public class SLACalculatorMemory impleme
     }
 
     /*
-     * Confirm END_MISS alert against source of truth - DB
+     * Confirm alerts against source of truth - DB. Also required in case of High Availability
      */
     private void confirmWithDB(SLACalcStatus slaCalc) {
-        boolean isMiss = false, ended = false;
+        boolean ended = false, isEndMiss = false;
         try {
             switch (slaCalc.getAppType()) {
                 case WORKFLOW_JOB:
                     WorkflowJobBean wf = jpaService.execute(new WorkflowJobGetForSLAJPAExecutor(slaCalc.getId()));
-                    if (wf.getEndTime() == null) {
-                        isMiss = true;
-                    }
-                    else {
+                    if (wf.getEndTime() != null) {
                         ended = true;
                         if (wf.getStatus() == WorkflowJob.Status.KILLED || wf.getStatus() == WorkflowJob.Status.FAILED
                                 || wf.getEndTime().getTime() > slaCalc.getExpectedEnd().getTime()) {
-                            isMiss = true;
+                            isEndMiss = true;
                         }
                     }
                     slaCalc.setActualStart(wf.getStartTime());
@@ -681,14 +698,11 @@ public class SLACalculatorMemory impleme
                     break;
                 case WORKFLOW_ACTION:
                     WorkflowActionBean wa = jpaService.execute(new WorkflowActionGetForSLAJPAExecutor(slaCalc.getId()));
-                    if (wa.getEndTime() == null) {
-                        isMiss = true;
-                    }
-                    else {
+                    if (wa.getEndTime() != null) {
                         ended = true;
                         if (wa.isTerminalWithFailure()
                                 || wa.getEndTime().getTime() > slaCalc.getExpectedEnd().getTime()) {
-                            isMiss = true;
+                            isEndMiss = true;
                         }
                     }
                     slaCalc.setActualStart(wa.getStartTime());
@@ -698,54 +712,98 @@ public class SLACalculatorMemory impleme
                 case COORDINATOR_ACTION:
                     CoordinatorActionBean ca = jpaService.execute(new CoordActionGetForSLAJPAExecutor(slaCalc.getId()));
                     if (ca.isTerminalWithFailure()) {
-                        isMiss = ended = true;
+                        isEndMiss = ended = true;
                         slaCalc.setActualStart(null);
                         slaCalc.setActualEnd(ca.getLastModifiedTime());
                     }
                     if (ca.getExternalId() != null) {
                         wf = jpaService.execute(new WorkflowJobGetForSLAJPAExecutor(ca.getExternalId()));
-                        if (wf.getEndTime() == null) {
-                            isMiss = true;
-                        }
-                        else {
+                        if (wf.getEndTime() != null) {
                             ended = true;
                             if (wf.getEndTime().getTime() > slaCalc.getExpectedEnd().getTime()) {
-                                isMiss = true;
+                                isEndMiss = true;
                             }
                         }
                         slaCalc.setActualEnd(wf.getEndTime());
                         slaCalc.setActualStart(wf.getStartTime());
                     }
-                    else {
-                        isMiss = true;
-                    }
                     slaCalc.setJobStatus(ca.getStatusStr());
                     break;
                 default:
-                    XLog.getLog(SLAService.class).debug("Unsupported App-type for SLA - " + slaCalc.getAppType());
+                    LOG.debug("Unsupported App-type for SLA - " + slaCalc.getAppType());
             }
+
+            byte eventProc = slaCalc.getEventProcessed();
             if (ended) {
-                slaCalc.setActualDuration(slaCalc.getActualEnd().getTime() - slaCalc.getActualStart().getTime());
-                if (((slaCalc.getEventProcessed() >> 1) & 1) == 0) {
-                    processDurationSLA(slaCalc.getExpectedDuration(), slaCalc.getActualDuration(), slaCalc);
+                if (isEndMiss) {
+                    slaCalc.setSLAStatus(SLAStatus.MISS);
+                }
+                else {
+                    slaCalc.setSLAStatus(SLAStatus.MET);
+                }
+                if (slaCalc.getActualStart() != null) {
+                    slaCalc.setActualDuration(slaCalc.getActualEnd().getTime() - slaCalc.getActualStart().getTime());
+                    if (((eventProc >> 1) & 1) == 0) {
+                        processDurationSLA(slaCalc.getExpectedDuration(), slaCalc.getActualDuration(), slaCalc);
+                    }
+                }
+                if (eventProc < 4) {
+                    if (isEndMiss) {
+                        slaCalc.setEventStatus(EventStatus.END_MISS);
+                    }
+                    else {
+                        slaCalc.setEventStatus(EventStatus.END_MET);
+                    }
+                    eventHandler.queueEvent(new SLACalcStatus(slaCalc));
                 }
                 slaCalc.setEventProcessed(8);
             }
-            if (isMiss) {
-                slaCalc.setEventStatus(EventStatus.END_MISS);
-                slaCalc.setSLAStatus(SLAStatus.MISS);
-            }
             else {
-                slaCalc.setEventStatus(EventStatus.END_MET);
-                slaCalc.setSLAStatus(SLAStatus.MET);
+                if (slaCalc.getActualStart() != null) {
+                    slaCalc.setSLAStatus(SLAStatus.IN_PROCESS);
+                }
+                if ((eventProc & 1) == 0) {
+                    if (slaCalc.getActualStart() != null) {
+                        if (slaCalc.getExpectedStart().getTime() < slaCalc.getActualStart().getTime()) {
+                            slaCalc.setEventStatus(EventStatus.START_MISS);
+                        }
+                        else {
+                            slaCalc.setEventStatus(EventStatus.START_MET);
+                        }
+                        eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+                        eventProc++;
+                    }
+                    else if (slaCalc.getExpectedStart().getTime() < System.currentTimeMillis()) {
+                        slaCalc.setEventStatus(EventStatus.START_MISS);
+                        eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+                        eventProc++;
+                    }
+                }
+                if (((eventProc >> 1) & 1) == 0 && slaCalc.getActualStart() != null
+                        && slaCalc.getExpectedDuration() != -1) {
+                    if (System.currentTimeMillis() - slaCalc.getActualStart().getTime() > slaCalc.getExpectedDuration()) {
+                        slaCalc.setEventStatus(EventStatus.DURATION_MISS);
+                        eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+                        eventProc += 2;
+                    }
+                }
+                if (eventProc < 4 && slaCalc.getExpectedEnd().getTime() < System.currentTimeMillis()) {
+                    slaCalc.setEventStatus(EventStatus.END_MISS);
+                    slaCalc.setSLAStatus(SLAStatus.MISS);
+                    eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+                    eventProc += 4;
+                }
+                slaCalc.setEventProcessed(eventProc);
             }
         }
         catch (Exception e) {
-            XLog.getLog(SLAService.class).warn(
-                    "Error while confirming End_miss against DB: "
-                            + ". Setting END_MISS since time limit has been exceeded", e);
-            slaCalc.setEventStatus(EventStatus.END_MISS);
-            slaCalc.setSLAStatus(SLAStatus.MISS);
+            LOG.warn("Error while confirming against DB: ", e);
+            if (slaCalc.getEventProcessed() < 4 && slaCalc.getExpectedEnd().getTime() < System.currentTimeMillis()) {
+                slaCalc.setEventStatus(EventStatus.END_MISS);
+                slaCalc.setSLAStatus(SLAStatus.MISS);
+                eventHandler.queueEvent(new SLACalcStatus(slaCalc));
+                slaCalc.setEventProcessed(slaCalc.getEventProcessed() + 4);
+            }
         }
     }
 

Modified: oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLAOperations.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLAOperations.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLAOperations.java (original)
+++ oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/SLAOperations.java Mon Jul 29 16:57:44 2013
@@ -94,17 +94,15 @@ public class SLAOperations {
 
         // Setting expected duration in milliseconds
         String expectedDurationStr = getTagElement(eSla, MAX_DURATION);
-        long defaultDuration = 0;
-        if (sla.getExpectedStart() != null) {
-            defaultDuration = sla.getExpectedEnd().getTime() - sla.getExpectedStart().getTime();
-            sla.setExpectedDuration(defaultDuration);
-        }
         if (expectedDurationStr != null && expectedDurationStr.length() > 0) {
             float expectedDuration = Float.parseFloat(expectedDurationStr);
             if (expectedDuration > 0) {
                 sla.setExpectedDuration((long) (expectedDuration * 60 * 1000));
             }
         }
+        else if (sla.getExpectedStart() != null) {
+            sla.setExpectedDuration(sla.getExpectedEnd().getTime() - sla.getExpectedStart().getTime());
+        }
 
         // Parse desired alert-types i.e. start-miss, end-miss, start-met etc..
         String alertEvents = getTagElement(eSla, ALERT_EVENTS);

Modified: oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java (original)
+++ oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java Mon Jul 29 16:57:44 2013
@@ -307,8 +307,8 @@ public class SLAEmailEventListener exten
         printField(body, EmailField.ACTUAL_START_TIME.toString(), event.getActualStart());
         printField(body, EmailField.EXPECTED_END_TIME.toString(), event.getExpectedEnd());
         printField(body, EmailField.ACTUAL_END_TIME.toString(), event.getActualEnd());
-        printField(body, EmailField.EXPECTED_DURATION.toString(), event.getExpectedDuration());
-        printField(body, EmailField.ACTUAL_DURATION.toString(), event.getActualDuration());
+        printField(body, EmailField.EXPECTED_DURATION.toString(), getDurationInMins(event.getExpectedDuration()));
+        printField(body, EmailField.ACTUAL_DURATION.toString(), getDurationInMins(event.getActualDuration()));
 
         try {
             msg.setText(body.toString());
@@ -319,6 +319,13 @@ public class SLAEmailEventListener exten
         }
     }
 
+    private long getDurationInMins(long duration) {
+        if (duration < 0) {
+            return duration;
+        }
+        return duration / 60000; //Convert millis to minutes
+    }
+
     private String getJobLink(String jobId) {
         StringBuffer url = new StringBuffer();
         String param = "/?job=";

Modified: oozie/branches/branch-4.0/core/src/main/resources/oozie-log4j.properties
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/resources/oozie-log4j.properties?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/main/resources/oozie-log4j.properties (original)
+++ oozie/branches/branch-4.0/core/src/main/resources/oozie-log4j.properties Mon Jul 29 16:57:44 2013
@@ -48,8 +48,9 @@ log4j.logger.org.apache.oozie.wf.service
 log4j.logger.org.apache.oozie.wf.servlet=INFO, test
 log4j.logger.org.apache.oozie.store=DEBUG, test
 log4j.logger.org.apache.oozie.workflow=INFO, test
-log4j.logger.org.apache.oozie.service=INFO, test
+log4j.logger.org.apache.oozie.service=DEBUG, test
 log4j.logger.org.apache.oozie.servlet=INFO, test
+log4j.logger.org.apache.oozie.sla=DEBUG, test
 log4j.logger.org.apache.hadoop=INFO, test
 log4j.logger.org.mortbay=INFO, test
 log4j.logger.org.hsqldb=INFO, test

Modified: oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java (original)
+++ oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java Mon Jul 29 16:57:44 2013
@@ -46,8 +46,6 @@ public class TestJMSTopicService extends
     @Before
     protected void setUp() throws Exception {
         super.setUp();
-        services = setupServicesForTopic();
-        services.init();
     }
 
     @After
@@ -63,165 +61,127 @@ public class TestJMSTopicService extends
     }
 
     @Test
-    public void testTopicAsUser() {
-        try {
-            JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
-            WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
-            assertEquals(wfj.getUser(), jmsTopicService.getTopic(wfj.getId()));
-            WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
-            assertEquals(wfj.getUser(), jmsTopicService.getTopic(wab.getId()));
-            CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
-            assertEquals(wfj.getUser(), jmsTopicService.getTopic(cjb.getId()));
-            CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
-                    "coord-action-for-action-input-check.xml", 0);
-            assertEquals(wfj.getUser(), jmsTopicService.getTopic(cab.getId()));
-            BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
-            assertEquals(wfj.getUser(), jmsTopicService.getTopic(bjb.getId()));
-            BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
-            assertEquals(wfj.getUser(), jmsTopicService.getTopic(bab.getBundleActionId()));
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-        }
-
+    public void testTopicAsUser() throws Exception {
+        services = setupServicesForTopic();
+        services.init();
+        JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
+        WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
+        assertEquals(wfj.getUser(), jmsTopicService.getTopic(wfj.getId()));
+        WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
+        assertEquals(wfj.getUser(), jmsTopicService.getTopic(wab.getId()));
+        CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
+        assertEquals(wfj.getUser(), jmsTopicService.getTopic(cjb.getId()));
+        CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
+                "coord-action-for-action-input-check.xml", 0);
+        assertEquals(wfj.getUser(), jmsTopicService.getTopic(cab.getId()));
+        BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
+        assertEquals(wfj.getUser(), jmsTopicService.getTopic(bjb.getId()));
+        BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
+        assertEquals(wfj.getUser(), jmsTopicService.getTopic(bab.getBundleActionId()));
     }
 
     @Test
-    public void testTopicAsJobId() {
-        try {
-            final String TOPIC_PREFIX = "oozie.";
-            services.destroy();
-            services = setupServicesForTopic();
-            services.getConf().set(JMSTopicService.TOPIC_NAME, "default=" + JMSTopicService.TopicType.JOBID.getValue());
-            services.getConf().set(JMSTopicService.TOPIC_PREFIX, TOPIC_PREFIX);
-            services.init();
-            JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
-            WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
-            assertEquals(TOPIC_PREFIX, jmsTopicService.getTopicPrefix());
-            assertEquals(TOPIC_PREFIX+wfj.getId(), jmsTopicService.getTopic(wfj.getId()));
-            WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
-            assertEquals(TOPIC_PREFIX+wfj.getId(), jmsTopicService.getTopic(wab.getId()));
-            CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
-            assertEquals(TOPIC_PREFIX+cjb.getId(), jmsTopicService.getTopic(cjb.getId()));
-            CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
-                    "coord-action-for-action-input-check.xml", 0);
-            assertEquals(TOPIC_PREFIX+cjb.getId(), jmsTopicService.getTopic(cab.getId()));
-            BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
-            assertEquals(TOPIC_PREFIX+bjb.getId(), jmsTopicService.getTopic(bjb.getId()));
-            BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
-            assertEquals(TOPIC_PREFIX+bjb.getId(), jmsTopicService.getTopic(bab.getBundleActionId()));
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-        }
-
+    public void testTopicAsJobId() throws Exception {
+        final String TOPIC_PREFIX = "oozie.";
+        services = setupServicesForTopic();
+        services.getConf().set(JMSTopicService.TOPIC_NAME, "default=" + JMSTopicService.TopicType.JOBID.getValue());
+        services.getConf().set(JMSTopicService.TOPIC_PREFIX, TOPIC_PREFIX);
+        services.init();
+        JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
+        WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
+        assertEquals(TOPIC_PREFIX, jmsTopicService.getTopicPrefix());
+        assertEquals(TOPIC_PREFIX + wfj.getId(), jmsTopicService.getTopic(wfj.getId()));
+        WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
+        assertEquals(TOPIC_PREFIX + wfj.getId(), jmsTopicService.getTopic(wab.getId()));
+        CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
+        assertEquals(TOPIC_PREFIX + cjb.getId(), jmsTopicService.getTopic(cjb.getId()));
+        CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
+                "coord-action-for-action-input-check.xml", 0);
+        assertEquals(TOPIC_PREFIX + cjb.getId(), jmsTopicService.getTopic(cab.getId()));
+        BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
+        assertEquals(TOPIC_PREFIX + bjb.getId(), jmsTopicService.getTopic(bjb.getId()));
+        BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
+        assertEquals(TOPIC_PREFIX + bjb.getId(), jmsTopicService.getTopic(bab.getBundleActionId()));
     }
 
     @Test
-    public void testTopicAsFixedString() {
-        try {
-            services.destroy();
-            services = setupServicesForTopic();
-            services.getConf().set(
-                    JMSTopicService.TOPIC_NAME,
-                    JMSTopicService.JobType.WORKFLOW.getValue() + " =workflow,"
-                            + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord,"
-                            + JMSTopicService.JobType.BUNDLE.getValue() + "=bundle");
-            services.init();
-            JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
-            WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
-            assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
-            WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
-            assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
-            CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
-            assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
-            CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
-                    "coord-action-for-action-input-check.xml", 0);
-            assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
-            BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
-            assertEquals("bundle", jmsTopicService.getTopic(bjb.getId()));
-            BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
-            assertEquals("bundle", jmsTopicService.getTopic(bab.getBundleActionId()));
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-        }
-
+    public void testTopicAsFixedString() throws Exception {
+        services = setupServicesForTopic();
+        services.getConf().set(
+                JMSTopicService.TOPIC_NAME,
+                JMSTopicService.JobType.WORKFLOW.getValue() + " =workflow,"
+                        + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord,"
+                        + JMSTopicService.JobType.BUNDLE.getValue() + "=bundle");
+        services.init();
+        JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
+        WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
+        assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
+        WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
+        assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
+        CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
+        assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
+        CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
+                "coord-action-for-action-input-check.xml", 0);
+        assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
+        BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
+        assertEquals("bundle", jmsTopicService.getTopic(bjb.getId()));
+        BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
+        assertEquals("bundle", jmsTopicService.getTopic(bab.getBundleActionId()));
     }
 
     @Test
-    public void testMixedTopic1() {
-        try {
-            services.destroy();
-            services = setupServicesForTopic();
-            services.getConf().set(
-                    JMSTopicService.TOPIC_NAME,
-                    JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow,"
-                            + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord, default = "
-                            + JMSTopicService.TopicType.JOBID.getValue());
-            services.init();
-            JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
-            WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
-            assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
-            WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
-            assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
-            CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
-            assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
-            CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
-                    "coord-action-for-action-input-check.xml", 0);
-            assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
-            BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
-            assertEquals(bjb.getId(), jmsTopicService.getTopic(bjb.getId()));
-            BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
-            assertEquals(bjb.getId(), jmsTopicService.getTopic(bab.getBundleActionId()));
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-        }
-
+    public void testMixedTopic1() throws Exception {
+        services = setupServicesForTopic();
+        services.getConf().set(
+                JMSTopicService.TOPIC_NAME,
+                JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow,"
+                        + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord, default = "
+                        + JMSTopicService.TopicType.JOBID.getValue());
+        services.init();
+        JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
+        WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
+        assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
+        WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
+        assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
+        CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
+        assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
+        CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
+                "coord-action-for-action-input-check.xml", 0);
+        assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
+        BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
+        assertEquals(bjb.getId(), jmsTopicService.getTopic(bjb.getId()));
+        BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
+        assertEquals(bjb.getId(), jmsTopicService.getTopic(bab.getBundleActionId()));
     }
 
     @Test
-    public void testMixedTopic2() {
-        try {
-            services.destroy();
-            services = setupServicesForTopic();
-            services.getConf().set(
-                    JMSTopicService.TOPIC_NAME,
-                    JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow,"
-                            + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord");
-            services.init();
-            JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
-            WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
-            assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
-            WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
-            assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
-            CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
-            assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
-            CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
-                    "coord-action-for-action-input-check.xml", 0);
-            assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
-            BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
-            // As no default is specified, user will be considered as topic
-            assertEquals(bjb.getUser(), jmsTopicService.getTopic(bjb.getId()));
-            BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
-            assertEquals(bjb.getUser(), jmsTopicService.getTopic(bab.getBundleActionId()));
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-        }
-
+    public void testMixedTopic2() throws Exception {
+        services = setupServicesForTopic();
+        services.getConf().set(
+                JMSTopicService.TOPIC_NAME,
+                JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow,"
+                        + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord");
+        services.init();
+        JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
+        WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
+        assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
+        WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
+        assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
+        CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
+        assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
+        CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED,
+                "coord-action-for-action-input-check.xml", 0);
+        assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
+        BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
+        // As no default is specified, user will be considered as topic
+        assertEquals(bjb.getUser(), jmsTopicService.getTopic(bjb.getId()));
+        BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
+        assertEquals(bjb.getUser(), jmsTopicService.getTopic(bab.getBundleActionId()));
     }
 
     @Test
     public void testIncorrectConfigurationJobType() {
         try {
-            services.destroy();
             services = setupServicesForTopic();
             services.getConf().set(JMSTopicService.TOPIC_NAME,
                     "InvalidJobType" + " = workflow," + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord");
@@ -236,7 +196,6 @@ public class TestJMSTopicService extends
     @Test
     public void testIncorrectConfigurationDefault() {
         try {
-            services.destroy();
             services = setupServicesForTopic();
             services.getConf().set(JMSTopicService.TOPIC_NAME, "default=" + "invalidvalue");
             services.init();
@@ -248,55 +207,37 @@ public class TestJMSTopicService extends
     }
 
     @Test
-    public void testTopicProperties1() {
-        try {
-            services.destroy();
-            services = setupServicesForTopic();
-            services.init();
-            JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
-            Properties props = jmsTopicService.getTopicPatternProperties();
-            assertEquals("${username}", props.get(AppType.WORKFLOW_JOB));
-            assertEquals("${username}", props.get(AppType.WORKFLOW_ACTION));
-            assertEquals("${username}", props.get(AppType.COORDINATOR_JOB));
-            assertEquals("${username}", props.get(AppType.COORDINATOR_ACTION));
-            assertEquals("${username}", props.get(AppType.BUNDLE_JOB));
-            assertEquals("${username}", props.get(AppType.BUNDLE_ACTION));
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-        }
+    public void testTopicProperties1() throws Exception {
+        services = setupServicesForTopic();
+        services.init();
+        JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
+        Properties props = jmsTopicService.getTopicPatternProperties();
+        assertEquals("${username}", props.get(AppType.WORKFLOW_JOB));
+        assertEquals("${username}", props.get(AppType.WORKFLOW_ACTION));
+        assertEquals("${username}", props.get(AppType.COORDINATOR_JOB));
+        assertEquals("${username}", props.get(AppType.COORDINATOR_ACTION));
+        assertEquals("${username}", props.get(AppType.BUNDLE_JOB));
+        assertEquals("${username}", props.get(AppType.BUNDLE_ACTION));
     }
 
-
     @Test
-    public void testTopicProperties2() {
-        try {
-            services.destroy();
-            services = setupServicesForTopic();
-            services.getConf().set(
-                    JMSTopicService.TOPIC_NAME,
-                    JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow,"
-                            + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord");
-            services.init();
-            JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
-            Properties props = jmsTopicService.getTopicPatternProperties();
-            assertEquals("workflow", props.get(AppType.WORKFLOW_JOB));
-            assertEquals("workflow", props.get(AppType.WORKFLOW_ACTION));
-
-            assertEquals("coord", props.get(AppType.COORDINATOR_JOB));
-            assertEquals("coord", props.get(AppType.COORDINATOR_ACTION));
-
-            assertEquals("${username}", props.get(AppType.BUNDLE_JOB));
-            assertEquals("${username}", props.get(AppType.BUNDLE_ACTION));
+    public void testTopicProperties2() throws Exception {
+        services = setupServicesForTopic();
+        services.getConf().set(
+                JMSTopicService.TOPIC_NAME,
+                JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow,"
+                        + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord");
+        services.init();
+        JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
+        Properties props = jmsTopicService.getTopicPatternProperties();
+        assertEquals("workflow", props.get(AppType.WORKFLOW_JOB));
+        assertEquals("workflow", props.get(AppType.WORKFLOW_ACTION));
 
-            services.destroy();
+        assertEquals("coord", props.get(AppType.COORDINATOR_JOB));
+        assertEquals("coord", props.get(AppType.COORDINATOR_ACTION));
 
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-        }
+        assertEquals("${username}", props.get(AppType.BUNDLE_JOB));
+        assertEquals("${username}", props.get(AppType.BUNDLE_ACTION));
     }
 
 }

Modified: oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestPartitionDependencyManagerEhcache.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestPartitionDependencyManagerEhcache.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestPartitionDependencyManagerEhcache.java (original)
+++ oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/service/TestPartitionDependencyManagerEhcache.java Mon Jul 29 16:57:44 2013
@@ -77,7 +77,7 @@ public class TestPartitionDependencyMana
         LOG.info("Time taken to insert and retrive " + numItems + " items is "
                 + (System.currentTimeMillis() - startTime));
         // timeToIdleSeconds is 1
-        Thread.sleep(1000);
+        Thread.sleep(1100);
         for (int i = 0; i < numItems; i++) {
             assertNull(pdms.getWaitingActions(new HCatURI("hcat://hcat.server.com:5080/mydb/mytbl/id=" + "" + i)));
         }

Modified: oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLACalculatorMemory.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLACalculatorMemory.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLACalculatorMemory.java (original)
+++ oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLACalculatorMemory.java Mon Jul 29 16:57:44 2013
@@ -425,7 +425,9 @@ public class TestSLACalculatorMemory ext
         SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
         EventHandlerService ehs = Services.get().get(EventHandlerService.class);
         slaCalcMemory.init(new Configuration(false));
-        SLARegistrationBean slaRegBean = _createSLARegistration("job-1", AppType.WORKFLOW_JOB);
+
+        WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB);
         slaRegBean.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
         slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 1 * 3600 * 1000));
 
@@ -487,15 +489,12 @@ public class TestSLACalculatorMemory ext
         EventHandlerService ehs = Services.get().get(EventHandlerService.class);
         SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
         slaCalcMemory.init(new Configuration(false));
-        SLARegistrationBean slaRegBean = _createSLARegistration("job-1", AppType.WORKFLOW_JOB);
-        Date startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000); // 1
-                                                                                     // hour
-                                                                                     // back
+        WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB);
+        Date startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000); // 1 hour back
         slaRegBean.setExpectedStart(startTime);
         slaRegBean.setExpectedDuration(3600 * 1000);
-        slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000)); // 1
-                                                                                               // hour
-                                                                                               // ahead
+        slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000)); // 1 hour ahead
         String jobId = slaRegBean.getId();
         slaCalcMemory.addRegistration(slaRegBean.getId(), slaRegBean);
         slaCalcMemory.updateJobSla(jobId);
@@ -522,9 +521,7 @@ public class TestSLACalculatorMemory ext
         Date startTime = new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000); // 1 hour ahead
         slaRegBean.setExpectedStart(startTime);
         slaRegBean.setExpectedDuration(3600 * 1000);
-        slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000)); // 1
-                                                                                               // hour
-                                                                                               // back
+        slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000)); // 1 hour back
         String jobId = slaRegBean.getId();
         slaCalcMemory.addRegistration(slaRegBean.getId(), slaRegBean);
         slaCalcMemory.updateJobSla(jobId);

Modified: oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEmailEventListener.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEmailEventListener.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEmailEventListener.java (original)
+++ oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEmailEventListener.java Mon Jul 29 16:57:44 2013
@@ -213,8 +213,10 @@ public class TestSLAEmailEventListener e
         Date actualStartDate = DateUtils.parseDateUTC("2013-01-01T00:10Z");
         Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T00:20Z");
         Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T00:40Z");
-        long expectedDuration = (expectedEndDate.getTime() - expectedStartDate.getTime()) / (1000 * 60);
-        long actualDuration = (actualEndDate.getTime() - actualStartDate.getTime()) / (1000 * 60);
+        long expectedDuration = expectedEndDate.getTime() - expectedStartDate.getTime();
+        long actualDuration = actualEndDate.getTime() - actualStartDate.getTime();
+        long expectedDurationInMins = expectedDuration / 60000;
+        long actualDurationInMins = actualDuration / 60000;
         event.setId("0000000-000000000000001-oozie-wrkf-C@1");
         eventBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
         event.setEventStatus(EventStatus.DURATION_MISS);
@@ -275,8 +277,8 @@ public class TestSLAEmailEventListener e
         assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_START_TIME.toString() + sep + actualStartDate) > -1);
         assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_END_TIME.toString() + sep + expectedEndDate) > -1);
         assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_END_TIME.toString() + sep + actualEndDate) > -1);
-        assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_DURATION.toString() + sep + expectedDuration) > -1);
-        assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_DURATION.toString() + sep + actualDuration) > -1);
+        assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_DURATION.toString() + sep + expectedDurationInMins) > -1);
+        assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_DURATION.toString() + sep + actualDurationInMins) > -1);
     }
 
     public void testUserAlertEventSetting() throws Exception {

Modified: oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEventGeneration.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEventGeneration.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEventGeneration.java (original)
+++ oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAEventGeneration.java Mon Jul 29 16:57:44 2013
@@ -100,6 +100,7 @@ public class TestSLAEventGeneration exte
                 EventHandlerService.class.getName() + "," + SLAService.class.getName());
         conf.setClass(EventHandlerService.CONF_LISTENERS, SLAJobEventListener.class, JobEventListener.class);
         conf.setInt(EventHandlerService.CONF_WORKER_INTERVAL, 10000);
+        conf.setInt(EventHandlerService.CONF_WORKER_THREADS, 0);
         conf.setInt(EventHandlerService.CONF_BATCH_SIZE, 1);
         services.init();
         jpa = services.get(JPAService.class);
@@ -340,12 +341,10 @@ public class TestSLAEventGeneration exte
     @Test
     public void testCoordinatorActionCommands() throws Exception {
         EventHandlerService ehs = services.get(EventHandlerService.class);
-        assertNotNull(ehs);
         // reduce noise from WF Job events (also default) by setting it to only
         // coord action
         ehs.setAppTypes(new HashSet<String>(Arrays.asList(new String[] { "coordinator_action" })));
         SLAService slas = services.get(SLAService.class);
-        assertNotNull(slas);
 
         String coordXml = IOUtils.getResourceAsString("coord-action-sla.xml", -1);
         Path appPath = getFsTestCaseDir();
@@ -387,6 +386,7 @@ public class TestSLAEventGeneration exte
         assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
         assertEquals(30 * 60 * 1000, slaEvent.getExpectedDuration());
         assertEquals(alert_events, slaEvent.getAlertEvents());
+        waitForEventGeneration(200);
         ehs.getEventQueue().clear(); //clear the coord-action WAITING event generated
         slas.runSLAWorker();
         slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
@@ -408,9 +408,13 @@ public class TestSLAEventGeneration exte
         assertEquals(WorkflowJob.Status.RUNNING.name(), slaEvent.getJobStatus());
 
         // test that sla processes the Job Event from Kill command
+        ehs.getEventQueue().clear();
         new CoordKillXCommand(jobId).call();
+        waitForEventGeneration(200);
         ehs.new EventWorker().run();
-        ehs.getEventQueue().poll(); //ignore duration event
+        waitForEventGeneration(300);
+        slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
+        assertEquals(EventStatus.DURATION_MISS, slaEvent.getEventStatus());
         slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
         assertEquals(actionId, slaEvent.getId());
         assertNotNull(slaEvent.getActualEnd());
@@ -489,6 +493,16 @@ public class TestSLAEventGeneration exte
 
     }
 
+    private void waitForEventGeneration(int wait) {
+        final EventHandlerService ehs = Services.get().get(EventHandlerService.class);
+        waitFor(wait, new Predicate() {
+            @Override
+            public boolean evaluate() throws Exception {
+                return ehs.getEventQueue().peek() != null;
+            }
+        });
+    }
+
     private void _testWorkflowJobCommands(Configuration conf, EventHandlerService ehs, SLAService slas, boolean isNew)
             throws Exception {
         cal.setTime(new Date());
@@ -526,8 +540,9 @@ public class TestSLAEventGeneration exte
         new StartXCommand(jobId).call();
         slaEvent = slas.getSLACalculator().get(jobId);
         slaEvent.setEventProcessed(0); //resetting to receive sla events
+        waitForEventGeneration(200);
         ehs.new EventWorker().run();
-        Thread.sleep(300); // time for listeners to run
+        waitForEventGeneration(300);
         slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
         assertEquals(jobId, slaEvent.getId());
         assertNotNull(slaEvent.getActualStart());
@@ -536,17 +551,24 @@ public class TestSLAEventGeneration exte
         ehs.getEventQueue().clear();
 
         // test that sla processes the Job Event from Kill command
+        // job must already be killed (test xml) so set some status for KillX to work
+        JPAService jpaService = Services.get().get(JPAService.class);
+        WorkflowJobBean wf = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
+        wf.setStatus(WorkflowJob.Status.FAILED);
+        jpaService.execute(new WorkflowJobUpdateJPAExecutor(wf));
         new KillXCommand(jobId).call();
+        waitForEventGeneration(1000);
         ehs.getEventQueue().poll(); //ignore the wf-action event generated
+        waitForEventGeneration(1000); //wait for wf job kill event to generate
         ehs.new EventWorker().run();
-        Thread.sleep(300); // time for listeners to run
+        waitForEventGeneration(2000); // time for listeners to run
         ehs.getEventQueue().poll(); // ignore duration event
         slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
         assertEquals(jobId, slaEvent.getId());
         assertNotNull(slaEvent.getActualEnd());
         assertEquals(EventStatus.END_MISS, slaEvent.getEventStatus());
         assertEquals(SLAStatus.MISS, slaEvent.getSLAStatus());
-        assertEquals(WorkflowJob.Status.KILLED.name(), slaEvent.getJobStatus());
+        assertEquals(WorkflowJob.Status.FAILED.name(), slaEvent.getJobStatus());
     }
 
 }

Modified: oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAService.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAService.java?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAService.java (original)
+++ oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/sla/TestSLAService.java Mon Jul 29 16:57:44 2013
@@ -60,6 +60,7 @@ public class TestSLAService extends XDat
                 + "org.apache.oozie.sla.service.SLAService");
         conf.setClass(EventHandlerService.CONF_LISTENERS, DummySLAEventListener.class, SLAEventListener.class);
         conf.setLong(SLAService.CONF_JOB_EVENT_LATENCY, 0);
+        conf.setInt(EventHandlerService.CONF_WORKER_THREADS, 0);
         services.init();
         cleanUpDBTables();
     }

Modified: oozie/branches/branch-4.0/core/src/test/resources/wf-job-sla.xml
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/resources/wf-job-sla.xml?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/core/src/test/resources/wf-job-sla.xml (original)
+++ oozie/branches/branch-4.0/core/src/test/resources/wf-job-sla.xml Mon Jul 29 16:57:44 2013
@@ -35,8 +35,11 @@
             </configuration>
         </map-reduce>
         <ok to="end"/>
-        <error to="end"/>
+        <error to="fail"/>
     </action>
+    <kill name="fail">
+        <message>Workflow failed</message>
+    </kill>
     <end name="end"/>
     <sla:info>
         <sla:nominal-time>${nominal_time}</sla:nominal-time>

Modified: oozie/branches/branch-4.0/docs/src/site/twiki/DG_SLAMonitoring.twiki
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/docs/src/site/twiki/DG_SLAMonitoring.twiki?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/docs/src/site/twiki/DG_SLAMonitoring.twiki (original)
+++ oozie/branches/branch-4.0/docs/src/site/twiki/DG_SLAMonitoring.twiki Mon Jul 29 16:57:44 2013
@@ -103,9 +103,9 @@ For the list of tags usable under =<sla:
 This new schema is much more compact and meaningful, getting rid of redundant and unused tags.
 
    * ==nominal-time==: As the name suggests, this is the time relative to which your jobs' SLAs will be calculated. Generally since Oozie workflows are aligned with synchronous data dependencies, this nominal time can be parameterized to be passed the value of your coordinator nominal time. Nominal time is also required in case of independent workflows and you can specify the time in which you expect the workflow to be run if you don't have a synchronous dataset associated with it.
-   * ==should-start==: Relative to =nominal-time= this is the amount of time (alongwith time-unit) within which, your job should *start running*, to meet SLA. This is optional.
-   * ==should-end==: Relative to =nominal-time= this is the amount of time (alongwith time-unit) within which, your job should *finish*, to meet SLA.
-   * ==max-duration==: This is the maximum amount of time (alongwith time-unit) for your job run, to meet SLA. This is optional.
+   * ==should-start==: Relative to =nominal-time= this is the amount of time (along with time-unit - MINUTES, HOURS, DAYS) within which your job should *start running* to meet SLA. This is optional.
+   * ==should-end==: Relative to =nominal-time= this is the amount of time (along with time-unit - MINUTES, HOURS, DAYS) within which your job should *finish* to meet SLA.
+   * ==max-duration==: This is the maximum amount of time (along with time-unit - MINUTES, HOURS, DAYS) your job is expected to run. This is optional.
    * ==alert-events==: Specify the types of events for which *Email* alerts should be sent. Allowable values in this comma-separated list are start_miss, end_miss and duration_miss. *_met events can generally be deemed low priority and hence email alerting for these is not neccessary. However, note that this setting is only for alerts via *email* alerts and not via JMS messages, where all events send out notifications, and user can filter them using desired selectors. This is optional and only applicable when alert-contact is configured.
    * ==alert-contact==: Specify a comma separated list of email addresses where you wish your alerts to be sent. This is optional and need not be configured if you just want to view your job SLA history in the UI and do not want to receive email alerts.
 
@@ -294,6 +294,11 @@ SLA Details:
   Actual Duration (in mins) - -1
 </verbatim>
 
+---++ Known issues
+There are two known issues when you define SLA for a workflow action.
+   * If there are decision nodes and SLA is defined for a workflow action not in the execution path because of the decision node, you will still get an SLA_MISS notification.
+   * If you have dangling action nodes in your workflow definition and SLA is defined for it, you will still get an SLA_MISS notification.
+
 [[index][::Go back to Oozie Documentation Index::]]
 
 </noautolink>

Modified: oozie/branches/branch-4.0/release-log.txt
URL: http://svn.apache.org/viewvc/oozie/branches/branch-4.0/release-log.txt?rev=1508134&r1=1508133&r2=1508134&view=diff
==============================================================================
--- oozie/branches/branch-4.0/release-log.txt (original)
+++ oozie/branches/branch-4.0/release-log.txt Mon Jul 29 16:57:44 2013
@@ -1,5 +1,6 @@
 -- Oozie 4.0.0 release
 
+OOZIE-1472 Confirm against database before generating start and duration miss events (rohini)
 OOZIE-1473 getKey() not overridden in some commands causing duplicates in queue (virag)
 OOZIE-1470 BundleStatusUpdateXCommand should get lock for bundle job (virag)
 OOZIE-1469 loadState() and/or verifyPrecondition() are blank in some commands (virag)