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 7 parameters: scenario, scheduler, numPMS, numCloudPartners, inputFile, generalLogPath, 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(numPMs, numCloudPartners, schedulerLog, scenario);
63 scheduler = new SchedulerB(numPMs, numCloudPartners, schedulerLog, scenario);
66 scheduler = new SchedulerC(numPMs, numCloudPartners, schedulerLog, scenario);
69 ScenarioData data = scheduler.initAndStart(apps);
70 CSVLogger logger = new CSVLogger(generalLog);
71 logger.logScenarioData(data);
76 * Commandline arguments parsed (mandatory):
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
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];
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);
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() ) {
109 else if (!generalLog.exists()) {
110 generalLog.createNewFile();
114 throw new IOException("Can not write to general log file");
116 boolean schedulerLogOK = false;
117 schedulerLog = new File(schedulerLogStr);
118 if (schedulerLog.exists()) {
119 schedulerLogOK = schedulerLog.canWrite();
120 schedulerLog.delete();
121 schedulerLog.createNewFile();
123 schedulerLog.createNewFile();
124 schedulerLogOK = true;
127 throw new IOException("Can not write to scheduler log file "
129 } catch (Exception e) {