storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kabh...@apache.org
Subject [1/3] storm git commit: STORM-2095 remove any remaining files when deleting blobstore directory
Date Tue, 03 Jan 2017 14:16:23 GMT
Repository: storm
Updated Branches:
  refs/heads/1.x-branch 36674e407 -> 4d882dc0a


STORM-2095 remove any remaining files when deleting blobstore directory


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

Branch: refs/heads/1.x-branch
Commit: b02c6a2edfdbf32766aeeaaef94a95bde64ecfe5
Parents: 36674e4
Author: Wissman, Matthew <matthew.wissman@here.com>
Authored: Thu Dec 29 09:29:39 2016 -0600
Committer: Jungtaek Lim <kabhwan@gmail.com>
Committed: Tue Jan 3 23:14:08 2017 +0900

----------------------------------------------------------------------
 .../storm/blobstore/FileBlobStoreImpl.java      | 32 ++++++++++---
 .../apache/storm/blobstore/BlobStoreTest.java   | 47 +++++++++++++-------
 2 files changed, 56 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/b02c6a2e/storm-core/src/jvm/org/apache/storm/blobstore/FileBlobStoreImpl.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/blobstore/FileBlobStoreImpl.java b/storm-core/src/jvm/org/apache/storm/blobstore/FileBlobStoreImpl.java
index 423e73c..6c6877f 100644
--- a/storm-core/src/jvm/org/apache/storm/blobstore/FileBlobStoreImpl.java
+++ b/storm-core/src/jvm/org/apache/storm/blobstore/FileBlobStoreImpl.java
@@ -17,15 +17,14 @@
  */
 package org.apache.storm.blobstore;
 
-import org.apache.storm.Config;
-import org.apache.storm.utils.Utils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -35,6 +34,11 @@ import java.util.NoSuchElementException;
 import java.util.Timer;
 import java.util.TimerTask;
 
+import org.apache.storm.Config;
+import org.apache.storm.utils.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * Very basic blob store impl with no ACL handling.
  */
@@ -236,7 +240,23 @@ public class FileBlobStoreImpl {
     }
 
     protected void delete(File path) throws IOException {
-        Files.deleteIfExists(path.toPath());
+        if (Files.exists(path.toPath())){
+
+            Files.walkFileTree(path.toPath(), new SimpleFileVisitor<Path>() {
+
+                @Override
+                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws
IOException {
+                    Files.delete(file);
+                    return FileVisitResult.CONTINUE;
+                }
+
+                @Override
+                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws
IOException {
+                    Files.delete(dir);
+                    return FileVisitResult.CONTINUE;
+                }
+            });
+        }
     }
 
     public void shutdown() {

http://git-wip-us.apache.org/repos/asf/storm/blob/b02c6a2e/storm-core/test/jvm/org/apache/storm/blobstore/BlobStoreTest.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/blobstore/BlobStoreTest.java b/storm-core/test/jvm/org/apache/storm/blobstore/BlobStoreTest.java
index 5f6f50a..1d68326 100644
--- a/storm-core/test/jvm/org/apache/storm/blobstore/BlobStoreTest.java
+++ b/storm-core/test/jvm/org/apache/storm/blobstore/BlobStoreTest.java
@@ -17,16 +17,29 @@
  */
 package org.apache.storm.blobstore;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.storm.Config;
 import org.apache.storm.generated.AuthorizationException;
 import org.apache.storm.generated.KeyAlreadyExistsException;
 import org.apache.storm.generated.KeyNotFoundException;
 import org.apache.storm.generated.SettableBlobMeta;
-
 import org.apache.storm.security.auth.NimbusPrincipal;
 import org.apache.storm.security.auth.SingleUserPrincipal;
 import org.apache.storm.utils.Utils;
-import org.apache.commons.io.FileUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -34,24 +47,10 @@ import org.mockito.Mockito;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.security.auth.Subject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.UUID;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.Arrays;
-import java.util.ArrayList;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.spy;
 
 public class BlobStoreTest {
   private static final Logger LOG = LoggerFactory.getLogger(BlobStoreTest.class);
@@ -168,6 +167,20 @@ public class BlobStoreTest {
     testMultiple(initLocalFs());
   }
 
+  @Test
+  public void testDeleteAfterFailedCreate() throws Exception{
+    LocalFsBlobStore store = initLocalFs();
+
+    SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler
+            .WORLD_EVERYTHING);
+    AtomicOutputStream out = store.createBlob("test", metadata, null);
+      out.write(1);
+
+
+    store.deleteBlob("test",null);
+
+  }
+
   public Subject getSubject(String name) {
     Subject subject = new Subject();
     SingleUserPrincipal user = new SingleUserPrincipal(name);


Mime
View raw message