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 = "SchedSimulator needs exactly 5 parameters: scenario, scheduler, inputFile, logFilePath, schedulerLogPath";
29 private static final Logger log = LoggerFactory
30 .getLogger(SchedSimulator.class);
32 private static ScenarioType scenario;
33 private static SchedulerType schedulerType;
34 private static File inputFile;
35 private static File generalLog;
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);
53 LinkedList<Application> apps = CSVParser.parseFile(inputFile);
54 Collections.sort(apps);
55 AbstractScheduler scheduler;
56 switch (schedulerType) {
58 scheduler = new SchedulerA(schedulerLog,schedulerType,scenario);
60 scheduler = new SchedulerB(schedulerLog,schedulerType,scenario);
62 scheduler = new SchedulerC(schedulerLog,schedulerType,scenario);
64 ScenarioData data = scheduler.initAndStart(apps);
65 CSVLogger logger = new CSVLogger(generalLog);
66 logger.logScenarioData(data);
71 * Commandline arguments parsed (mandatory):
74 * - scenario input file with applications
75 * - general output file for all schedulers
76 * - specific output file for this scheduler/scenario combination
77 * @param args the command line arguments to parse
79 private static void parseCommandLineArgs(String[] args) {
80 String scenarioStr = args[0];
81 String schedulerTypeStr = args[1];
82 String inputFileStr = args[2];
83 String schedulerLogStr = args[3];
84 String scenarioLogFileStr = args[4];
86 scenario = ScenarioType.valueOf(scenarioStr);
87 schedulerType = SchedulerType.valueOf(schedulerTypeStr);
88 inputFile = new File(inputFileStr);
89 if (!inputFile.canRead())
90 throw new IOException("Can not read input file");
91 generalLog = new File(schedulerLogStr);
92 boolean logFileOK = false;
93 if ( generalLog.canWrite() ) {
96 else if (!generalLog.exists()) {
97 generalLog.createNewFile();
101 throw new IOException("Can not write to scheduler log file");
102 boolean fileWriteOK = false;
103 schedulerLog = new File(scenarioLogFileStr);
104 if (schedulerLog.exists()) {
105 fileWriteOK = schedulerLog.canWrite();
106 schedulerLog.delete();
107 schedulerLog.createNewFile();
109 schedulerLog.createNewFile();
113 throw new IOException("Can not write to Scenario Log File "
114 + scenarioLogFileStr);
115 } catch (Exception e) {