hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [1/2] hadoop git commit: HADOOP-12667 s3a to support createNonRecursive API. Contributed by Sean Mackrory
Date Wed, 05 Oct 2016 14:02:56 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 bdbb75e08 -> 6ed335a01
  refs/heads/trunk 6cfe64937 -> d6be1e75d


HADOOP-12667 s3a to support createNonRecursive API. Contributed by Sean Mackrory


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6ed335a0
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6ed335a0
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6ed335a0

Branch: refs/heads/branch-2
Commit: 6ed335a018a1ddfeb262ab84476441edb319dfae
Parents: bdbb75e
Author: Steve Loughran <stevel@apache.org>
Authored: Wed Oct 5 15:01:15 2016 +0100
Committer: Steve Loughran <stevel@apache.org>
Committed: Wed Oct 5 15:01:15 2016 +0100

----------------------------------------------------------------------
 .../org/apache/hadoop/fs/s3a/S3AFileSystem.java | 27 +++++++++
 .../hadoop/fs/s3a/ITestS3AMiscOperations.java   | 63 ++++++++++++++++++++
 2 files changed, 90 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/6ed335a0/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
index b22f8c6..54560a0 100644
--- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
+++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
@@ -26,6 +26,7 @@ import java.io.InterruptedIOException;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -59,6 +60,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CreateFlag;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileAlreadyExistsException;
@@ -513,6 +515,31 @@ public class S3AFileSystem extends FileSystem {
   }
 
   /**
+   * {@inheritDoc}
+   * @throws FileNotFoundException if the parent directory is not present -or
+   * is not a directory.
+   */
+  @Override
+  public FSDataOutputStream createNonRecursive(Path path,
+      FsPermission permission,
+      EnumSet<CreateFlag> flags,
+      int bufferSize,
+      short replication,
+      long blockSize,
+      Progressable progress) throws IOException {
+    Path parent = path.getParent();
+    if (parent != null) {
+      // expect this to raise an exception if there is no parent
+      if (!getFileStatus(parent).isDirectory()) {
+        throw new FileAlreadyExistsException("Not a directory: " + parent);
+      }
+    }
+    return create(path, permission,
+        flags.contains(CreateFlag.OVERWRITE), bufferSize,
+        replication, blockSize, progress);
+  }
+
+  /**
    * Append to an existing file (optional operation).
    * @param f the existing file to be appended.
    * @param bufferSize the size of the buffer to be used.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/6ed335a0/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AMiscOperations.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AMiscOperations.java
b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AMiscOperations.java
new file mode 100644
index 0000000..59fcb05
--- /dev/null
+++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AMiscOperations.java
@@ -0,0 +1,63 @@
+/**
+ * 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.fs.s3a;
+
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileAlreadyExistsException;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.contract.ContractTestUtils;
+import org.junit.Test;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * Tests of the S3A FileSystem which don't have a specific home and can share
+ * a filesystem instance with others..
+ */
+public class ITestS3AMiscOperations extends AbstractS3ATestBase {
+
+  @Test
+  public void testCreateNonRecursiveSuccess() throws IOException {
+    Path shouldWork = path("nonrecursivenode");
+    try(FSDataOutputStream out = createNonRecursive(shouldWork)) {
+      out.write(0);
+      out.close();
+    }
+    assertIsFile(shouldWork);
+  }
+
+  @Test(expected = FileNotFoundException.class)
+  public void testCreateNonRecursiveNoParent() throws IOException {
+    createNonRecursive(path("/recursive/node"));
+  }
+
+  @Test(expected = FileAlreadyExistsException.class)
+  public void testCreateNonRecursiveParentIsFile() throws IOException {
+    Path parent = path("/file.txt");
+    ContractTestUtils.touch(getFileSystem(), parent);
+    createNonRecursive(new Path(parent, "fail"));
+  }
+
+  private FSDataOutputStream createNonRecursive(Path path) throws IOException {
+    return getFileSystem().createNonRecursive(path, false, 4096,
+        (short) 3, (short) 4096,
+        null);
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message