Skip to content

Commit

Permalink
Updated read proprties file to load from given path.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhigham committed Dec 15, 2015
1 parent 7f9482d commit a2ef9e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
16 changes: 13 additions & 3 deletions FlexiMonkey/src/dice/eu/fleximonkey/CommandLineParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import java.io.IOException;

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -81,13 +82,20 @@ public static void main(String[] args) {
diskstress.setArgName("host,vmpassword,memeorytotal,loops,sshkeypath");
options.addOption(diskstress);

options.addOption("f", "file", true, "Load from properties file");
//test loading
//options.addOption("f", "file", true, "Load from properties file");
Option loadfile = new Option("f", "file", true, "Load from properties file");
// Set maximum of 1 arguments
loadfile.setArgs(1);
loadfile.setArgName("filepath");
options.addOption(loadfile);

options.addOption("h", "help", false, "Shows help");

//Checks what user has entered as first parameter and checks available options
try {
CommandLine commandLine = parser.parse(options, args);
//log.log( Level.INFO, "Looking for command line option");
LoggerWrapper.myLogger.info("Looking for command line option");

if (commandLine.hasOption("r")) {
//Executes random Stop VM on FCO platform
Expand All @@ -104,9 +112,11 @@ public static void main(String[] args) {
}

if (commandLine.hasOption("f")) {
String[] argument = commandLine.getOptionValues("f");
String filepath = argument[0];
//Reads config file for options
ReadConfig readconfigfile = new ReadConfig();
readconfigfile.readconfig();
readconfigfile.readconfig(filepath);
LoggerWrapper.myLogger.info( "Reading config file");


Expand Down
45 changes: 12 additions & 33 deletions FlexiMonkey/src/dice/eu/fleximonkey/FlexiMonkeyReadConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dice.eu.fleximonkey;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -24,9 +25,9 @@ public class FlexiMonkeyReadConfig {
String sshkeypath="";
String iperfserver ="";
String loops ="";
InputStream inputStream;

public String getPropValues() throws IOException {

public String getPropValues(String filepath) throws IOException {
@SuppressWarnings("unused")
LoggerWrapper loggerWrapper = null;
try {
Expand All @@ -40,45 +41,23 @@ public String getPropValues() throws IOException {
}
try {
LoggerWrapper.myLogger.info("Loading values from config.properties file");

Properties prop = new Properties();
String propFileName = "config.properties";

inputStream = getClass().getClassLoader().getResourceAsStream(
propFileName);

if (inputStream != null) {
prop.load(inputStream);
} else {
String propFileName = filepath;
InputStream input = new FileInputStream(propFileName);

prop.load(input);

{
prop.load(input);
LoggerWrapper.myLogger.severe("Exception in reading proprties file ");

throw new FileNotFoundException("property file '"
+ propFileName + "' not found in the classpath");
}
LoggerWrapper.myLogger.info("Getting values from config file");

// get the property values from the config file
action = prop.getProperty("action");
cores = prop.getProperty("cores");
time = prop.getProperty("time");
vmpassword = prop.getProperty("password");
host = prop.getProperty("host");
cloudapiurl = prop.getProperty("cloudapiurl");
cloudusername = prop.getProperty("cloudusername");
cloudpassword = prop.getProperty("cloudpassword");
cloudUUID = prop.getProperty("cloudUUID");
memorytesterloops = prop.getProperty("memorytesterloops");
service = prop.getProperty("service");
filepath = prop.getProperty("filepath");
sshkeypath = prop.getProperty("sshkeypath");
loops = prop.getProperty("loops");
} catch (Exception e) {
LoggerWrapper.myLogger.severe("Exception in reading proprties: " + e);
} finally {
//Close input
inputStream.close();
}
//return the values from the file

return result;
}
}
}
4 changes: 2 additions & 2 deletions FlexiMonkey/src/dice/eu/fleximonkey/ReadConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

public class ReadConfig {

public void readconfig(){
public void readconfig(String filepath){
@SuppressWarnings("unused")
LoggerWrapper loggerWrapper = null;
try {
Expand All @@ -17,7 +17,7 @@ public void readconfig(){
}
FlexiMonkeyReadConfig properties = new FlexiMonkeyReadConfig();
try {
properties.getPropValues();
properties.getPropValues(filepath);
} catch (IOException e) {
LoggerWrapper.myLogger.severe("Error getting file values " + e.toString());
}
Expand Down

0 comments on commit a2ef9e2

Please sign in to comment.