From 35095c04ac6951f9e2c9d99981580f040c7a9f37 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Sat, 28 Apr 2018 19:35:17 +0200 Subject: [PATCH 1/2] Fix for CASSANDRA-14425 Fix affects 2 parts: - `SettingsCommandUser.java` where there is a check, is the file exists - `Stress.java` where error handling happens. The main reason for this is that when file is loaded from URI, then the caught exception is wrapped into generic `IOError` exception that isn't handled explicitly. --- .../src/org/apache/cassandra/stress/Stress.java | 13 +++++++++++++ .../stress/settings/SettingsCommandUser.java | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/stress/src/org/apache/cassandra/stress/Stress.java b/tools/stress/src/org/apache/cassandra/stress/Stress.java index 3c0fa96fe274..bba2ef9f8535 100644 --- a/tools/stress/src/org/apache/cassandra/stress/Stress.java +++ b/tools/stress/src/org/apache/cassandra/stress/Stress.java @@ -26,6 +26,7 @@ import org.apache.cassandra.stress.util.MultiResultLogger; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.WindowsTimer; +import org.apache.commons.lang3.exception.ExceptionUtils; public final class Stress { @@ -87,6 +88,18 @@ private static int run(String[] arguments) printHelpMessage(); return 1; } + catch (Throwable e) + { + Throwable rc = ExceptionUtils.getRootCause(e); + if (rc instanceof FileNotFoundException) + { + e.printStackTrace(); + System.out.printf("File '%s' doesn't exist!!%n", rc.getMessage()); + printHelpMessage(); + return 1; + } + throw e; + } MultiResultLogger logout = settings.log.getOutput(); diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java index fd34d7450d00..809b4e59084d 100644 --- a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java +++ b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java @@ -22,6 +22,7 @@ import java.io.File; +import java.io.FileNotFoundException; import java.net.URI; import java.util.Arrays; import java.util.Collections; @@ -73,7 +74,17 @@ public SettingsCommandUser(Options options) for (String curYamlPath : yamlPaths) { File yamlFile = new File(curYamlPath); - StressProfile profile = StressProfile.load(yamlFile.exists() ? yamlFile.toURI() : URI.create(curYamlPath)); + URI yamlURI; + if (yamlFile.exists()) { + yamlURI = yamlFile.toURI(); + } else { + yamlURI = URI.create(curYamlPath); + String uriScheme = yamlURI.getScheme(); + if (uriScheme == null || "file".equals(uriScheme)) { + throw new IllegalArgumentException("File '" + yamlURI.getPath() + "' doesn't exist."); + } + } + StressProfile profile = StressProfile.load(yamlURI); String specName = profile.specName; if (default_profile_name == null) {default_profile_name=specName;} //first file is default if (profiles.containsKey(specName)) From b3faaae61f4e745a89365dea34c1b5d0b97313d4 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Sat, 28 Apr 2018 21:03:56 +0200 Subject: [PATCH 2/2] remove not necessary debug prints --- tools/stress/src/org/apache/cassandra/stress/Stress.java | 3 +-- .../apache/cassandra/stress/settings/SettingsCommandUser.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/stress/src/org/apache/cassandra/stress/Stress.java b/tools/stress/src/org/apache/cassandra/stress/Stress.java index bba2ef9f8535..1fd808fd081b 100644 --- a/tools/stress/src/org/apache/cassandra/stress/Stress.java +++ b/tools/stress/src/org/apache/cassandra/stress/Stress.java @@ -93,8 +93,7 @@ private static int run(String[] arguments) Throwable rc = ExceptionUtils.getRootCause(e); if (rc instanceof FileNotFoundException) { - e.printStackTrace(); - System.out.printf("File '%s' doesn't exist!!%n", rc.getMessage()); + System.out.printf("File '%s' doesn't exist!%n", rc.getMessage()); printHelpMessage(); return 1; } diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java index 809b4e59084d..cbf8a3a3be50 100644 --- a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java +++ b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java @@ -81,7 +81,7 @@ public SettingsCommandUser(Options options) yamlURI = URI.create(curYamlPath); String uriScheme = yamlURI.getScheme(); if (uriScheme == null || "file".equals(uriScheme)) { - throw new IllegalArgumentException("File '" + yamlURI.getPath() + "' doesn't exist."); + throw new IllegalArgumentException("File '" + yamlURI.getPath() + "' doesn't exist!"); } } StressProfile profile = StressProfile.load(yamlURI);