1 package at.ac.tuwien.lsdc;
4 import java.io.IOException;
5 import java.util.LinkedList;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 import at.ac.tuwien.lsdc.sched.AbstractScheduler;
11 import at.ac.tuwien.lsdc.sched.SchedulerA;
12 import at.ac.tuwien.lsdc.sched.SchedulerB;
13 import at.ac.tuwien.lsdc.sched.SchedulerC;
14 import at.ac.tuwien.lsdc.types.Application;
15 import at.ac.tuwien.lsdc.types.ScenarioData;
16 import at.ac.tuwien.lsdc.types.SchedulerEvent;
17 import at.ac.tuwien.lsdc.types.SchedulerType;
18 import at.ac.tuwien.lsdc.util.CSVParser;
19 import at.ac.tuwien.lsdc.util.CSVScenariosLogger;
22 * Read config (command line properties) and start Scheduler-Simulation.
24 public class SchedSimulator {
26 private static final String USAGE = "USAGE";
28 private static final Logger log = LoggerFactory
29 .getLogger(SchedSimulator.class);
31 private static SchedulerType schedulerType;
32 private static File inputFile;
33 private static File logFile;
34 private static File scenarioLogFile;
36 public static void main(String[] args) throws Exception {
37 if (args.length == 4) {
38 parseCommandLineArgs(args);
39 } else if (args.length == 1) {
40 String[] newArgs = args[0].split(" ");
41 if (newArgs.length == 4) {
42 parseCommandLineArgs(newArgs);
48 LinkedList<Application> apps = CSVParser.parseFile(inputFile);
49 AbstractScheduler scheduler;
50 switch (schedulerType) {
52 scheduler = new SchedulerA();
54 scheduler = new SchedulerB();
56 scheduler = new SchedulerC();
59 ScenarioData data = scheduler.initAndStart(apps);
60 // CSVScenariosLogger logger = new
61 // CSVScenariosLogger("out_scen"+scenario+"sched"+schedulerType+".csv");
62 // logger.appendScenarioData(data);
65 private static void parseCommandLineArgs(String[] args) {
66 String schedulerTypeStr = args[0];
67 String inputFileStr = args[1];
68 String logFileStr = args[2];
69 String scenarioLogFileStr = args[3];
71 schedulerType = SchedulerType.valueOf(schedulerTypeStr);
72 inputFile = new File(inputFileStr);
73 if (!inputFile.canRead())
74 throw new IOException("Can not read input file");
75 logFile = new File(logFileStr);
76 boolean logFileOK = false;
77 if ( logFile.canWrite() ) {
80 else if (!logFile.exists()) {
85 throw new IOException("Can not write to log file");
86 boolean fileWriteOK = false;
87 scenarioLogFile = new File(scenarioLogFileStr);
88 if (scenarioLogFile.exists()) {
89 fileWriteOK = scenarioLogFile.canWrite();
90 scenarioLogFile.delete();
91 scenarioLogFile.createNewFile();
93 scenarioLogFile.createNewFile();
97 throw new IOException("Can not write to Scenario Log File "
98 + scenarioLogFileStr);
99 } catch (Exception e) {
106 private static void createLogFile() {