Author: kamrul
Date: Tue Nov 13 20:31:51 2012
New Revision: 1408942
URL: http://svn.apache.org/viewvc?rev=1408942&view=rev
Log:
OOZIE-1061 Add new EL functions to retrieve HCatalog server, DB and table
name(mohammad)
Modified:
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/util/HCatURI.java
oozie/branches/hcat-intre/core/src/main/resources/oozie-default.xml
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/util/TestHCatURI.java
Modified:
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
URL:
http://svn.apache.org/viewvc/oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java?rev=1408942&r1=1408941&r2=1408942&view=diff
==============================================================================
---
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
(original)
+++
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
Tue Nov 13 20:31:51 2012
@@ -18,6 +18,7 @@
package org.apache.oozie.coord;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -30,6 +31,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.oozie.client.OozieClient;
import org.apache.oozie.util.DateUtils;
import org.apache.oozie.util.ELEvaluator;
+import org.apache.oozie.util.HCatURI;
import org.apache.oozie.util.ParamChecker;
import org.apache.oozie.util.XLog;
import org.apache.oozie.service.HadoopAccessorException;
@@ -379,6 +381,99 @@ public class CoordELFunctions {
}
/**
+ * Extract the hcat server name from the URI-template associate with
+ * 'dataInName'. Caller needs to specify the EL-evaluator level variable
+ * 'oozie.coord.el.dataset.bean' with synchronous dataset object
+ * (SyncCoordDataset)
+ *
+ * @param dataInName
+ * @return server name
+ */
+ public static String ph3_coord_metaServer(String dataInName) {
+ HCatURI hcatURI = getURI(dataInName);
+ if (hcatURI != null) {
+ return hcatURI.getServer();
+ }
+ else {
+ return "";
+ }
+ }
+
+ /**
+ * Extract the hcat DB name from the URI-template associate with
+ * 'dataInName'. Caller needs to specify the EL-evaluator level variable
+ * 'oozie.coord.el.dataset.bean' with synchronous dataset object
+ * (SyncCoordDataset)
+ *
+ * @param dataInName
+ * @return DB name
+ */
+ public static String ph3_coord_metaDb(String dataInName) {
+ HCatURI hcatURI = getURI(dataInName);
+ if (hcatURI != null) {
+ return hcatURI.getDb();
+ }
+ else {
+ return "";
+ }
+ }
+
+ /**
+ * Extract the hcat Table name from the URI-template associate with
+ * 'dataInName'. Caller needs to specify the EL-evaluator level variable
+ * 'oozie.coord.el.dataset.bean' with synchronous dataset object
+ * (SyncCoordDataset)
+ *
+ * @param dataInName
+ * @return Table name
+ */
+ public static String ph3_coord_metaTable(String dataInName) {
+ HCatURI hcatURI = getURI(dataInName);
+ if (hcatURI != null) {
+ return hcatURI.getTable();
+ }
+ else {
+ return "";
+ }
+ }
+
+ private static HCatURI getURI(String dataInName) {
+ StringBuilder uriTemplate = new StringBuilder();
+ ELEvaluator eval = ELEvaluator.getCurrent();
+ String uris = (String) eval.getVariable(".datain." + dataInName);
+ if (uris != null) {
+ String[] uri = uris.split(CoordELFunctions.DIR_SEPARATOR, -1);
+ if (uri.length == 0) {
+ XLog.getLog(CoordELFunctions.class).warn("URI is empty");
+ return null;
+ }
+ else {
+ uriTemplate.append(uri[0]);
+ }
+ }
+ else {
+ XLog.getLog(CoordELFunctions.class).warn("URI is NULL");
+ return null;
+ }
+ XLog.getLog(CoordELFunctions.class).info("uriTemplate [{0}] ",
uriTemplate);
+ if (HCatURI.isHcatURI(uriTemplate.toString())) {
+ HCatURI hcatURI;
+ try {
+ hcatURI = new HCatURI(uriTemplate.toString());
+ }
+ catch (URISyntaxException e) {
+ XLog.getLog(CoordELFunctions.class).info("uriTemplate [{0}].
Reason [{1}]: ", uriTemplate, e);
+ throw new RuntimeException("HCat URI can't be parsed " + e);
+ }
+ return hcatURI;
+ }
+ else {
+ XLog.getLog(CoordELFunctions.class).error("Not a HCat URI
template: " + uriTemplate);
+ throw new RuntimeException("Not a HCat URI template: " +
uriTemplate);
+ }
+ }
+
+ /**
* Used to specify a list of URI's that are used as input dir to the
workflow job. <p/> Look for two evaluator-level
* variables <p/> A) .datain.<DATAIN_NAME> B)
.datain.<DATAIN_NAME>.unresolved <p/> A defines the current list of
* URI. <p/> B defines whether there are any unresolved EL-function (i.e
latest) <p/> If there are something
@@ -618,6 +713,52 @@ public class CoordELFunctions {
return ph1_coord_future_echo(n, instance);
}
+ /**
+ * Echo the same EL function without evaluating anything
+ *
+ * @param dataInName
+ * @return the same EL function
+ */
+ public static String ph1_coord_metaServer_echo(String dataInName) {
+ // Checking if the dataIn/dataOut is correct?
+ isValidDataIn(dataInName);
+ return echoUnResolved("metaServer", "'" + dataInName + "'");
+ }
+
+ /**
+ * Echo the same EL function without evaluating anything
+ *
+ * @param dataInName
+ * @return the same EL function
+ */
+ public static String ph1_coord_metaDb_echo(String dataInName) {
+ // Checking if the dataIn/dataOut is correct?
+ isValidDataIn(dataInName);
+ return echoUnResolved("metaDb", "'" + dataInName + "'");
+ }
+
+ /**
+ * Echo the same EL function without evaluating anything
+ *
+ * @param dataInName
+ * @return the same EL function
+ */
+ public static String ph1_coord_metaTable_echo(String dataInName) {
+ // Checking if the dataIn/dataOut is correct?
+ isValidDataIn(dataInName);
+ return echoUnResolved("metaTable", "'" + dataInName + "'");
+ }
+
+ private static boolean isValidDataIn(String dataInName) {
+ ELEvaluator eval = ELEvaluator.getCurrent();
+ String val = (String) eval.getVariable("oozie.dataname." + dataInName);
+ if (val == null || (val.equals("data-in") == false &&
val.equals("data-out") == false)) {
+ XLog.getLog(CoordELFunctions.class).error("dataset name " +
dataInName + " is not valid. val :" + val);
+ throw new RuntimeException("data set name " + dataInName + " is
not valid");
+ }
+ return true;
+ }
+
public static String ph1_coord_dataIn_echo(String n) {
ELEvaluator eval = ELEvaluator.getCurrent();
String val = (String) eval.getVariable("oozie.dataname." + n);
Modified:
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/util/HCatURI.java
URL:
http://svn.apache.org/viewvc/oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/util/HCatURI.java?rev=1408942&r1=1408941&r2=1408942&view=diff
==============================================================================
---
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/util/HCatURI.java
(original)
+++
oozie/branches/hcat-intre/core/src/main/java/org/apache/oozie/util/HCatURI.java
Tue Nov 13 20:31:51 2012
@@ -239,6 +239,21 @@ public class HCatURI {
return sb.toString();
}
+ /**
+ * Determine if any URI is Hcatalog specific URI
+ *
+ * @param hcatURI
+ * @return true if hcatalog URI otherwise false
+ */
+ public static boolean isHcatURI(String hcatURI) {
+ if (hcatURI != null && hcatURI.startsWith("hcat://")) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
@Override
public boolean equals(Object obj) {
HCatURI uri = (HCatURI) obj;
Modified: oozie/branches/hcat-intre/core/src/main/resources/oozie-default.xml
URL:
http://svn.apache.org/viewvc/oozie/branches/hcat-intre/core/src/main/resources/oozie-default.xml?rev=1408942&r1=1408941&r2=1408942&view=diff
==============================================================================
--- oozie/branches/hcat-intre/core/src/main/resources/oozie-default.xml
(original)
+++ oozie/branches/hcat-intre/core/src/main/resources/oozie-default.xml Tue Nov
13 20:31:51 2012
@@ -8,9 +8,9 @@
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -752,7 +752,10 @@
coord:actionId=org.apache.oozie.coord.CoordELFunctions#ph1_coord_actionId_echo,
coord:name=org.apache.oozie.coord.CoordELFunctions#ph1_coord_name_echo,
coord:conf=org.apache.oozie.coord.CoordELFunctions#coord_conf,
- coord:user=org.apache.oozie.coord.CoordELFunctions#coord_user
+ coord:user=org.apache.oozie.coord.CoordELFunctions#coord_user,
+
coord:metaServer=org.apache.oozie.coord.CoordELFunctions#ph1_coord_metaServer_echo,
+
coord:metaDb=org.apache.oozie.coord.CoordELFunctions#ph1_coord_metaDb_echo,
+
coord:metaTable=org.apache.oozie.coord.CoordELFunctions#ph1_coord_metaTable_echo
</value>
<description>
EL functions declarations, separated by commas, format is
[PREFIX:]NAME=CLASS#METHOD.
@@ -999,7 +1002,10 @@
coord:actionId=org.apache.oozie.coord.CoordELFunctions#ph3_coord_actionId,
coord:name=org.apache.oozie.coord.CoordELFunctions#ph3_coord_name,
coord:conf=org.apache.oozie.coord.CoordELFunctions#coord_conf,
- coord:user=org.apache.oozie.coord.CoordELFunctions#coord_user
+ coord:user=org.apache.oozie.coord.CoordELFunctions#coord_user,
+
coord:metaServer=org.apache.oozie.coord.CoordELFunctions#ph3_coord_metaServer,
+
coord:metaDb=org.apache.oozie.coord.CoordELFunctions#ph3_coord_metaDb,
+
coord:metaTable=org.apache.oozie.coord.CoordELFunctions#ph3_coord_metaTable
</value>
<description>
EL functions declarations, separated by commas, format is
[PREFIX:]NAME=CLASS#METHOD.
Modified:
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
URL:
http://svn.apache.org/viewvc/oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java?rev=1408942&r1=1408941&r2=1408942&view=diff
==============================================================================
---
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
(original)
+++
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
Tue Nov 13 20:31:51 2012
@@ -148,6 +148,69 @@ public class TestCoordELFunctions extend
assertEquals("${coord:current(-3)}",
CoordELFunctions.evalAndWrap(eval, expr));
}
+ /**
+ * Test metaServer EL function (phase 1) which echo back the EL function
itself
+ *
+ * @throws Exception
+ */
+ public void testMetaServerPh1() throws Exception {
+ init("coord-job-submit-data");
+ String expr = "${coord:metaServer('ABC')}";
+ // +ve test
+ eval.setVariable("oozie.dataname.ABC", "data-in");
+ assertEquals("${coord:metaServer('ABC')}",
CoordELFunctions.evalAndWrap(eval, expr));
+ // -ve test
+ expr = "${coord:metaServer('ABCD')}";
+ try {
+ assertEquals("${coord:metaServer('ABCD')}",
CoordELFunctions.evalAndWrap(eval, expr));
+ fail("should throw exception beacuse Data in is not defiend");
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ /**
+ * Test metaDB EL function (phase 1) which echo back the EL function itself
+ *
+ * @throws Exception
+ */
+ public void testMetaDbPh1() throws Exception {
+ init("coord-job-submit-data");
+ String expr = "${coord:metaDb('ABC')}";
+ // +ve test
+ eval.setVariable("oozie.dataname.ABC", "data-in");
+ assertEquals("${coord:metaDb('ABC')}",
CoordELFunctions.evalAndWrap(eval, expr));
+ // -ve test
+ expr = "${coord:metaDb('ABCD')}";
+ try {
+ assertEquals("${coord:metaDb('ABCD')}",
CoordELFunctions.evalAndWrap(eval, expr));
+ fail("should throw exception beacuse Data in is not defiend");
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ /**
+ * Test metaDB EL function (phase 1) which echo back the EL function itself
+ *
+ * @throws Exception
+ */
+ public void testMetaTablePh1() throws Exception {
+ init("coord-job-submit-data");
+ String expr = "${coord:metaTable('ABC')}";
+ // +ve test
+ eval.setVariable("oozie.dataname.ABC", "data-in");
+ assertEquals("${coord:metaTable('ABC')}",
CoordELFunctions.evalAndWrap(eval, expr));
+ // -ve test
+ expr = "${coord:metaTable('ABCD')}";
+ try {
+ assertEquals("${coord:metaTable('ABCD')}",
CoordELFunctions.evalAndWrap(eval, expr));
+ fail("should throw exception beacuse Data in is not defiend");
+ }
+ catch (Exception ex) {
+ }
+ }
+
public void testDataNamesPh1() throws Exception {
init("coord-job-submit-data");
String expr = "${coord:dataIn('ABC')}";
@@ -375,16 +438,16 @@ public class TestCoordELFunctions extend
ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-02T00:00Z"));
ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles"));
expr = "${coord:current(0)} ${coord:current(1)} ${coord:current(-1)}
${coord:current(-3)}";
- assertEquals("2009-05-29T23:00Z 2009-05-30T23:00Z 2009-05-28T23:00Z
2009-05-26T23:00Z", CoordELFunctions
- .evalAndWrap(eval, expr));
+ assertEquals("2009-05-29T23:00Z 2009-05-30T23:00Z 2009-05-28T23:00Z
2009-05-26T23:00Z",
+ CoordELFunctions.evalAndWrap(eval, expr));
appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-05-30T00:45Z"));
ds.setFrequency(30);
ds.setTimeUnit(TimeUnit.MINUTE);
ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-08T00:00Z"));
expr = "${coord:current(0)} ${coord:current(1)} ${coord:current(-1)}
${coord:current(-3)}";
- assertEquals("2009-05-30T00:30Z 2009-05-30T01:00Z 2009-05-30T00:00Z
2009-05-29T23:00Z", eval.evaluate(expr,
-
String.class));
+ assertEquals("2009-05-30T00:30Z 2009-05-30T01:00Z 2009-05-30T00:00Z
2009-05-29T23:00Z",
+ eval.evaluate(expr, String.class));
SyncCoordAction appInst = new SyncCoordAction();
SyncCoordDataset ds = new SyncCoordDataset();
@@ -437,7 +500,7 @@ public class TestCoordELFunctions extend
ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles"));
expr = "${coord:current(-2)} ${coord:current(-1)} ${coord:current(0)}
${coord:current(1)} ${coord:current(2)}";
assertEquals("2009-03-06T10:00Z 2009-03-07T10:00Z 2009-03-08T09:00Z
2009-03-09T09:00Z 2009-03-10T09:00Z",
- CoordELFunctions.evalAndWrap(eval, expr));
+ CoordELFunctions.evalAndWrap(eval, expr));
// Winter DST Transition
appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-11-01T08:00Z"));
@@ -450,7 +513,7 @@ public class TestCoordELFunctions extend
// System.out.println("AAAAA " + CoordELFunctions.evalAndWrap(eval,
// expr));
assertEquals("2009-10-30T08:00Z 2009-10-31T08:00Z 2009-11-01T08:00Z
2009-11-02T09:00Z 2009-11-03T09:00Z",
- CoordELFunctions.evalAndWrap(eval, expr));
+ CoordELFunctions.evalAndWrap(eval, expr));
// EndofDay testing
ds.setFrequency(1);
@@ -699,23 +762,32 @@ public class TestCoordELFunctions extend
// Year
expr = "${coord:offset(0, \"YEAR\")} ${coord:offset(1, \"YEAR\")}
${coord:offset(-1, \"YEAR\")}"
+ " ${coord:offset(-3, \"YEAR\")}";
- assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z", eval.evaluate(expr, String.class));
+ assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z",
+ eval.evaluate(expr, String.class));
// Month
expr = "${coord:offset(0, \"MONTH\")} ${coord:offset(12, \"MONTH\")}
${coord:offset(-12, \"MONTH\")}"
+ " ${coord:offset(-36, \"MONTH\")}";
- assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z", eval.evaluate(expr, String.class));
+ assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z",
+ eval.evaluate(expr, String.class));
// Day
+ // its -1096 instead of -1095 because of DST (extra 1 day)
expr = "${coord:offset(0, \"DAY\")} ${coord:offset(365, \"DAY\")}
${coord:offset(-365, \"DAY\")}"
- + " ${coord:offset(-1096, \"DAY\")}"; // its -1096 instead
of -1095 because of DST (extra 1 day)
- assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z", eval.evaluate(expr, String.class));
+ + " ${coord:offset(-1096, \"DAY\")}";
+ assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z",
+ eval.evaluate(expr, String.class));
// Hour
+ // its -26304 instead of -26280 because of DST (extra 24 hours)
expr = "${coord:offset(0, \"HOUR\")} ${coord:offset(8760, \"HOUR\")}
${coord:offset(-8760, \"HOUR\")}"
- + " ${coord:offset(-26304, \"HOUR\")}"; // its -26304 instead
of -26280 because of DST (extra 24 hours)
- assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z", eval.evaluate(expr, String.class));
+ + " ${coord:offset(-26304, \"HOUR\")}";
+
+ assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z",
+ eval.evaluate(expr, String.class));
// Minute
+ // its -1578240 instead of -1576800 because of DST (extra 1440 minutes)
expr = "${coord:offset(0, \"MINUTE\")} ${coord:offset(525600,
\"MINUTE\")} ${coord:offset(-525600, \"MINUTE\")}"
- + " ${coord:offset(-1578240, \"MINUTE\")}"; // its -1578240
instead of -1576800 because of DST (extra 1440 minutes)
- assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z", eval.evaluate(expr, String.class));
+ + " ${coord:offset(-1578240, \"MINUTE\")}";
+ assertEquals("2015-01-02T00:01Z 2016-01-02T00:01Z 2014-01-02T00:01Z
2012-01-02T00:01Z",
+ eval.evaluate(expr, String.class));
appInst.setNominalTime(DateUtils.parseDateOozieTZ("2015-01-02T00:45Z"));
ds.setFrequency(1);
@@ -725,25 +797,31 @@ public class TestCoordELFunctions extend
// Minute
expr = "${coord:offset(0, \"MINUTE\")} ${coord:offset(1, \"MINUTE\")}
${coord:offset(-1, \"MINUTE\")}"
+ " ${coord:offset(-3, \"MINUTE\")}";
- assertEquals("2015-01-02T00:45Z 2015-01-02T00:46Z 2015-01-02T00:44Z
2015-01-02T00:42Z", eval.evaluate(expr, String.class));
+ assertEquals("2015-01-02T00:45Z 2015-01-02T00:46Z 2015-01-02T00:44Z
2015-01-02T00:42Z",
+ eval.evaluate(expr, String.class));
// Hour
expr = "${coord:offset(0, \"HOUR\")} ${coord:offset(1, \"HOUR\")}
${coord:offset(-1, \"HOUR\")}"
+ " ${coord:offset(-3, \"HOUR\")}";
- assertEquals("2015-01-02T00:45Z 2015-01-02T01:45Z 2015-01-01T23:45Z
2015-01-01T21:45Z", eval.evaluate(expr, String.class));
+ assertEquals("2015-01-02T00:45Z 2015-01-02T01:45Z 2015-01-01T23:45Z
2015-01-01T21:45Z",
+ eval.evaluate(expr, String.class));
// Day
expr = "${coord:offset(0, \"DAY\")} ${coord:offset(1, \"DAY\")}
${coord:offset(-1, \"DAY\")}"
+ " ${coord:offset(-3, \"DAY\")}";
- assertEquals("2015-01-02T00:45Z 2015-01-03T00:45Z 2015-01-01T00:45Z
2014-12-30T00:45Z", eval.evaluate(expr, String.class));
+ assertEquals("2015-01-02T00:45Z 2015-01-03T00:45Z 2015-01-01T00:45Z
2014-12-30T00:45Z",
+ eval.evaluate(expr, String.class));
// Month
expr = "${coord:offset(0, \"MONTH\")} ${coord:offset(1, \"MONTH\")}
${coord:offset(-1, \"MONTH\")}"
+ " ${coord:offset(-3, \"MONTH\")}";
- assertEquals("2015-01-02T00:45Z 2015-02-02T00:45Z 2014-12-02T00:45Z
2014-10-01T23:45Z", eval.evaluate(expr, String.class));
+ assertEquals("2015-01-02T00:45Z 2015-02-02T00:45Z 2014-12-02T00:45Z
2014-10-01T23:45Z",
+ eval.evaluate(expr, String.class));
// Year
expr = "${coord:offset(0, \"YEAR\")} ${coord:offset(1, \"YEAR\")}
${coord:offset(-1, \"YEAR\")}"
+ " ${coord:offset(-3, \"YEAR\")}";
- assertEquals("2015-01-02T00:45Z 2016-01-02T00:45Z 2014-01-02T00:45Z
2012-01-02T00:45Z", eval.evaluate(expr, String.class));
+ assertEquals("2015-01-02T00:45Z 2016-01-02T00:45Z 2014-01-02T00:45Z
2012-01-02T00:45Z",
+ eval.evaluate(expr, String.class));
- // Test rewinding when the given offset isn't a multiple of the
frequency
+ // Test rewinding when the given offset isn't a multiple of the
+ // frequency
appInst.setNominalTime(DateUtils.parseDateOozieTZ("2015-01-02T00:45Z"));
ds.setFrequency(4);
ds.setTimeUnit(TimeUnit.HOUR);
@@ -765,7 +843,8 @@ public class TestCoordELFunctions extend
try {
CoordELFunctions.evalAndWrap(eval, expr);
fail("eval of " + expr + " should have thrown an exception");
- } catch(Exception e) {
+ }
+ catch (Exception e) {
assertTrue(e.getMessage().contains("Unable to evaluate"));
}
@@ -774,7 +853,8 @@ public class TestCoordELFunctions extend
try {
CoordELFunctions.evalAndWrap(eval, expr);
fail("eval of " + expr + " should have thrown an exception");
- } catch(Exception e) {
+ }
+ catch (Exception e) {
assertTrue(e.getMessage().contains("Unable to evaluate"));
}
}
@@ -886,13 +966,52 @@ public class TestCoordELFunctions extend
assertEquals("2009-09-10T23:59Z", CoordELFunctions.evalAndWrap(eval,
expr));
}
+ /**
+ * Test metaServer EL function (phase 3) which returns the HCat server
from URI
+ *
+ * @throws Exception
+ */
+ public void testMetaServer() throws Exception {
+ init("coord-action-start",
"hcat://hcat.yahoo.com:5080/mydb/clicks/?datastamp=12®ion=us");
+ eval.setVariable(".datain.ABC",
"hcat://hcat.yahoo.com:5080/mydb/clicks/?datastamp=12®ion=us");
+ eval.setVariable(".datain.ABC.unresolved", Boolean.FALSE);
+ String expr = "${coord:metaServer('ABC')}";
+ assertEquals("hcat.yahoo.com:5080", CoordELFunctions.evalAndWrap(eval,
expr));
+ }
+
+ /**
+ * Test metaDb EL function (phase 3) which returns the DB name from URI
+ *
+ * @throws Exception
+ */
+ public void testMetaDb() throws Exception {
+ init("coord-action-start",
"hcat://hcat.yahoo.com:5080/mydb/clicks/?datastamp=12®ion=us");
+ eval.setVariable(".datain.ABC",
"hcat://hcat.yahoo.com:5080/mydb/clicks/?datastamp=12®ion=us");
+ eval.setVariable(".datain.ABC.unresolved", Boolean.FALSE);
+ String expr = "${coord:metaDb('ABC')}";
+ assertEquals("mydb", CoordELFunctions.evalAndWrap(eval, expr));
+ }
+
+ /**
+ * Test metaTable EL function (phase 3) which returns the HCat table from
URI
+ *
+ * @throws Exception
+ */
+ public void testMetaTable() throws Exception {
+ init("coord-action-start",
"hcat://hcat.yahoo.com:5080/mydb/clicks/?datastamp=12®ion=us");
+ eval.setVariable(".datain.ABC",
"hcat://hcat.yahoo.com:5080/mydb/clicks/?datastamp=12®ion=us");
+ eval.setVariable(".datain.ABC.unresolved", Boolean.FALSE);
+ String expr = "${coord:metaTable('ABC')}";
+ assertEquals("clicks", CoordELFunctions.evalAndWrap(eval, expr));
+ }
+
public void testDataIn() throws Exception {
init("coord-action-start");
eval.setVariable(".datain.ABC",
"file:///tmp/coord/US/2009/1/30,file:///tmp/coord/US/2009/1/31");
eval.setVariable(".datain.ABC.unresolved", Boolean.FALSE);
String expr = "${coord:dataIn('ABC')}";
-
assertEquals("file:///tmp/coord/US/2009/1/30,file:///tmp/coord/US/2009/1/31",
CoordELFunctions.evalAndWrap(
- eval, expr));
+
assertEquals("file:///tmp/coord/US/2009/1/30,file:///tmp/coord/US/2009/1/31",
+ CoordELFunctions.evalAndWrap(eval, expr));
eval.setVariable(".datain.ABC",
"file:///tmp/coord/US/2009/1/30,file:///tmp/coord/US/2009/1/31");
eval.setVariable(".datain.ABC.unresolved", Boolean.TRUE);
assertEquals(expr, CoordELFunctions.evalAndWrap(eval, expr));
@@ -902,8 +1021,8 @@ public class TestCoordELFunctions extend
init("coord-action-start");
eval.setVariable(".dataout.ABC",
"file:///tmp/coord/US/2009/1/30,file:///tmp/coord/US/2009/1/31");
String expr = "${coord:dataOut('ABC')}";
-
assertEquals("file:///tmp/coord/US/2009/1/30,file:///tmp/coord/US/2009/1/31",
CoordELFunctions.evalAndWrap(
- eval, expr));
+
assertEquals("file:///tmp/coord/US/2009/1/30,file:///tmp/coord/US/2009/1/31",
+ CoordELFunctions.evalAndWrap(eval, expr));
}
public void testActionId() throws Exception {
@@ -930,28 +1049,28 @@ public class TestCoordELFunctions extend
String expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-job-submit-instances");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-job-submit-data");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-sla-submit");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-action-create");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-action-create-inst");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-sla-create");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-action-start");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
init("coord-action-create-inst");
- expr = "${coord:user()}";
+ expr = "${coord:user()}";
assertEquals("test_user", CoordELFunctions.evalAndWrap(eval, expr));
}
@@ -960,6 +1079,10 @@ public class TestCoordELFunctions extend
*/
private void init(String tag) throws Exception {
+ init(tag, "hdfs://localhost:9000/user/" + getTestUser() +
"/US/${YEAR}/${MONTH}/${DAY}");
+ }
+
+ private void init(String tag, String uriTemplate) throws Exception {
eval = Services.get().get(ELService.class).createEvaluator(tag);
eval.setVariable(OozieClient.USER_NAME, "test_user");
eval.setVariable(OozieClient.GROUP_NAME, "test_group");
@@ -970,7 +1093,7 @@ public class TestCoordELFunctions extend
ds.setTimeUnit(TimeUnit.DAY);
ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles"));
ds.setName("test");
- ds.setUriTemplate("hdfs://localhost:9000/user/" + getTestUser() +
"/US/${YEAR}/${MONTH}/${DAY}");
+ ds.setUriTemplate(uriTemplate);
ds.setType("SYNC");
ds.setDoneFlag("");
appInst.setActualTime(DateUtils.parseDateOozieTZ("2009-09-10T23:59Z"));
Modified:
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/util/TestHCatURI.java
URL:
http://svn.apache.org/viewvc/oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/util/TestHCatURI.java?rev=1408942&r1=1408941&r2=1408942&view=diff
==============================================================================
---
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/util/TestHCatURI.java
(original)
+++
oozie/branches/hcat-intre/core/src/test/java/org/apache/oozie/util/TestHCatURI.java
Tue Nov 13 20:31:51 2012
@@ -232,4 +232,12 @@ public class TestHCatURI {
assertFalse(uri1.equals(uri5));
assertFalse(uri5.equals(uri1));
}
+
+ @Test
+ public void testIsHCatURI() {
+ String hcatURI =
"hcat://hcat.yahoo.com:5080/mydb/clicks/?region=us×tamp=1201";
+ assertTrue(HCatURI.isHcatURI(hcatURI)); // +ve test
+ hcatURI =
"hdfs://hcat.yahoo.com:5080/mydb/clicks/?region=us×tamp=1201";
+ assertFalse(HCatURI.isHcatURI(hcatURI)); // -ve test
+ }
}