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 log.info("TEST =================================");
56 LinkedList<Application> apps = CSVParser.parseFile(inputFile);
57 log.info("apps size = "+apps.size());
58 Collections.sort(apps);
59 AbstractScheduler scheduler;
60 switch (schedulerType) {
62 scheduler = new SchedulerA(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario);
64 scheduler = new SchedulerB(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario);
66 scheduler = new SchedulerC(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario);
68 ScenarioData data = scheduler.initAndStart(apps);
69 CSVLogger logger = new CSVLogger(generalLog);
70 // logger.logScenarioData(data);
75 * Commandline arguments parsed (mandatory):
78 * - number of available PMs
79 * - number of cloud partners
80 * - scenario input file with applications
81 * - general output file for all schedulers
82 * - specific output file for this scheduler/scenario combination
83 * @param args the command line arguments to parse
85 private static void parseCommandLineArgs(String[] args) {
86 String scenarioStr = args[0];
87 String schedulerTypeStr = args[1];
88 String numPMsStr = args[2];
89 String numCloudPartnersStr = args[3];
90 String inputFileStr = args[4];
91 String generalLogStr = args[5];
92 String schedulerLogStr = args[6];
95 scenario = ScenarioType.valueOf(scenarioStr);
96 schedulerType = SchedulerType.valueOf(schedulerTypeStr);
97 numPMs = Integer.parseInt(numPMsStr);
98 numCloudPartners = Integer.parseInt(numCloudPartnersStr);
99 inputFile = new File(inputFileStr);
101 if (!inputFile.canRead())
102 throw new IOException("Can not read input file");
103 generalLog = new File(generalLogStr);
104 boolean generalLogOK = false;
105 if ( generalLog.canWrite() ) {
108 else if (!generalLog.exists()) {
109 generalLog.createNewFile();
113 throw new IOException("Can not write to general log file");
115 boolean schedulerLogOK = false;
116 schedulerLog = new File(schedulerLogStr);
117 if (schedulerLog.exists()) {
118 schedulerLogOK = schedulerLog.canWrite();
119 schedulerLog.delete();
120 schedulerLog.createNewFile();
122 schedulerLog.createNewFile();
123 schedulerLogOK = true;
126 throw new IOException("Can not write to scheduler log file "
128 } catch (Exception e) {