Repository: oozie Updated Branches: refs/heads/master 2b655d746 -> c6e1e5425
OOZIE-2819 Make Oozie REST API accept multibyte characters for script Actions (asasvari via rkanter) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/c6e1e542 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/c6e1e542 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/c6e1e542 Branch: refs/heads/master Commit: c6e1e5425d4608bb276e9347ee57ca1b2839dbd2 Parents: 2b655d7 Author: Robert Kanter <[email protected]> Authored: Wed Mar 15 18:38:07 2017 -0700 Committer: Robert Kanter <[email protected]> Committed: Wed Mar 15 18:38:07 2017 -0700 ---------------------------------------------------------------------- .../hadoop/ScriptLanguageActionExecutor.java | 3 +- .../TestScriptLanguageActionExecutor.java | 101 +++++++++++++++++++ release-log.txt | 1 + 3 files changed, 104 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/c6e1e542/core/src/main/java/org/apache/oozie/action/hadoop/ScriptLanguageActionExecutor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/action/hadoop/ScriptLanguageActionExecutor.java b/core/src/main/java/org/apache/oozie/action/hadoop/ScriptLanguageActionExecutor.java index f254126..92e149d 100644 --- a/core/src/main/java/org/apache/oozie/action/hadoop/ScriptLanguageActionExecutor.java +++ b/core/src/main/java/org/apache/oozie/action/hadoop/ScriptLanguageActionExecutor.java @@ -28,6 +28,7 @@ import org.jdom.Element; import org.jdom.Namespace; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; public abstract class ScriptLanguageActionExecutor extends JavaActionExecutor { @@ -73,7 +74,7 @@ public abstract class ScriptLanguageActionExecutor extends JavaActionExecutor { scriptFile = new Path(actionPath, script); FileSystem fs = context.getAppFileSystem(); dos = fs.create(scriptFile); - dos.writeBytes(scriptContent); + dos.write(scriptContent.getBytes(StandardCharsets.UTF_8)); addToCache(conf, actionPath, script + "#" + name, false); } http://git-wip-us.apache.org/repos/asf/oozie/blob/c6e1e542/core/src/test/java/org/apache/oozie/action/hadoop/TestScriptLanguageActionExecutor.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/action/hadoop/TestScriptLanguageActionExecutor.java b/core/src/test/java/org/apache/oozie/action/hadoop/TestScriptLanguageActionExecutor.java new file mode 100644 index 0000000..0ce9092 --- /dev/null +++ b/core/src/test/java/org/apache/oozie/action/hadoop/TestScriptLanguageActionExecutor.java @@ -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.action.hadoop; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.oozie.action.ActionExecutor; +import org.apache.oozie.service.ServiceException; +import org.apache.oozie.service.Services; +import org.jdom.Element; +import org.jdom.Namespace; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.BDDMockito; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.nio.charset.StandardCharsets; + +import static org.apache.oozie.service.ConfigurationService.OOZIE_CONFIG_DIR; +import static org.apache.oozie.service.Services.OOZIE_HOME_DIR; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +//@RunWith(MockitoJUnitRunner.class) +@RunWith(PowerMockRunner.class) +@PrepareForTest(Services.class) +public class TestScriptLanguageActionExecutor { + + @Mock private ActionExecutor.Context mockContext; + @Mock private Element mockScript; + @Mock private Element mockElement; + @Mock private Path mockPath; + @Mock private Configuration mockConfiguration; + @Mock private FSDataOutputStream fsDataOutputStream; + @Mock private FileSystem mockFs; + @Mock private Configuration mockActionConfig; + @Mock private Services mockServices; + + @Before + public void setup() throws ServiceException { + PowerMockito.mockStatic(Services.class); + + when(Services.get()).thenReturn(mockServices); + doReturn(mockConfiguration).when(mockServices).getConf(); + } + + @Test + public void multibyteInputsAreAcceptedInScripts() throws Exception { + final String testInput = "ææª"; + doReturn(mockScript).when(mockElement).getChild(anyString(), any(Namespace.class)); + doReturn("script").when(mockScript).getTextTrim(); + doReturn(mockActionConfig).when(mockContext).getProtoActionConf(); + doReturn(testInput).when(mockActionConfig).get(anyString()); + doReturn(new Path(".")).when(mockContext).getActionDir(); + doReturn(mockFs).when(mockContext).getAppFileSystem(); + doReturn(fsDataOutputStream).when(mockFs).create(any(Path.class)); + + ScriptLanguageActionExecutor scriptLanguageActionExecutor = spy(new ScriptLanguageActionExecutor("pig") { + @Override + protected String getScriptName() { + return null; + } + }); + scriptLanguageActionExecutor.addScriptToCache(mockConfiguration, mockElement, mockPath, mockContext); + byte[] expectedInput = testInput.getBytes(StandardCharsets.UTF_8); + verify(fsDataOutputStream).write(expectedInput); + } + + @After + public void cleanUp() { + Services.get().destroy(); + } +} http://git-wip-us.apache.org/repos/asf/oozie/blob/c6e1e542/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 9eb90db..4c355c3 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 4.4.0 release (trunk - unreleased) +OOZIE-2819 Make Oozie REST API accept multibyte characters for script Actions (asasvari via rkanter) OOZIE-2750 Spelling errors in the log messages and exception messages (gsohn via rkanter) OOZIE-2807 Oozie gets RM delegation token even for checking job status (satishsaley) OOZIE-1887 Remove the utils dir (kvntrieu via rkanter)
