From 5abbdec640fb9c1a04c33f2a84806563a79db3ed Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Mon, 20 May 2013 13:36:23 +0200 Subject: [PATCH] Some refactorings --- .gitignore | 3 ++ README.txt | 14 ++++++++++ build.xml | 11 ++++++-- .../tutormeeting-2013-05-03.txt | 0 src/at/ac/tuwien/lsdc/JobGenerator.java | 17 ++++++----- src/at/ac/tuwien/lsdc/SchedSimulator.java | 28 +++++++++++++------ 6 files changed, 56 insertions(+), 17 deletions(-) rename tutormeeting-2013-05-03.txt => docs/tutormeeting-2013-05-03.txt (100%) diff --git a/.gitignore b/.gitignore index 4b4256a..1ca90e8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ ### software development: ignore generated stuff ### #*.[oa] *.class +logs +scenarios #*.pyc #build/* @@ -15,6 +17,7 @@ .classpath .project .settings/* +.metadata #gen/* #bin/* target/* diff --git a/README.txt b/README.txt index 8c74456..78177c5 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,17 @@ +Compile project + ant compile + +Compile + run predefined generator for scenario A + ant run-generator-A + +Compile + run predefined generator for scenario B (not yet implemented) + ant run-generator-B + +Compile + run predefined generator for scenario C (not yet implemented) + ant run-generator-C + + + "make clean" rm -rf target diff --git a/build.xml b/build.xml index 5c4e095..a1e67e7 100644 --- a/build.xml +++ b/build.xml @@ -19,6 +19,8 @@ + + @@ -63,13 +65,18 @@ + - + - + + + + diff --git a/tutormeeting-2013-05-03.txt b/docs/tutormeeting-2013-05-03.txt similarity index 100% rename from tutormeeting-2013-05-03.txt rename to docs/tutormeeting-2013-05-03.txt diff --git a/src/at/ac/tuwien/lsdc/JobGenerator.java b/src/at/ac/tuwien/lsdc/JobGenerator.java index e56dd83..60460a2 100644 --- a/src/at/ac/tuwien/lsdc/JobGenerator.java +++ b/src/at/ac/tuwien/lsdc/JobGenerator.java @@ -14,7 +14,7 @@ import au.com.bytecode.opencsv.CSVWriter; public class JobGenerator { private static final Logger log = LoggerFactory .getLogger(JobGenerator.class); - private static final String USAGE = "JobGenerator needs exactly 3 parameters: Szenario, count, targetFile"; + private static final String USAGE = "JobGenerator needs exactly 3 parameters: scenario, count, targetFile"; private static ScenarioType scenario; private static int count; @@ -22,6 +22,8 @@ public class JobGenerator { private static int numWBA; private static int numHPA; + + private static Random rand = new Random(); private static CSVWriter writer; @@ -36,6 +38,9 @@ public class JobGenerator { log.info(USAGE); System.exit(1); } + } else { + log.info(USAGE); + System.exit(1); } writer = new CSVWriter(new FileWriter(targetFile), ';', CSVWriter.NO_QUOTE_CHARACTER); @@ -96,8 +101,7 @@ public class JobGenerator { } private static int randomInt(int low, int high) { - Random r = new Random(); - return (r.nextInt(high - low) + low); + return (rand.nextInt(high - low) + low); } private static void generateWBA(int timestamp) { @@ -111,16 +115,15 @@ public class JobGenerator { private static void generateHPA(int timestamp) { int size = randomInt(150, 500); - int ram = randomInt(100, 400); - int cpu = randomInt(100, 700); + int ram = randomInt(100, 700); + int cpu = randomInt(100, 400); int duration = randomInt(1, 50); numHPA++; writeApplication(timestamp,size,ram,cpu,duration); } private static void generateWBAorHPA(int timestamp) { - Random r = new Random(); - boolean wba = r.nextBoolean(); + boolean wba = rand.nextBoolean(); if (wba && (numWBA < (count / 2))) { generateWBA(timestamp); } else if (numHPA < (count / 2)) { diff --git a/src/at/ac/tuwien/lsdc/SchedSimulator.java b/src/at/ac/tuwien/lsdc/SchedSimulator.java index d334013..ee741f8 100644 --- a/src/at/ac/tuwien/lsdc/SchedSimulator.java +++ b/src/at/ac/tuwien/lsdc/SchedSimulator.java @@ -24,15 +24,15 @@ import at.ac.tuwien.lsdc.util.CSVParser; */ public class SchedSimulator { - private static final String USAGE = "USAGE"; + private static final String USAGE = "SchedSimulator needs exactly 5 parameters: scenario, scheduler, inputFile, logFilePath, schedulerLogPath"; private static final Logger log = LoggerFactory .getLogger(SchedSimulator.class); - private static SchedulerType schedulerType; private static ScenarioType scenario; + private static SchedulerType schedulerType; private static File inputFile; - private static File logfile; + private static File generalLog; private static File schedulerLog; public static void main(String[] args) throws Exception { @@ -46,6 +46,9 @@ public class SchedSimulator { log.info(USAGE); System.exit(1); } + } else { + log.info(USAGE); + System.exit(1); } LinkedList apps = CSVParser.parseFile(inputFile); Collections.sort(apps); @@ -59,11 +62,20 @@ public class SchedSimulator { scheduler = new SchedulerC(schedulerLog,schedulerType,scenario); } ScenarioData data = scheduler.initAndStart(apps); - CSVLogger logger = new CSVLogger(logfile); + CSVLogger logger = new CSVLogger(generalLog); logger.logScenarioData(data); logger.close(); } + /** + * Commandline arguments parsed (mandatory): + * - type of scenario + * - type of scheduler + * - scenario input file with applications + * - general output file for all schedulers + * - specific output file for this scheduler/scenario combination + * @param args the command line arguments to parse + */ private static void parseCommandLineArgs(String[] args) { String scenarioStr = args[0]; String schedulerTypeStr = args[1]; @@ -76,13 +88,13 @@ public class SchedSimulator { inputFile = new File(inputFileStr); if (!inputFile.canRead()) throw new IOException("Can not read input file"); - logfile = new File(schedulerLogStr); + generalLog = new File(schedulerLogStr); boolean logFileOK = false; - if ( logfile.canWrite() ) { + if ( generalLog.canWrite() ) { logFileOK = true; } - else if (!logfile.exists()) { - logfile.createNewFile(); + else if (!generalLog.exists()) { + generalLog.createNewFile(); logFileOK = true; } if (!logFileOK) -- 2.43.0