ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [09/30] ignite git commit: Clean up work directory for benchmarks.
Date Mon, 29 May 2017 07:18:25 GMT
Clean up work directory for benchmarks.


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

Branch: refs/heads/ignite-5075-pds
Commit: 7325232b120b0c11e7ab3089958637ec99472eb9
Parents: 49fcd2cc
Author: oleg-ostanin <oostanin@gridgain.com>
Authored: Thu May 25 19:32:09 2017 +0300
Committer: oleg-ostanin <oostanin@gridgain.com>
Committed: Thu May 25 19:32:09 2017 +0300

----------------------------------------------------------------------
 .../yardstick/IgniteBenchmarkArguments.java     | 11 ++++
 .../org/apache/ignite/yardstick/IgniteNode.java |  5 ++
 .../apache/ignite/yardstick/io/FileUtils.java   | 64 ++++++++++++++++++++
 3 files changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7325232b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
index ea48bf3..74413f5 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
@@ -101,6 +101,10 @@ public class IgniteBenchmarkArguments {
     private boolean storeEnabled;
 
     /** */
+    @Parameter(names = {"-cwd", "--cleanWorkDirectory"}, description = "Clean Work Directory")
+    private boolean cleanWorkDirectory = false;
+
+    /** */
     @Parameter(names = {"-wb", "--writeBehind"}, description = "Enable or disable writeBehind
for cache store")
     private boolean writeBehind;
 
@@ -422,6 +426,13 @@ public class IgniteBenchmarkArguments {
     }
 
     /**
+     * @return Flag for cleaning working directory.
+     */
+    public boolean cleanWorkDirectory() {
+        return cleanWorkDirectory;
+    }
+
+    /**
      * @return Description.
      */
     public String description() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/7325232b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java
index 029c0fd..6e25fc4 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java
@@ -32,8 +32,10 @@ import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
+import org.apache.ignite.yardstick.io.FileUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
@@ -83,6 +85,9 @@ public class IgniteNode implements BenchmarkServer {
 
         assert c != null;
 
+        if (args.cleanWorkDirectory())
+            FileUtils.cleanDirectory(U.workDirectory(c.getWorkDirectory(), c.getIgniteHome()));
+
         ApplicationContext appCtx = tup.get2();
 
         assert appCtx != null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/7325232b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/io/FileUtils.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/io/FileUtils.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/io/FileUtils.java
new file mode 100644
index 0000000..1bddc81
--- /dev/null
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/io/FileUtils.java
@@ -0,0 +1,64 @@
+/*
+ * 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.ignite.yardstick.io;
+
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.LinkedList;
+
+/**
+ * Utility class for working with files.
+ */
+public class FileUtils {
+    /**
+     * Clean directory.
+     *
+     * @param path path to directory.
+     */
+    public static void cleanDirectory(String path) throws IOException {
+        LinkedList<Path> paths = new LinkedList<>();
+
+        appendOrRemove(paths, Files.newDirectoryStream(Paths.get(path)));
+
+        while (!paths.isEmpty()) {
+            if (Files.newDirectoryStream(paths.getLast()).iterator().hasNext())
+                appendOrRemove(paths, Files.newDirectoryStream(paths.getLast()));
+            else
+                Files.delete(paths.removeLast());
+        }
+    }
+
+    /**
+     * Add path to the stack if path is directory, otherwise delete it.
+     *
+     * @param paths Stack of paths.
+     * @param ds Stream of paths.
+     */
+    private static void appendOrRemove(LinkedList<Path> paths, DirectoryStream<Path>
ds) throws IOException {
+        for (Path p : ds) {
+            if (Files.isDirectory(p))
+                paths.add(p);
+            else
+                Files.delete(p);
+        }
+    }
+}
+


Mime
View raw message