1 package at.ac.tuwien.lsdc;
4 import java.io.IOException;
5 import java.util.Collections;
6 import java.util.LinkedList;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
11 import at.ac.tuwien.lsdc.sched.AbstractScheduler;
12 import at.ac.tuwien.lsdc.sched.SchedulerA;
13 import at.ac.tuwien.lsdc.sched.SchedulerB;
14 import at.ac.tuwien.lsdc.sched.SchedulerC;
15 import at.ac.tuwien.lsdc.types.Application;
16 import at.ac.tuwien.lsdc.types.ScenarioData;
17 import at.ac.tuwien.lsdc.types.ScenarioType;
18 import at.ac.tuwien.lsdc.types.SchedulerType;
19 import at.ac.tuwien.lsdc.util.CSVLogger;
20 import at.ac.tuwien.lsdc.util.CSVParser;
23 * Read config (command line properties) and start Scheduler-Simulation.
25 public class SchedSimulator {
27 private static final String USAGE = "USAGE";
29 private static final Logger log = LoggerFactory
30 .getLogger(SchedSimulator.class);
32 private static SchedulerType schedulerType;
33 private static ScenarioType scenario;
34 private static File inputFile;
35 private static File logfile;
36 private static File schedulerLog;
38 public static void main(String[] args) throws Exception {
39 if (args.length == 5) {
40 parseCommandLineArgs(args);
41 } else if (args.length == 1) {
42 String[] newArgs = args[0].split(" ");
43 if (newArgs.length == 5) {
44 parseCommandLineArgs(newArgs);
50 LinkedList<Application> apps = CSVParser.parseFile(inputFile);
51 Collections.sort(apps);
52 AbstractScheduler scheduler;
53 switch (schedulerType) {
55 scheduler = new SchedulerA(schedulerLog,schedulerType,scenario);
57 scheduler = new SchedulerB(schedulerLog,schedulerType,scenario);
59 scheduler = new SchedulerC(schedulerLog,schedulerType,scenario);
61 ScenarioData data = scheduler.initAndStart(apps);
62 CSVLogger logger = new CSVLogger(logfile);
63 logger.logScenarioData(data);
67 private static void parseCommandLineArgs(String[] args) {
68 String scenarioStr = args[0];
69 String schedulerTypeStr = args[1];
70 String inputFileStr = args[2];
71 String schedulerLogStr = args[3];
72 String scenarioLogFileStr = args[4];
74 scenario = ScenarioType.valueOf(scenarioStr);
75 schedulerType = SchedulerType.valueOf(schedulerTypeStr);
76 inputFile = new File(inputFileStr);
77 if (!inputFile.canRead())
78 throw new IOException("Can not read input file");
79 logfile = new File(schedulerLogStr);
80 boolean logFileOK = false;
81 if ( logfile.canWrite() ) {
84 else if (!logfile.exists()) {
85 logfile.createNewFile();
89 throw new IOException("Can not write to scheduler log file");
90 boolean fileWriteOK = false;
91 schedulerLog = new File(scenarioLogFileStr);
92 if (schedulerLog.exists()) {
93 fileWriteOK = schedulerLog.canWrite();
94 schedulerLog.delete();
95 schedulerLog.createNewFile();
97 schedulerLog.createNewFile();
101 throw new IOException("Can not write to Scenario Log File "
102 + scenarioLogFileStr);
103 } catch (Exception e) {