From 388aa5ea5257cb89d353b1e6daacaddd2a3472ef Mon Sep 17 00:00:00 2001
From: Andreas Egger <egger.andreas.1@gmail.com>
Date: Tue, 21 May 2013 09:59:35 +0200
Subject: [PATCH] Refactoring

---
 build.xml                                 | 12 ++++----
 src/at/ac/tuwien/lsdc/SchedSimulator.java | 37 +++++++++++++----------
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/build.xml b/build.xml
index 0d2484a..f32caf6 100644
--- a/build.xml
+++ b/build.xml
@@ -27,7 +27,7 @@
 		<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="project.classpath" debug="true" deprecation="true" includeantruntime="false" />
 	</target>
 
-	<target name="run-generator-A" depends="compile" description="Run Group GUI (JMS).">
+	<target name="run-generator-A" depends="compile" description="Compile project">
 		<java classname="at.ac.tuwien.lsdc.JobGenerator" fork="true" classpathref="project.classpath">
 			<assertions refid="project.assertions" />
 			<arg value="A" />
@@ -36,21 +36,21 @@
 		</java>
 	</target>
 
-	<target name="run-generator" depends="compile, input-runargs" description="Run Group GUI (JMS).">
+	<target name="run-generator" depends="compile, input-runargs" description="Run generator with user defined arguments">
 		<java classname="at.ac.tuwien.lsdc.JobGenerator" fork="true" classpathref="project.classpath">
 			<assertions refid="project.assertions" />
 			<arg value="${args}" />
 		</java>
 	</target>
 
-	<target name="run-scheduler" depends="compile, input-runargs" description="Run Group GUI (JMS).">
+	<target name="run-scheduler" depends="compile, input-runargs" description="Run scheduler with user defined arguments">
 		<java classname="at.ac.tuwien.lsdc.SchedSimulator" fork="true" classpathref="project.classpath">
 			<assertions refid="project.assertions" />
 			<arg value="${args}" />
 		</java>
 	</target>
 
-	<target name="run-scheduler-A-A" depends="compile" description="Run Group GUI (JMS).">
+	<target name="run-scheduler-A-A" depends="compile" description="Run scheduler A on scenario A">
 		<java classname="at.ac.tuwien.lsdc.SchedSimulator" fork="true" classpathref="project.classpath">
 			<assertions refid="project.assertions" />
 			<arg value="A" />
@@ -63,7 +63,7 @@
 		</java>
 	</target>
 
-	<target name="run-scheduler-A-B" depends="compile" description="Run Group GUI (JMS).">
+	<target name="run-scheduler-A-B" depends="compile" description="Run scheduler B on scenario A">
 		<java classname="at.ac.tuwien.lsdc.SchedSimulator" fork="true" classpathref="project.classpath">
 			<assertions refid="project.assertions" />
 			<arg value="A" />
@@ -76,7 +76,7 @@
 		</java>
 	</target>
 
-	<target name="run-scheduler-A-C" depends="compile" description="Run Group GUI (JMS).">
+	<target name="run-scheduler-A-C" depends="compile" description="Run scheduler C on scenario A">
 		<java classname="at.ac.tuwien.lsdc.SchedSimulator" fork="true" classpathref="project.classpath">
 			<assertions refid="project.assertions" />
 			<arg value="A" />
diff --git a/src/at/ac/tuwien/lsdc/SchedSimulator.java b/src/at/ac/tuwien/lsdc/SchedSimulator.java
index 003e6c2..83256c0 100644
--- a/src/at/ac/tuwien/lsdc/SchedSimulator.java
+++ b/src/at/ac/tuwien/lsdc/SchedSimulator.java
@@ -24,7 +24,7 @@ import at.ac.tuwien.lsdc.util.CSVParser;
  */
 public class SchedSimulator {
 
-	private static final String USAGE = "SchedSimulator needs exactly 5 parameters: scenario, scheduler, inputFile, logFilePath, schedulerLogPath";
+	private static final String USAGE = "SchedSimulator needs exactly 7 parameters: scenario, scheduler, numPMS, numCloudPartners, inputFile, generalLogPath, schedulerLogPath";
 
 	private static final Logger log = LoggerFactory
 			.getLogger(SchedSimulator.class);
@@ -73,6 +73,8 @@ public class SchedSimulator {
 	 * Commandline arguments parsed (mandatory):
 	 * - type of scenario
 	 * - type of scheduler
+	 * - number of available PMs
+	 * - number of cloud partners
 	 * - scenario input file with applications
 	 * - general output file for all schedulers
 	 * - specific output file for this scheduler/scenario combination
@@ -84,40 +86,43 @@ public class SchedSimulator {
 		String numPMsStr = args[2];
 		String numCloudPartnersStr = args[3];
 		String inputFileStr = args[4];
-		String schedulerLogStr = args[5];
-		String scenarioLogFileStr = args[6];
+		String generalLogStr = args[5];
+		String schedulerLogStr = args[6];
+
 		try {
 			scenario = ScenarioType.valueOf(scenarioStr);
 			schedulerType = SchedulerType.valueOf(schedulerTypeStr);
 			numPMs = Integer.parseInt(numPMsStr);
 			numCloudPartners = Integer.parseInt(numCloudPartnersStr);
 			inputFile = new File(inputFileStr);
+			
 			if (!inputFile.canRead())
 				throw new IOException("Can not read input file");
-			generalLog = new File(schedulerLogStr);
-			boolean  logFileOK = false;
+			generalLog = new File(generalLogStr);
+			boolean  generalLogOK = false;
 			if ( generalLog.canWrite() ) {
-				logFileOK = true;
+				generalLogOK = true;
 			}
 			else if (!generalLog.exists()) {
 				generalLog.createNewFile();
-				logFileOK = true;
+				generalLogOK = true;
 			}
-			if (!logFileOK)
-				throw new IOException("Can not write to scheduler log file");
-			boolean fileWriteOK = false;
-			schedulerLog = new File(scenarioLogFileStr);
+			if (!generalLogOK)
+				throw new IOException("Can not write to general log file");
+			
+			boolean schedulerLogOK = false;
+			schedulerLog = new File(schedulerLogStr);
 			if (schedulerLog.exists()) {
-				fileWriteOK = schedulerLog.canWrite();
+				schedulerLogOK = schedulerLog.canWrite();
 				schedulerLog.delete();
 				schedulerLog.createNewFile();
 			} else {
 				schedulerLog.createNewFile();
-				fileWriteOK = true;
+				schedulerLogOK = true;
 			}
-			if (!fileWriteOK)
-				throw new IOException("Can not write to Scenario Log File "
-						+ scenarioLogFileStr);
+			if (!schedulerLogOK)
+				throw new IOException("Can not write to scheduler log file "
+						+ schedulerLogStr);
 		} catch (Exception e) {
 			e.printStackTrace();
 			log.info(USAGE);
-- 
2.43.0