OOZIE-2225 Add wild card filter for gathering jobs (sai-krish via rkanter)

Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/71ff6cea
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/71ff6cea
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/71ff6cea

Branch: refs/heads/oya
Commit: 71ff6cea51684c5ff0ee59a64d66ff6e9ce346c3
Parents: 72ee258
Author: Robert Kanter <[email protected]>
Authored: Tue Nov 1 17:54:11 2016 -0700
Committer: Robert Kanter <[email protected]>
Committed: Tue Nov 1 17:54:11 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/oozie/cli/OozieCLI.java     |  7 +-
 .../org/apache/oozie/client/OozieClient.java    |  2 +
 .../org/apache/oozie/CoordinatorEngine.java     |  1 +
 .../main/java/org/apache/oozie/DagEngine.java   |  1 +
 .../jpa/WorkflowsJobGetJPAExecutor.java         |  8 +-
 .../apache/oozie/store/StoreStatusFilter.java   | 33 +++++++
 .../org/apache/oozie/util/JobsFilterUtils.java  |  1 +
 .../jpa/TestBundleJobInfoGetJPAExecutor.java    | 94 +++++++++++++++++++
 .../jpa/TestCoordJobInfoGetJPAExecutor.java     | 95 +++++++++++++++++++-
 .../jpa/TestWorkflowsJobGetJPAExecutor.java     | 73 +++++++++++++++
 docs/src/site/twiki/DG_CommandLineTool.twiki    |  1 +
 docs/src/site/twiki/WebServicesAPI.twiki        |  1 +
 release-log.txt                                 |  1 +
 13 files changed, 312 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java 
