You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by mo...@apache.org on 2013/05/20 18:51:39 UTC
svn commit: r1484523 [4/5] - in /oozie/trunk: ./
client/src/main/java/org/apache/oozie/
client/src/main/java/org/apache/oozie/cli/
client/src/main/java/org/apache/oozie/client/
client/src/main/java/org/apache/oozie/client/event/
client/src/main/java/or...
Added: oozie/trunk/core/src/main/java/org/apache/oozie/sla/service/SLAService.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/sla/service/SLAService.java?rev=1484523&view=auto
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/sla/service/SLAService.java (added)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/sla/service/SLAService.java Mon May 20 16:51:37 2013
@@ -0,0 +1,144 @@
+/**
+ * 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.oozie.sla.service;
+
+import java.util.Date;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.client.event.JobEvent.EventStatus;
+import org.apache.oozie.executor.jpa.JPAExecutorException;
+import org.apache.oozie.service.EventHandlerService;
+import org.apache.oozie.service.SchedulerService;
+import org.apache.oozie.service.Service;
+import org.apache.oozie.service.ServiceException;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.sla.SLACalculator;
+import org.apache.oozie.sla.SLACalculatorMemory;
+import org.apache.oozie.sla.SLARegistrationBean;
+import org.apache.oozie.util.XLog;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class SLAService implements Service {
+
+ public static final String CONF_PREFIX = "oozie.sla.service.SLAService.";
+ public static final String CONF_CALCULATOR_IMPL = CONF_PREFIX + "calculator.impl";
+ public static final String CONF_CAPACITY = CONF_PREFIX + "capacity";
+ public static final String CONF_ALERT_TYPES = CONF_PREFIX + "alert.types";
+
+ private static SLACalculator calcImpl;
+ private static boolean slaEnabled = false;
+ private EventHandlerService eventHandler;
+ public static XLog LOG;
+
+ @Override
+ public void init(Services services) throws ServiceException {
+ try {
+ Configuration conf = services.getConf();
+ Class<? extends SLACalculator> calcClazz = (Class<? extends SLACalculator>) conf.getClass(
+ CONF_CALCULATOR_IMPL, null);
+ calcImpl = calcClazz == null ? new SLACalculatorMemory() : (SLACalculator) calcClazz.newInstance();
+ calcImpl.init(conf);
+ eventHandler = Services.get().get(EventHandlerService.class);
+ if (eventHandler == null) {
+ throw new ServiceException(ErrorCode.E0103, "EventHandlerService", "Add it under config "
+ + Services.CONF_SERVICE_EXT_CLASSES + " or declare it BEFORE SLAService");
+ }
+ LOG = XLog.getLog(getClass());
+
+ Runnable slaThread = new SLAWorker(calcImpl);
+ // schedule runnable by default every 30 sec
+ services.get(SchedulerService.class).schedule(slaThread, 10, 30, SchedulerService.Unit.SEC);
+ slaEnabled = true;
+ LOG.info("SLAService initialized with impl [{0}] capacity [{1}]", calcImpl.getClass().getName(),
+ conf.get(SLAService.CONF_CAPACITY));
+ }
+ catch (Exception ex) {
+ throw new ServiceException(ErrorCode.E0102, ex.getMessage(), ex);
+ }
+ }
+
+ @Override
+ public void destroy() {
+ slaEnabled = false;
+ }
+
+ @Override
+ public Class<? extends Service> getInterface() {
+ return SLAService.class;
+ }
+
+ public static boolean isEnabled() {
+ return slaEnabled;
+ }
+
+ public SLACalculator getSLACalculator() {
+ return calcImpl;
+ }
+
+ @VisibleForTesting
+ public void runSLAWorker() {
+ new SLAWorker(calcImpl).run();
+ }
+
+ private class SLAWorker implements Runnable {
+
+ SLACalculator calc;
+
+ public SLAWorker(SLACalculator calc) {
+ this.calc = calc;
+ }
+
+ @Override
+ public void run() {
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ calc.updateAllSlaStatus();
+ }
+ }
+
+ public boolean addRegistrationEvent(SLARegistrationBean reg) throws ServiceException {
+ try {
+ if (calcImpl.addRegistration(reg.getJobId(), reg)) {
+ return true;
+ }
+ else {
+ LOG.warn("SLA queue full. Unable to add new SLA entry for job [{0}]", reg.getJobId());
+ }
+ }
+ catch (JPAExecutorException ex) {
+ LOG.warn("Could not add new SLA entry for job [{0}]", reg.getJobId(), ex);
+ }
+ return false;
+ }
+
+ public boolean addStatusEvent(String jobId, String status, EventStatus eventStatus, Date startTime, Date endTime)
+ throws ServiceException {
+ try {
+ if (calcImpl.addJobStatus(jobId, status, eventStatus, startTime, endTime)) {
+ return true;
+ }
+ }
+ catch (JPAExecutorException jpe) {
+ LOG.error("Exception while adding SLA Status event for Job [{0}]", jobId);
+ }
+ return false;
+ }
+
+}
Modified: oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java Mon May 20 16:51:37 2013
@@ -23,11 +23,8 @@ import java.util.List;
import java.util.concurrent.Callable;
import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
import org.apache.oozie.ErrorCode;
import org.apache.oozie.SLAEventBean;
-import org.apache.oozie.command.CommandException;
import org.apache.oozie.executor.jpa.JPAExecutorException;
import org.apache.oozie.executor.jpa.SLAEventsGetForSeqIdJPAExecutor;
import org.apache.oozie.service.InstrumentationService;
@@ -36,6 +33,7 @@ import org.apache.oozie.service.Services
import org.apache.oozie.util.Instrumentation;
import org.apache.oozie.util.ParamChecker;
+@Deprecated
public class SLAStore extends Store {
private EntityManager entityManager;
private static final String INSTR_GROUP = "db";
Modified: oozie/trunk/core/src/main/java/org/apache/oozie/util/XmlUtils.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/util/XmlUtils.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/util/XmlUtils.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/util/XmlUtils.java Mon May 20 16:51:37 2013
@@ -6,9 +6,9 @@
* 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.
@@ -45,12 +45,13 @@ import javax.xml.validation.Validator;
import org.apache.hadoop.conf.Configuration;
import org.apache.oozie.service.SchemaService;
-import org.apache.oozie.service.Services;
import org.apache.oozie.service.SchemaService.SchemaName;
+import org.apache.oozie.service.Services;
import org.jdom.Comment;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
@@ -62,10 +63,10 @@ import org.xml.sax.SAXException;
* XML utility methods.
*/
public class XmlUtils {
- public static final String SLA_NAME_SPACE_URI = "uri:oozie:sla:0.1";
private static class NoExternalEntityEntityResolver implements EntityResolver {
+ @Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource(new ByteArrayInputStream(new byte[0]));
}
@@ -400,4 +401,12 @@ public class XmlUtils {
return result.toString();
}
+ public static Element getSLAElement(Element elem) {
+ Element eSla_1 = elem.getChild("info", Namespace.getNamespace(SchemaService.SLA_NAME_SPACE_URI));
+ Element eSla_2 = elem.getChild("info", Namespace.getNamespace(SchemaService.SLA_NAMESPACE_URI_2));
+ Element eSla = (eSla_2 != null) ? eSla_2 : eSla_1;
+
+ return eSla;
+ }
+
}
Modified: oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java Mon May 20 16:51:37 2013
@@ -31,6 +31,7 @@ import org.apache.oozie.util.XLog;
import org.apache.oozie.util.XmlUtils;
import org.jdom.Element;
+@Deprecated
public class SLADbOperations {
public static final String CLIENT_ID_TAG = "oozie:sla:client-id";
@@ -188,7 +189,9 @@ public class SLADbOperations {
try {
Element eSla = XmlUtils.parseXml(slaXml);
Element eAppName = eSla.getChild("app-name", eSla.getNamespace());
- return createSlaStatusEvent(id, stat, appType, eAppName.getText(), log);
+ //stop-gap null handling till deprecated class is removed
+ String appNameStr = eAppName != null ? eAppName.getText() : null;
+ return createSlaStatusEvent(id, stat, appType, appNameStr, log);
}
catch (Exception e) {
throw new CommandException(ErrorCode.E1007, " id " + id, e.getMessage(), e);
Modified: oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java Mon May 20 16:51:37 2013
@@ -6,9 +6,9 @@
* 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.
@@ -28,6 +28,7 @@ import org.apache.oozie.service.Services
import org.apache.oozie.util.DateUtils;
import org.jdom.Element;
+@Deprecated
public class SLADbXOperations {
public static final String CLIENT_ID_TAG = "oozie:sla:client-id";
@@ -61,7 +62,7 @@ public class SLADbXOperations {
// Setting expected start time
String strRelExpectedStart = getTagElement(eSla, "should-start");
if (strRelExpectedStart == null || strRelExpectedStart.length() == 0) {
- throw new CommandException(ErrorCode.E1102);
+ throw new CommandException(ErrorCode.E1101);
}
int relExpectedStart = Integer.parseInt(strRelExpectedStart);
if (relExpectedStart < 0) {
Modified: oozie/trunk/core/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/resources/META-INF/persistence.xml?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/main/resources/META-INF/persistence.xml (original)
+++ oozie/trunk/core/src/main/resources/META-INF/persistence.xml Mon May 20 16:51:37 2013
@@ -32,11 +32,15 @@
<class>org.apache.oozie.SLAEventBean</class>
<class>org.apache.oozie.BundleJobBean</class>
<class>org.apache.oozie.BundleActionBean</class>
+ <class>org.apache.oozie.sla.SLARegistrationBean</class>
+ <class>org.apache.oozie.sla.SLACalculatorBean</class>
+ <class>org.apache.oozie.sla.SLASummaryBean</class>
<class>org.apache.oozie.client.rest.JsonWorkflowJob</class>
<class>org.apache.oozie.client.rest.JsonWorkflowAction</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorJob</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorAction</class>
<class>org.apache.oozie.client.rest.JsonSLAEvent</class>
+ <class>org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent</class>
<class>org.apache.oozie.client.rest.JsonBundleJob</class>
<class>org.apache.oozie.util.db.ValidateConnectionBean</class>
@@ -53,7 +57,11 @@
org.apache.oozie.SLAEventBean;
org.apache.oozie.BundleJobBean;
org.apache.oozie.BundleActionBean;
+ org.apache.oozie.sla.SLARegistrationBean;
+ org.apache.oozie.sla.SLACalculatorBean;
+ org.apache.oozie.sla.SLASummaryBean;
org.apache.oozie.client.rest.JsonSLAEvent;
+ org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent;
org.apache.oozie.client.rest.JsonWorkflowJob;
org.apache.oozie.client.rest.JsonWorkflowAction;
org.apache.oozie.client.rest.JsonCoordinatorJob;
@@ -87,11 +95,15 @@
<class>org.apache.oozie.SLAEventBean</class>
<class>org.apache.oozie.BundleJobBean</class>
<class>org.apache.oozie.BundleActionBean</class>
+ <class>org.apache.oozie.sla.SLARegistrationBean</class>
+ <class>org.apache.oozie.sla.SLACalculatorBean</class>
+ <class>org.apache.oozie.sla.SLASummaryBean</class>
<class>org.apache.oozie.client.rest.JsonWorkflowJob</class>
<class>org.apache.oozie.client.rest.JsonWorkflowAction</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorJob</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorAction</class>
<class>org.apache.oozie.client.rest.JsonSLAEvent</class>
+ <class>org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent</class>
<class>org.apache.oozie.client.rest.JsonBundleJob</class>
<class>org.apache.oozie.util.db.ValidateConnectionBean</class>
@@ -108,7 +120,11 @@
org.apache.oozie.SLAEventBean;
org.apache.oozie.BundleJobBean;
org.apache.oozie.BundleActionBean;
+ org.apache.oozie.sla.SLARegistrationBean;
+ org.apache.oozie.sla.SLACalculatorBean;
+ org.apache.oozie.sla.SLASummaryBean;
org.apache.oozie.client.rest.JsonSLAEvent;
+ org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent;
org.apache.oozie.client.rest.JsonWorkflowJob;
org.apache.oozie.client.rest.JsonWorkflowAction;
org.apache.oozie.client.rest.JsonCoordinatorJob;
@@ -143,11 +159,15 @@
<class>org.apache.oozie.SLAEventBean</class>
<class>org.apache.oozie.BundleJobBean</class>
<class>org.apache.oozie.BundleActionBean</class>
+ <class>org.apache.oozie.sla.SLARegistrationBean</class>
+ <class>org.apache.oozie.sla.SLACalculatorBean</class>
+ <class>org.apache.oozie.sla.SLASummaryBean</class>
<class>org.apache.oozie.client.rest.JsonWorkflowJob</class>
<class>org.apache.oozie.client.rest.JsonWorkflowAction</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorJob</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorAction</class>
<class>org.apache.oozie.client.rest.JsonSLAEvent</class>
+ <class>org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent</class>
<class>org.apache.oozie.client.rest.JsonBundleJob</class>
<class>org.apache.oozie.util.db.ValidateConnectionBean</class>
@@ -164,7 +184,11 @@
org.apache.oozie.SLAEventBean;
org.apache.oozie.BundleJobBean;
org.apache.oozie.BundleActionBean;
+ org.apache.oozie.sla.SLARegistrationBean;
+ org.apache.oozie.sla.SLACalculatorBean;
+ org.apache.oozie.sla.SLASummaryBean;
org.apache.oozie.client.rest.JsonSLAEvent;
+ org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent;
org.apache.oozie.client.rest.JsonWorkflowJob;
org.apache.oozie.client.rest.JsonWorkflowAction;
org.apache.oozie.client.rest.JsonCoordinatorJob;
@@ -198,11 +222,15 @@
<class>org.apache.oozie.SLAEventBean</class>
<class>org.apache.oozie.BundleJobBean</class>
<class>org.apache.oozie.BundleActionBean</class>
+ <class>org.apache.oozie.sla.SLARegistrationBean</class>
+ <class>org.apache.oozie.sla.SLACalculatorBean</class>
+ <class>org.apache.oozie.sla.SLASummaryBean</class>
<class>org.apache.oozie.client.rest.JsonWorkflowJob</class>
<class>org.apache.oozie.client.rest.JsonWorkflowAction</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorJob</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorAction</class>
<class>org.apache.oozie.client.rest.JsonSLAEvent</class>
+ <class>org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent</class>
<class>org.apache.oozie.client.rest.JsonBundleJob</class>
<class>org.apache.oozie.util.db.ValidateConnectionBean</class>
@@ -219,7 +247,11 @@
org.apache.oozie.SLAEventBean;
org.apache.oozie.BundleJobBean;
org.apache.oozie.BundleActionBean;
+ org.apache.oozie.sla.SLARegistrationBean;
+ org.apache.oozie.sla.SLACalculatorBean;
+ org.apache.oozie.sla.SLASummaryBean;
org.apache.oozie.client.rest.JsonSLAEvent;
+ org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent;
org.apache.oozie.client.rest.JsonWorkflowJob;
org.apache.oozie.client.rest.JsonWorkflowAction;
org.apache.oozie.client.rest.JsonCoordinatorJob;
@@ -254,11 +286,15 @@
<class>org.apache.oozie.SLAEventBean</class>
<class>org.apache.oozie.BundleJobBean</class>
<class>org.apache.oozie.BundleActionBean</class>
+ <class>org.apache.oozie.sla.SLARegistrationBean</class>
+ <class>org.apache.oozie.sla.SLACalculatorBean</class>
+ <class>org.apache.oozie.sla.SLASummaryBean</class>
<class>org.apache.oozie.client.rest.JsonWorkflowJob</class>
<class>org.apache.oozie.client.rest.JsonWorkflowAction</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorJob</class>
<class>org.apache.oozie.client.rest.JsonCoordinatorAction</class>
<class>org.apache.oozie.client.rest.JsonSLAEvent</class>
+ <class>org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent</class>
<class>org.apache.oozie.client.rest.JsonBundleJob</class>
<class>org.apache.oozie.util.db.ValidateConnectionBean</class>
@@ -275,7 +311,11 @@
org.apache.oozie.SLAEventBean;
org.apache.oozie.BundleJobBean;
org.apache.oozie.BundleActionBean;
+ org.apache.oozie.sla.SLARegistrationBean;
+ org.apache.oozie.sla.SLACalculatorBean;
+ org.apache.oozie.sla.SLASummaryBean;
org.apache.oozie.client.rest.JsonSLAEvent;
+ org.apache.oozie.client.rest.sla.JsonSLARegistrationEvent;
org.apache.oozie.client.rest.JsonWorkflowJob;
org.apache.oozie.client.rest.JsonWorkflowAction;
org.apache.oozie.client.rest.JsonCoordinatorJob;
Modified: oozie/trunk/core/src/main/resources/oozie-default.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/resources/oozie-default.xml?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/main/resources/oozie-default.xml (original)
+++ oozie/trunk/core/src/main/resources/oozie-default.xml Mon May 20 16:51:37 2013
@@ -204,7 +204,7 @@
<property>
<name>oozie.service.SchedulerService.threads</name>
- <value>5</value>
+ <value>10</value>
<description>
The number of threads to be used by the SchedulerService to run deamon tasks.
If maxed out, scheduled daemon tasks will be queued up and delayed until threads become available.
@@ -1255,7 +1255,7 @@
<property>
<name>oozie.service.SchemaService.wf.ext.schemas</name>
- <value>oozie-sla-0.1.xsd</value>
+ <value>oozie-sla-0.1.xsd,oozie-sla-0.2.xsd</value>
<description>
Schemas for additional actions types.
@@ -1266,7 +1266,7 @@
<property>
<name>oozie.service.SchemaService.coord.ext.schemas</name>
- <value>oozie-sla-0.1.xsd</value>
+ <value>oozie-sla-0.1.xsd,oozie-sla-0.2.xsd</value>
<description>
Schemas for additional actions types.
@@ -1827,7 +1827,7 @@
</property>
<property>
- <name>oozie.service.EventHandlerService.app.types</name>
+ <name>oozie.service.EventHandlerService.filter.app.types</name>
<value>workflow_job, coordinator_action</value>
<description>
The app-types among workflow/coordinator/bundle job/action for which
@@ -1845,7 +1845,9 @@
<property>
<name>oozie.service.EventHandlerService.event.listeners</name>
- <value>org.apache.oozie.jms.JMSJobEventListener</value>
+ <value>org.apache.oozie.jms.JMSJobEventListener,
+ org.apache.oozie.sla.listener.SLAJobEventListener
+ </value>
</property>
<property>
@@ -1873,4 +1875,36 @@
</description>
</property>
+ <property>
+ <name>oozie.service.EventHandlerService.worker.threads</name>
+ <value>3</value>
+ <description>
+ Number of worker threads to be scheduled to run and process events.
+ </description>
+ </property>
+
+ <property>
+ <name>oozie.sla.service.SLAService.capacity</name>
+ <value>5000</value>
+ <description>
+ Maximum number of sla records to be contained in the memory structure.
+ </description>
+ </property>
+
+ <property>
+ <name>oozie.sla.service.SLAService.alert.types</name>
+ <value>END_MISS</value>
+ <description>
+ Default types of SLA events for being alerted of.
+ </description>
+ </property>
+
+ <property>
+ <name>oozie.sla.service.SLAService.calculator.impl</name>
+ <value>org.apache.oozie.sla.SLACalculatorMemory</value>
+ <description>
+ The implementation for SLACalculator in use by the SLAService.
+ </description>
+ </property>
+
</configuration>
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/TestSLAEventBean.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/TestSLAEventBean.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/TestSLAEventBean.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/TestSLAEventBean.java Mon May 20 16:51:37 2013
@@ -24,13 +24,13 @@ import org.apache.oozie.util.DateUtils;
import org.apache.oozie.util.XmlUtils;
import org.jdom.Element;
+@Deprecated
public class TestSLAEventBean extends XTestCase {
private static final Date ee = new Date(1L);
private static final Date es = new Date(2L);
private static final Date st = new Date(3L);
- @SuppressWarnings("deprecation")
private void set(SLAEventBean bean) {
bean.setAlertContact("ac");
bean.setAlertFrequency("af");
@@ -58,7 +58,6 @@ public class TestSLAEventBean extends XT
bean.setUser("u");
}
- @SuppressWarnings("deprecation")
public void testSetGet() {
final SLAEventBean bean = new SLAEventBean();
@@ -106,7 +105,6 @@ public class TestSLAEventBean extends XT
+ " <app-name>an</app-name>\r\n" + " </status>\r\n" + "</event>", actualXml);
}
- @SuppressWarnings("deprecation")
public void testToXmlRegistrationEvent() {
final SLAEventBean bean = new SLAEventBean();
set(bean);
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionMaterializeCommand.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionMaterializeCommand.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionMaterializeCommand.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionMaterializeCommand.java Mon May 20 16:51:37 2013
@@ -32,6 +32,7 @@ import org.apache.oozie.store.StoreExcep
import org.apache.oozie.test.XTestCase;
import org.apache.oozie.util.DateUtils;
+@SuppressWarnings("deprecation")
public class TestCoordActionMaterializeCommand extends XTestCase {
private Services services;
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java Mon May 20 16:51:37 2013
@@ -41,6 +41,7 @@ import org.apache.oozie.service.Services
import org.apache.oozie.test.XDataTestCase;
import org.apache.oozie.util.DateUtils;
+@SuppressWarnings("deprecation")
public class TestCoordMaterializeTransitionXCommand extends XDataTestCase {
@Override
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventGeneration.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventGeneration.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventGeneration.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventGeneration.java Mon May 20 16:51:37 2013
@@ -23,6 +23,7 @@ import java.util.HashSet;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
+import org.apache.oozie.AppType;
import org.apache.oozie.CoordinatorActionBean;
import org.apache.oozie.CoordinatorJobBean;
import org.apache.oozie.WorkflowActionBean;
@@ -32,7 +33,7 @@ import org.apache.oozie.client.Coordinat
import org.apache.oozie.client.OozieClient;
import org.apache.oozie.client.WorkflowAction;
import org.apache.oozie.client.WorkflowJob;
-import org.apache.oozie.client.event.Event.AppType;
+import org.apache.oozie.client.event.Event;
import org.apache.oozie.client.event.JobEvent.EventStatus;
import org.apache.oozie.command.coord.CoordActionCheckXCommand;
import org.apache.oozie.command.coord.CoordActionInputCheckXCommand;
@@ -45,12 +46,18 @@ import org.apache.oozie.command.wf.Start
import org.apache.oozie.command.wf.SuspendXCommand;
import org.apache.oozie.command.wf.WorkflowXCommand;
import org.apache.oozie.coord.CoordELFunctions;
+import org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor;
+import org.apache.oozie.executor.jpa.CoordActionUpdateJPAExecutor;
+import org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor;
+import org.apache.oozie.executor.jpa.WorkflowActionUpdateJPAExecutor;
+import org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor;
+import org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor;
+import org.apache.oozie.executor.jpa.WorkflowJobUpdateJPAExecutor;
import org.apache.oozie.service.EventHandlerService;
import org.apache.oozie.service.JPAService;
import org.apache.oozie.service.Services;
import org.apache.oozie.test.XDataTestCase;
import org.apache.oozie.util.DateUtils;
-import org.apache.oozie.util.IOUtils;
import org.apache.oozie.workflow.WorkflowInstance;
import org.apache.oozie.workflow.lite.ActionNodeDef;
import org.apache.oozie.workflow.lite.EndNodeDef;
@@ -59,14 +66,9 @@ import org.apache.oozie.workflow.lite.Li
import org.apache.oozie.workflow.lite.StartNodeDef;
import org.apache.oozie.workflow.lite.TestLiteWorkflowLib.TestActionNodeHandler;
import org.apache.oozie.workflow.lite.TestLiteWorkflowLib.TestControlNodeHandler;
-import org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor;
-import org.apache.oozie.executor.jpa.CoordActionUpdateJPAExecutor;
-import org.apache.oozie.executor.jpa.CoordJobUpdateJPAExecutor;
-import org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor;
-import org.apache.oozie.executor.jpa.WorkflowActionUpdateJPAExecutor;
-import org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor;
-import org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor;
-import org.apache.oozie.executor.jpa.WorkflowJobUpdateJPAExecutor;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Testcase to test that events are correctly generated from corresponding
@@ -74,23 +76,29 @@ import org.apache.oozie.executor.jpa.Wor
*/
public class TestEventGeneration extends XDataTestCase {
+ EventQueue queue;
+
+ @Override
+ @Before
protected void setUp() throws Exception {
super.setUp();
Services services = new Services();
Configuration conf = services.getConf();
conf.set(Services.CONF_SERVICE_EXT_CLASSES, "org.apache.oozie.service.EventHandlerService");
services.init();
+ queue = services.get(EventHandlerService.class).getEventQueue();
}
+ @Override
+ @After
protected void tearDown() throws Exception {
Services.get().destroy();
super.tearDown();
}
+ @Test
public void testWorkflowJobEvent() throws Exception {
- EventHandlerService ehs = _testEventHandlerService();
- EventQueue queue = ehs.getEventQueue();
- assertEquals(queue.getCurrentSize(), 0);
+ assertEquals(queue.size(), 0);
WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
JPAService jpaService = Services.get().get(JPAService.class);
@@ -99,7 +107,7 @@ public class TestEventGeneration extends
WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.RUNNING, job.getStatus());
- assertEquals(1, queue.getCurrentSize());
+ assertEquals(1, queue.size());
WorkflowJobEvent event = (WorkflowJobEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.STARTED, event.getEventStatus());
@@ -108,13 +116,13 @@ public class TestEventGeneration extends
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
- assertEquals(0, queue.getCurrentSize());
+ assertEquals(0, queue.size());
// Suspending job
new SuspendXCommand(job.getId()).call();
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.SUSPENDED, job.getStatus());
- assertEquals(1, queue.getCurrentSize());
+ assertEquals(1, queue.size());
event = (WorkflowJobEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.SUSPEND, event.getEventStatus());
@@ -122,13 +130,13 @@ public class TestEventGeneration extends
assertEquals(job.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
- assertEquals(0, queue.getCurrentSize());
+ assertEquals(0, queue.size());
// Resuming job
new ResumeXCommand(job.getId()).call();
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.RUNNING, job.getStatus());
- assertEquals(1, queue.getCurrentSize());
+ assertEquals(1, queue.size());
event = (WorkflowJobEvent) queue.poll();
assertNotNull(event);
assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
@@ -136,13 +144,13 @@ public class TestEventGeneration extends
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
- assertEquals(0, queue.getCurrentSize());
+ assertEquals(0, queue.size());
// Killing job
new KillXCommand(job.getId()).call();
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.KILLED, job.getStatus());
- assertEquals(1, queue.getCurrentSize());
+ assertEquals(1, queue.size());
event = (WorkflowJobEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.FAILURE, event.getEventStatus());
@@ -152,7 +160,7 @@ public class TestEventGeneration extends
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
assertEquals(job.getEndTime(), event.getEndTime());
- assertEquals(0, queue.getCurrentSize());
+ assertEquals(0, queue.size());
// Successful job (testing SignalX)
job = _createWorkflowJob();
@@ -164,7 +172,7 @@ public class TestEventGeneration extends
new SignalXCommand(job.getId(), wfAction.getId()).call();
job = jpaService.execute(new WorkflowJobGetJPAExecutor(job.getId()));
assertEquals(WorkflowJob.Status.SUCCEEDED, job.getStatus());
- assertEquals(1, queue.getCurrentSize());
+ assertEquals(1, queue.size());
event = (WorkflowJobEvent) queue.poll();
assertNotNull(event);
assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
@@ -173,22 +181,22 @@ public class TestEventGeneration extends
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
assertEquals(job.getEndTime(), event.getEndTime());
- assertEquals(0, queue.getCurrentSize());
+ assertEquals(0, queue.size());
}
+ @Test
public void testCoordinatorActionEvent() throws Exception {
- EventHandlerService ehs = _testEventHandlerService();
+ EventHandlerService ehs = Services.get().get(EventHandlerService.class);
// 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" })));
- EventQueue queue = ehs.getEventQueue();
- assertEquals(queue.getCurrentSize(), 0);
+ assertEquals(queue.size(), 0);
Date startTime = DateUtils.parseDateOozieTZ("2013-01-01T10:00Z");
Date endTime = DateUtils.parseDateOozieTZ("2013-01-01T10:14Z");
CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false,
false, 0);
- _modifyCoordForRunning(coord);
+ modifyCoordForRunning(coord);
final JPAService jpaService = Services.get().get(JPAService.class);
// Action WAITING on materialization
@@ -196,7 +204,7 @@ public class TestEventGeneration extends
final CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(coord.getId() + "@1");
CoordinatorActionBean action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.WAITING, action.getStatus());
- assertEquals(1, queue.getCurrentSize());
+ assertEquals(1, queue.size());
CoordinatorActionEvent event = (CoordinatorActionEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.WAITING, event.getEventStatus());
@@ -207,7 +215,7 @@ public class TestEventGeneration extends
assertEquals(action.getCreatedTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
- assertEquals(0, queue.getCurrentSize());
+ assertEquals(0, queue.size());
// Make Action ready
new CoordActionInputCheckXCommand(action.getId(), coord.getId()).call();
@@ -215,13 +223,13 @@ public class TestEventGeneration extends
assertEquals(CoordinatorAction.Status.READY, action.getStatus());
waitFor(1 * 100, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return jpaService.execute(coordGetCmd).getStatus() == CoordinatorAction.Status.RUNNING;
}
});
- assertEquals(1, queue.getCurrentSize());
- event = (CoordinatorActionEvent) queue.poll();
- assertNotNull(event);
+
+ event = _pollQueue();
assertEquals(EventStatus.STARTED, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
@@ -230,7 +238,6 @@ public class TestEventGeneration extends
assertEquals(action.getCreatedTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
- assertEquals(0, queue.getCurrentSize());
// Action Success
action = jpaService.execute(coordGetCmd);
@@ -240,9 +247,7 @@ public class TestEventGeneration extends
new CoordActionCheckXCommand(action.getId(), 0).call();
action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.SUCCEEDED, action.getStatus());
- assertEquals(1, queue.getCurrentSize());
- event = (CoordinatorActionEvent) queue.poll();
- assertNotNull(event);
+ event = _pollQueue();
assertEquals(EventStatus.SUCCESS, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
@@ -251,7 +256,6 @@ public class TestEventGeneration extends
assertEquals(action.getCreatedTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
- assertEquals(0, queue.getCurrentSize());
// Action Failure
action.setStatus(CoordinatorAction.Status.RUNNING);
@@ -261,9 +265,7 @@ public class TestEventGeneration extends
new CoordActionCheckXCommand(action.getId(), 0).call();
action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
- assertEquals(1, queue.getCurrentSize());
- event = (CoordinatorActionEvent) queue.poll();
- assertNotNull(event);
+ event = _pollQueue();
assertEquals(EventStatus.FAILURE, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
@@ -272,13 +274,11 @@ public class TestEventGeneration extends
assertEquals(action.getCreatedTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
- assertEquals(0, queue.getCurrentSize());
}
+ @Test
public void testWorkflowJobEventError() throws Exception {
- EventHandlerService ehs = _testEventHandlerService();
- EventQueue queue = ehs.getEventQueue();
final WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.FAILED, WorkflowInstance.Status.FAILED);
// create event with error code and message
WorkflowXCommand<Void> myCmd = new KillXCommand(job.getId()) {
@@ -297,13 +297,13 @@ public class TestEventGeneration extends
}
+ @Test
public void testCoordinatorActionEventDependencies() throws Exception {
- EventHandlerService ehs = _testEventHandlerService();
- EventQueue queue = ehs.getEventQueue();
final CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
final CoordinatorActionBean action = addRecordToCoordActionTable(coord.getId(), 1,
CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
- JPAService jpaService = Services.get().get(JPAService.class);
+ final JPAService jpaService = Services.get().get(JPAService.class);
+
CoordinatorXCommand<Void> myCmd = new CoordActionCheckXCommand(action.getId(), 0) {
@Override
protected Void execute() {
@@ -339,21 +339,6 @@ public class TestEventGeneration extends
}
- private EventHandlerService _testEventHandlerService() throws Exception {
- Services services = Services.get();
- EventHandlerService ehs = services.get(EventHandlerService.class);
- assertNotNull(ehs);
- return ehs;
- }
-
- private void _modifyCoordForRunning(CoordinatorJobBean coord) throws Exception {
- String wfXml = IOUtils.getResourceAsString("wf-credentials.xml", -1);
- writeToFile(wfXml, getFsTestCaseDir(), "workflow.xml");
- String coordXml = coord.getJobXml();
- coord.setJobXml(coordXml.replace("hdfs:///tmp/workflows/", getFsTestCaseDir() + "/workflow.xml"));
- Services.get().get(JPAService.class).execute(new CoordJobUpdateJPAExecutor(coord));
- }
-
private WorkflowJobBean _createWorkflowJob() throws Exception {
LiteWorkflowApp app = new LiteWorkflowApp("my-app", "<workflow-app/>",
new StartNodeDef(TestControlNodeHandler.class, "one"))
@@ -381,4 +366,12 @@ public class TestEventGeneration extends
return workflow;
}
+ private CoordinatorActionEvent _pollQueue() {
+ Event e;
+ do {
+ e = queue.poll();
+ } while (!(e instanceof CoordinatorActionEvent));
+ return (CoordinatorActionEvent) e;
+ }
+
}
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventQueue.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventQueue.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventQueue.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/event/TestEventQueue.java Mon May 20 16:51:37 2013
@@ -23,7 +23,11 @@ import org.apache.oozie.service.EventHan
import org.apache.oozie.service.JMSAccessorService;
import org.apache.oozie.service.JMSTopicService;
import org.apache.oozie.service.Services;
+import org.apache.oozie.sla.service.SLAService;
import org.apache.oozie.test.XDataTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test case to check correct functioning of MemoryEventQueue
@@ -32,22 +36,25 @@ public class TestEventQueue extends XDat
private Services services;
+ @Before
protected void setUp() throws Exception {
super.setUp();
services = new Services();
Configuration conf = services.getConf();
conf.set(Services.CONF_SERVICE_EXT_CLASSES,
JMSAccessorService.class.getName() + "," + JMSTopicService.class.getName() + ","
- + EventHandlerService.class.getName());
+ + EventHandlerService.class.getName() + "," + SLAService.class.getName());
conf.setInt(EventHandlerService.CONF_BATCH_SIZE, 3);
services.init();
}
+ @After
protected void tearDown() throws Exception {
services.destroy();
super.tearDown();
}
+ @Test
public void testMemoryEventQueueBasic() throws Exception {
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
assertNotNull(ehs);
@@ -56,18 +63,20 @@ public class TestEventQueue extends XDat
assertTrue(eventQ instanceof MemoryEventQueue); //default
}
+ @Test
public void testQueueOperations() throws Exception {
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
EventQueue eventQ = ehs.getEventQueue();
- assertEquals(eventQ.getCurrentSize(), 0);
+ assertEquals(eventQ.size(), 0);
assertEquals(eventQ.getBatchSize(), 3);
// create some events to enqueue
WorkflowJobEvent wfEvent = new WorkflowJobEvent("1234-W", "1234-C", WorkflowJob.Status.RUNNING, getTestUser(),
"myapp", null, null);
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++) {
ehs.queueEvent(wfEvent);
- assertEquals(eventQ.getCurrentSize(), 10);
+ }
+ assertEquals(eventQ.size(), 10);
// test single threads polling from queue
int numThreads = 1;
@@ -76,13 +85,14 @@ public class TestEventQueue extends XDat
thread[i] = new Thread(ehs.new EventWorker());
thread[i].run();
}
- assertEquals(eventQ.getCurrentSize(), 7); // n(events) - n(batch) i.e.
+ assertEquals(eventQ.size(), 7); // n(events) - n(batch) i.e.
// 10-3 = 7
// restore events count to 10
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
ehs.queueEvent(wfEvent);
- assertEquals(eventQ.getCurrentSize(), 10);
+ }
+ assertEquals(eventQ.size(), 10);
// test two threads polling concurrently from queue
numThreads = 2;
thread = new Thread[numThreads];
@@ -90,26 +100,28 @@ public class TestEventQueue extends XDat
thread[i] = new Thread(ehs.new EventWorker());
thread[i].run();
}
- assertEquals(eventQ.getCurrentSize(), 4); // n(events) - n(batch)*n(threads)
+ assertEquals(eventQ.size(), 4); // n(events) - n(batch)*n(threads)
// i.e. 10 - 3*2 = 4
// enqueue events again
- for (int i = 0; i < 6; i++)
+ for (int i = 0; i < 6; i++) {
ehs.queueEvent(wfEvent);
- assertEquals(eventQ.getCurrentSize(), 10);
+ }
+ assertEquals(eventQ.size(), 10);
// test the 2 threads draining repeatedly (mimicking SchedulerService)
// from queue
int repetition = 3;
int r = 0;
while (r < repetition) {
- if (eventQ.isEmpty())
+ if (eventQ.isEmpty()) {
break;
+ }
for (int i = 0; i < numThreads; i++) {
thread[i].run();
}
r++;
}
- assertEquals(eventQ.getCurrentSize(), 0);
+ assertEquals(eventQ.size(), 0);
}
}
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestSLAEventsGetJPAExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestSLAEventsGetJPAExecutor.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestSLAEventsGetJPAExecutor.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestSLAEventsGetJPAExecutor.java Mon May 20 16:51:37 2013
@@ -26,6 +26,7 @@ import org.apache.oozie.service.JPAServi
import org.apache.oozie.service.Services;
import org.apache.oozie.test.XDataTestCase;
+@Deprecated
public class TestSLAEventsGetJPAExecutor extends XDataTestCase {
Services services;
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java Mon May 20 16:51:37 2013
@@ -29,7 +29,7 @@ import org.apache.activemq.broker.Broker
import org.apache.hadoop.conf.Configuration;
import org.apache.oozie.client.CoordinatorAction;
import org.apache.oozie.client.WorkflowJob;
-import org.apache.oozie.client.event.Event.AppType;
+import org.apache.oozie.AppType;
import org.apache.oozie.client.event.JobEvent.EventStatus;
import org.apache.oozie.client.event.Event.MessageType;
import org.apache.oozie.client.event.jms.JMSMessagingUtils;
@@ -52,13 +52,14 @@ import org.junit.Test;
public class TestJMSJobEventListener extends XTestCase {
private Services services;
+ private Configuration conf;
@Before
@Override
protected void setUp() throws Exception {
super.setUp();
services = new Services();
- Configuration conf = services.getConf();
+ conf = services.getConf();
conf.set(Services.CONF_SERVICE_EXT_CLASSES,
JMSAccessorService.class.getName() + "," + JMSTopicService.class.getName());
conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#" + ActiveMQConnFactory
@@ -77,7 +78,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnWorkflowJobStartedEvent() throws ParseException {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.RUNNING, "user1",
"wf-app-name1", startDate, null);
@@ -110,7 +111,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnWorkflowJobSuccessEvent() throws ParseException {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date endDate = new Date();
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.SUCCEEDED, "user1",
@@ -145,7 +146,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnWorkflowJobFailureEvent() throws ParseException {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date endDate = new Date();
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user1",
@@ -182,7 +183,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnWorkflowJobSuspendEvent() throws ParseException {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.SUSPENDED, "user1",
"wf-app-name1", startDate, null);
@@ -216,7 +217,7 @@ public class TestJMSJobEventListener ext
@Test
public void testWorkflowJobSelectors() throws ParseException {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user_1",
"wf-app-name1", new Date(), new Date());
ConnectionContext jmsContext = getConnectionContext();
@@ -241,7 +242,7 @@ public class TestJMSJobEventListener ext
@Test
public void testWorkflowJobSelectorsNegative() {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user1",
"wf-app-name1", new Date(), new Date());
ConnectionContext jmsContext = getConnectionContext();
@@ -264,7 +265,7 @@ public class TestJMSJobEventListener ext
@Test
public void testWorkflowJobSelectorsOr() {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user1",
"wf-app-name1", new Date(), new Date());
ConnectionContext jmsContext = getConnectionContext();
@@ -291,7 +292,7 @@ public class TestJMSJobEventListener ext
@Test
public void testWorkflowJobSelectorsAnd() {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user1",
"wf-app-name1", new Date(), new Date());
ConnectionContext jmsContext = getConnectionContext();
@@ -331,7 +332,7 @@ public class TestJMSJobEventListener ext
+ "ConnectionFactory");
services.init();
JMSJobEventListener wfEventListener = new JMSJobEventListener();
- wfEventListener.init();
+ wfEventListener.init(conf);
BrokerService broker = new BrokerService();
broker.addConnector(brokerURl);
broker.start();
@@ -366,7 +367,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnCoordinatorActionWaitingEvent() throws ParseException {
JMSJobEventListener wfEventListner = new JMSJobEventListener();
- wfEventListner.init();
+ wfEventListner.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.WAITING,
@@ -403,7 +404,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnCoordinatorActionStartEvent() throws ParseException {
JMSJobEventListener coordEventListener = new JMSJobEventListener();
- coordEventListener.init();
+ coordEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.RUNNING,
@@ -439,7 +440,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnCoordinatorJobSuccessEvent() throws ParseException {
JMSJobEventListener coordEventListener = new JMSJobEventListener();
- coordEventListener.init();
+ coordEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
Date endDate = new Date();
@@ -477,7 +478,7 @@ public class TestJMSJobEventListener ext
@Test
public void testOnCoordinatorJobFailureEvent() throws ParseException {
JMSJobEventListener coordEventListener = new JMSJobEventListener();
- coordEventListener.init();
+ coordEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
Date endDate = new Date();
@@ -517,7 +518,7 @@ public class TestJMSJobEventListener ext
@Test
public void testCoordinatorActionSelectors() throws ParseException {
JMSJobEventListener coordEventListener = new JMSJobEventListener();
- coordEventListener.init();
+ coordEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.FAILED,
@@ -544,7 +545,7 @@ public class TestJMSJobEventListener ext
@Test
public void testCoordinatorActionSelectorsNegative() throws ParseException {
JMSJobEventListener coordEventListener = new JMSJobEventListener();
- coordEventListener.init();
+ coordEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.FAILED,
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/service/TestEventHandlerService.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestEventHandlerService.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/service/TestEventHandlerService.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/service/TestEventHandlerService.java Mon May 20 16:51:37 2013
@@ -30,11 +30,15 @@ import org.apache.oozie.event.WorkflowAc
import org.apache.oozie.event.WorkflowJobEvent;
import org.apache.oozie.event.listener.JobEventListener;
import org.apache.oozie.test.XDataTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestEventHandlerService extends XDataTestCase {
static StringBuilder output = new StringBuilder();
+ @Before
protected void setUp() throws Exception {
super.setUp();
Services services = new Services();
@@ -44,11 +48,13 @@ public class TestEventHandlerService ext
services.init();
}
+ @After
protected void tearDown() throws Exception {
Services.get().destroy();
super.tearDown();
}
+ @Test
public void testService() throws Exception {
EventHandlerService ehs = _testEventHandlerService();
// check default initializations
@@ -56,8 +62,17 @@ public class TestEventHandlerService ext
Set<String> jobtypes = ehs.getAppTypes();
assertTrue(jobtypes.contains("workflow_job"));
assertTrue(jobtypes.contains("coordinator_action"));
+
+ Services services = Services.get();
+ services.destroy();
+ services = new Services();
+ Configuration conf = services.getConf();
+ conf.set(Services.CONF_SERVICE_EXT_CLASSES, "");
+ services.init();
+ assertFalse(EventHandlerService.isEnabled());
}
+ @Test
public void testEventListener() throws Exception {
EventHandlerService ehs = _testEventHandlerService();
/*
@@ -133,6 +148,7 @@ public class TestEventHandlerService ext
Services services = Services.get();
EventHandlerService ehs = services.get(EventHandlerService.class);
assertNotNull(ehs);
+ assertTrue(EventHandlerService.isEnabled());
return ehs;
}
@@ -174,7 +190,7 @@ public class TestEventHandlerService ext
}
@Override
- public void init() {
+ public void init(Configuration conf) {
}
@Override
Modified: oozie/trunk/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java?rev=1484523&r1=1484522&r2=1484523&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/service/TestJMSTopicService.java Mon May 20 16:51:37 2013
@@ -31,8 +31,7 @@ import org.apache.oozie.client.Coordinat
import org.apache.oozie.client.Job;
import org.apache.oozie.client.WorkflowAction;
import org.apache.oozie.client.WorkflowJob;
-import org.apache.oozie.client.event.Event.AppType;
-import org.apache.oozie.service.JMSTopicService.JobType;
+import org.apache.oozie.AppType;
import org.apache.oozie.service.Services;
import org.apache.oozie.test.XDataTestCase;
import org.apache.oozie.workflow.WorkflowInstance;
Added: oozie/trunk/core/src/test/java/org/apache/oozie/sla/TestSLACalculationJPAExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/sla/TestSLACalculationJPAExecutor.java?rev=1484523&view=auto
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/sla/TestSLACalculationJPAExecutor.java (added)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/sla/TestSLACalculationJPAExecutor.java Mon May 20 16:51:37 2013
@@ -0,0 +1,272 @@
+/**
+ * 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.oozie.sla;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.FaultInjection;
+import org.apache.oozie.client.event.SLAEvent.EventStatus;
+import org.apache.oozie.client.rest.JsonBean;
+import org.apache.oozie.command.SkipCommitFaultInjection;
+import org.apache.oozie.executor.jpa.JPAExecutorException;
+import org.apache.oozie.executor.jpa.sla.SLACalculationInsertUpdateJPAExecutor;
+import org.apache.oozie.executor.jpa.sla.SLACalculatorGetJPAExecutor;
+import org.apache.oozie.executor.jpa.sla.SLASummaryGetJPAExecutor;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Testcase to check db operations on tables SLA_CALCULATOR and SLA_SUMMARY
+ */
+public class TestSLACalculationJPAExecutor extends XDataTestCase {
+ Services services;
+ Calendar cal;
+
+ @Override
+ @Before
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ cal = Calendar.getInstance();
+ }
+
+ @Override
+ @After
+ protected void tearDown() throws Exception {
+ services.destroy();
+ super.tearDown();
+ }
+
+ /**
+ * Test simple insert
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testInsert() throws Exception {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+
+ String wfId = "workflow-1";
+ SLACalculatorBean bean1 = _createSLACalcBean(wfId, false, false);
+
+ cal.setTime(new Date());
+ cal.add(Calendar.DAY_OF_MONTH, -2);
+ Date expStart = cal.getTime();
+ cal.add(Calendar.DAY_OF_MONTH, -1);
+ Date expEnd = cal.getTime();
+ Date actStart = new Date();
+ cal.add(Calendar.DAY_OF_MONTH, 2);
+ Date actEnd = cal.getTime();
+ SLASummaryBean bean2 = _createSLASummaryBean(wfId, "RUNNING", EventStatus.START_MISS, expStart, expEnd, 1000,
+ actStart, actEnd, 2000);
+
+ List<JsonBean> list = new ArrayList<JsonBean>();
+ list.add(bean1);
+ list.add(bean2);
+ SLACalculationInsertUpdateJPAExecutor writeCmd = new SLACalculationInsertUpdateJPAExecutor();
+ writeCmd.setInsertList(list);
+ jpaService.execute(writeCmd);
+
+ SLACalculatorGetJPAExecutor readCmd1 = new SLACalculatorGetJPAExecutor(wfId);
+ SLACalculatorBean scBean = jpaService.execute(readCmd1);
+ assertNotNull(scBean);
+ assertEquals(wfId, scBean.getJobId());
+ assertFalse(scBean.isStartProcessed());
+ assertFalse(scBean.isEndProcessed());
+
+ SLASummaryGetJPAExecutor readCmd2 = new SLASummaryGetJPAExecutor(wfId);
+ SLASummaryBean ssBean = jpaService.execute(readCmd2);
+ assertEquals(wfId, ssBean.getJobId());
+ assertEquals("RUNNING", ssBean.getJobStatus());
+ assertEquals(EventStatus.START_MISS, ssBean.getEventStatus());
+ assertEquals(expStart, ssBean.getExpectedStart());
+ assertEquals(expEnd, ssBean.getExpectedEnd());
+ assertEquals(1000, ssBean.getExpectedDuration());
+ assertEquals(actStart, ssBean.getActualStart());
+ assertEquals(actEnd, ssBean.getActualEnd());
+ assertEquals(2000, ssBean.getActualDuration());
+
+ }
+
+ /**
+ * Test insert + update
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testInsertUpdate() throws Exception {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+
+ String wfId = "workflow-1";
+ // initial insert
+ SLACalculatorBean bean1 = _createSLACalcBean(wfId, false, false);
+
+ cal.setTime(new Date());
+ cal.add(Calendar.DAY_OF_MONTH, -2);
+ Date expStart = cal.getTime();
+ cal.add(Calendar.DAY_OF_MONTH, -1);
+ Date expEnd = cal.getTime();
+ Date actStart = new Date();
+ SLASummaryBean bean2 = _createSLASummaryBean(wfId, "RUNNING", EventStatus.START_MISS, expStart, expEnd, 1000,
+ actStart, null, 2000);
+ List<JsonBean> list = new ArrayList<JsonBean>();
+ list.add(bean1);
+ list.add(bean2);
+ SLACalculationInsertUpdateJPAExecutor writeCmd = new SLACalculationInsertUpdateJPAExecutor();
+ writeCmd.setInsertList(list);
+ jpaService.execute(writeCmd);
+
+ // update existing record
+ Date newDate = new Date();
+ bean1 = _createSLACalcBean(wfId, true, true);
+ bean2 = _createSLASummaryBean(wfId, "RUNNING", EventStatus.DURATION_MISS, expStart, expEnd, 1000, actStart,
+ newDate, 2000);
+ list = new ArrayList<JsonBean>();
+ list.add(bean1);
+ list.add(bean2);
+ writeCmd.setUpdateList(list);
+ writeCmd.setInsertList(null);
+ jpaService.execute(writeCmd);
+
+ SLACalculatorGetJPAExecutor readCmd1 = new SLACalculatorGetJPAExecutor(wfId);
+ SLACalculatorBean scBean = jpaService.execute(readCmd1);
+ assertNotNull(scBean);
+ assertEquals(wfId, scBean.getJobId());
+ assertTrue(scBean.isStartProcessed());
+ assertTrue(scBean.isEndProcessed());
+
+ SLASummaryGetJPAExecutor readCmd2 = new SLASummaryGetJPAExecutor(wfId);
+ SLASummaryBean sdBean = jpaService.execute(readCmd2);
+ // check updated + original fields
+ assertEquals(wfId, sdBean.getJobId());
+ assertEquals(EventStatus.DURATION_MISS, sdBean.getEventStatus());
+ assertEquals(expStart, sdBean.getExpectedStart());
+ assertEquals(expEnd, sdBean.getExpectedEnd());
+ assertEquals(1000, sdBean.getExpectedDuration());
+ assertEquals(actStart, sdBean.getActualStart());
+ assertEquals(newDate, sdBean.getActualEnd());
+ assertEquals(2000, sdBean.getActualDuration());
+
+ }
+
+ /**
+ * Test inserts and updates rollback
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRollback() throws Exception {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+
+ String wfId1 = "workflow-1";
+ String wfId2 = "workflow-2";
+ // initial insert
+ SLACalculatorBean bean1 = _createSLACalcBean(wfId1, false, false);
+ SLASummaryBean bean2 = _createSLASummaryBean(wfId1, "RUNNING", EventStatus.START_MISS, new Date(), new Date(),
+ 1000, null, null, 2000);
+ List<JsonBean> list = new ArrayList<JsonBean>();
+ list.add(bean1);
+ list.add(bean2);
+ SLACalculationInsertUpdateJPAExecutor writeCmd = new SLACalculationInsertUpdateJPAExecutor(list, null);
+ jpaService.execute(writeCmd);
+
+ // update existing record and insert another
+ Date newDate = new Date();
+ bean1 = _createSLACalcBean(wfId1, true, true);
+ bean2 = new SLASummaryBean();
+ bean2.setJobId(wfId1);
+ bean2.setActualEnd(newDate);
+ List<JsonBean> updateList = new ArrayList<JsonBean>();
+ updateList.add(bean1);
+ updateList.add(bean2);
+
+ SLACalculatorBean bean3 = _createSLACalcBean(wfId2, false, false);
+ SLASummaryBean bean4 = _createSLASummaryBean(wfId2, "RUNNING", EventStatus.END_MISS, new Date(), new Date(),
+ 1000, null, null, 2000);
+ List<JsonBean> insertList = new ArrayList<JsonBean>();
+ insertList.add(bean3);
+ insertList.add(bean4);
+ writeCmd = new SLACalculationInsertUpdateJPAExecutor(insertList, updateList);
+
+ // set fault injection to true, so transaction is roll backed
+ setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
+ setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
+ try {
+ jpaService.execute(writeCmd);
+ fail("Expected exception due to commit failure but didn't get any");
+ }
+ catch (Exception e) {
+ }
+ FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
+
+ // Check whether transactions are rolled back or not
+ SLACalculatorGetJPAExecutor readCmd1 = new SLACalculatorGetJPAExecutor(wfId1);
+ SLACalculatorBean scBean = jpaService.execute(readCmd1);
+ // isStartProcessed should NOT be toggled to true
+ assertFalse(scBean.isStartProcessed());
+ SLASummaryGetJPAExecutor readCmd2 = new SLASummaryGetJPAExecutor(wfId1);
+ SLASummaryBean sdBean = jpaService.execute(readCmd2);
+ // actualEnd should be null as before
+ assertNull(sdBean.getActualEnd());
+
+ readCmd1 = new SLACalculatorGetJPAExecutor(wfId2);
+ try {
+ scBean = jpaService.execute(readCmd1);
+ fail("Expected exception but didnt get any");
+ }
+ catch (JPAExecutorException jpaee) {
+ assertEquals(ErrorCode.E0603, jpaee.getErrorCode());
+ }
+ }
+
+ private SLACalculatorBean _createSLACalcBean(String jobId, boolean startProc, boolean endProc) {
+ SLACalculatorBean bean = new SLACalculatorBean();
+ bean.setJobId(jobId);
+ bean.setStartProcessed(startProc);
+ bean.setEndProcessed(endProc);
+ return bean;
+ }
+
+ private SLASummaryBean _createSLASummaryBean(String jobId, String status, EventStatus slaType, Date eStart,
+ Date eEnd, long eDur, Date aStart, Date aEnd, long aDur) {
+ SLASummaryBean bean = new SLASummaryBean();
+ bean.setJobId(jobId);
+ bean.setJobStatus(status);
+ bean.setEventStatus(slaType);
+ bean.setExpectedStart(eStart);
+ bean.setExpectedEnd(eEnd);
+ bean.setExpectedDuration(eDur);
+ bean.setActualStart(aStart);
+ bean.setActualEnd(aEnd);
+ bean.setActualDuration(aDur);
+ return bean;
+ }
+}