cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/2] git commit: ninja add support for yaml profile as a url
Date Fri, 03 Oct 2014 20:59:41 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk ba6bc8dd3 -> 50c5da991


ninja add support for yaml profile as a url


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

Branch: refs/heads/trunk
Commit: aca80da38c3d86a40cc63d9a122f7d45258e4685
Parents: 4539237
Author: Jake Luciani <jake@apache.org>
Authored: Fri Oct 3 16:59:03 2014 -0400
Committer: Jake Luciani <jake@apache.org>
Committed: Fri Oct 3 16:59:03 2014 -0400

----------------------------------------------------------------------
 .../apache/cassandra/stress/StressProfile.java   | 19 ++++++++++---------
 .../stress/settings/SettingsCommandUser.java     | 11 ++++++++++-
 2 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/aca80da3/tools/stress/src/org/apache/cassandra/stress/StressProfile.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java
index b0a149c..76642be 100644
--- a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java
+++ b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java
@@ -68,11 +68,9 @@ import org.yaml.snakeyaml.Yaml;
 import org.yaml.snakeyaml.constructor.Constructor;
 import org.yaml.snakeyaml.error.YAMLException;
 
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOError;
-import java.io.IOException;
-import java.io.Serializable;
+import java.io.*;
+import java.net.URI;
+import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -524,17 +522,20 @@ public class StressProfile implements Serializable
         }
     }
 
-    public static StressProfile load(File file) throws IOError
+    public static StressProfile load(URI file) throws IOError
     {
         try
         {
-            byte[] profileBytes = Files.readAllBytes(Paths.get(file.toURI()));
-
             Constructor constructor = new Constructor(StressYaml.class);
 
             Yaml yaml = new Yaml(constructor);
 
-            StressYaml profileYaml = yaml.loadAs(new ByteArrayInputStream(profileBytes),
StressYaml.class);
+            InputStream yamlStream = file.toURL().openStream();
+
+            if (yamlStream.available() == 0)
+                throw new IOException("Unable to load yaml file from: "+file);
+
+            StressYaml profileYaml = yaml.loadAs(yamlStream, StressYaml.class);
 
             StressProfile profile = new StressProfile();
             profile.init(profileYaml);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/aca80da3/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java
----------------------------------------------------------------------
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 a6dad35..4e2997f 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 @@ package org.apache.cassandra.stress.settings;
 
 
 import java.io.File;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -58,7 +59,15 @@ public class SettingsCommandUser extends SettingsCommand
 
         clustering = options.clustering.get();
         ratios = options.ops.ratios();
-        profile = StressProfile.load(new File(options.profile.value()));
+
+        String yamlPath = options.profile.value();
+        File yamlFile = new File(yamlPath);
+        if (yamlFile.exists())
+        {
+            yamlPath = "file:///" + yamlFile.getAbsolutePath();
+        }
+
+        profile = StressProfile.load(URI.create(yamlPath));
 
         if (ratios.size() == 0)
             throw new IllegalArgumentException("Must specify at least one command with a
non-zero ratio");


Mime
View raw message