b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
index f1d0f2b..807cf22 100644
--- a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
+++ b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
@@ -454,9 +454,10 @@ public class OozieCLI {
                 "job type ('Supported in Oozie-2.0 or later versions ONLY - 
'coordinator' or 'bundle' or 'wf'(default))");
         Option len = new Option(LEN_OPTION, true, "number of jobs (default 
'100')");
         Option filter = new Option(FILTER_OPTION, true,
-                
"user=<U>\\;name=<N>\\;group=<G>\\;status=<S>\\;frequency=<F>\\;unit=<M>" +
-                        "\\;startcreatedtime=<SC>\\;endcreatedtime=<EC> 
\\;sortBy=<SB>" +
-                        "(valid unit values are 'months', 'days', 'hours' or 
'minutes'. " +
+                
"text=<*>\\;user=<U>\\;name=<N>\\;group=<G>\\;status=<S>\\;frequency=<F>\\;unit=<M>"
 +
+                        "\\;startcreatedtime=<SC>\\;endcreatedtime=<EC> 
\\;sortBy=<SB>\n" +
+                        "(text filter: matches partially with name and user or 
complete match with job ID" +
+                        "valid unit values are 'months', 'days', 'hours' or 
'minutes'. " +
                         "startcreatedtime, endcreatedtime: time of format 
yyyy-MM-dd'T'HH:mm'Z'. " +
                         "valid values for sortBy are 'createdTime' or 
'lastModifiedTime'.)");
         Option localtime = new Option(LOCAL_TIME_OPTION, false, "use local 
time (same as passing your time zone to -" +

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/client/src/main/java/org/apache/oozie/client/OozieClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/oozie/client/OozieClient.java 
b/client/src/main/java/org/apache/oozie/client/OozieClient.java
index a2021fe..12c80cb 100644
--- a/client/src/main/java/org/apache/oozie/client/OozieClient.java
+++ b/client/src/main/java/org/apache/oozie/client/OozieClient.java
@@ -127,6 +127,8 @@ public class OozieClient {
 
     public static final String FILTER_USER = "user";
 
+    public static final String FILTER_TEXT = "text";
+
     public static final String FILTER_GROUP = "group";
 
     public static final String FILTER_NAME = "name";

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/main/java/org/apache/oozie/CoordinatorEngine.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/CoordinatorEngine.java 
b/core/src/main/java/org/apache/oozie/CoordinatorEngine.java
index cec6347..91fe5a1 100644
--- a/core/src/main/java/org/apache/oozie/CoordinatorEngine.java
+++ b/core/src/main/java/org/apache/oozie/CoordinatorEngine.java
@@ -613,6 +613,7 @@ public class CoordinatorEngine extends BaseEngine {
         FILTER_NAMES.add(OozieClient.FILTER_SORT_BY);
         FILTER_NAMES.add(OozieClient.FILTER_CREATED_TIME_START);
         FILTER_NAMES.add(OozieClient.FILTER_CREATED_TIME_END);
+        FILTER_NAMES.add(OozieClient.FILTER_TEXT);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/main/java/org/apache/oozie/DagEngine.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/DagEngine.java 
b/core/src/main/java/org/apache/oozie/DagEngine.java
index 01aeddf..7597142 100644
--- a/core/src/main/java/org/apache/oozie/DagEngine.java
+++ b/core/src/main/java/org/apache/oozie/DagEngine.java
@@ -467,6 +467,7 @@ public class DagEngine extends BaseEngine {
     private static final Set<String> FILTER_NAMES = new HashSet<String>();
 
     static {
+        FILTER_NAMES.add(OozieClient.FILTER_TEXT);
         FILTER_NAMES.add(OozieClient.FILTER_USER);
         FILTER_NAMES.add(OozieClient.FILTER_NAME);
         FILTER_NAMES.add(OozieClient.FILTER_GROUP);

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowsJobGetJPAExecutor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowsJobGetJPAExecutor.java
 
b/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowsJobGetJPAExecutor.java
index 3c03267..13af8f8 100644
--- 
a/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowsJobGetJPAExecutor.java
+++ 
b/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowsJobGetJPAExecutor.java
@@ -216,7 +216,7 @@ public class WorkflowsJobGetJPAExecutor implements 
JPAExecutor<WorkflowsInfo> {
                             colArray.add(colVar);
                         }
                     }
-                    if 
(entry.getKey().equalsIgnoreCase(OozieClient.FILTER_CREATED_TIME_START)) {
+                    else if 
(entry.getKey().equalsIgnoreCase(OozieClient.FILTER_CREATED_TIME_START)) {
                         List<String> values = 
filter.get(OozieClient.FILTER_CREATED_TIME_START);
                         colName = "createdTimestampStart";
                         if (values.size() > 1) {
@@ -246,7 +246,7 @@ public class WorkflowsJobGetJPAExecutor implements 
JPAExecutor<WorkflowsInfo> {
                         colArray.add(colVar);
 
                     }
-                    if 
(entry.getKey().equalsIgnoreCase(OozieClient.FILTER_CREATED_TIME_END)) {
+                    else if 
(entry.getKey().equalsIgnoreCase(OozieClient.FILTER_CREATED_TIME_END)) {
                         List<String> values = 
filter.get(OozieClient.FILTER_CREATED_TIME_END);
                         colName = "createdTimestampEnd";
                         if (values.size() > 1) {
@@ -275,6 +275,10 @@ public class WorkflowsJobGetJPAExecutor implements 
JPAExecutor<WorkflowsInfo> {
                         orArray.add(colName);
                         colArray.add(colVar);
                     }
+                    // w.id = text || w.appName.contains(text) || 
w.user.contains(text)
+                    else if 
(entry.getKey().equalsIgnoreCase(OozieClient.FILTER_TEXT)) {
+                        StoreStatusFilter.filterJobsUsingText(filter, sb, 
isEnabled, seletStr, valArray, orArray, colArray);
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/main/java/org/apache/oozie/store/StoreStatusFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/store/StoreStatusFilter.java 
b/core/src/main/java/org/apache/oozie/store/StoreStatusFilter.java
index fb1db29..b649ae5 100644
--- a/core/src/main/java/org/apache/oozie/store/StoreStatusFilter.java
+++ b/core/src/main/java/org/apache/oozie/store/StoreStatusFilter.java
@@ -50,6 +50,8 @@ public class StoreStatusFilter {
     public static final String TIME_FORMAT = " Specify time either in UTC 
format (yyyy-MM-dd'T'HH:mm'Z') or " +
             "a offset value in days/hours/minutes e.g. (-2d/h/m) from the 
current time.";
 
+    private static final String textFilterStr = "(w.appName LIKE :text1 OR 
w.user LIKE :text2 OR w.id = :text3)";
+
 
     public static void filter(Map<String, List<String>> filter, List<String> 
orArray, List<String> colArray,
            List<Object> valArray, StringBuilder sb, String seletStr, String 
countStr) throws JPAExecutorException {
@@ -320,6 +322,10 @@ public class StoreStatusFilter {
                             orArray.add(colName);
                             colArray.add(colVar);
                         }
+                        // job.id = text || job.appName.contains(text) || 
job.user.contains(text)
+                        else if 
(entry.getKey().equalsIgnoreCase(OozieClient.FILTER_TEXT)) {
+                            filterJobsUsingText(filter, sb, isEnabled, 
seletStr, valArray, orArray, colArray);
+                        }
                     }
                 }
             }
@@ -382,4 +388,31 @@ public class StoreStatusFilter {
         }
         return sortByStr;
     }
+
+    public static void filterJobsUsingText(Map<String, List<String>> filter, 
StringBuilder sb, boolean isEnabled,
+           String seletStr, List<Object> valArray, List<String> orArray, 
List<String> colArray) throws JPAExecutorException {
+        List<String> values = filter.get(OozieClient.FILTER_TEXT);
+        if (values.size() != 1) {
+            throw new JPAExecutorException(ErrorCode.E0302,
+                    "cannot specify multiple strings to search");
+        }
+        if (!isEnabled) {
+            sb.append(seletStr).append(" where " + textFilterStr);
+        }
+        else {
+            sb.append(" and " + textFilterStr);
+        }
+
+        valArray.add("%" + values.get(0) + "%");
+        orArray.add("appName");
+        colArray.add("text1");
+
+        valArray.add("%" + values.get(0) + "%");
+        orArray.add("user");
+        colArray.add("text2");
+
+        valArray.add(values.get(0));
+        orArray.add("id");
+        colArray.add("text3");
+    }
 }

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/main/java/org/apache/oozie/util/JobsFilterUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/util/JobsFilterUtils.java 
b/core/src/main/java/org/apache/oozie/util/JobsFilterUtils.java
index 18df836..85bfe4b 100644
--- a/core/src/main/java/org/apache/oozie/util/JobsFilterUtils.java
+++ b/core/src/main/java/org/apache/oozie/util/JobsFilterUtils.java
@@ -46,6 +46,7 @@ public class JobsFilterUtils {
         FILTER_NAMES.add(OozieClient.FILTER_SORT_BY);
         FILTER_NAMES.add(OozieClient.FILTER_CREATED_TIME_START);
         FILTER_NAMES.add(OozieClient.FILTER_CREATED_TIME_END);
+        FILTER_NAMES.add(OozieClient.FILTER_TEXT);
     }
 
     public static Map<String, List<String>> parseFilter(String filter) throws 
ServletException{

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleJobInfoGetJPAExecutor.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleJobInfoGetJPAExecutor.java
 
b/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleJobInfoGetJPAExecutor.java
index 0b1f644..e0851f5 100644
--- 
a/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleJobInfoGetJPAExecutor.java
+++ 
b/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleJobInfoGetJPAExecutor.java
@@ -28,6 +28,8 @@ import java.util.Map;
 import org.apache.oozie.BundleJobBean;
 import org.apache.oozie.BundleJobInfo;
 import org.apache.oozie.client.BundleJob;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.XException;
 import org.apache.oozie.client.Job;
 import org.apache.oozie.client.OozieClient;
 import org.apache.oozie.service.JPAService;
@@ -146,6 +148,98 @@ public class TestBundleJobInfoGetJPAExecutor extends 
XDataTestCase {
         assertEquals(2, ret.getBundleJobs().size());
     }
 
+    public void testGetJobInfoForText() throws Exception {
+        BundleJobBean bundleJob1 = 
addRecordToBundleJobTable(BundleJob.Status.RUNNING, false);
+        BundleJobBean bundleJob2 = 
addRecordToBundleJobTable(BundleJob.Status.KILLED, false);
+
+        bundleJob1.setAppName("oozie-bundle1");
+        bundleJob2.setAppName("oozie-bundle2");
+
+        
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB,
 bundleJob1);
+        
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB,
 bundleJob2);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+        Map<String, List<String>> filter = new HashMap<String, List<String>>();
+        BundleJobInfoGetJPAExecutor bundleInfoGetCmd = new 
BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        BundleJobInfo ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(2, ret.getBundleJobs().size());
+        filter.clear();
+
+        ArrayList<String> textList = new ArrayList<String>();
+        textList.add("tes");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getBundleJobs().size(), 2);
+
+        textList.clear();
+        textList.add("oozie-bundle1");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getBundleJobs().size(), 1);
+
+        textList.clear();
+        textList.add("random");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getBundleJobs().size(), 0);
+
+        textList.clear();
+        textList.add("oozie-bundle");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getBundleJobs().size(), 2);
+
+        textList.add("tes");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        try{
+            jpaService.execute(bundleInfoGetCmd);
+            fail("BundleJobInfoGetJPAExecutor should have thrown E0302 
exception.");
+        } catch (XException e) {
+            assertEquals(ErrorCode.E0302, e.getErrorCode());
+            assertEquals(e.getMessage(), "E0302: Invalid parameter [cannot 
specify multiple strings to search]");
+        }
+
+        // Update bundle appName, user and validate text filter
+        bundleJob1.setAppName("updated-app-name1");
+        bundleJob2.setAppName("updated-app-name2");
+        
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB,
 bundleJob1);
+        
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB,
 bundleJob2);
+
+        textList.clear();
+        textList.add("oozie-bundle");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getBundleJobs().size(), 0);
+
+        textList.clear();
+        textList.add("updated-app");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getBundleJobs().size(), 2);
+
+        textList.clear();
+        textList.add("updated-app-name1");
+        bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(bundleInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getBundleJobs().size(), 1);
+    }
+
     private void _testGetJobInfoForGroup() throws Exception {
         JPAService jpaService = Services.get().get(JPAService.class);
         assertNotNull(jpaService);

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobInfoGetJPAExecutor.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobInfoGetJPAExecutor.java
 
b/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobInfoGetJPAExecutor.java
index 7d468f1..a8d4d5b 100644
--- 
a/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobInfoGetJPAExecutor.java
+++ 
b/core/src/test/java/org/apache/oozie/executor/jpa/TestCoordJobInfoGetJPAExecutor.java
@@ -27,7 +27,7 @@ import java.util.Map;
 
 import org.apache.oozie.CoordinatorJobBean;
 import org.apache.oozie.CoordinatorJobInfo;
-import org.apache.oozie.ErrorCode;
+import org.apache.oozie.XException;
 import org.apache.oozie.client.CoordinatorJob;
 import org.apache.oozie.client.OozieClient;
 import org.apache.oozie.service.JPAService;
@@ -35,6 +35,7 @@ import org.apache.oozie.service.Services;
 import org.apache.oozie.store.StoreStatusFilter;
 import org.apache.oozie.test.XDataTestCase;
 import org.apache.oozie.util.DateUtils;
+import org.apache.oozie.ErrorCode;
 
 public class TestCoordJobInfoGetJPAExecutor extends XDataTestCase {
     Services services;
@@ -231,6 +232,98 @@ public class TestCoordJobInfoGetJPAExecutor extends 
XDataTestCase {
         assertEquals(ret.getCoordJobs().size(), 2);
     }
 
+    public void testGetJobInfoForText() throws Exception {
+        CoordinatorJobBean coordinatorJob1 = 
addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+        CoordinatorJobBean coordinatorJob2 = 
addRecordToCoordJobTable(CoordinatorJob.Status.KILLED, false, false);
+
+        coordinatorJob1.setAppName("oozie-coord1");
+        coordinatorJob2.setAppName("oozie-coord2");
+
+        
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB,
 coordinatorJob1);
+        
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB,
 coordinatorJob2);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+        Map<String, List<String>> filter = new HashMap<String, List<String>>();
+        CoordJobInfoGetJPAExecutor coordInfoGetCmd = new 
CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        CoordinatorJobInfo ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(2, ret.getCoordJobs().size());
+        filter.clear();
+
+        ArrayList<String> textList = new ArrayList<String>();
+        textList.add("tes");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getCoordJobs().size(), 2);
+
+        textList.clear();
+        textList.add("oozie-coord1");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getCoordJobs().size(), 1);
+
+        textList.clear();
+        textList.add("random");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getCoordJobs().size(), 0);
+
+        textList.clear();
+        textList.add("oozie-coord");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getCoordJobs().size(), 2);
+
+        textList.add("tes");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        try{
+            jpaService.execute(coordInfoGetCmd);
+            fail("CoordJobInfoGetJPAExecutor should have thrown E0302 
exception.");
+        } catch (XException e) {
+            assertEquals(ErrorCode.E0302, e.getErrorCode());
+            assertEquals(e.getMessage(), "E0302: Invalid parameter [cannot 
specify multiple strings to search]");
+        }
+
+        // Update coord appName and validate text filter
+        coordinatorJob1.setAppName("updated-app-name1");
+        coordinatorJob2.setAppName("updated-app-name2");
+        
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB,
 coordinatorJob1);
