Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ninja add support for yaml profile as a url
  • Loading branch information
tjake committed Oct 3, 2014
1 parent 4539237 commit aca80da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
19 changes: 10 additions & 9 deletions tools/stress/src/org/apache/cassandra/stress/StressProfile.java
Expand Up @@ -68,11 +68,9 @@
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;
Expand Down Expand Up @@ -524,17 +522,20 @@ static Generator getGenerator(final String name, final DataType type, GeneratorC
}
}

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);
Expand Down
Expand Up @@ -22,6 +22,7 @@


import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -58,7 +59,15 @@ public SettingsCommandUser(Options options)

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");
Expand Down

0 comments on commit aca80da

Please sign in to comment.