DELETE directory operation can be implemented using following interfaces.
FileSystem.delete(org.apache.hadoop.fs.Path)
is used to delete a directory from the QueryIO cluster.
NameNode URL and replication count are provided in the Hadoop configuration and it is used to create file system object.
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DFSConfigKeys; public class DeleteBucket { /* * This program deletes the specified directory from HDFS. */ public static void main(String[] args) throws IOException{ Configuration conf = new Configuration(true); //Create a configuration object to define hdfs properties conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://192.168.0.1:9000"); // URL for your namenode conf.set(DFSConfigKeys.DFS_REPLICATION_KEY, "3"); // Replication count for files you write FileSystem dfs = FileSystem.get(conf); //Initialize DFS FileSystem object with QueryIO configurations dfs.delete(new Path("/queryio/demo/"), true); // Deletes files in the folder recursively } }
HTTP DELETE
operation can be used for delete directory operation. Following sample is explained using curl
command.
Syntax of curl
command used is
curl -i -X DELETE "http://<host>:<port>/<path>?user.name=<username>&op=DELETE[&recursive=<true|false>]"
-i option
: Include the HTTP-header in the output like server-name, date of the document, HTTP-version etc. -X option
: (HTTP) Specifies a custom request method to use when communicating with the HTTP server.DELETE
: submit HTTP DELETE request.<HOST>
: QueryIO server hostname.<PORT>
: Port on which server is working.<PATH>
: A valid path to directory name.user.name=<username>
: QueryIO account username for authentication.op=DELETE
: DELETE directory operation.[&recursive=<true|false>]
: Optional. It signifies the operation act on the content in the subdirectories. Valid values are true/false. Default value is false.Sample Request: curl -i -X DELETE "http://192.168.0.1:50070/webhdfs/v1/queryio/demo?user.name=admin&op=DELETE&resursive=true"
Above request will delete directory "demo" and all its subdirectories.
The following is the actual HTTP request:
DELETE /webhdfs/v1/queryio/demo?user.name=admin&op=DELETE&resursive=true HTTP/1.1 User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5 Host: 192.168.0.1:50070 Accept: */*
Delete directory operation using WEBHDFS api returns a JSON object. If successful, the HTTP 200 response code is returned. Following is the HTTP response sent when QueryIO Server successfully deletes a directory:
HTTP/1.1 200 OK Content-Type: application/json Expires: Thu, 01-Jan-1970 00:00:00 GMT Set-Cookie: hadoop.auth="u=admin&p=admin&t=simple&e=1356635081222&s=GrDdraO+6ZAYdridUnl3YsSqQGE=";Path=/ Transfer-Encoding: chunked Server: Jetty(6.1.26) {"boolean":true}