Repository: oozie
Updated Branches:
  refs/heads/master a9b3c7bb4 -> ef3e88cb4


OOZIE-2171 Some error code messages are not parsed correctly due to unescaped 
single quote (rkanter)


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

Branch: refs/heads/master
Commit: ef3e88cb4ae4fdfc29d4170dc51bf31f0965bbdd
Parents: a9b3c7b
Author: Robert Kanter <rkan...@cloudera.com>
Authored: Tue Mar 17 10:52:42 2015 -0700
Committer: Robert Kanter <rkan...@cloudera.com>
Committed: Tue Mar 17 10:52:42 2015 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/oozie/ErrorCode.java   | 12 +++---
 .../java/org/apache/oozie/TestErrorCode.java    | 42 ++++++++++++++++++
 .../TestCoordActionInputCheckXCommand.java      |  2 +-
 .../service/TestHadoopAccessorService.java      | 45 ++++++++++++++++++++
 release-log.txt                                 |  1 +
 5 files changed, 95 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/ef3e88cb/core/src/main/java/org/apache/oozie/ErrorCode.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/ErrorCode.java 
b/core/src/main/java/org/apache/oozie/ErrorCode.java
index 8ee550a..4e9f62b 100644
--- a/core/src/main/java/org/apache/oozie/ErrorCode.java
+++ b/core/src/main/java/org/apache/oozie/ErrorCode.java
@@ -21,7 +21,7 @@ package org.apache.oozie;
 import org.apache.oozie.util.XLog;
 
 public enum ErrorCode {
-    E0000(XLog.STD, "System property 'oozie.home.dir' not defined"),
+    E0000(XLog.STD, "System property ''oozie.home.dir'' not defined"),
     E0001(XLog.OPS, "Could not create runtime directory, {0}"),
     E0002(XLog.STD, "System is in safe mode"),
     E0003(XLog.OPS, "Oozie home directory must be an absolute path [{0}]"),
@@ -29,7 +29,7 @@ public enum ErrorCode {
 
     E0010(XLog.OPS, "Could not initialize log service, {0}"),
     E0011(XLog.OPS, "Log4j file must be a file name [{0}]"),
-    E0012(XLog.OPS, "Log4j file must be a '.properties' file [{0}]"),
+    E0012(XLog.OPS, "Log4j file must be a ''.properties'' file [{0}]"),
     E0013(XLog.OPS, "Log4j file [{0}] not found in configuration dir [{1}] 
neither in classpath"),
 
     E0020(XLog.OPS, "Environment variable {0} not defined"),
@@ -73,7 +73,7 @@ public enum ErrorCode {
     E0402(XLog.STD, "Invalid callback ID [{0}]"),
     E0403(XLog.STD, "Invalid callback data, {0}"),
     E0404(XLog.STD, "Only one of the properties are allowed [{0}]"),
-    E0405(XLog.STD, "Submission request doesn't have any application or lib 
path"),
+    E0405(XLog.STD, "Submission request doesn''t have any application or lib 
path"),
 
     E0420(XLog.STD, "Invalid jobs filter [{0}], {1}"),
     E0421(XLog.STD, "Invalid job filter [{0}], {1}"),
@@ -143,7 +143,7 @@ public enum ErrorCode {
     E0734(XLog.STD, "Invalid transition from node [{0}] to node [{1}] while 
using fork/join"),
     E0735(XLog.STD, "There was an invalid \"error to\" transition to node 
[{1}] while using fork/join"),
     E0736(XLog.STD, "Workflow definition length [{0}] exceeded maximum allowed 
length [{1}]"),
-    E0737(XLog.STD, "Invalid transition from node [{0}] to node [{1}] -- nodes 
of type 'end' are not allowed within Fork/Join"),
+    E0737(XLog.STD, "Invalid transition from node [{0}] to node [{1}] -- nodes 
of type ''end'' are not allowed within Fork/Join"),
     E0738(XLog.STD, "The following {0} parameters are required but were not 
defined and no default values are available: {1}"),
     E0739(XLog.STD, "Parameter name cannot be empty"),
     E0740(XLog.STD, "Invalid node type encountered (node [{0}])"),
@@ -177,8 +177,8 @@ public enum ErrorCode {
     E0821(XLog.STD, "Received early callback for action still in PREP state; 
will wait [{0}]ms and requeue up to [{1}] more times"),
     E0822(XLog.STD, "Received early callback for action [{0}] while still in 
PREP state and exhausted all requeues"),
 
-    E0900(XLog.OPS, "JobTracker [{0}] not allowed, not in Oozie's whitelist. 
Allowed values are: {1}"),
-    E0901(XLog.OPS, "NameNode [{0}] not allowed, not in Oozie's whitelist. 
Allowed values are: {1}"),
+    E0900(XLog.OPS, "JobTracker [{0}] not allowed, not in Oozie''s whitelist. 
Allowed values are: {1}"),
+    E0901(XLog.OPS, "NameNode [{0}] not allowed, not in Oozie''s whitelist. 
Allowed values are: {1}"),
     E0902(XLog.OPS, "Exception occured: [{0}]"),
     E0903(XLog.OPS, "Invalid JobConf, it has not been created by 
HadoopAccessorService"),
     E0904(XLog.STD, "Scheme [{0}] not supported in uri [{1}]"),

http://git-wip-us.apache.org/repos/asf/oozie/blob/ef3e88cb/core/src/test/java/org/apache/oozie/TestErrorCode.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/TestErrorCode.java 
b/core/src/test/java/org/apache/oozie/TestErrorCode.java
new file mode 100644
index 0000000..c5493f8
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/TestErrorCode.java
@@ -0,0 +1,42 @@
+/**
+ * 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;
+
+import org.apache.oozie.test.XTestCase;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+public class TestErrorCode extends XTestCase {
+
+    // MessageFormat requires that single quotes are escaped by another single 
quote; otherwise, it (a) doesn't render the single
+    // quote and (b) doesn't parse the {#} tokens after the single quote.  For 
example, foo("{0} don't have {1}", "I", "a problem")
+    // would render as "I dont have {1}".  This test checks that we don't 
accidently do this.  It should be
+    // foo("{0} don''t have {1}", "I", "a problem"), which would result in "I 
dont have a problem".
+    public void testEscapedSingleQuotes() throws Exception {
+        Pattern singleQuotePattern = 
Pattern.compile("^'[^']|[^']'[^']|[^']'$");
+        for (ErrorCode ec : ErrorCode.values()) {
+            String tmpl = ec.getTemplate();
+            Matcher m = singleQuotePattern.matcher(tmpl);
+            assertFalse("Found an unescaped single quote in " + ec + " (" + 
tmpl + ").\nMake sure to replace all ' with ''",
+                    m.find());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/oozie/blob/ef3e88cb/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionInputCheckXCommand.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionInputCheckXCommand.java
 
b/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionInputCheckXCommand.java
index 37766e7..f78dafd 100644
--- 
a/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionInputCheckXCommand.java
+++ 
b/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionInputCheckXCommand.java
@@ -559,7 +559,7 @@ public class TestCoordActionInputCheckXCommand extends 
XDataTestCase {
         }
         catch (IOException ioe) {
             assertEquals(caicc.getCoordActionErrorCode(), "E0901");
-            assertTrue(caicc.getCoordActionErrorMsg().contains("not in Oozies 
whitelist"));
+            assertTrue(caicc.getCoordActionErrorMsg().contains("not in Oozie's 
whitelist"));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/oozie/blob/ef3e88cb/core/src/test/java/org/apache/oozie/service/TestHadoopAccessorService.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/oozie/service/TestHadoopAccessorService.java 
b/core/src/test/java/org/apache/oozie/service/TestHadoopAccessorService.java
index e25387e..bf3dbd9 100644
--- a/core/src/test/java/org/apache/oozie/service/TestHadoopAccessorService.java
+++ b/core/src/test/java/org/apache/oozie/service/TestHadoopAccessorService.java
@@ -178,4 +178,49 @@ public class TestHadoopAccessorService extends XTestCase {
         has.checkSupportedFilesystem(new URI("/blah"));
     }
 
+    public void testValidateJobTracker() throws Exception {
+        HadoopAccessorService has = new HadoopAccessorService();
+        Configuration conf = new Configuration(false);
+        conf.set("oozie.service.HadoopAccessorService.jobTracker.whitelist", " 
");
+        has.init(conf);
+        has.validateJobTracker("foo");
+        has.validateJobTracker("bar");
+        has.validateJobTracker("blah");
+        conf.set("oozie.service.HadoopAccessorService.jobTracker.whitelist", 
"foo,bar");
+        has.init(conf);
+        has.validateJobTracker("foo");
+        has.validateJobTracker("bar");
+        try {
+            has.validateJobTracker("blah");
+            fail("Should have gotten an exception");
+        } catch (HadoopAccessorException hae) {
+            assertEquals(ErrorCode.E0900, hae.getErrorCode());
+            assertEquals("E0900: JobTracker [blah] not allowed, not in Oozie's 
whitelist. Allowed values are: [foo, bar]",
+                    hae.getMessage());
+        }
+        has.destroy();
+    }
+
+    public void testValidateNameNode() throws Exception {
+        HadoopAccessorService has = new HadoopAccessorService();
+        Configuration conf = new Configuration(false);
+        conf.set("oozie.service.HadoopAccessorService.nameNode.whitelist", " 
");
+        has.init(conf);
+        has.validateNameNode("foo");
+        has.validateNameNode("bar");
+        has.validateNameNode("blah");
+        conf.set("oozie.service.HadoopAccessorService.nameNode.whitelist", 
"foo,bar");
+        has.init(conf);
+        has.validateNameNode("foo");
+        has.validateNameNode("bar");
+        try {
+            has.validateNameNode("blah");
+            fail("Should have gotten an exception");
+        } catch (HadoopAccessorException hae) {
+            assertEquals(ErrorCode.E0901, hae.getErrorCode());
+            assertEquals("E0901: NameNode [blah] not allowed, not in Oozie's 
whitelist. Allowed values are: [foo, bar]",
+                    hae.getMessage());
+        }
+        has.destroy();
+    }
 }

http://git-wip-us.apache.org/repos/asf/oozie/blob/ef3e88cb/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 721f681..274e210 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 4.2.0 release (trunk - unreleased)
 
+OOZIE-2171 Some error code messages are not parsed correctly due to unescaped 
single quote (rkanter)
 OOZIE-2108 bulk kill, suspend, resume jobs using existing filter, offset, len, 
and jobtype params (bzhang)
 OOZIE-2167 TestCoordMaterializeTransitionXCommand fails (rkanter)
 OOZIE-1964 Hive Server 2 action doesn't return Hadoop Job IDs (rkanter)

Reply via email to