]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/SchedSimulator.java
forgot to commit SchedulerType
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / SchedSimulator.java
1 package at.ac.tuwien.lsdc;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.LinkedList;
6
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
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;
20
21 /**
22  * Read config (command line properties) and start Scheduler-Simulation.
23  */
24 public class SchedSimulator {
25
26         private static final String USAGE = "USAGE";
27
28         private static final Logger log = LoggerFactory
29                         .getLogger(SchedSimulator.class);
30
31         private static SchedulerType schedulerType;
32         private static File inputFile;
33         private static File logFile;
34         private static File scenarioLogFile;
35
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);
43                         } else {
44                                 log.info(USAGE);
45                                 System.exit(1);
46                         }
47                 }
48                 LinkedList<Application> apps = CSVParser.parseFile(inputFile);
49                 AbstractScheduler scheduler;
50                 switch (schedulerType) {
51                 case A:
52                         scheduler = new SchedulerA();
53                 case B:
54                         scheduler = new SchedulerB();
55                 default:
56                         scheduler = new SchedulerC();
57                 }
58
59                 ScenarioData data = scheduler.initAndStart(apps);
60                 // CSVScenariosLogger logger = new
61                 // CSVScenariosLogger("out_scen"+scenario+"sched"+schedulerType+".csv");
62                 // logger.appendScenarioData(data);
63         }
64
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];
70                 try {
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() ) {
78                                 logFileOK = true;
79                         }
80                         else if (!logFile.exists()) {
81                                 createLogFile();
82                                 logFileOK = true;
83                         }
84                         if (!logFileOK)
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();
92                         } else {
93                                 scenarioLogFile.createNewFile();
94                                 fileWriteOK = true;
95                         }
96                         if (!fileWriteOK)
97                                 throw new IOException("Can not write to Scenario Log File "
98                                                 + scenarioLogFileStr);
99                 } catch (Exception e) {
100                         e.printStackTrace();
101                         log.info(USAGE);
102                         System.exit(1);
103                 }
104         }
105         
106         private static void createLogFile() {
107                 
108         }
109 }