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 au.com.bytecode.opencsv.CSVWriter;
13 public class JobGenerator {
14 private static final Logger log = LoggerFactory
15 .getLogger(JobGenerator.class);
16 private static final String USAGE = "JobGenerator needs exactly 3 parameters: Szenario, count, targetFile";
18 private enum ScenarioType {
22 private static ScenarioType scenario;
23 private static int count;
24 private static File targetFile;
26 private static int numWBA;
27 private static int numHPA;
29 private static CSVWriter writer;
31 public static void main(String[] args) throws Exception {
32 if (args.length == 3) {
33 doArgumentHandling(args);
34 } else if (args.length == 1) {
35 String[] newArgs = args[0].split(" ");
36 if (newArgs.length == 3) {
37 doArgumentHandling(newArgs);
43 writer = new CSVWriter(new FileWriter(targetFile), ';',
44 CSVWriter.NO_QUOTE_CHARACTER);
47 for (int i = 0; i < count; i++) {
48 timestamp = timestamp + randomInt(1, 10);
51 generateWBA(timestamp);
54 generateHPA(timestamp);
57 generateWBAorHPA(timestamp);
61 log.info("Created CSV " + targetFile.getName() + " for Scenario "
62 + scenario.toString());
63 log.info("Total: " + (numWBA + numHPA) + " Expected: " + count);
64 log.info("WBA: " + numWBA + " HPA: " + numHPA);
68 private static void doArgumentHandling(String[] args) {
69 log.info("handling args");
70 String scenarioStr = args[0];
71 String countStr = args[1];
72 String targetFileStr = args[2];
73 scenario = ScenarioType.valueOf(scenarioStr);
75 boolean fileWriteOK = false;
76 count = Integer.parseInt(countStr);
77 targetFile = new File(targetFileStr);
78 if (targetFile.exists()) {
79 fileWriteOK = targetFile.canWrite();
81 targetFile.createNewFile();
83 targetFile.createNewFile();
87 throw new IOException("Can not write to File " + targetFileStr);
88 } catch (Exception e) {
95 private static void writeCSVHeader() {
96 String[] header = new String[] { "Timestamp", "Size", "RAM", "CPU",
98 writer.writeNext(header);
101 private static int randomInt(int low, int high) {
102 Random r = new Random();
103 return (r.nextInt(high - low) + low);
106 private static void generateWBA(int timestamp) {
107 int size = randomInt(20, 100);
108 int ram = randomInt(30, 50);
109 int cpu = randomInt(50, 100);
110 int duration = randomInt(1, 50);
112 writeApplication(timestamp,size,ram,cpu,duration);
115 private static void generateHPA(int timestamp) {
116 int size = randomInt(150, 500);
117 int ram = randomInt(100, 400);
118 int cpu = randomInt(100, 700);
119 int duration = randomInt(1, 50);
121 writeApplication(timestamp,size,ram,cpu,duration);
124 private static void generateWBAorHPA(int timestamp) {
125 Random r = new Random();
126 boolean wba = r.nextBoolean();
127 if (wba && (numWBA < (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);