Index: /gssim/trunk/build.xml
===================================================================
--- /gssim/trunk/build.xml	(revision 5)
+++ /gssim/trunk/build.xml	(revision 14)
@@ -180,3 +180,27 @@
 	</target>
 
+	<target name="genWorkload">
+		<available property="properties.file" type="file" file="${config}" value="${config}"/>
+		<antcall target="generateWorkload"/>
+	</target>
+	
+	<target name="generateWorkload" depends="compile" if="properties.file">
+		<echo message="Generating workload described in: ${properties.file}"/>
+		
+	 	<java classname="simulator.workload.generator.WorkloadGenerator" classpath="${build}/classes" fork="true">
+			<arg file="${properties.file}"/>
+			<classpath>
+				<path refid="class.path"/>
+				<pathelement path="${jars}/commons-beanutils.jar"/>
+				<pathelement path="${jars}/commons-digester-1.7.jar"/>
+				<pathelement path="${jars}/junit-4.4.jar"/>
+				<pathelement path="${jars}/log4j-1.2.13.jar"/>
+				<pathelement path="${jars}/xalan-2.6.jar"/>
+				<pathelement path="${jars}/xerces/xerces-2_9_0/xercesImpl.jar"/>
+				<pathelement path="${jars}/xerces/xerces-2_9_0/xml-apis.jar"/>
+				<dirset dir="properties" />
+			</classpath>
+	 	</java>
+	</target>
+	
 </project>
Index: /gssim/trunk/daemon/Daemon.cpp
===================================================================
--- /gssim/trunk/daemon/Daemon.cpp	(revision 5)
+++ /gssim/trunk/daemon/Daemon.cpp	(revision 14)
@@ -28,5 +28,5 @@
 #define EVENT_SIZE  ( sizeof (struct inotify_event) )
 #define EVENT_BUF_LEN     ( 1024 * ( EVENT_SIZE + 16 ) )
-#define RUNNING_DIR	"/opt/app/gssim/daemon"
+#define RUNNING_DIR	"/home/mcichenski/daemon"
 #define LOCK_FILE	"daemon.lock"
 #define LOG_FILE	"daemon.log"
@@ -38,4 +38,5 @@
 char gssimdir[255];
 char gssimexecfile[255];
+char gssimpropertyfile[255];
 char basedir[255];
 char msg[255];
@@ -162,7 +163,11 @@
 	if ( (fin.rdstate() & (ifstream::failbit | ifstream::eofbit)) != 0 )
 	{
-		cerr << "Error while reading gssim dir" << endl;
-		exit(-1);
-	}
+		cerr << "Error while reading gssim dir " << gssimdir << endl;
+		cerr << "config file: " << config_file << endl;
+		exit(-1);
+	}
+	strcpy(msg, "Gssim directory found: ");
+	strcat(msg, gssimdir);
+	log_message(LOG_FILE, msg);
 
 	fin.getline(gssimexecfile, 255);
@@ -172,5 +177,18 @@
 		exit(-1);
 	}	
-	
+	strcpy(msg, "Gssim exec file found: ");
+	strcat(msg, gssimexecfile);
+	log_message(LOG_FILE, msg);
+
+	fin.getline(gssimpropertyfile, 255);
+	if ( (fin.rdstate() & (ifstream::failbit | ifstream::eofbit)) != 0 )
+	{
+		cerr << "Error while reading gssim property file name" << endl;;
+		exit(-1);
+	}	
+	strcpy(msg, "Gssim property file found: ");
+	strcat(msg, gssimpropertyfile);
+	log_message(LOG_FILE, msg);
+
 	fin.getline(basedir, 255);
 	if ( (fin.rdstate() & (ifstream::failbit | ifstream::eofbit)) != 0 )
@@ -179,4 +197,7 @@
 		exit(-1);
 	}	
+	strcpy(msg, "Base watch directory found: ");
+	strcat(msg, basedir);
+	log_message(LOG_FILE, msg);
 	
 	fin.close();
@@ -202,5 +223,5 @@
 	
 	strcpy(msg, "Directory ");
-	strcat(msg, basedir);
+	strcat(msg, paths[wd]);
 	strcat(msg, " is added to watch list");
 	log_message(LOG_FILE, msg);
