You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by su...@apache.org on 2017/01/05 22:09:19 UTC

knox git commit: KNOX-810 Add status in HDFS for ClientDSL (Vincent Devillers via Sumit Gupta)

Repository: knox
Updated Branches:
  refs/heads/master 978826a6f -> 215cedac6


KNOX-810 Add status in HDFS for ClientDSL (Vincent Devillers via Sumit Gupta)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/215cedac
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/215cedac
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/215cedac

Branch: refs/heads/master
Commit: 215cedac6c3348d3ad60e444122436c41ad6da87
Parents: 978826a
Author: Sumit Gupta <su...@apache.org>
Authored: Thu Jan 5 17:08:00 2017 -0500
Committer: Sumit Gupta <su...@apache.org>
Committed: Thu Jan 5 17:08:00 2017 -0500

----------------------------------------------------------------------
 .../hadoop/gateway/shell/hdfs/Example.groovy    |  2 +
 .../apache/hadoop/gateway/shell/hdfs/Hdfs.java  |  4 ++
 .../hadoop/gateway/shell/hdfs/Status.java       | 68 ++++++++++++++++++++
 3 files changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/215cedac/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Example.groovy
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Example.groovy b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Example.groovy
index ac0762b..0b2c86e 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Example.groovy
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Example.groovy
@@ -32,6 +32,8 @@ hadoop = Hadoop.login( gateway, username, password )
 
 println Hdfs.ls(hadoop).dir( "/" ).now().string
 
+println Hdfs.status(hadoop).file( "/" ).now().string
+
 Hdfs.rm(hadoop).file( "/tmp/test" ).recursive().now()
 
 Hdfs.mkdir(hadoop).dir( "/tmp/test").now()

http://git-wip-us.apache.org/repos/asf/knox/blob/215cedac/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Hdfs.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Hdfs.java b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Hdfs.java
index ffbf22c..0984c01 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Hdfs.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Hdfs.java
@@ -27,6 +27,10 @@ public class Hdfs {
     return new Rename.Request( session );
   }
 
+  public static Status.Request status(Hadoop session ) {
+    return new Status.Request( session );
+  }
+
   public static Ls.Request ls( Hadoop session ) {
     return new Ls.Request( session );
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/215cedac/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Status.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Status.java b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Status.java
new file mode 100644
index 0000000..05ad890
--- /dev/null
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hdfs/Status.java
@@ -0,0 +1,68 @@
+/**
+ * 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.gateway.shell.hdfs;
+
+import org.apache.hadoop.gateway.shell.AbstractRequest;
+import org.apache.hadoop.gateway.shell.BasicResponse;
+import org.apache.hadoop.gateway.shell.Hadoop;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.util.concurrent.Callable;
+
+public class Status {
+
+  public static class Request extends AbstractRequest<Response> {
+
+    private String file;
+
+    Request(Hadoop session) {
+      super(session);
+    }
+
+    public Request file(String file) {
+      this.file = file;
+      return this;
+    }
+
+    public Callable<Response> callable() {
+      return new Callable<Response>() {
+        @Override
+        public Response call() throws Exception {
+          URIBuilder uri = uri(Hdfs.SERVICE_PATH, file);
+          addQueryParam(uri, "op", "GETFILESTATUS");
+          HttpGet get = new HttpGet(uri.build());
+          return new Response(execute(get));
+        }
+      };
+    }
+  }
+
+  public static class Response extends BasicResponse {
+
+    Response(HttpResponse response) throws IOException {
+      super(response);
+    }
+
+    public boolean exists() {
+      return getStatusCode() == 200;
+    }
+  }
+}