From aca80da38c3d86a40cc63d9a122f7d45258e4685 Mon Sep 17 00:00:00 2001 From: Jake Luciani Date: Fri, 3 Oct 2014 16:59:03 -0400 Subject: [PATCH] ninja add support for yaml profile as a url --- .../cassandra/stress/StressProfile.java | 19 ++++++++++--------- .../stress/settings/SettingsCommandUser.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java index b0a149c128..76642be12f 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); 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 a6dad3536b..4e2997fa37 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");