You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by ka...@apache.org on 2012/05/02 19:16:20 UTC
svn commit: r1333117 - in /incubator/oozie/branches/branch-3.2/core/src:
main/java/org/apache/oozie/executor/jpa/
test/java/org/apache/oozie/executor/jpa/
Author: kamrul
Date: Wed May 2 17:16:19 2012
New Revision: 1333117
URL: http://svn.apache.org/viewvc?rev=1333117&view=rev
Log:
Adding new files for OOZIE-815: Remove select * from queries related to coord action (Virag via Mohammad)
Added:
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForCheckJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInfoJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInputCheckJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForStartJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForTimeoutJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForInputCheckJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionIdsForDateRangeJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetByLastModifiedTimeJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForCheckJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInfoJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInputCheckJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForStartJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForTimeoutJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForInputCheckJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForStartJPAExecutor.java
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobGetActionIdsForDatesJPAExecutor.java
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForCheckJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForCheckJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForCheckJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForCheckJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,95 @@
+/**
+ * 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.executor.jpa;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.util.DateUtils;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * JPAExecutor to get attributes of CoordinatorActionBean required by CoordActionCheckCommand
+ */
+public class CoordActionGetForCheckJPAExecutor implements JPAExecutor<CoordinatorActionBean> {
+
+ private String coordActionId = null;
+
+ public CoordActionGetForCheckJPAExecutor(String coordActionId) {
+ ParamChecker.notNull(coordActionId, "coordActionId");
+ this.coordActionId = coordActionId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+ */
+ @Override
+ public String getName() {
+ return "CoordActionGetForCheckJPAExecutor";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
+ */
+ @Override
+ public CoordinatorActionBean execute(EntityManager em) throws JPAExecutorException {
+ try {
+ Query q = em.createNamedQuery("GET_COORD_ACTION_FOR_CHECK");
+ q.setParameter("id", coordActionId);
+ Object[] obj = (Object[]) q.getSingleResult();
+ CoordinatorActionBean caBean = getBeanForRunningCoordAction(obj);
+ return caBean;
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+
+ }
+
+ private CoordinatorActionBean getBeanForRunningCoordAction(Object[] arr) {
+ CoordinatorActionBean bean = new CoordinatorActionBean();
+ if (arr[0] != null) {
+ bean.setId((String) arr[0]);
+ }
+ if (arr[1] != null) {
+ bean.setJobId((String) arr[1]);
+ }
+ if (arr[2] != null) {
+ bean.setStatus(CoordinatorAction.Status.valueOf((String) arr[2]));
+ }
+ if (arr[3] != null) {
+ bean.setPending((Integer) arr[3]);
+ }
+ if (arr[4] != null) {
+ bean.setExternalId((String) arr[4]);
+ }
+ if (arr[5] != null) {
+ bean.setLastModifiedTime(DateUtils.toDate((Timestamp) arr[5]));
+ }
+ if (arr[6] != null){
+ bean.setSlaXml((String) arr[6]);
+ }
+ return bean;
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInfoJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInfoJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInfoJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInfoJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,176 @@
+/**
+ * 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.executor.jpa;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.util.DateUtils;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * Load the CoordinatorAction into a Bean and return it.
+ */
+public class CoordActionGetForInfoJPAExecutor implements JPAExecutor<CoordinatorActionBean> {
+
+ private String coordActionId = null;
+ public static final String COORD_GET_ALL_COLS_FOR_ACTION = "oozie.coord.action.get.all.attributes";
+
+ public CoordActionGetForInfoJPAExecutor(String coordActionId) {
+ ParamChecker.notNull(coordActionId, "coordActionId");
+ this.coordActionId = coordActionId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+ */
+ @Override
+ public String getName() {
+ return "CoordActionGetForInfoJPAExecutor";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public CoordinatorActionBean execute(EntityManager em) throws JPAExecutorException {
+ // Maintain backward compatibility for action info cmd
+ if (!(Services.get().getConf().getBoolean(COORD_GET_ALL_COLS_FOR_ACTION, false))) {
+ List<Object[]> actionObjects;
+ try {
+ Query q = em.createNamedQuery("GET_COORD_ACTION_FOR_INFO");
+ q.setParameter("id", coordActionId);
+ actionObjects = q.getResultList();
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+
+ if (actionObjects != null && actionObjects.size() > 0) {
+ CoordinatorActionBean bean = getBeanForRunningCoordAction(actionObjects.get(0));
+ return bean;
+ }
+ else {
+ throw new JPAExecutorException(ErrorCode.E0605, coordActionId);
+ }
+ } else {
+ List<CoordinatorActionBean> caBeans;
+ try {
+ Query q = em.createNamedQuery("GET_COORD_ACTION");
+ q.setParameter("id", coordActionId);
+ caBeans = q.getResultList();
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+
+ if (caBeans != null && caBeans.size() > 0) {
+ CoordinatorActionBean bean = getBeanForCoordAction(caBeans.get(0));
+ return bean;
+ }
+ else {
+ throw new JPAExecutorException(ErrorCode.E0605, coordActionId);
+ }
+
+ }
+ }
+
+
+ private CoordinatorActionBean getBeanForCoordAction(CoordinatorActionBean a){
+ if (a != null) {
+ CoordinatorActionBean action = new CoordinatorActionBean();
+ action.setId(a.getId());
+ action.setActionNumber(a.getActionNumber());
+ action.setActionXml(a.getActionXml());
+ action.setConsoleUrl(a.getConsoleUrl());
+ action.setCreatedConf(a.getCreatedConf());
+ action.setExternalStatus(a.getExternalStatus());
+ action.setMissingDependencies(a.getMissingDependencies());
+ action.setRunConf(a.getRunConf());
+ action.setTimeOut(a.getTimeOut());
+ action.setTrackerUri(a.getTrackerUri());
+ action.setType(a.getType());
+ action.setCreatedTime(a.getCreatedTime());
+ action.setExternalId(a.getExternalId());
+ action.setJobId(a.getJobId());
+ action.setLastModifiedTime(a.getLastModifiedTime());
+ action.setNominalTime(a.getNominalTime());
+ action.setSlaXml(a.getSlaXml());
+ action.setStatus(a.getStatus());
+ action.setPending(a.getPending());
+ action.setRerunTime(a.getRerunTime());
+ return action;
+ }
+ return null;
+ }
+
+ private CoordinatorActionBean getBeanForRunningCoordAction(Object[] arr) {
+ CoordinatorActionBean bean = new CoordinatorActionBean();
+ if (arr[0] != null) {
+ bean.setId((String) arr[0]);
+ }
+ if (arr[1] != null) {
+ bean.setJobId((String) arr[1]);
+ }
+ if (arr[2] != null) {
+ bean.setActionNumber((Integer) arr[2]);
+ }
+ if (arr[3] != null) {
+ bean.setConsoleUrl((String) arr[3]);
+ }
+ if (arr[4] != null) {
+ bean.setErrorCode((String) arr[4]);
+ }
+ if (arr[5] != null) {
+ bean.setErrorMessage((String) arr[5]);
+ }
+ if (arr[6] != null) {
+ bean.setExternalId((String) arr[6]);
+ }
+ if (arr[7] != null) {
+ bean.setExternalStatus((String) arr[7]);
+ }
+ if (arr[8] != null) {
+ bean.setTrackerUri((String) arr[8]);
+ }
+ if (arr[9] != null) {
+ bean.setCreatedTime(DateUtils.toDate((Timestamp) arr[9]));
+ }
+ if (arr[10] != null) {
+ bean.setNominalTime(DateUtils.toDate((Timestamp) arr[10]));
+ }
+ if (arr[11] != null) {
+ bean.setStatus(CoordinatorAction.Status.valueOf((String) arr[11]));
+ }
+ if (arr[12] != null) {
+ bean.setLastModifiedTime(DateUtils.toDate((Timestamp) arr[12]));
+ }
+ if (arr[13] != null) {
+ bean.setMissingDependencies((String) arr[13]);
+ }
+ return bean;
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInputCheckJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInputCheckJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInputCheckJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForInputCheckJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,101 @@
+/**
+ * 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.executor.jpa;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.util.DateUtils;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * JPAExecutor to get attributes of CoordinatorActionBean required by CoordActionInputCheckXCommand
+ */
+public class CoordActionGetForInputCheckJPAExecutor implements JPAExecutor<CoordinatorActionBean> {
+
+ private String coordActionId = null;
+
+ public CoordActionGetForInputCheckJPAExecutor(String coordActionId) {
+ ParamChecker.notNull(coordActionId, "coordActionId");
+ this.coordActionId = coordActionId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+ */
+ @Override
+ public String getName() {
+ return "CoordActionGetForInputCheckJPAExecutor";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
+ */
+ @Override
+ public CoordinatorActionBean execute(EntityManager em) throws JPAExecutorException {
+ try {
+ Query q = em.createNamedQuery("GET_COORD_ACTION_FOR_INPUTCHECK");
+ q.setParameter("id", coordActionId);
+ Object[] obj = (Object[]) q.getSingleResult();
+ CoordinatorActionBean caBean = getBeanForRunningCoordAction(obj);
+ return caBean;
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+
+ }
+
+ private CoordinatorActionBean getBeanForRunningCoordAction(Object[] arr) {
+ CoordinatorActionBean bean = new CoordinatorActionBean();
+ if (arr[0] != null) {
+ bean.setId((String) arr[0]);
+ }
+ if (arr[1] != null) {
+ bean.setJobId((String) arr[1]);
+ }
+ if (arr[2] != null) {
+ bean.setStatus(CoordinatorAction.Status.valueOf((String) arr[2]));
+ }
+ if (arr[3] != null) {
+ bean.setRunConf((String) arr[3]);
+ }
+ if (arr[4] != null) {
+ bean.setNominalTime(DateUtils.toDate((Timestamp) arr[4]));
+ }
+ if (arr[5] != null) {
+ bean.setCreatedTime(DateUtils.toDate((Timestamp) arr[5]));
+ }
+ if (arr[6] != null) {
+ bean.setActionXml((String) arr[6]);
+ }
+ if (arr[7] != null) {
+ bean.setMissingDependencies((String) arr[7]);
+ }
+ if (arr[8] != null) {
+ bean.setTimeOut((Integer) arr[8]);
+ }
+ return bean;
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForStartJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForStartJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForStartJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForStartJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,100 @@
+/**
+ * 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.executor.jpa;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * JPAExecutor to get attributes of CoordinatorActionBean required by CoordActionStartXCommand
+ */
+public class CoordActionGetForStartJPAExecutor implements JPAExecutor<CoordinatorActionBean> {
+
+ private String coordActionId = null;
+
+ public CoordActionGetForStartJPAExecutor(String coordActionId) {
+ ParamChecker.notNull(coordActionId, "coordActionId");
+ this.coordActionId = coordActionId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+ */
+ @Override
+ public String getName() {
+ return "CoordActionGetForStartExecutor";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
+ */
+ @Override
+ public CoordinatorActionBean execute(EntityManager em) throws JPAExecutorException {
+ try {
+ Query q = em.createNamedQuery("GET_COORD_ACTION_FOR_START");
+ q.setParameter("id", coordActionId);
+ Object[] obj = (Object[]) q.getSingleResult();
+ CoordinatorActionBean caBean = getBeanForRunningCoordAction(obj);
+ return caBean;
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+
+ }
+
+ private CoordinatorActionBean getBeanForRunningCoordAction(Object[] arr) {
+ CoordinatorActionBean bean = new CoordinatorActionBean();
+ if (arr[0] != null) {
+ bean.setId((String) arr[0]);
+ }
+ if (arr[1] != null) {
+ bean.setJobId((String) arr[1]);
+ }
+ if (arr[2] != null) {
+ bean.setStatus(CoordinatorAction.Status.valueOf((String) arr[2]));
+ }
+ if (arr[3] != null) {
+ bean.setPending((Integer) arr[3]);
+ }
+ if (arr[4] != null) {
+ bean.setCreatedConf((String) arr[4]);
+ }
+ if (arr[5] != null) {
+ bean.setSlaXml((String) arr[5]);
+ }
+ if (arr[6] != null) {
+ bean.setActionXml((String) arr[6]);
+ }
+ if (arr[7] != null) {
+ bean.setExternalId((String) arr[7]);
+ }
+ if (arr[8] != null) {
+ bean.setErrorMessage((String) arr[8]);
+ }
+ if (arr[9] != null) {
+ bean.setErrorCode((String) arr[9]);
+ }
+ return bean;
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForTimeoutJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForTimeoutJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForTimeoutJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionGetForTimeoutJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,86 @@
+/**
+ * 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.executor.jpa;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * JPAExecutor to get attributes of CoordinatorActionBean required by CoordActionTimeoutXCommand
+ */
+public class CoordActionGetForTimeoutJPAExecutor implements JPAExecutor<CoordinatorActionBean> {
+
+ private String coordActionId = null;
+
+ public CoordActionGetForTimeoutJPAExecutor(String coordActionId) {
+ ParamChecker.notNull(coordActionId, "coordActionId");
+ this.coordActionId = coordActionId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+ */
+ @Override
+ public String getName() {
+ return "CoordActionGetForTimeoutJPAExecutor";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
+ */
+ @Override
+ public CoordinatorActionBean execute(EntityManager em) throws JPAExecutorException {
+ try {
+ Query q = em.createNamedQuery("GET_COORD_ACTION_FOR_TIMEOUT");
+ q.setParameter("id", coordActionId);
+ Object[] obj = (Object[]) q.getSingleResult();
+ CoordinatorActionBean caBean = getBeanForRunningCoordAction(obj);
+ return caBean;
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+
+ }
+
+ private CoordinatorActionBean getBeanForRunningCoordAction(Object[] arr) {
+ CoordinatorActionBean bean = new CoordinatorActionBean();
+ if (arr[0] != null) {
+ bean.setId((String) arr[0]);
+ }
+ if (arr[1] != null) {
+ bean.setJobId((String) arr[1]);
+ }
+ if (arr[2] != null) {
+ bean.setStatus(CoordinatorAction.Status.valueOf((String) arr[2]));
+ }
+ if (arr[3] != null) {
+ bean.setRunConf((String) arr[3]);
+ }
+ if (arr[4] != null) {
+ bean.setPending((Integer) arr[4]);
+ }
+ return bean;
+
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForInputCheckJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForInputCheckJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForInputCheckJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForInputCheckJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,75 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * Updates the action status, pending status, last modified time, actionXml and missingDependencies of CoordinatorAction and persists it.
+ * It executes SQL update query and return type is Void.
+ */
+public class CoordActionUpdateForInputCheckJPAExecutor implements JPAExecutor<Void> {
+
+ private CoordinatorActionBean coordAction = null;
+
+ public CoordActionUpdateForInputCheckJPAExecutor(CoordinatorActionBean coordAction) {
+ ParamChecker.notNull(coordAction, "coordAction");
+ this.coordAction = coordAction;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.
+ * EntityManager)
+ */
+ @Override
+ public Void execute(EntityManager em) throws JPAExecutorException {
+ try {
+ Query q = em.createNamedQuery("UPDATE_COORD_ACTION_FOR_INPUTCHECK");
+ q.setParameter("id", coordAction.getId());
+ q.setParameter("status", coordAction.getStatus().toString());
+ q.setParameter("lastModifiedTime", new Date());
+ q.setParameter("actionXml", coordAction.getActionXml());
+ q.setParameter("missingDependencies", coordAction.getMissingDependencies());
+ q.executeUpdate();
+ // Since the return type is Void, we have to return null
+ return null;
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+ */
+ @Override
+ public String getName() {
+ return "CoordActionUpdateForInputCheckJPAExecutor";
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,76 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * Updates the action status, last modified time, runConf, externalId and pending of CoordinatorAction and persists it.
+ * It executes SQL update query and return type is Void.
+ */
+public class CoordActionUpdateForStartJPAExecutor implements JPAExecutor<Void> {
+
+ private CoordinatorActionBean coordAction = null;
+
+ public CoordActionUpdateForStartJPAExecutor(CoordinatorActionBean coordAction) {
+ ParamChecker.notNull(coordAction, "coordAction");
+ this.coordAction = coordAction;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.
+ * EntityManager)
+ */
+ @Override
+ public Void execute(EntityManager em) throws JPAExecutorException {
+ try {
+ Query q = em.createNamedQuery("UPDATE_COORD_ACTION_FOR_START");
+ q.setParameter("id", coordAction.getId());
+ q.setParameter("status", coordAction.getStatus().toString());
+ q.setParameter("lastModifiedTime", new Date());
+ q.setParameter("runConf", coordAction.getRunConf());
+ q.setParameter("externalId", coordAction.getExternalId());
+ q.setParameter("pending", coordAction.getPending());
+ q.executeUpdate();
+ // Since the return type is Void, we have to return null
+ return null;
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+ */
+ @Override
+ public String getName() {
+ return "CoordActionUpdateForStartJPAExecutor";
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionIdsForDateRangeJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionIdsForDateRangeJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionIdsForDateRangeJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionIdsForDateRangeJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,68 @@
+/**
+ * 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.executor.jpa;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * Load coordinator action ids by date range.
+ */
+public class CoordJobGetActionIdsForDateRangeJPAExecutor implements JPAExecutor<List<String>> {
+
+ private String jobId = null;
+ private Date startDate, endDate;
+
+ public CoordJobGetActionIdsForDateRangeJPAExecutor(String jobId, Date startDate, Date endDate) {
+ ParamChecker.notNull(jobId, "jobId");
+ this.jobId = jobId;
+ this.startDate = startDate;
+ this.endDate = endDate;
+ }
+
+ @Override
+ public String getName() {
+ return "CoordJobGetActionIdsForDateRangeJPAExecutor";
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public List<String> execute(EntityManager em) throws JPAExecutorException {
+ try {
+ Query q = em.createNamedQuery("GET_ACTION_IDS_FOR_DATES");
+ q.setParameter("jobId", jobId);
+ q.setParameter("startTime", new Timestamp(startDate.getTime()));
+ q.setParameter("endTime", new Timestamp(endDate.getTime()));
+ List<String> coordActionIds= q.getResultList();
+ return coordActionIds;
+ }
+ catch (Exception e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
+ }
+
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetByLastModifiedTimeJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetByLastModifiedTimeJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetByLastModifiedTimeJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetByLastModifiedTimeJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,83 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Date;
+import java.util.List;
+
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+
+public class TestCoordActionGetByLastModifiedTimeJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionGet() throws Exception {
+ // Get date before action is created
+ Date dateBeforeAction = new Date();
+ int actionNum = 1;
+ // Add two jobs with lastmodifiedtime > dateBeforeAction
+ CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ String jobId1 = job1.getId();
+ CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ String jobId2 = job2.getId();
+ addRecordToCoordActionTable(jobId1, actionNum++,
+ CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
+ addRecordToCoordActionTable(jobId2, actionNum++,
+ CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
+
+ _testCoordActionGetByLastModifiedTime(jobId1, jobId2, dateBeforeAction);
+ }
+
+
+ private void _testCoordActionGetByLastModifiedTime(String jobId1, String jobId2, Date dateBeforeAction)
+ throws Exception {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ // Call JPAExecutor to get actions which are modified after the given
+ // date
+ List<String> coordJobIds = jpaService
+ .execute(new CoordActionsGetByLastModifiedTimeJPAExecutor(dateBeforeAction));
+ assertEquals(2, coordJobIds.size());
+ assertEquals(jobId1, coordJobIds.get(0));
+ assertEquals(jobId2, coordJobIds.get(1));
+ }
+
+
+
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForCheckJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForCheckJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForCheckJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForCheckJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,76 @@
+/**
+ * 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.executor.jpa;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+
+public class TestCoordActionGetForCheckJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionGet() throws Exception {
+ int actionNum = 1;
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = createCoordAction(job.getId(), actionNum, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0);
+ action.setSlaXml(XDataTestCase.slaXml);
+ // Insert the action
+ insertRecordCoordAction(action);
+ _testGetActionForCheck(action.getId(), job.getId(), CoordinatorAction.Status.WAITING, 0, action.getId() + "_E", XDataTestCase.slaXml);
+ }
+
+ private void _testGetActionForCheck(String actionId, String jobId, CoordinatorAction.Status status, int pending, String extId, String slaXml) throws Exception {
+ try {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ CoordActionGetForCheckJPAExecutor actionGetCmd = new CoordActionGetForCheckJPAExecutor(actionId);
+ CoordinatorActionBean action = jpaService.execute(actionGetCmd);
+ assertNotNull(action);
+ assertEquals(actionId, action.getId());
+ assertEquals(status, action.getStatus());
+ assertEquals(pending, action.getPending());
+ assertEquals(extId, action.getExternalId());
+ assertEquals(slaXml, action.getSlaXml());
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ fail("Unable to GET a record for COORD Action By actionId =" + actionId);
+ }
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInfoJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInfoJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInfoJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInfoJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,159 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Date;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.CallableQueueService;
+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.XmlUtils;
+
+public class TestCoordActionGetForInfoJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionGet() throws Exception {
+ int actionNum = 1;
+ String errorCode = "000";
+ String errorMessage = "Dummy";
+ String resourceXmlName = "coord-action-get.xml";
+ String consoleUrl = "consoleUrl";
+ String externalStatus = "externalStatus";
+ String trackerUri = "trackerUri";
+ String missingDeps = "missingDeps";
+ String slaXml = "slaXml";
+
+ Date createdTime = new Date();
+ Date lastModifiedTime = new Date();
+
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = createCoordAction(job.getId(), actionNum, CoordinatorAction.Status.WAITING,
+ resourceXmlName, 0);
+ // Add extra attributes for action
+ action.setErrorCode(errorCode);
+ action.setErrorMessage(errorMessage);
+ action.setConsoleUrl(consoleUrl);
+ action.setExternalStatus(externalStatus);
+ action.setTrackerUri(trackerUri);
+ action.setCreatedTime(createdTime);
+ action.setMissingDependencies(missingDeps);
+ action.setLastModifiedTime(lastModifiedTime);
+ action.setSlaXml(slaXml);
+ // Insert the action
+ insertRecordCoordAction(action);
+
+ Path appPath = new Path(getFsTestCaseDir(), "coord");
+ String actionXml = getCoordActionXml(appPath, resourceXmlName);
+ String actionNominalTime = getActionNominalTime(actionXml);
+
+ // Pass the expected values
+ _testGetForInfo(action.getId(), job.getId(), CoordinatorAction.Status.WAITING, action.getId() + "_E",
+ errorCode, errorMessage, consoleUrl, externalStatus, trackerUri, createdTime, missingDeps,
+ DateUtils.parseDateUTC(actionNominalTime), actionNum, lastModifiedTime);
+
+ //services.destroy();
+ }
+
+ private void _testGetForInfo(String actionId, String jobId, CoordinatorAction.Status status, String extId,
+ String errorCode, String errorMessage, String consoleUrl, String externalStatus, String trackerUri,
+ Date createdTime, String missingDeps, Date nominalTime, int actionNumber, Date lastModifiedTime)
+ throws Exception {
+ try {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ CoordActionGetForInfoJPAExecutor actionGetCmd = new CoordActionGetForInfoJPAExecutor(actionId);
+ CoordinatorActionBean action = jpaService.execute(actionGetCmd);
+ assertNotNull(action);
+ // Check for expected values
+ assertEquals(actionId, action.getId());
+ assertEquals(jobId, action.getJobId());
+ assertEquals(status, action.getStatus());
+ assertEquals(extId, action.getExternalId());
+ assertEquals(errorMessage, action.getErrorMessage());
+ assertEquals(errorCode, action.getErrorCode());
+ assertEquals(consoleUrl, action.getConsoleUrl());
+ assertEquals(externalStatus, action.getExternalStatus());
+ assertEquals(trackerUri, action.getTrackerUri());
+ assertEquals(createdTime, action.getCreatedTime());
+ assertEquals(missingDeps, action.getMissingDependencies());
+ assertEquals(nominalTime, action.getNominalTime());
+ assertEquals(actionNumber, action.getActionNumber());
+ assertEquals(lastModifiedTime, action.getLastModifiedTime());
+
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ fail("Unable to GET a record for COORD Action By actionId =" + actionId);
+ }
+ }
+
+ public void testCoordActionGetAllColumns() throws Exception {
+ setSystemProperty(CoordActionGetForInfoJPAExecutor.COORD_GET_ALL_COLS_FOR_ACTION, "true");
+ new Services().init();
+ try {
+ String resourceXmlName = "coord-action-get.xml";
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = createCoordAction(job.getId(), 1, CoordinatorAction.Status.WAITING,
+ resourceXmlName, 0);
+ String slaXml = "slaXml";
+ action.setSlaXml(slaXml);
+ // Insert the action
+ insertRecordCoordAction(action);
+ _testGetForInfoAllActions(action.getId(), slaXml);
+ }
+ finally {
+ Services.get().destroy();
+ }
+ }
+
+ private void _testGetForInfoAllActions(String actionId, String slaXml) throws Exception{
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ CoordActionGetForInfoJPAExecutor actionGetCmd = new CoordActionGetForInfoJPAExecutor(actionId);
+ CoordinatorActionBean action = jpaService.execute(actionGetCmd);
+ assertEquals(CoordinatorAction.Status.WAITING, action.getStatus());
+ assertEquals(slaXml, action.getSlaXml());
+ assertEquals(0, action.getPending());
+
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInputCheckJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInputCheckJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInputCheckJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForInputCheckJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,108 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Date;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+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.XmlUtils;
+
+public class TestCoordActionGetForInputCheckJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionGet() throws Exception {
+ int actionNum = 1;
+ String resourceXmlName = "coord-action-get.xml";
+ Date dummyCreationTime = new Date();
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = createCoordAction(job.getId(), actionNum, CoordinatorAction.Status.WAITING,
+ resourceXmlName, 0);
+
+ // Add missDeps attribute to action
+ String testDir = getTestCaseDir();
+ String missDeps = "file://#testDir/2009/29/_SUCCESS#file://#testDir/2009/22/_SUCCESS#file://#testDir/2009/15/_SUCCESS#file://#testDir/2009/08/_SUCCESS";
+ missDeps = missDeps.replaceAll("#testDir", testDir);
+ action.setMissingDependencies(missDeps);
+ action.setCreatedTime(dummyCreationTime);
+
+ // Insert the action
+ insertRecordCoordAction(action);
+
+ Path appPath = new Path(getFsTestCaseDir(), "coord");
+ String actionXml = getCoordActionXml(appPath, resourceXmlName);
+ Configuration conf = getCoordConf(appPath);
+ String actionNominalTime = getActionNominalTime(actionXml);
+
+ // Pass the expected values
+ _testGetForInputCheckX(action.getId(), job.getId(), CoordinatorAction.Status.WAITING, 0, actionXml, XmlUtils
+ .prettyPrint(conf).toString(), DateUtils.parseDateUTC(actionNominalTime), dummyCreationTime, missDeps);
+ }
+
+
+ private void _testGetForInputCheckX(String actionId, String jobId, CoordinatorAction.Status status, int pending,
+ String actionXml, String runConf, Date nominalTime, Date createdTime, String missDeps) throws Exception {
+ try {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ CoordActionGetForInputCheckJPAExecutor actionGetCmd = new CoordActionGetForInputCheckJPAExecutor(actionId);
+ CoordinatorActionBean action = jpaService.execute(actionGetCmd);
+ assertNotNull(action);
+
+ // Check for expected column values
+ assertEquals(actionId, action.getId());
+ assertEquals(jobId, action.getJobId());
+ assertEquals(status, action.getStatus());
+ assertEquals(pending, action.getPending());
+ assertEquals(runConf, action.getRunConf());
+ assertEquals(actionXml, action.getActionXml());
+ assertEquals(nominalTime, action.getNominalTime());
+ assertEquals(createdTime, action.getCreatedTime());
+ assertEquals(missDeps, action.getMissingDependencies());
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ fail("Unable to GET a record for COORD Action By actionId =" + actionId);
+ }
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForStartJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForStartJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForStartJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForStartJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,102 @@
+/**
+ * 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.executor.jpa;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.util.XmlUtils;
+
+public class TestCoordActionGetForStartJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionGet() throws Exception {
+ int actionNum = 1;
+ String errorCode = "000";
+ String errorMessage = "Dummy";
+ String resourceXmlName = "coord-action-get.xml";
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = createCoordAction(job.getId(), actionNum, CoordinatorAction.Status.WAITING,
+ resourceXmlName, 0);
+ // Add extra attributes for action
+ action.setSlaXml(XDataTestCase.slaXml);
+ action.setErrorCode(errorCode);
+ action.setErrorMessage(errorMessage);
+ // Insert the action
+ insertRecordCoordAction(action);
+
+ Path appPath = new Path(getFsTestCaseDir(), "coord");
+ String actionXml = getCoordActionXml(appPath, resourceXmlName);
+ Configuration conf = getCoordConf(appPath);
+
+ // Pass the expected values
+ _testGetForStartX(action.getId(), job.getId(), CoordinatorAction.Status.WAITING, 0, action.getId() + "_E",
+ XDataTestCase.slaXml, resourceXmlName, XmlUtils.prettyPrint(conf).toString(), actionXml,
+ errorCode, errorMessage);
+ }
+
+ private void _testGetForStartX(String actionId, String jobId, CoordinatorAction.Status status, int pending,
+ String extId, String slaXml, String resourceXmlName, String createdConf, String actionXml,
+ String errorCode, String errorMessage) throws Exception {
+ try {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ CoordActionGetForStartJPAExecutor actionGetCmd = new CoordActionGetForStartJPAExecutor(actionId);
+ CoordinatorActionBean action = jpaService.execute(actionGetCmd);
+ assertNotNull(action);
+ // Check for expected values
+ assertEquals(actionId, action.getId());
+ assertEquals(jobId, action.getJobId());
+ assertEquals(status, action.getStatus());
+ assertEquals(pending, action.getPending());
+ assertEquals(createdConf, action.getCreatedConf());
+ assertEquals(slaXml, action.getSlaXml());
+ assertEquals(actionXml, action.getActionXml());
+ assertEquals(extId, action.getExternalId());
+ assertEquals(errorMessage, action.getErrorMessage());
+ assertEquals(errorCode, action.getErrorCode());
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ fail("Unable to GET a record for COORD Action By actionId =" + actionId);
+ }
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForTimeoutJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForTimeoutJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForTimeoutJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionGetForTimeoutJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,88 @@
+/**
+ * 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.executor.jpa;
+
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.util.XmlUtils;
+
+public class TestCoordActionGetForTimeoutJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionGet() throws Exception {
+ int actionNum = 1;
+ String resourceXmlName = "coord-action-get.xml";
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = createCoordAction(job.getId(), actionNum, CoordinatorAction.Status.WAITING,
+ resourceXmlName, 1);
+ // Insert the action
+ insertRecordCoordAction(action);
+ Path appPath = new Path(getFsTestCaseDir(), "coord");
+ Configuration conf = getCoordConf(appPath);
+ // Pass expected values
+ _testGetForInputCheckX(action.getId(), job.getId(), CoordinatorAction.Status.WAITING, XmlUtils
+ .prettyPrint(conf).toString(), 1);
+ }
+
+ private void _testGetForInputCheckX(String actionId, String jobId, CoordinatorAction.Status status, String runConf, int pending)
+ throws Exception {
+ try {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ CoordActionGetForTimeoutJPAExecutor actionGetCmd = new CoordActionGetForTimeoutJPAExecutor(actionId);
+ CoordinatorActionBean action = jpaService.execute(actionGetCmd);
+ assertNotNull(action);
+
+ // Check for expected column values
+ assertEquals(actionId, action.getId());
+ assertEquals(jobId, action.getJobId());
+ assertEquals(status, action.getStatus());
+ assertEquals(runConf, action.getRunConf());
+ assertEquals(pending, action.getPending());
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ fail("Unable to GET a record for COORD Action By External ID. actionId =" + actionId);
+ }
+ }
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForInputCheckJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForInputCheckJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForInputCheckJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForInputCheckJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,77 @@
+/**
+ * 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.executor.jpa;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+
+public class TestCoordActionUpdateForInputCheckJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionUpdateStatus() throws Exception {
+ int actionNum = 1;
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), actionNum,
+ CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
+ _testCoordActionUpdateStatus(action);
+ }
+
+ private void _testCoordActionUpdateStatus(CoordinatorActionBean action) throws Exception {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ action.setStatus(CoordinatorAction.Status.SUCCEEDED);
+ action.setActionXml("dummyXml");
+ action.setMissingDependencies("dummyDependencies");
+
+ // Call the JPAUpdate executor to execute the Update command
+ CoordActionUpdateForInputCheckJPAExecutor coordUpdCmd = new CoordActionUpdateForInputCheckJPAExecutor(action);
+ jpaService.execute(coordUpdCmd);
+
+ CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(action.getId());
+ CoordinatorActionBean newAction = jpaService.execute(coordGetCmd);
+
+ assertNotNull(newAction);
+ // Check for expected values
+ assertEquals(CoordinatorAction.Status.SUCCEEDED, newAction.getStatus());
+ assertEquals("dummyXml", newAction.getActionXml());
+ assertEquals("dummyDependencies", newAction.getMissingDependencies());
+ }
+
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForStartJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForStartJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForStartJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordActionUpdateForStartJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.executor.jpa;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+
+public class TestCoordActionUpdateForStartJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionUpdateStatus() throws Exception {
+ int actionNum = 1;
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), actionNum,
+ CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
+ _testCoordActionUpdateStatus(action);
+ }
+
+ private void _testCoordActionUpdateStatus(CoordinatorActionBean action) throws Exception {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+
+ action.setStatus(CoordinatorAction.Status.SUCCEEDED);
+ action.setRunConf("dummyConf");
+ action.setExternalId("dummyExternalId");
+ action.setPending(1);
+
+ // Call the JPAUpdate executor to execute the Update command
+ CoordActionUpdateForStartJPAExecutor coordUpdCmd = new CoordActionUpdateForStartJPAExecutor(action);
+ jpaService.execute(coordUpdCmd);
+
+ CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(action.getId());
+ CoordinatorActionBean newAction = jpaService.execute(coordGetCmd);
+
+ assertNotNull(newAction);
+ // Check for expected values
+ assertEquals(CoordinatorAction.Status.SUCCEEDED, newAction.getStatus());
+ assertEquals("dummyConf", newAction.getRunConf());
+ assertEquals("dummyExternalId", newAction.getExternalId());
+ assertEquals(1, newAction.getPending());
+ }
+
+}
Added: incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobGetActionIdsForDatesJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobGetActionIdsForDatesJPAExecutor.java?rev=1333117&view=auto
==============================================================================
--- incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobGetActionIdsForDatesJPAExecutor.java (added)
+++ incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobGetActionIdsForDatesJPAExecutor.java Wed May 2 17:16:19 2012
@@ -0,0 +1,85 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Date;
+import java.util.List;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.local.LocalOozie;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.util.DateUtils;
+
+public class TestCoordJobGetActionIdsForDatesJPAExecutor extends XDataTestCase {
+ Services services;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ services = new Services();
+ services.init();
+ cleanUpDBTables();
+ LocalOozie.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ LocalOozie.stop();
+ services.destroy();
+ super.tearDown();
+ }
+
+ public void testCoordActionGet() throws Exception {
+ int actionNum = 1;
+ CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ addRecordToCoordActionTable(job.getId(), actionNum, CoordinatorAction.Status.FAILED, "coord-action-get.xml", 0);
+
+ Path appPath = new Path(getFsTestCaseDir(), "coord");
+ String actionXml = getCoordActionXml(appPath, "coord-action-get.xml");
+ String actionNomialTime = getActionNominalTime(actionXml);
+ Date nominalTime = DateUtils.parseDateUTC(actionNomialTime);
+
+ Date d1 = new Date(nominalTime.getTime() - 1000);
+ Date d2 = new Date(nominalTime.getTime() + 1000);
+ _testGetActionForDates(job.getId(), d1, d2, 1);
+
+ d1 = new Date(nominalTime.getTime() + 1000);
+ d2 = new Date(nominalTime.getTime() + 2000);
+ _testGetActionForDates(job.getId(), d1, d2, 0);
+
+ cleanUpDBTables();
+ job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+ addRecordToCoordActionTable(job.getId(), actionNum, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0);
+ _testGetActionForDates(job.getId(), d1, d2, 0);
+ }
+
+ private void _testGetActionForDates(String jobId, Date d1, Date d2, int expected) throws Exception {
+ JPAService jpaService = Services.get().get(JPAService.class);
+ assertNotNull(jpaService);
+ CoordJobGetActionIdsForDateRangeJPAExecutor actionGetCmd = new CoordJobGetActionIdsForDateRangeJPAExecutor(jobId, d1, d2);
+ List<String> actionIds = jpaService.execute(actionGetCmd);
+ assertEquals(expected, actionIds.size());
+ }
+
+}