1 package at.ac.tuwien.lsdc;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.Random;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
11 import at.ac.tuwien.lsdc.types.ScenarioType;
12 import au.com.bytecode.opencsv.CSVWriter;
14 public class JobGenerator {
15 private static final Logger log = LoggerFactory
16 .getLogger(JobGenerator.class);
17 private static final String USAGE = "JobGenerator needs exactly 3 parameters: scenario, count, targetFile";
19 private static ScenarioType scenario;
20 private static int count;
21 private static File targetFile;
23 private static int numWBA;
24 private static int numHPA;
26 private static Random rand = new Random();
28 private static CSVWriter writer;
30 public static void main(String[] args) throws Exception {
31 if (args.length == 3) {
32 doArgumentHandling(args);
33 } else if (args.length == 1) {
34 String[] newArgs = args[0].split(" ");
35 if (newArgs.length == 3) {
36 doArgumentHandling(newArgs);
45 writer = new CSVWriter(new FileWriter(targetFile), ';',
46 CSVWriter.NO_QUOTE_CHARACTER);
49 for (int i = 0; i < count; i++) {
50 timestamp = timestamp + randomInt(0, 2);
53 generateWBA(timestamp);
56 generateHPA(timestamp);
59 generateWBAorHPA(timestamp);
63 log.info("Created CSV " + targetFile.getName() + " for Scenario "
64 + scenario.toString());
65 log.info("Total: " + (numWBA + numHPA) + " Expected: " + count);
66 log.info("WBA: " + numWBA + " HPA: " + numHPA);
70 private static void doArgumentHandling(String[] args) {
71 log.info("handling args");
72 String scenarioStr = args[0];
73 String countStr = args[1];
74 String targetFileStr = args[2];
76 scenario = ScenarioType.valueOf(scenarioStr);
77 boolean fileWriteOK = false;
78 count = Integer.parseInt(countStr);
79 targetFile = new File(targetFileStr);
80 if (targetFile.exists()) {
81 fileWriteOK = targetFile.canWrite();
83 targetFile.createNewFile();
85 targetFile.createNewFile();
89 throw new IOException("Can not write to File " + targetFileStr);
90 } catch (Exception e) {
97 private static void writeCSVHeader() {
98 String[] header = new String[] { "Timestamp", "Size", "RAM", "CPU",
100 writer.writeNext(header);
103 private static int randomInt(int low, int high) {
104 return (rand.nextInt(high - low) + low);
107 private static void generateWBA(int timestamp) {
108 int size = randomInt(20, 100);
109 int ram = randomInt(30, 50);
110 int cpu = randomInt(50, 100);
111 int duration = randomInt(10, 100) + 75;
113 writeApplication(timestamp,size,ram,cpu,duration);
116 private static void generateHPA(int timestamp) {
117 int size = randomInt(150, 500);
118 int ram = randomInt(100, 700);
119 int cpu = randomInt(100, 400);
120 int duration = randomInt(10, 100) + 75;
122 writeApplication(timestamp,size,ram,cpu,duration);
125 private static void generateWBAorHPA(int timestamp) {
126 boolean wba = rand.nextBoolean();
127 if ((wba && (numWBA < (count / 2))) || (numHPA == (count / 2))) {
128 generateWBA(timestamp);
129 } else if (numHPA < (count / 2)) {
130 generateHPA(timestamp);
134 private static void writeApplication(int timestamp, int size, int ram,
135 int cpu, int duration) {
136 String[] app = new String[] { String.valueOf(timestamp),
137 String.valueOf(size), String.valueOf(ram), String.valueOf(cpu),
138 String.valueOf(duration) };
139 writer.writeNext(app);