From 2b92c98c8e0c7c24f6933a46d85fca30707e5d51 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Tue, 14 May 2013 12:48:23 +0200 Subject: [PATCH] implemented main logic of JobGenerator (add header to file,decide which type applications to create,..) --- src/at/ac/tuwien/lsdc/JobGenerator.java | 96 +++++++++++++++++++++---- 1 file changed, 84 insertions(+), 12 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/JobGenerator.java b/src/at/ac/tuwien/lsdc/JobGenerator.java index 121362d..39d8812 100644 --- a/src/at/ac/tuwien/lsdc/JobGenerator.java +++ b/src/at/ac/tuwien/lsdc/JobGenerator.java @@ -1,33 +1,72 @@ package at.ac.tuwien.lsdc; import java.io.File; +import java.io.FileWriter; import java.io.IOException; +import java.util.Random; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import au.com.bytecode.opencsv.CSVWriter; + public class JobGenerator { - private static final Logger log = LoggerFactory.getLogger(JobGenerator.class); + private static final Logger log = LoggerFactory + .getLogger(JobGenerator.class); private static final String USAGE = "JobGenerator needs exactly 3 parameters: Szenario, count, targetFile"; - - private enum ScenarioType { A, B, C }; - + + private enum ScenarioType { + A, B, C + }; + private static ScenarioType scenario; private static int count; private static File targetFile; - + + private static int numWBA; + private static int numHPA; + + private static CSVWriter writer; public static void main(String[] args) throws Exception { - System.out.println("args: " + args + " len: " + args.length); - if (args.length != 3) { - log.info(USAGE); - System.exit(1); + if (args.length == 3) { + doArgumentHandling(args); + } else if (args.length == 1) { + String[] newArgs = args[0].split(" "); + if (newArgs.length == 3) { + doArgumentHandling(newArgs); + } else { + log.info(USAGE); + System.exit(1); + } } - log.info("Generate CSV with..."); - doArgumentHandling(args); + writer = new CSVWriter(new FileWriter(targetFile), ';', + CSVWriter.NO_QUOTE_CHARACTER); + writeCSVHeader(); + int timestamp = 1; + for (int i = 0; i < count;i++) { + timestamp = timestamp + calculateNextTimestamp(); + switch (scenario) { + case A: + generateWBA(timestamp); + break; + case B: + generateHPA(timestamp); + break; + case C: + generateWBAorHPA(timestamp); + break; + } + } + log.info("Created CSV " + targetFile.getName() + " for Scenario " + + scenario.toString()); + log.info("Total: " + (numWBA + numHPA) + " Expected: " + count); + log.info("WBA: " + numWBA + " HPA: " + numHPA); + writer.close(); } - + private static void doArgumentHandling(String[] args) { + log.info("handling args"); String scenarioStr = args[0]; String countStr = args[1]; String targetFileStr = args[2]; @@ -38,6 +77,8 @@ public class JobGenerator { targetFile = new File(targetFileStr); if (targetFile.exists()) { fileWriteOK = targetFile.canWrite(); + targetFile.delete(); + targetFile.createNewFile(); } else { targetFile.createNewFile(); fileWriteOK = true; @@ -50,4 +91,35 @@ public class JobGenerator { System.exit(1); } } + + private static void writeCSVHeader() { + String[] header = new String[] { "Timestamp", "Size", "RAM", "CPU", + "Duration" }; + writer.writeNext(header); + } + + private static int calculateNextTimestamp() { + // TODO: insert more random logic here ;) + return 1; + } + + private static void generateWBA(int timestamp) { + //TODO: generate Application & write to CSV + numWBA++; + } + + private static void generateHPA(int timestamp) { + //TODO: generate Application & write to CSV + numHPA++; + } + + private static void generateWBAorHPA(int timestamp) { + Random r = new Random(); + boolean wba = r.nextBoolean(); + if (wba && (numWBA < (count / 2))) { + generateWBA(timestamp); + } else if (numHPA < (count / 2)) { + generateHPA(timestamp); + } + } } -- 2.43.0