@@ -228,12 +249,13 @@
 						strcat(msg, event->name);
 						strcat(msg, " created.");
-						log_message(LOG_FILE, msg);								
-
-						char dir[255] = "\0";
-						strcat(dir, paths[event->wd]);
+						log_message(LOG_FILE, msg);
+
+						char dir[255];
+						strcpy(dir, paths[event->wd]);
 						strcat(dir, "/");
 						strcat(dir, event->name);
 						wd = inotify_add_watch(fd, dir, IN_CREATE
 								| IN_CLOSE_WRITE);
+						paths[wd] = dir;
 								
 						strcpy(msg, "Directory ");
@@ -241,6 +263,18 @@
 						strcat(msg, " is added to watch list");								
 						log_message(LOG_FILE, msg);								
-														
-						paths[wd] = dir;
+
+						strcpy(msg, "wd: ");
+						char str[255] = "\0";
+						sprintf(str, "%d", event->wd);
+						strcat(msg, str);
+						strcat(msg, " path: ");
+						strcat(msg, paths[event->wd]);
+						strcat(msg, " new_wd: ");
+						char str2[255] = "\0";
+						sprintf(str2, "%d", wd);
+						strcat(msg, str2);
+						strcat(msg, " new_path: ");
+						strcat(msg, paths[wd]);
+						log_message(LOG_FILE, msg);
 					}
 				} else if (event->mask & (IN_CLOSE_WRITE | IN_MOVED_TO)) {
@@ -280,8 +314,12 @@
 							strcat(gssim, "/");
 							strcat(gssim, gssimexecfile);
+							char property[255] = "\0";
+							strcpy(property, gssimdir);
+							strcat(property, "/");
+							strcat(property, gssimpropertyfile);
 							strcat(path, "/");
 							strcat(path, name.c_str());
 							cout << gssim << endl << path << endl;
-							execl(gssim, "gssim", path, NULL);
+							execl(gssim, "gssim", path, property, NULL);
 						} else {
 							waitpid(pid, NULL, 0);
Index: /gssim/trunk/daemon/daemon.config
===================================================================
--- /gssim/trunk/daemon/daemon.config	(revision 5)
+++ /gssim/trunk/daemon/daemon.config	(revision 14)
@@ -1,4 +1,5 @@
 /opt/app/gssim/
 start-db-analyzer.sh
+properties.config
 /opt/app/gssim/results/
 ------------------------------
@@ -6,5 +7,6 @@
 1) directory in which gssim is installed
 2) name of file that should be executed
-3) base directory which should be watched
+3) name of property file that should be loaded for db access
+4) base directory which should be watched
 
 Path to daemon running directory is precompiled
Index: /gssim/trunk/db/gssim/db/analyzer/Analyzer.java
===================================================================
--- /gssim/trunk/db/gssim/db/analyzer/Analyzer.java	(revision 5)
+++ /gssim/trunk/db/gssim/db/analyzer/Analyzer.java	(revision 14)
@@ -133,10 +133,10 @@
 	private Experiment experiment;
 	private String userDN;
-	private Integer expNoInSeries;
-
-	public Analyzer(int n) throws InstantiationException,
+	private Integer totalSimulationRuns;
+	private Integer currentSimulationRun;
+
+	public Analyzer() throws InstantiationException,
 			IllegalAccessException, ClassNotFoundException {
 
-		expNoInSeries = n;
 		jobID = new HashMap<Integer, Integer>();
 		taskID = new HashMap<Pair<Integer, Integer>, Integer>();
@@ -154,4 +154,5 @@
 		userDN = null;
 		factory = new MySQLDAOFactory();
+		totalSimulationRuns = 1;
 	}
 
@@ -170,5 +171,5 @@
 			InstantiationException, IllegalAccessException,
 			ClassNotFoundException {
-		Analyzer analyzer = new Analyzer(1);
+		Analyzer analyzer = new Analyzer();
 		analyzer.run(args);
 	}
