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: scheduler, scenario, 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[] splitArgs = args[0].split(" ");
45 if (splitArgs.length == 7) {
46 parseCommandLineArgs(splitArgs);
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);
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 schedulerTypeStr = args[0];
87 String scenarioStr = 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 schedulerType = SchedulerType.valueOf(schedulerTypeStr);
96 scenario = ScenarioType.valueOf(scenarioStr);
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 log.info(String.valueOf(generalLog.length()));
106 if ( generalLog.canWrite() ) {
109 else if (!generalLog.exists()) {
110 log.info("General Log doesn't exist, create new File");
111 generalLog.createNewFile();
115 throw new IOException("Can not write to general log file");
117 boolean schedulerLogOK = false;
118 schedulerLog = new File(schedulerLogStr);
119 log.info(schedulerLogStr.toString());
120 if (schedulerLog.exists()) {
121 schedulerLogOK = schedulerLog.canWrite();
122 schedulerLog.delete();
123 schedulerLog.createNewFile();
125 schedulerLog.createNewFile();
126 schedulerLogOK = true;
129 throw new IOException("Can not write to scheduler log file "
131 } catch (Exception e) {