From 6be26899b99b16976283536fa8b9cc6175edaf55 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Thu, 2 May 2013 18:47:03 +0200 Subject: [PATCH] added some Files and comments and methods --- src/at/ac/tuwien/lsdc/SchedSimulator.java | 35 ++++++++++++++++++ .../ac/tuwien/lsdc/federation/Federation.java | 16 ++++++++ .../lsdc/management/MachineManager.java | 8 ++++ .../tuwien/lsdc/sched/AbstractScheduler.java | 10 ++--- src/at/ac/tuwien/lsdc/types/ScenarioData.java | 35 ++++++++++++++++++ .../ac/tuwien/lsdc/types/SchedulerData.java | 37 +++++++++++++++++++ src/at/ac/tuwien/lsdc/util/CSVParser.java | 8 +++- ...CSVLogger.java => CSVScenariosLogger.java} | 11 +++++- .../tuwien/lsdc/util/CSVSchedulerLogger.java | 35 ++++++++++++++++++ 9 files changed, 185 insertions(+), 10 deletions(-) create mode 100644 src/at/ac/tuwien/lsdc/management/MachineManager.java create mode 100644 src/at/ac/tuwien/lsdc/types/ScenarioData.java create mode 100644 src/at/ac/tuwien/lsdc/types/SchedulerData.java rename src/at/ac/tuwien/lsdc/util/{CSVLogger.java => CSVScenariosLogger.java} (66%) create mode 100644 src/at/ac/tuwien/lsdc/util/CSVSchedulerLogger.java diff --git a/src/at/ac/tuwien/lsdc/SchedSimulator.java b/src/at/ac/tuwien/lsdc/SchedSimulator.java index 327b2e7..9495902 100644 --- a/src/at/ac/tuwien/lsdc/SchedSimulator.java +++ b/src/at/ac/tuwien/lsdc/SchedSimulator.java @@ -1,15 +1,50 @@ package at.ac.tuwien.lsdc; +import java.util.LinkedList; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.ac.tuwien.lsdc.sched.AbstractScheduler; +import at.ac.tuwien.lsdc.sched.SchedulerA; +import at.ac.tuwien.lsdc.sched.SchedulerB; +import at.ac.tuwien.lsdc.sched.SchedulerC; +import at.ac.tuwien.lsdc.types.Application; +import at.ac.tuwien.lsdc.types.ScenarioData; +import at.ac.tuwien.lsdc.util.CSVParser; +import at.ac.tuwien.lsdc.util.CSVScenariosLogger; + /** * Read config (command line properties) and start Scheduler-Simulation. */ public class SchedSimulator { private static final Logger log = LoggerFactory.getLogger(SchedSimulator.class); + + private static String schedulerType; + private static String inputFile; + private static String scenario; public static void main(String[] args) throws Exception { log.info("Hello World!"); + parseCommandLineArgs(args); + CSVParser parser = new CSVParser(inputFile); + LinkedList apps = parser.parseFile(); + AbstractScheduler scheduler; + switch (schedulerType) { + case "A": + scheduler = new SchedulerA(); + case "B": + scheduler = new SchedulerB(); + default: + scheduler = new SchedulerC(); + } + + ScenarioData data = scheduler.initAndStart(apps); + CSVScenariosLogger logger = new CSVScenariosLogger("out_scen"+scenario+"sched"+schedulerType+".csv"); + logger.appendScenarioData(data); + } + + private static void parseCommandLineArgs(String[] args) { + } } diff --git a/src/at/ac/tuwien/lsdc/federation/Federation.java b/src/at/ac/tuwien/lsdc/federation/Federation.java index b275bc6..48cd704 100644 --- a/src/at/ac/tuwien/lsdc/federation/Federation.java +++ b/src/at/ac/tuwien/lsdc/federation/Federation.java @@ -1,5 +1,21 @@ package at.ac.tuwien.lsdc.federation; +import at.ac.tuwien.lsdc.types.Application; + public class Federation { + + private int numPartners; + + public Federation(int numPartners) { + this.numPartners = numPartners; + } + + public boolean doOutsource(Application app) { + for (int i=0;i to Scheduler - public String initAndStart(List apps) { + public ScenarioData initAndStart(List apps) { for (Application a : apps) { // read start timestamp // save as Event in Map @@ -67,7 +65,7 @@ public abstract class AbstractScheduler { // this creates the total summary which should be written to a CSV at the // end - protected String doEndLogging() { - return "CSV-String"; + protected ScenarioData doEndLogging() { + return new ScenarioData(schedulerName,scenario,1,1,1,1,1,1); } } diff --git a/src/at/ac/tuwien/lsdc/types/ScenarioData.java b/src/at/ac/tuwien/lsdc/types/ScenarioData.java new file mode 100644 index 0000000..fbb3cd5 --- /dev/null +++ b/src/at/ac/tuwien/lsdc/types/ScenarioData.java @@ -0,0 +1,35 @@ +package at.ac.tuwien.lsdc.types; + +public class ScenarioData { + + private String scheduler; + private String scenario; + private long totalPMs; + private long totalVMs; + private long totalDuration; + private long totalConsumption; + private int totalInSourced; + private int totalOutSourced; + + public ScenarioData(String scheduler, String scenario, long totalPMs, + long totalVMs, long totalDuration, long totalConsumption, + int totalInSourced, int totalOutSourced) { + this.scheduler = scheduler; + this.scenario = scenario; + this.totalPMs = totalPMs; + this.totalVMs = totalVMs; + this.totalDuration = totalDuration; + this.totalConsumption = totalConsumption; + this.totalInSourced = totalInSourced; + this.totalOutSourced = totalOutSourced; + } + + @Override + public String toString() { + return scheduler + ";" + scenario + ";" + totalPMs + ";" + totalVMs + ";" + totalDuration + + ";" + totalConsumption + + ";" + totalInSourced + ";" + + totalOutSourced; + } + +} diff --git a/src/at/ac/tuwien/lsdc/types/SchedulerData.java b/src/at/ac/tuwien/lsdc/types/SchedulerData.java new file mode 100644 index 0000000..ca4d14c --- /dev/null +++ b/src/at/ac/tuwien/lsdc/types/SchedulerData.java @@ -0,0 +1,37 @@ +package at.ac.tuwien.lsdc.types; + +public class SchedulerData { + + private long timestamp; + private long totalRAM; + private long totalCPU; + private long totalSize; + private long runningPMs; + private long runningVMs; + private long totalConsumption; + private int inSourced; + private int outSourced; + + public SchedulerData(long timestamp, long totalRAM, long totalCPU, + long totalSize, long runningPMs, long runningVMs, + long totalConsumption, int inSourced, int outSourced) { + this.timestamp = timestamp; + this.totalRAM = totalRAM; + this.totalCPU = totalCPU; + this.totalSize = totalSize; + this.runningPMs = runningPMs; + this.runningVMs = runningVMs; + this.totalConsumption = totalConsumption; + this.inSourced = inSourced; + this.outSourced = outSourced; + } + + @Override + public String toString() { + return timestamp + ";" + totalRAM + ";" + totalCPU + ";" + + totalSize + ";" + runningPMs + ";" + + runningVMs + ";" + totalConsumption + + ";" + inSourced + ";" + outSourced; + } + +} diff --git a/src/at/ac/tuwien/lsdc/util/CSVParser.java b/src/at/ac/tuwien/lsdc/util/CSVParser.java index 284d79d..4d3273e 100644 --- a/src/at/ac/tuwien/lsdc/util/CSVParser.java +++ b/src/at/ac/tuwien/lsdc/util/CSVParser.java @@ -2,8 +2,10 @@ package at.ac.tuwien.lsdc.util; import java.io.FileReader; import java.io.IOException; +import java.util.LinkedList; import java.util.List; +import at.ac.tuwien.lsdc.types.Application; import au.com.bytecode.opencsv.CSVReader; public class CSVParser { @@ -13,9 +15,11 @@ public class CSVParser { this.filename = filename; } - public List readFile() throws IOException { + public LinkedList parseFile() throws IOException { CSVReader reader = new CSVReader(new FileReader(filename)); - return reader.readAll(); + List file = reader.readAll(); + reader.close(); + return new LinkedList(); } diff --git a/src/at/ac/tuwien/lsdc/util/CSVLogger.java b/src/at/ac/tuwien/lsdc/util/CSVScenariosLogger.java similarity index 66% rename from src/at/ac/tuwien/lsdc/util/CSVLogger.java rename to src/at/ac/tuwien/lsdc/util/CSVScenariosLogger.java index 82f69ac..ca28f85 100644 --- a/src/at/ac/tuwien/lsdc/util/CSVLogger.java +++ b/src/at/ac/tuwien/lsdc/util/CSVScenariosLogger.java @@ -4,15 +4,22 @@ import java.io.FileWriter; import java.io.IOException; import java.util.List; +import at.ac.tuwien.lsdc.types.ScenarioData; import au.com.bytecode.opencsv.CSVWriter; -public class CSVLogger { +public class CSVScenariosLogger { private final String filename; - public CSVLogger(String filename) { + public CSVScenariosLogger(String filename) { this.filename = filename; } + + public void appendScenarioData( ScenarioData data ) { + //check if filename exists + //if not create file with header + //append line data.toString() + } public void writeFile(List data) throws IOException { CSVWriter writer = new CSVWriter(new FileWriter(filename), '\t'); diff --git a/src/at/ac/tuwien/lsdc/util/CSVSchedulerLogger.java b/src/at/ac/tuwien/lsdc/util/CSVSchedulerLogger.java new file mode 100644 index 0000000..b87da9b --- /dev/null +++ b/src/at/ac/tuwien/lsdc/util/CSVSchedulerLogger.java @@ -0,0 +1,35 @@ +package at.ac.tuwien.lsdc.util; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +import at.ac.tuwien.lsdc.types.SchedulerData; +import au.com.bytecode.opencsv.CSVWriter; + +public class CSVSchedulerLogger { + + private final String filename; + + public CSVSchedulerLogger(String filename) { + this.filename = filename; + } + + public void appendSchedulerData(SchedulerData data) { + // check if filename exists + // if not create file with header + // append line data.toString() + } + + public void writeFile(List data) throws IOException { + CSVWriter writer = new CSVWriter(new FileWriter(filename), '\t'); + writer.writeAll(data); + writer.close(); + } + + public void writeLine(String[] data) throws IOException { + CSVWriter writer = new CSVWriter(new FileWriter(filename), '\t'); + writer.writeNext(data); + writer.close(); + } +} -- 2.43.0