geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kh...@apache.org
Subject [32/35] geode git commit: first working filesize checks added new tests
Date Tue, 28 Mar 2017 16:47:00 GMT
first working filesize checks
added new tests


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

Branch: refs/heads/feature/GEODE-2420
Commit: 3aa0d806d77e8788c4b2b1237171a8a0664e376c
Parents: 99ebe3f
Author: Ken Howe <khowe@pivotal.io>
Authored: Fri Mar 17 16:07:28 2017 -0700
Committer: Ken Howe <khowe@pivotal.io>
Committed: Mon Mar 27 14:27:05 2017 -0700

----------------------------------------------------------------------
 .../cli/commands/ExportLogsCommand.java         | 42 ++++++++++++++------
 1 file changed, 30 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/3aa0d806/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
index d6da5e4..9b05569 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
@@ -29,7 +29,6 @@ import org.apache.geode.management.internal.cli.functions.ExportLogsFunction;
 import org.apache.geode.management.internal.cli.functions.SizeExportLogsFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
-import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.util.ExportLogsCacheWriter;
 import org.apache.geode.internal.logging.log4j.LogLevel;
 import org.apache.geode.management.internal.configuration.utils.ZipUtils;
@@ -97,18 +96,17 @@ public class ExportLogsCommand implements CommandMarker {
       @CliOption(key = CliStrings.EXPORT_LOGS__STATSONLY, unspecifiedDefaultValue = "false",
           specifiedDefaultValue = "true",
           help = CliStrings.EXPORT_LOGS__STATSONLY__HELP) boolean statsOnly,
+<<<<<<< HEAD
       @CliOption(key = CliStrings.EXPORT_LOGS__FILESIZELIMIT,
           unspecifiedDefaultValue = CliStrings.EXPORT_LOGS__FILESIZELIMIT__UNSPECIFIED_DEFAULT,
           specifiedDefaultValue = CliStrings.EXPORT_LOGS__FILESIZELIMIT__SPECIFIED_DEFAULT,
+=======
+      @CliOption(key = CliStrings.EXPORT_LOGS__FILESIZELIMIT, unspecifiedDefaultValue = "false",
+          specifiedDefaultValue = "true",
+>>>>>>> first working filesize checks
           help = CliStrings.EXPORT_LOGS__FILESIZELIMIT__HELP) String fileSizeLimit) {
     Result result = null;
-    GemFireCacheImpl cache = this.cache;
-    if (cache == null || cache.isClosed()) {
-      new Exception("KEN: cache is null").printStackTrace();
-      cache = GemFireCacheImpl.getInstance();
-    } else {
-      new Exception("KEN: cache has been created").printStackTrace();
-    }
+    GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
     try {
       Set<DistributedMember> targetMembers =
           CliUtil.findMembersIncludingLocators(groups, memberIds);
@@ -186,12 +184,16 @@ public class ExportLogsCommand implements CommandMarker {
       ZipUtils.zipDirectory(exportedLogsDir, exportedLogsZipFile);
       FileUtils.deleteDirectory(tempDir.toFile());
 
+<<<<<<< HEAD
 //      try {
         isFileSizeCheckEnabledAndWithinLimit(parseFileSizeLimit(fileSizeLimit),
             exportedLogsZipFile.toFile());
 //      } catch (IllegalArgumentException e) {
 //        return ResultBuilder.createUserErrorResult("TOO BIG: fileSizeLimit = " + fileSizeLimit);
 //      }
+=======
+      checkOverDiskSpaceThreshold(parseFileSizeLimit(fileSizeLimit), exportedLogsZipFile.toFile());
+>>>>>>> first working filesize checks
 
       result = ResultBuilder.createInfoResult(exportedLogsZipFile.toString());
     } catch (Exception ex) {
@@ -204,12 +206,28 @@ public class ExportLogsCommand implements CommandMarker {
     return result;
   }
 
-  protected static Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
+  /**
+   * Returns file size limit in bytes
+   */
+  int parseFileSizeLimit(String fileSizeLimit) {
+    if (StringUtils.isEmpty(fileSizeLimit)) {
+      return 0;
+    }
+
+    int sizeLimit = parseSize(fileSizeLimit);
+    int byteMultiplier = parseByteMultiplier(fileSizeLimit);
+
+    return sizeLimit * byteMultiplier;
   }
 
-  boolean isOverDiskSpaceThreshold() {
-    return false;
+  /**
+   * Throws IllegalArgumentException if file size is over fileSizeLimitBytes
+   */
+  void checkOverDiskSpaceThreshold(int fileSizeLimitBytes, File file) {
+    // TODO:GEODE-2420: warn user if exportedLogsZipFile size > threshold
+    if (FileUtils.sizeOf(file) > fileSizeLimitBytes) {
+      throw new IllegalArgumentException("TOO BIG"); // FileTooBigException
+    }
   }
 
   /**


Mime
View raw message