+        
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB,
 coordinatorJob2);
+
+        textList.clear();
+        textList.add("oozie-coord");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getCoordJobs().size(), 0);
+
+        textList.clear();
+        textList.add("updated-app");
+        filter.put(OozieClient.FILTER_TEXT, textList);
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getCoordJobs().size(), 2);
+
+        textList.clear();
+        textList.add("updated-app-name1");
+        coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
+        ret = jpaService.execute(coordInfoGetCmd);
+        assertNotNull(ret);
+        assertEquals(ret.getCoordJobs().size(), 1);
+    }
+
     private void _testGetJobInfoForFrequency() throws Exception {
         JPAService jpaService = Services.get().get(JPAService.class);
         assertNotNull(jpaService);

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/core/src/test/java/org/apache/oozie/executor/jpa/TestWorkflowsJobGetJPAExecutor.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/oozie/executor/jpa/TestWorkflowsJobGetJPAExecutor.java
 
b/core/src/test/java/org/apache/oozie/executor/jpa/TestWorkflowsJobGetJPAExecutor.java
index ddb5506..398678b 100644
--- 
a/core/src/test/java/org/apache/oozie/executor/jpa/TestWorkflowsJobGetJPAExecutor.java
+++ 
b/core/src/test/java/org/apache/oozie/executor/jpa/TestWorkflowsJobGetJPAExecutor.java
@@ -32,10 +32,14 @@ import org.apache.oozie.client.OozieClient;
 import org.apache.oozie.client.WorkflowJob;
 import org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery;
 import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.LiteWorkflowStoreService;
 import org.apache.oozie.service.Services;
 import org.apache.oozie.test.XDataTestCase;
 import org.apache.oozie.util.DateUtils;
+import org.apache.oozie.workflow.WorkflowApp;
 import org.apache.oozie.workflow.WorkflowInstance;
+import org.apache.oozie.workflow.lite.LiteWorkflowApp;
+import org.apache.oozie.workflow.lite.StartNodeDef;
 
 public class TestWorkflowsJobGetJPAExecutor extends XDataTestCase {
     Services services;
@@ -148,6 +152,75 @@ public class TestWorkflowsJobGetJPAExecutor extends 
XDataTestCase {
         compareWf(workflowJob1, retBean);
     }
 
+    public void testGetWFInfoForText() throws Exception {
+        WorkflowJobBean workflowJob1 = 
addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowJobBean workflowJob2 = 
addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        workflowJob1.setAppName("wf-name-1");
+        workflowJob2.setAppName("wf-name-2");
+
+        
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW,
 workflowJob1);
+        
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW,
 workflowJob2);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+        Map<String, List<String>> filter = new HashMap<String, List<String>>();
+        List<String> list = new ArrayList<String>();
+        WorkflowsJobGetJPAExecutor wfGetCmd = new 
WorkflowsJobGetJPAExecutor(filter, 1, 20);
+        WorkflowsInfo wfInfo = jpaService.execute(wfGetCmd);
+        assertNotNull(wfInfo);
+        assertEquals(2, wfInfo.getWorkflows().size());
+        WorkflowJobBean retBean = wfInfo.getWorkflows().get(0);
+        compareWf(workflowJob2, retBean);
+
+        list.add("wf-name");
+        filter.put(OozieClient.FILTER_TEXT, list);
+        wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
+        wfInfo = jpaService.execute(wfGetCmd);
+        assertNotNull(wfInfo);
+        assertEquals(2, wfInfo.getWorkflows().size());
+
+        list.clear();
+        list.add("wf-name-1");
+        filter.put(OozieClient.FILTER_TEXT, list);
+        wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
+        wfInfo = jpaService.execute(wfGetCmd);
+        assertNotNull(wfInfo);
+        assertEquals(1, wfInfo.getWorkflows().size());
+
+        list.add("extra-param");
+        filter.put(OozieClient.FILTER_TEXT, list);
+        wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 2);
+        try{
+            jpaService.execute(wfGetCmd);
+            fail("WorkflowsJobGetJPAExecutor should have thrown E0302 
exception.");
+        } catch (XException e) {
+            assertEquals(ErrorCode.E0302, e.getErrorCode());
+            assertEquals(e.getMessage(), "E0302: Invalid parameter [cannot 
specify multiple strings to search]");
+        }
+
+        workflowJob1.setAppName("updated-name-1");
+        workflowJob2.setAppName("updated-name-2");
+
+        
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW,
 workflowJob1);
