]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/SchedSimulator.java
Modified presentation a bit
[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.Collections;
6 import java.util.LinkedList;
7
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
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;
21
22 /**
23  * Read config (command line properties) and start Scheduler-Simulation.
24  */
25 public class SchedSimulator {
26
27         private static final String USAGE = "SchedSimulator needs exactly 7 parameters: scenario, scheduler, numPMS, numCloudPartners, inputFile, generalLogPath, schedulerLogPath";
28
29         private static final Logger log = LoggerFactory
30                         .getLogger(SchedSimulator.class);
31
32         private static ScenarioType scenario;
33         private static SchedulerType schedulerType;
34         private static int numPMs;
35         private static int numCloudPartners;
36         private static File inputFile;
37         private static File generalLog;
38         private static File schedulerLog;
39
40         public static void main(String[] args) throws Exception {
41                 if (args.length == 7) {
42                         parseCommandLineArgs(args);
43                 } else if (args.length == 1) {
44                         String[] newArgs = args[0].split(" ");
45                         if (newArgs.length == 7) {
46                                 parseCommandLineArgs(newArgs);
47                         } else {
48                                 log.info(USAGE);
49                                 System.exit(1);
50                         }
51                 } else {
52                         log.info(USAGE);
53                         System.exit(1);
54                 }
55                 LinkedList<Application> apps = CSVParser.parseFile(inputFile);
56                 Collections.sort(apps);
57                 AbstractScheduler scheduler;
58                 switch (schedulerType) {
59                 case A:
60                         scheduler = new SchedulerA(numPMs, numCloudPartners, schedulerLog, scenario);
61                         break;
62                 case B:
63                         scheduler = new SchedulerB(numPMs, numCloudPartners, schedulerLog, scenario);
64                         break;
65                 default:
66                         scheduler = new SchedulerC(numPMs, numCloudPartners, schedulerLog, scenario);
67                         break;
68                 }
69                 ScenarioData data = scheduler.initAndStart(apps);
70                 CSVLogger logger = new CSVLogger(generalLog);
71 //              logger.logScenarioData(data);
72                 logger.close();
73         }
74
75         /**
76          * Commandline arguments parsed (mandatory):
77          * - type of scenario
78          * - type of scheduler
79          * - number of available PMs
80          * - number of cloud partners
81          * - scenario input file with applications
82          * - general output file for all schedulers
83          * - specific output file for this scheduler/scenario combination
84          * @param args the command line arguments to parse
85          */
86         private static void parseCommandLineArgs(String[] args) {
87                 String scenarioStr = args[0];
88                 String schedulerTypeStr = args[1];
89                 String numPMsStr = args[2];
90                 String numCloudPartnersStr = args[3];
91                 String inputFileStr = args[4];
92                 String generalLogStr = args[5];
93                 String schedulerLogStr = args[6];
94
95                 try {
96                         scenario = ScenarioType.valueOf(scenarioStr);
97                         schedulerType = SchedulerType.valueOf(schedulerTypeStr);
98                         numPMs = Integer.parseInt(numPMsStr);
99                         numCloudPartners = Integer.parseInt(numCloudPartnersStr);
100                         inputFile = new File(inputFileStr);
101                         
102                         if (!inputFile.canRead())
103                                 throw new IOException("Can not read input file");
104                         generalLog = new File(generalLogStr);
105                         boolean  generalLogOK = false;
106                         if ( generalLog.canWrite() ) {
107                                 generalLogOK = true;
108                         }
109                         else if (!generalLog.exists()) {
110                                 generalLog.createNewFile();
111                                 generalLogOK = true;
112                         }
113                         if (!generalLogOK)
114                                 throw new IOException("Can not write to general log file");
115                         
116                         boolean schedulerLogOK = false;
117                         schedulerLog = new File(schedulerLogStr);
118                         if (schedulerLog.exists()) {
119                                 schedulerLogOK = schedulerLog.canWrite();
120                                 schedulerLog.delete();
121                                 schedulerLog.createNewFile();
122                         } else {
123                                 schedulerLog.createNewFile();
124                                 schedulerLogOK = true;
125                         }
126                         if (!schedulerLogOK)
127                                 throw new IOException("Can not write to scheduler log file "
128                                                 + schedulerLogStr);
129                 } catch (Exception e) {
130                         e.printStackTrace();
131                         log.info(USAGE);
132                         System.exit(1);
133                 }
134         }
135
136 }