HADOOP-6869. Functionality to creating file or folder on a remote daemon side. Contributed by Vinay Thota.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@979942 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Konstantin Boudnik 2010-07-28 03:19:02 +00:00
parent 5c5c163aa3
commit d010dd60e1
4 changed files with 128 additions and 0 deletions

View File

@ -437,6 +437,9 @@ Release 0.21.0 - Unreleased
HADOOP-6692. Add FileContext#listStatus that returns an iterator. HADOOP-6692. Add FileContext#listStatus that returns an iterator.
(hairong) (hairong)
HADOOP-6869. Functionality to creating file or folder on a remote daemon
side (Vinay Thota via cos)
IMPROVEMENTS IMPROVEMENTS
HADOOP-6798. Align Ivy version for all Hadoop subprojects. (cos) HADOOP-6798. Align Ivy version for all Hadoop subprojects. (cos)

View File

@ -34,6 +34,8 @@ import org.apache.hadoop.util.Shell.ShellCommandExecutor;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -53,6 +55,10 @@ public aspect DaemonProtocolAspect {
new HashMap<Object, List<ControlAction>>(); new HashMap<Object, List<ControlAction>>();
private static final Log LOG = LogFactory.getLog( private static final Log LOG = LogFactory.getLog(
DaemonProtocolAspect.class.getName()); DaemonProtocolAspect.class.getName());
private static FsPermission defaultPermission = new FsPermission(
FsAction.READ_WRITE, FsAction.READ_WRITE, FsAction.READ_WRITE);
/** /**
* Set if the daemon process is ready or not, concrete daemon protocol should * Set if the daemon process is ready or not, concrete daemon protocol should
* implement pointcuts to determine when the daemon is ready and use the * implement pointcuts to determine when the daemon is ready and use the
@ -127,6 +133,50 @@ public aspect DaemonProtocolAspect {
return cloneFileStatus(fileStatus); return cloneFileStatus(fileStatus);
} }
/**
* Create a file with given permissions in a file system.
* @param path - source path where the file has to create.
* @param fileName - file name.
* @param permission - file permissions.
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
public void DaemonProtocol.createFile(String path, String fileName,
FsPermission permission, boolean local) throws IOException {
Path p = new Path(path);
FileSystem fs = getFS(p, local);
Path filePath = new Path(path, fileName);
fs.create(filePath);
if (permission == null) {
fs.setPermission(filePath, defaultPermission);
} else {
fs.setPermission(filePath, permission);
}
fs.close();
}
/**
* Create a folder with given permissions in a file system.
* @param path - source path where the file has to be creating.
* @param folderName - folder name.
* @param permission - folder permissions.
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
public void DaemonProtocol.createFolder(String path, String folderName,
FsPermission permission, boolean local) throws IOException {
Path p = new Path(path);
FileSystem fs = getFS(p, local);
Path folderPath = new Path(path, folderName);
fs.mkdirs(folderPath);
if (permission == null) {
fs.setPermission(folderPath, defaultPermission);
} else {
fs.setPermission(folderPath, permission);
}
fs.close();
}
public FileStatus[] DaemonProtocol.listStatus(String path, boolean local) public FileStatus[] DaemonProtocol.listStatus(String path, boolean local)
throws IOException { throws IOException {
Path p = new Path(path); Path p = new Path(path);

View File

@ -27,6 +27,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.test.system.process.RemoteProcess; import org.apache.hadoop.test.system.process.RemoteProcess;
/** /**
* Abstract class which encapsulates the DaemonClient which is used in the * Abstract class which encapsulates the DaemonClient which is used in the
@ -165,6 +167,56 @@ public abstract class AbstractDaemonClient<PROXY extends DaemonProtocol> {
return getProxy().getFileStatus(path, local); return getProxy().getFileStatus(path, local);
} }
/**
* Create a file with full permissions in a file system.
* @param path - source path where the file has to create.
* @param fileName - file name
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
public void createFile(String path, String fileName,
boolean local) throws IOException {
getProxy().createFile(path, fileName, null, local);
}
/**
* Create a file with given permissions in a file system.
* @param path - source path where the file has to create.
* @param fileName - file name.
* @param permission - file permissions.
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
public void createFile(String path, String fileName,
FsPermission permission, boolean local) throws IOException {
getProxy().createFile(path, fileName, permission, local);
}
/**
* Create a folder with default permissions in a file system.
* @param path - source path where the file has to be creating.
* @param folderName - folder name.
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
public void createFolder(String path, String folderName,
boolean local) throws IOException {
getProxy().createFolder(path, folderName, null, local);
}
/**
* Create a folder with given permissions in a file system.
* @param path - source path where the file has to be creating.
* @param folderName - folder name.
* @param permission - folder permissions.
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
public void createFolder(String path, String folderName,
FsPermission permission, boolean local) throws IOException {
getProxy().createFolder(path, folderName, permission, local);
}
/** /**
* List the statuses of the files/directories in the given path if the path is * List the statuses of the files/directories in the given path if the path is
* a directory. * a directory.

View File

@ -23,8 +23,10 @@ import java.io.IOException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.Writable;
import org.apache.hadoop.ipc.VersionedProtocol; import org.apache.hadoop.ipc.VersionedProtocol;
import org.apache.hadoop.fs.permission.FsPermission;
/** /**
* RPC interface of a given Daemon. * RPC interface of a given Daemon.
@ -76,6 +78,27 @@ public interface DaemonProtocol extends VersionedProtocol{
*/ */
FileStatus getFileStatus(String path, boolean local) throws IOException; FileStatus getFileStatus(String path, boolean local) throws IOException;
/**
* Create a file with given permissions in a file system.
* @param path - source path where the file has to create.
* @param fileName - file name.
* @param permission - file permissions.
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
void createFile(String path, String fileName,
FsPermission permission, boolean local) throws IOException;
/**
* Create a folder with given permissions in a file system.
* @param path - source path where the file has to be creating.
* @param folderName - folder name.
* @param permission - folder permissions.
* @param local - identifying the path whether its local or not.
* @throws IOException - if an I/O error occurs.
*/
public void createFolder(String path, String folderName,
FsPermission permission, boolean local) throws IOException;
/** /**
* List the statuses of the files/directories in the given path if the path is * List the statuses of the files/directories in the given path if the path is
* a directory. * a directory.