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 int numPMs;
35 private static int numCloudPartners;
36 private static File inputFile;
37 private static File generalLog;
38 private static File schedulerLog;
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);
55 LinkedList<Application> apps = CSVParser.parseFile(inputFile);
56 Collections.sort(apps);
57 AbstractScheduler scheduler;
58 switch (schedulerType) {
60 scheduler = new SchedulerA(schedulerLog,schedulerType,scenario);
62 scheduler = new SchedulerB(schedulerLog,schedulerType,scenario);
64 scheduler = new SchedulerC(schedulerLog,schedulerType,scenario);
66 ScenarioData data = scheduler.initAndStart(apps);
67 CSVLogger logger = new CSVLogger(generalLog);
68 logger.logScenarioData(data);
73 * Commandline arguments parsed (mandatory):
76 * - scenario input file with applications
77 * - general output file for all schedulers
78 * - specific output file for this scheduler/scenario combination
79 * @param args the command line arguments to parse
81 private static void parseCommandLineArgs(String[] args) {
82 String scenarioStr = args[0];
83 String schedulerTypeStr = args[1];
84 String numPMsStr = args[2];
85 String numCloudPartnersStr = args[3];
86 String inputFileStr = args[4];
87 String schedulerLogStr = args[5];
88 String scenarioLogFileStr = args[6];
90 scenario = ScenarioType.valueOf(scenarioStr);
91 schedulerType = SchedulerType.valueOf(schedulerTypeStr);
92 numPMs = Integer.parseInt(numPMsStr);
93 numCloudPartners = Integer.parseInt(numCloudPartnersStr);
94 inputFile = new File(inputFileStr);
95 if (!inputFile.canRead())
96 throw new IOException("Can not read input file");
97 generalLog = new File(schedulerLogStr);
98 boolean logFileOK = false;
99 if ( generalLog.canWrite() ) {
102 else if (!generalLog.exists()) {
103 generalLog.createNewFile();
107 throw new IOException("Can not write to scheduler log file");
108 boolean fileWriteOK = false;
109 schedulerLog = new File(scenarioLogFileStr);
110 if (schedulerLog.exists()) {
111 fileWriteOK = schedulerLog.canWrite();
112 schedulerLog.delete();
113 schedulerLog.createNewFile();
115 schedulerLog.createNewFile();
119 throw new IOException("Can not write to Scenario Log File "
120 + scenarioLogFileStr);
121 } catch (Exception e) {