You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by vi...@apache.org on 2012/06/29 19:13:59 UTC
svn commit: r1355475 - in /incubator/oozie/trunk: ./
client/src/main/resources/ core/src/main/java/org/apache/oozie/action/hadoop/
core/src/test/java/org/apache/oozie/action/hadoop/ docs/src/site/twiki/
Author: virag
Date: Fri Jun 29 17:13:57 2012
New Revision: 1355475
URL: http://svn.apache.org/viewvc?rev=1355475&view=rev
Log:
OOZIE-872 Support touchz in fs node of oozie worklfow (britt via virag)
Modified:
incubator/oozie/trunk/client/src/main/resources/oozie-workflow-0.4.xsd
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java
incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
incubator/oozie/trunk/release-log.txt
Modified: incubator/oozie/trunk/client/src/main/resources/oozie-workflow-0.4.xsd
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/client/src/main/resources/oozie-workflow-0.4.xsd?rev=1355475&r1=1355474&r2=1355475&view=diff
==============================================================================
--- incubator/oozie/trunk/client/src/main/resources/oozie-workflow-0.4.xsd (original)
+++ incubator/oozie/trunk/client/src/main/resources/oozie-workflow-0.4.xsd Fri Jun 29 17:13:57 2012
@@ -182,6 +182,7 @@
<xs:element name="mkdir" type="workflow:MKDIR"/>
<xs:element name="move" type="workflow:MOVE"/>
<xs:element name="chmod" type="workflow:CHMOD"/>
+ <xs:element name="touchz" type="workflow:TOUCHZ"/>
</xs:choice>
</xs:complexType>
@@ -267,6 +268,10 @@
<xs:attribute name="dir-files" type="xs:string"/>
</xs:complexType>
+ <xs:complexType name="TOUCHZ">
+ <xs:attribute name="path" type="xs:string" use="required"/>
+ </xs:complexType>
+
<xs:complexType name="CREDENTIALS">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="credential" type="workflow:CREDENTIAL"/>
Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java?rev=1355475&r1=1355474&r2=1355475&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java Fri Jun 29 17:13:57 2012
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
+import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -117,6 +118,12 @@ public class FsActionExecutor extends Ac
String permissionsMask = commandElement.getAttributeValue("permissions").trim();
chmod(context, path, permissionsMask, dirFiles);
}
+ else {
+ if (command.equals("touchz")) {
+ Path path = getPath(commandElement, "path");
+ touchz(context, path);
+ }
+ }
}
}
}
@@ -285,6 +292,27 @@ public class FsActionExecutor extends Ac
}
}
+ void touchz(Context context, Path path) throws ActionExecutorException {
+ try {
+ validatePath(path, true);
+ FileSystem fs = getFileSystemFor(path, context);
+
+ FileStatus st;
+ if (fs.exists(path)) {
+ st = fs.getFileStatus(path);
+ if (st.isDir()) {
+ throw new Exception(path.toString() + " is a directory");
+ } else if (st.getLen() != 0)
+ throw new Exception(path.toString() + " must be a zero-length file");
+ }
+ FSDataOutputStream out = fs.create(path);
+ out.close();
+ }
+ catch (Exception ex) {
+ throw convertException(ex);
+ }
+ }
+
FsPermission createShortPermission(String permissions, Path path) throws ActionExecutorException {
if (permissions.length() == 3) {
char user = permissions.charAt(0);
Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java?rev=1355475&r1=1355474&r2=1355475&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java Fri Jun 29 17:13:57 2012
@@ -29,6 +29,8 @@ import org.apache.oozie.service.Workflow
import org.apache.oozie.util.XConfiguration;
import org.apache.oozie.util.XmlUtils;
import org.jdom.Element;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.text.MessageFormat;
public class TestFsActionExecutor extends ActionExecutorTestCase {
@@ -218,6 +220,58 @@ public class TestFsActionExecutor extend
assertEquals("rwx---r--", fs.getFileStatus(grandchild).getPermission().toString());
}
+ public void testTouchz() throws Exception {
+ FsActionExecutor ae = new FsActionExecutor();
+ FileSystem fs = getFileSystem();
+
+ Path dir = new Path(getFsTestCaseDir(), "dir1");
+ Path f1 = new Path(dir + "/newfile1");
+ Path f2 = new Path(dir + "/newfile2");
+ Context context = createContext("<fs/>");
+
+ fs.mkdirs(dir);
+ fs.createNewFile(f1);
+
+ assertTrue(fs.exists(f1));
+ assertTrue(fs.getFileStatus(f1).getLen() == 0);
+
+ ae.touchz(context, f1);
+ ae.touchz(context, f2);
+
+ assertTrue(fs.exists(f1));
+ assertTrue(fs.exists(f2));
+
+ FileStatus fs1 = fs.getFileStatus(f1);
+ FileStatus fs2 = fs.getFileStatus(f2);
+
+ assertFalse(fs1.isDir());
+ assertFalse(fs2.isDir());
+ assertTrue(fs1.getLen() == 0);
+ assertTrue(fs2.getLen() == 0);
+
+ try {
+ ae.touchz(context, dir);
+ fail();
+ }
+ catch (Exception ex) {
+ assertTrue(ex.getMessage().contains("is a directory"));
+ }
+
+ //Test touchz on a non-zero length file
+ Path f3 = new Path(dir + "/newfile3");
+ Writer writer = new OutputStreamWriter(fs.create(f3));
+ writer.write("This is not a zero length file");
+ writer.close();
+
+ try {
+ ae.touchz(context, f3);
+ fail();
+ }
+ catch (Exception ex) {
+ assertTrue(ex.getMessage().contains("must be a zero-length file"));
+ }
+ }
+
public void testDoOperations() throws Exception {
FsActionExecutor ae = new FsActionExecutor();
FileSystem fs = getFileSystem();
@@ -236,13 +290,18 @@ public class TestFsActionExecutor extend
fs.mkdirs(chmod2);
Path child2 = new Path(chmod2, "child2");
fs.mkdirs(child2);
+ Path newFile1 = new Path(mkdir + "newFile1");
+ Path newFile2 = new Path(mkdir + "newFile2");
+ fs.createNewFile(newFile1);
String str = MessageFormat.format("<root><mkdir path=''{0}''/>" +
"<delete path=''{1}''/>" +
"<move source=''{2}'' target=''{3}''/>" +
"<chmod path=''{4}'' permissions=''-rwxrwxrwx''/>" +
"<chmod path=''{5}'' permissions=''-rwxrwx---'' dir-files=''false''/>" +
- "</root>", mkdir, delete, source, target, chmod1, chmod2);
+ "<touchz path=''{6}''/>" +
+ "<touchz path=''{7}''/>" +
+ "</root>", mkdir, delete, source, target, chmod1, chmod2, newFile1, newFile2);
Element xml = XmlUtils.parseXml(str);
@@ -252,6 +311,8 @@ public class TestFsActionExecutor extend
assertFalse(fs.exists(delete));
assertFalse(fs.exists(source));
assertTrue(fs.exists(target));
+ assertTrue(fs.exists(newFile1));
+ assertTrue(fs.exists(newFile2));
assertEquals("rwxrwxrwx", fs.getFileStatus(chmod1).getPermission().toString());
assertNotSame("rwxrwxrwx", fs.getFileStatus(child1).getPermission().toString());
@@ -278,14 +339,18 @@ public class TestFsActionExecutor extend
fs.mkdirs(chmod2);
Path child2 = new Path(chmod2, "child2");
fs.mkdirs(child2);
+ Path newFile1 = new Path(mkdir + "newFile1");
+ Path newFile2 = new Path(mkdir + "newFile2");
+ fs.createNewFile(newFile1);
String actionXml = MessageFormat.format("<fs><mkdir path=''{0}''/>" +
"<delete path=''{1}''/>" +
"<move source=''{2}'' target=''{3}''/>" +
"<chmod path=''{4}'' permissions=''-rwxrwxrwx''/>" +
"<chmod path=''{5}'' permissions=''-rwxrwx---'' dir-files=''false''/>" +
- "</fs>", mkdir, delete, source, target, chmod1, chmod2);
-
+ "<touchz path=''{6}''/>" +
+ "<touchz path=''{7}''/>" +
+ "</fs>", mkdir, delete, source, target, chmod1, chmod2, newFile1, newFile2);
Context context = createContext(actionXml);
WorkflowAction action = context.getAction();
@@ -308,6 +373,8 @@ public class TestFsActionExecutor extend
assertFalse(fs.exists(delete));
assertFalse(fs.exists(source));
assertTrue(fs.exists(target));
+ assertTrue(fs.exists(newFile1));
+ assertTrue(fs.exists(newFile2));
assertEquals("rwxrwxrwx", fs.getFileStatus(chmod1).getPermission().toString());
assertNotSame("rwxrwxrwx", fs.getFileStatus(child1).getPermission().toString());
Modified: incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki?rev=1355475&r1=1355474&r2=1355475&view=diff
==============================================================================
--- incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki (original)
+++ incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki Fri Jun 29 17:13:57 2012
@@ -1022,6 +1022,7 @@ executed. Thus there is less chance of a
...
<chmod path='[PATH]' permissions='[PERMISSIONS]' dir-files='false' />
...
+ <touchz path='[PATH]' />
</fs>
<ok to="[NODE-NAME]"/>
<error to="[NODE-NAME]"/>
@@ -1046,6 +1047,8 @@ In the =move= command the =source= path
The =chmod= command changes the permissions for the specified path. Permissions can be specified using the Unix Symbolic representation (e.g. -rwxrw-rw-) or an octal representation (755).
When doing a =chmod= command on a directory, by default the command is applied to the directory and the files one level within the directory. To apply the =chmod= command to the directory, without affecting the files within it, the =dir-files= attribute must be set to =false=.
+The =touchz= command creates a zero length file in the specified path if none exists. If one already exists, then touchz will perform a touch operation.
+
If relative paths are used it will be relative to the specified user home directory.
*Example:*
Modified: incubator/oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1355475&r1=1355474&r2=1355475&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Fri Jun 29 17:13:57 2012
@@ -1,5 +1,6 @@
-- Oozie 3.3.0 release (trunk - unreleased)
+OOZIE-872 Support touchz in fs node of oozie worklfow (britt via virag)
OOZIE-769 Adding "-debug" option to Oozie CLI for debug statements to stdout (mona via virag)
OOZIE-795 update the oozie commit build profile (virag)
OOZIE-860 start-instance and end-instance should limit 1 (britt via virag)