Просмотр исходного кода

HADOOP-1250. Move a chmod utility from streaming to FileUtil. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@529379 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 лет назад
Родитель
Сommit
5b758be6f2

+ 2 - 0
CHANGES.txt

@@ -204,6 +204,8 @@ Trunk (unreleased changes)
 61. HADOOP-1214.  Replace streaming classes with new counterparts 
     from Hadoop core.  (Runping Qi via tomwhite)
 
+62. HADOOP-1250.  Move a chmod utility from streaming to FileUtil.
+    (omalley via cutting)
 
 Release 0.12.3 - 2007-04-06
 

+ 0 - 93
src/contrib/streaming/src/java/org/apache/hadoop/streaming/MustangFile.java

@@ -1,93 +0,0 @@
-/**
- * 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.hadoop.streaming;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * A simulation of some Java SE 6 File methods.
- * http://java.sun.com/developer/technicalArticles/J2SE/Desktop/mustang/enhancements/
- *
- * Limitations of this version: requires Cygwin on Windows, does not perform SecurityManager checks,
- *  always returns true (success) without verifying that the operation worked.
- *
- * Note: not specifying ownerOnly maps to ownerOnly = false
- * From man chmod: If no user specs are given, the effect is as if `a' were given. 
- * This class is mainly used to change permissions when files are unjarred from the 
- * job.jar. The executable specified in the mappper/reducer is set to be executable 
- * using this class.
- */
-public class MustangFile extends File {
-
-  public MustangFile(File parent, String child) {
-    super(parent, child);
-  }
-
-  public MustangFile(String pathname) {
-    super(pathname);
-  }
-
-  public MustangFile(String parent, String child) {
-    super(parent, child);
-  }
-
-  public boolean setReadable(boolean readable, boolean ownerOnly) {
-    chmod("r", readable, ownerOnly);
-    return SUCCESS;
-  }
-
-  public boolean setReadable(boolean readable) {
-    chmod("r", readable, false);
-    return SUCCESS;
-  }
-
-  public boolean setWritable(boolean writable, boolean ownerOnly) {
-    chmod("w", writable, ownerOnly);
-    return SUCCESS;
-  }
-
-  public boolean setWritable(boolean writable) {
-    chmod("w", writable, false);
-    return SUCCESS;
-  }
-
-  public boolean setExecutable(boolean executable, boolean ownerOnly) {
-    chmod("x", executable, ownerOnly);
-    return SUCCESS;
-  }
-
-  public boolean setExecutable(boolean executable) {
-    chmod("x", executable, false);
-    return SUCCESS;
-  }
-
-  void chmod(String perms, boolean plus, boolean ownerOnly) {
-    String[] argv = new String[3];
-    argv[0] = "/bin/chmod";
-    String spec = ownerOnly ? "u" : "ugoa";
-    spec += (plus ? "+" : "-");
-    spec += perms;
-    argv[1] = spec;
-    argv[2] = getAbsolutePath();
-    StreamUtil.exec(argv, System.err);
-  }
-
-  final static boolean SUCCESS = true;
-}

+ 2 - 6
src/contrib/streaming/src/java/org/apache/hadoop/streaming/PipeMapRed.java

@@ -21,7 +21,6 @@ package org.apache.hadoop.streaming;
 import java.io.*;
 import java.net.Socket;
 import java.net.URI;
-import java.nio.channels.*;
 import java.nio.charset.CharacterCodingException;
 import java.io.IOException;
 import java.util.Date;
@@ -34,6 +33,7 @@ import java.util.regex.*;
 
 import org.apache.commons.logging.*;
 
+import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.mapred.FileSplit;
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.PhasedFileSystem;
@@ -45,10 +45,8 @@ import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.BytesWritable;
 import org.apache.hadoop.io.Writable;
 
-import org.apache.hadoop.fs.LocalFileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.FSDataOutputStream;
 
 /** Shared functionality for PipeMapper, PipeReducer.
  *  @author Michel Tourn
@@ -229,13 +227,12 @@ public abstract class PipeMapRed {
       }
       String[] argvSplit = splitArgs(argv);
       String prog = argvSplit[0];
-      String userdir = System.getProperty("user.dir");
       File currentDir = new File(".").getAbsoluteFile();
       File jobCacheDir = new File(currentDir.getParentFile().getParent(), "work");
       if (new File(prog).isAbsolute()) {
         // we don't own it. Hope it is executable
       } else {
-        new MustangFile(new File(jobCacheDir, prog).toString()).setExecutable(true, true);
+        FileUtil.chmod(new File(jobCacheDir, prog).toString(), "a+x");
       }
 
       if (job_.getInputValueClass().equals(BytesWritable.class)) {
@@ -628,7 +625,6 @@ public abstract class PipeMapRed {
 
   String numRecInfo() {
     long elapsed = (System.currentTimeMillis() - startTime_) / 1000;
-    long total = numRecRead_ + numRecWritten_ + numRecSkipped_;
     return "R/W/S=" + numRecRead_ + "/" + numRecWritten_ + "/" + numRecSkipped_ + " in:"
         + safeDiv(numRecRead_, elapsed) + " [rec/s]" + " out:" + safeDiv(numRecWritten_, elapsed)
         + " [rec/s]";

+ 15 - 0
src/java/org/apache/hadoop/fs/FileUtil.java

@@ -396,4 +396,19 @@ public class FileUtil {
    }
    return returnVal;
  }
+  
+  /**
+   * Change the permissions on a filename.
+   * @param filename the name of the file to change
+   * @param perm the permission string
+   * @return the exit code from the command
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public static int chmod(String filename, String perm
+                          ) throws IOException, InterruptedException {
+    String cmd = "chmod " + perm + " " + filename;
+    Process p = Runtime.getRuntime().exec( cmd, null );
+    return p.waitFor();
+  }
 }