Merge branch 'cassandra-2.1' into trunk

This commit is contained in:
Jake Luciani 2014-10-03 16:59:30 -04:00
commit 50c5da991c
2 changed files with 20 additions and 10 deletions

View File

@ -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);

View File

@ -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");