+        
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW,
 workflowJob2);
+
+        list.clear();
+        list.add("wf-name-1");
+        filter.put(OozieClient.FILTER_TEXT, list);
+        wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
+        wfInfo = jpaService.execute(wfGetCmd);
+        assertNotNull(wfInfo);
+        assertEquals(0, wfInfo.getWorkflows().size());
+
+        list.clear();
+        list.add("updated-name");
+        filter.put(OozieClient.FILTER_TEXT, list);
+        wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
+        wfInfo = jpaService.execute(wfGetCmd);
+        assertNotNull(wfInfo);
+        assertEquals(2, wfInfo.getWorkflows().size());
+    }
+
     public void testWfJobsGetWithCreatedTime() throws Exception {
         JPAService jpaService = Services.get().get(JPAService.class);
         Date createdTime1 = DateUtils.parseDateUTC("2012-01-01T10:00Z");

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/docs/src/site/twiki/DG_CommandLineTool.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/DG_CommandLineTool.twiki 
b/docs/src/site/twiki/DG_CommandLineTool.twiki
index e7b165c..35eee40 100644
--- a/docs/src/site/twiki/DG_CommandLineTool.twiki
+++ b/docs/src/site/twiki/DG_CommandLineTool.twiki
@@ -1001,6 +1001,7 @@ The =filter=option syntax is: 
<code>[NAME=VALUE][;NAME=VALUE]*</code>.
 
 Valid filter names are:
 
+   * text: any text that might be a part of application name or a part of user 
name or a complete job ID
    * name: the workflow application name from the workflow definition.
    * user: the user that submitted the job.
    * group: the group for the job.

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/docs/src/site/twiki/WebServicesAPI.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/WebServicesAPI.twiki 
b/docs/src/site/twiki/WebServicesAPI.twiki
index 13e1691..b76e934 100644
--- a/docs/src/site/twiki/WebServicesAPI.twiki
+++ b/docs/src/site/twiki/WebServicesAPI.twiki
@@ -1657,6 +1657,7 @@ The syntax for the filter is 
<verbatim>[NAME=VALUE][;NAME=VALUE]*</verbatim>
 
 Valid filter names are:
 
+   * text: any text that might be a part of application name or a part of user 
name or a complete job ID
    * name: the application name from the workflow/coordinator/bundle definition
    * user: the user who submitted the job
    * group: the group for the job (support for the group filter is 
discontinued. version: 3.2.0 OOZIE-228).

http://git-wip-us.apache.org/repos/asf/oozie/blob/71ff6cea/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 8cb548e..a8292a5 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 4.4.0 release (trunk - unreleased)
 
+OOZIE-2225 Add wild card filter for gathering jobs (sai-krish via rkanter)
 OOZIE-2536 Hadoop's cleanup of local directory in uber mode causing failures 
(satishsaley via rohini)
 OOZIE-1986 Add FindBugs report to pre-commit build (andras.piros via rkanter)
 OOZIE-2634 Queue dump command message is confusing when the queue is empty 
(andras.piros via rkanter)

Reply via email to