@@ -206,5 +207,5 @@
 		if (args.length < 1 || args.length > 3)
 			throw new RuntimeException(
-					"Program should be run with 1-4 arguments: "
+					"Program should be run with 1-3 arguments: "
 							+ "*.tar file or directory with experiment results, "
 							+ "encrypted or unencrypted properties file, "
@@ -217,21 +218,4 @@
 		try {
 
-			if (gssimResults.getName().endsWith(".tar")) {
-
-				FileInputStream fileStream = new FileInputStream(gssimResults);
-				tarInputStream = new TarArchiveInputStream(fileStream);
-				prepareStreams(tarInputStream, config);
-
-			} else if (gssimResults.isDirectory()) {
-
-				PrepareStreams(gssimResults, config);
-
-			} else
-				throw new RuntimeException(
-						"This program should be run with one argument: "
-								+ "*.tar file or directory with experiment results");
-
-			checkFilesPresence(config);
-
 			connection = factory.createDBConnection(config.getDb(), config
 					.getUser(), config.getPassword());
@@ -239,7 +223,30 @@
 			connection.setAutoCommit(false);
 
-			setup(inputStreams.get("propertiesInputStream"), config);
-			process();
-
+			currentSimulationRun = 0;
+			
+			while (currentSimulationRun != totalSimulationRuns)
+			{
+				currentSimulationRun++;
+				config.initFileNames(currentSimulationRun);
+				if (gssimResults.getName().endsWith(".tar")) {
+	
+					FileInputStream fileStream = new FileInputStream(gssimResults);
+					tarInputStream = new TarArchiveInputStream(fileStream);
+					prepareStreams(tarInputStream, config);
+	
+				} else if (gssimResults.isDirectory()) {
+	
+					PrepareStreams(gssimResults, config);
+	
+				} else
+					throw new RuntimeException(
+							"This program should be run with one argument: "
+									+ "*.tar file or directory with experiment results");
+	
+				checkFilesPresence(config);
+				
+				setup(inputStreams.get("propertiesInputStream"), config);
+				process();
+			}
 			connection.commit();
 			log.info("Database operations are commited");
@@ -582,5 +589,10 @@
 		}
 
-		if (properties.containsKey("experiment.id")) {
+		if (properties.containsKey("numberofsimulations"))
+		{
+			totalSimulationRuns = Integer.parseInt((String) properties.get("numberofsimulations"));
+		}
+		
+		if (properties.containsKey("experiment.id") && currentSimulationRun == 1) {
 			experiment = new Experiment();
 			experiment.setPK(Integer.parseInt((String) properties.get("experiment.id")));
@@ -596,15 +608,34 @@
 
 			configuration = new Configuration();
-			configurationDAO.insert(configuration, false);
 
 			user = new User();
 			user.setDN("unknown_user");
-			userDAO.insert(user, false);
-
+
+			Integer metaExpId = null;
+			String name = "experiment";
+			
+			if (properties.containsKey("experiment.id"))
+			{
+				experiment = new Experiment();
+				experiment.setPK(Integer.parseInt((String) properties.get("experiment.id")));
+				experiment = experimentDAO.select(experiment);
+				
+				metaExpId = experiment.getMetaexpId();
+				name = experiment.getName();
+				user.setId(experiment.getUserId());
+				configuration.setId(experiment.getConfigId());
+			}
+			else
+			{
+				userDAO.insert(user, false);
+				configurationDAO.insert(configuration, false);
+			}
+			
 			experiment = new Experiment();
 			experiment.setConfigId(configuration.getId());
 			experiment.setUserId(user.getId());
 			experiment.setCommissionDate(new Timestamp((new Date()).getTime()));
-			experiment.setName("default-name");
+			experiment.setMetaexpId(metaExpId);
+			experiment.setName(name+ "_" + currentSimulationRun.toString());
 			experiment.setStatus("FINISHED");
 			experimentDAO.insert(experiment, false);
Index: /gssim/trunk/db/gssim/db/config/MySQLConfig.java
===================================================================
--- /gssim/trunk/db/gssim/db/config/MySQLConfig.java	(revision 5)
+++ /gssim/trunk/db/gssim/db/config/MySQLConfig.java	(revision 14)
@@ -12,5 +12,5 @@
 		super(propertiesPath);
 		
-		initOtherConfigParameters();
+		initParameters(1);
 	}
 
@@ -20,5 +20,5 @@
 		super(encryptedPropertiesPath, keyPath);
 		
-		initOtherConfigParameters();
+		initParameters(1);
 		
 		System.out.println(user);
@@ -32,17 +32,9 @@
 		db = "localhost:3306/gssim_results";
 		
-		initOtherConfigParameters();
+		initParameters(1);
 	}
 
-	private void initOtherConfigParameters() {
-		statsFile = "Stats_Simulation 1_Simulation.txt";
-		jobsFile = "Stats_Simulation 1_Jobs.txt";
-		tasksFile = "Stats_Simulation 1_Raw_Tasks.txt";
-		resourcesFile = "Stats_Simulation 1_Raw_Resources.txt";
-		energyFile = "Stats_Simulation 1_Energy.txt";
-		resourceLoadFile = "Stats_Simulation 1_Resource_Load.txt";
-		accumulatedResourcesFile = "Stats_Simulation 1_Accumulated_Resources.txt";
-		networkFile = "Stats_Simulation 1_Network.txt";
-		propertiesFile = "experiment.properties";
+	private void initParameters(Integer simulationRun) {
+		initFileNames(simulationRun);
 
 		extractDirectoryPath = null;
@@ -50,9 +42,8 @@
 		propertiesIgnoreKeys = new ArrayList<String>();
 
+		//why this is specific to MySQLConfig implementation?
 		propertiesIgnoreKeys.add("createstatistics.formatoutput");
 		propertiesIgnoreKeys.add("printhistory");
-		propertiesIgnoreKeys.add("readscenario.workloadfilename");
 		propertiesIgnoreKeys.add("readscenario.inputfolder");
-		propertiesIgnoreKeys.add("resdesc");
 		propertiesIgnoreKeys.add("stats.outputfolder");
 		propertiesIgnoreKeys.add("user.dn");
Index: /gssim/trunk/db/gssim/db/config/Config.java
===================================================================
--- /gssim/trunk/db/gssim/db/config/Config.java	(revision 5)
+++ /gssim/trunk/db/gssim/db/config/Config.java	(revision 14)
@@ -94,4 +94,17 @@
 	}	
 	
+	public void initFileNames(Integer simulationRun)
+	{
+		statsFile = "Stats_Simulation " + simulationRun.toString() + "_Simulation.txt";
+		jobsFile = "Stats_Simulation " + simulationRun.toString() + "_Jobs.txt";
+		tasksFile = "Stats_Simulation " + simulationRun.toString() + "_Raw_Tasks.txt";
+		resourcesFile = "Stats_Simulation " + simulationRun.toString() + "_Raw_Resources.txt";
+		energyFile = "Stats_Simulation " + simulationRun.toString() + "_Energy.txt";
+		resourceLoadFile = "Stats_Simulation " + simulationRun.toString() + "_Resource_Load.txt";
+		accumulatedResourcesFile = "Stats_Simulation " + simulationRun.toString() + "_Accumulated_Resources.txt";
+		networkFile = "Stats_Simulation " + simulationRun.toString() + "_Network.txt";
+		propertiesFile = "experiment.properties";
+	}
+	
 	/**
 	 * Gets the stats file.
Index: /gssim/trunk/db/gssim/db/mysql/ExperimentStatsDAO.java
===================================================================
--- /gssim/trunk/db/gssim/db/mysql/ExperimentStatsDAO.java	(revision 5)
+++ /gssim/trunk/db/gssim/db/mysql/ExperimentStatsDAO.java	(revision 14)
@@ -51,5 +51,5 @@
 	@Override
 	protected PreparedStatementAdapter createSelectStmt() throws SQLException {
-		String sql = "SELECT * FROM unit_details WHERE id = ? AND name = ?";
+		String sql = "SELECT * FROM experiment_stats WHERE id = ? AND name = ?";
 		PreparedStatementAdapter stmt = new PreparedStatementAdapter(this
 				.getConnection().prepareStatement(sql));
Index: /gssim/trunk/db/gssim/db/mysql/ResourceEnTimelineDAO.java
===================================================================
--- /gssim/trunk/db/gssim/db/mysql/ResourceEnTimelineDAO.java	(revision 5)
+++ /gssim/trunk/db/gssim/db/mysql/ResourceEnTimelineDAO.java	(revision 14)
@@ -1,4 +1,5 @@
 package gssim.db.mysql;
 
+import gssim.db.dao.data.ResourceAllTimeline;
 import gssim.db.dao.data.ResourceEnTimeline;
 import gssim.db.find.Finder;
@@ -63,4 +64,16 @@
 		return null;
 	}
+	
+	protected PreparedStatementAdapter createSumStmt() throws SQLException {
+		String sql = "SELECT timestamp, SUM(`usage`) as 'usage'" + 
+					" FROM resource_energy_timeline rat" +
+					" JOIN resource r ON r.PK = rat.fk_resource_id" +
+					" WHERE exp_id = ?" +
+					" AND (timestamp between ? AND ?)" +
+					" GROUP BY TIMESTAMP";
+		PreparedStatementAdapter stmt = new PreparedStatementAdapter(this
+				.getConnection().prepareStatement(sql));
+		return stmt;
+	}
 
 	@Override
@@ -204,4 +217,29 @@
 		throw new NotImplemented();
 	}
+	
+	public List<ResourceEnTimeline> sum(Finder finder) throws SQLException {
+
+		PreparedStatementAdapter stmt = createSumStmt();
+		List<ResourceEnTimeline> list = new ArrayList<ResourceEnTimeline>();
+
+		stmt.setInt(1, finder.getInteger("fkResourceId"));
+		stmt.setTimestamp(2, finder.getMinTimestamp("timestamp"));
+		stmt.setTimestamp(3, finder.getMaxTimestamp("timestamp"));
+		ResultSetAdapter result = new ResultSetAdapter(stmt.executeQuery());
+
+		while (result.next()) {
+			ResourceEnTimeline obj = new ResourceEnTimeline();
+
+			Timestamp timestamp = result.getTimestamp("timestamp");
+			Float usage = result.getFloatObj("usage");
+
+			obj.setTimestamp(timestamp);
+			obj.setUsage(usage);
+
+			list.add(obj);
+		}
+
+		return list;
+	}
 
 }
Index: /gssim/trunk/db/gssim/db/mysql/ResourceAllTimelineDAO.java
===================================================================
--- /gssim/trunk/db/gssim/db/mysql/ResourceAllTimelineDAO.java	(revision 5)
+++ /gssim/trunk/db/gssim/db/mysql/ResourceAllTimelineDAO.java	(revision 14)
@@ -64,4 +64,16 @@
 	}
 
+	protected PreparedStatementAdapter createSumStmt() throws SQLException {
+		String sql = "SELECT timestamp, SUM(`usage`) as 'usage'" + 
+					" FROM resource_allocation_timeline rat" +
+					" JOIN resource r ON r.PK = rat.fk_resource_id" +
+					" WHERE exp_id = ?" +
+					" AND (timestamp between ? AND ?)" +
+					" GROUP BY TIMESTAMP";
+		PreparedStatementAdapter stmt = new PreparedStatementAdapter(this
+				.getConnection().prepareStatement(sql));
+		return stmt;
+	}
+	
 	@Override
 	public boolean delete(ResourceAllTimeline obj, boolean commit)
@@ -204,4 +216,29 @@
 		throw new NotImplemented();
 	}
+	
+	public List<ResourceAllTimeline> sum(Finder finder) throws SQLException {
+
+		PreparedStatementAdapter stmt = createSumStmt();
+		List<ResourceAllTimeline> list = new ArrayList<ResourceAllTimeline>();
+
+		stmt.setInt(1, finder.getInteger("fkResourceId"));
+		stmt.setTimestamp(2, finder.getMinTimestamp("timestamp"));
+		stmt.setTimestamp(3, finder.getMaxTimestamp("timestamp"));
+		ResultSetAdapter result = new ResultSetAdapter(stmt.executeQuery());
+
+		while (result.next()) {
+			ResourceAllTimeline obj = new ResourceAllTimeline();
+
+			Timestamp timestamp = result.getTimestamp("timestamp");
+			Float usage = result.getFloatObj("usage");
+
+			obj.setTimestamp(timestamp);
+			obj.setUsage(usage);
+
+			list.add(obj);
+		}
+
+		return list;
+	}
 
 }
