Changeset 375 for trunk/sources
- Timestamp:
- 07/09/08 21:37:36 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 16 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs
r372 r375 33 33 public long Id { get; set; } 34 34 public string Name { get; set; } 35 public AgentStatus Status { get; set; }35 public ProcessStatus Status { get; set; } 36 36 private OperatorGraph operatorGraph; 37 37 … … 51 51 52 52 public void Save() { 53 AgentEntry entry = new AgentEntry(Id, Name, Status, DbPersistenceManager.Save(this)); 54 Database.Update(entry); 53 Database.UpdateAgent(Id, Name); 54 Database.UpdateAgent(Id, Status); 55 Database.UpdateAgent(Id, DbPersistenceManager.Save(this)); 55 56 } 56 57 57 58 public void Activate() { 58 Status = AgentStatus.Waiting;59 Status = ProcessStatus.Waiting; 59 60 Save(); 60 61 } -
trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs
r372 r375 46 46 private void ReloadList() { 47 47 agentList.Clear(); 48 foreach(AgentEntry a in database.GetAgent Entries()) {48 foreach(AgentEntry a in database.GetAgents()) { 49 49 Agent newAgent = (Agent)DbPersistenceManager.Restore(a.RawData); 50 50 newAgent.Database = database; … … 63 63 64 64 public void CreateAgent() { 65 long id = database.CreateAgent(); 66 Agent agent = new Agent(database, id); 65 Agent agent = new Agent(); 67 66 agent.Name = DateTime.Now.ToString(); 68 agent.Save(); 67 agent.Status = ProcessStatus.Unkown; 68 agent.Database = database; 69 long id = database.InsertAgent(agent.Name, DbPersistenceManager.Save(agent)); 70 agent.Id = id; 69 71 agentList.Add(agent); 70 72 } -
trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs
r372 r375 58 58 } 59 59 60 if(Agent.Status == AgentStatus.Unkown) activateButton.Enabled = true;60 if(Agent.Status == ProcessStatus.Unkown) activateButton.Enabled = true; 61 61 else activateButton.Enabled = false; 62 62 } -
trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs
r372 r375 29 29 30 30 namespace HeuristicLab.CEDMA.Console { 31 internalstatic class DbPersistenceManager {32 internalstatic IStorable Restore(byte[] serializedStorable) {31 public static class DbPersistenceManager { 32 public static IStorable Restore(byte[] serializedStorable) { 33 33 GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress); 34 34 return PersistenceManager.Load(stream); 35 35 } 36 internalstatic byte[] Save(IStorable storable) {36 public static byte[] Save(IStorable storable) { 37 37 MemoryStream memStream = new MemoryStream(); 38 38 GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true); -
trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs
r372 r375 30 30 public interface IAgent : IDatabaseItem { 31 31 string Name { get; } 32 AgentStatus Status { get; }32 ProcessStatus Status { get; } 33 33 IOperatorGraph OperatorGraph { get; } 34 34 void Save(); -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs
r372 r375 35 35 public string Name { get; set; } 36 36 [DataMember] 37 public AgentStatus Status { get; set; }37 public ProcessStatus Status { get; set; } 38 38 [DataMember] 39 39 public byte[] RawData { get; set; } 40 41 public AgentEntry(long id, string name, AgentStatus status, byte[] rawData) {42 Id = id;43 Name = name;44 Status = status;45 RawData = rawData;46 }47 40 } 48 41 } -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj
r372 r375 59 59 <ItemGroup> 60 60 <Compile Include="AgentEntry.cs" /> 61 <Compile Include="AgentStatus.cs" /> 61 <Compile Include="ProcessStatus.cs" /> 62 <Compile Include="RunEntry.cs" /> 62 63 <Compile Include="ResultEntry.cs" /> 63 64 <Compile Include="HeuristicLabCedmaDbInterfacesPlugin.cs" /> -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs
r372 r375 31 31 public interface IDatabase { 32 32 [OperationContract] 33 ICollection<AgentEntry> GetAgentEntries(); 33 long InsertAgent(string name, byte[] rawData); 34 35 [OperationContract(Name = "UpdateAgentName")] 36 void UpdateAgent(long id, string name); 37 38 [OperationContract(Name = "UpdateAgentStatus")] 39 void UpdateAgent(long id, ProcessStatus status); 40 41 [OperationContract(Name = "UpdateAgentData")] 42 void UpdateAgent(long id, byte[] rawData); 34 43 35 44 [OperationContract] 36 long CreateAgent();45 long InsertRun(long agentId, byte[] rawData); 37 46 38 [OperationContract (Name="UpdateAgent")]39 void Update (AgentEntry entry);47 [OperationContract] 48 void UpdateRunStart(long runId, DateTime CreationTime); 40 49 41 [OperationContract(Name ="UpdateResult")] 42 void Update(ResultEntry result); 50 [OperationContract] 51 void UpdateRunFinished(long runId, DateTime CreationTime); 52 53 [OperationContract] 54 void UpdateRunStatus(long runId, ProcessStatus status); 55 56 [OperationContract] 57 long InsertResult(long runId, byte[] rawData); 58 59 [OperationContract] 60 long InsertSubResult(long resultId, byte[] rawData); 61 62 63 // should be replaced by more powerful querying interface (LINQ provider?) 64 [OperationContract] 65 ICollection<AgentEntry> GetAgents(); 66 67 [OperationContract] 68 ICollection<RunEntry> GetRuns(); 69 70 [OperationContract] 71 ICollection<ResultEntry> GetResults(long runId); 72 73 [OperationContract] 74 ICollection<ResultEntry> GetSubResults(long resultId); 75 43 76 } 44 77 } -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ProcessStatus.cs
r372 r375 26 26 27 27 namespace HeuristicLab.CEDMA.DB.Interfaces { 28 public enum AgentStatus { Unkown, Active, Finished, Error, Waiting}28 public enum ProcessStatus { Unkown, Active, Finished, Error, Waiting} 29 29 } -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs
r372 r375 31 31 public class ResultEntry { 32 32 [DataMember] 33 p rivate long id;33 public long Id { get; set; } 34 34 [DataMember] 35 private byte[] rawData; 36 37 public ResultEntry(long id, byte[] rawData) { 38 this.id = id; 39 this.rawData = rawData; 40 } 41 42 public long Id { 43 get { return id; } 44 } 45 46 public byte[] RawData { 47 get { return rawData; } 48 } 35 public long RunId { get; set; } 36 [DataMember] 37 public long ResultId { get; set; } 38 [DataMember] 39 public DateTime CreationTime { get; set; } 40 [DataMember] 41 public byte[] RawData { get; set; } 49 42 } 50 43 } -
trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
r372 r375 32 32 33 33 namespace HeuristicLab.CEDMA.DB { 34 [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode. Single, UseSynchronizationContext = true)]34 [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)] 35 35 public class Database : IDatabase { 36 36 private string connectionString; 37 private object bigLock = new object(); 37 38 public Database(string connectionString) { 38 39 this.connectionString = connectionString; 39 40 } 40 41 42 #region create empty database 41 43 public void CreateNew() { 42 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 43 cnn.ConnectionString = connectionString; 44 cnn.Open(); 45 46 SQLiteCommand cAgent = cnn.CreateCommand(); 47 cAgent.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, Name text, Status text default 'Unknown', RawData Blob)"; 48 SQLiteCommand cProject = cnn.CreateCommand(); 49 cProject.CommandText = "CREATE TABLE Project (ID integer primary key autoincrement, Name text, Description text, CreationDate DateTime)"; 50 SQLiteCommand cResult = cnn.CreateCommand(); 51 cResult.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, AgentId integer, ParentResultId integer, CreationDate DateTime, RawData Blob)"; 52 cAgent.ExecuteNonQuery(); 53 cProject.ExecuteNonQuery(); 54 cResult.ExecuteNonQuery(); 55 } 56 } 57 58 public long CreateAgent() { 59 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 60 cnn.Open(); 61 SQLiteCommand c = cnn.CreateCommand(); 62 c.CommandText = "Insert into Agent (Name) values (@Name); select last_insert_rowid()"; 63 DbParameter nameParam = c.CreateParameter(); 64 nameParam.ParameterName = "@Name"; 65 nameParam.Value = DateTime.Now.ToString(); 66 c.Parameters.Add(nameParam); 67 long id = (long)c.ExecuteScalar(); 68 return id; 69 } 70 } 71 72 public ICollection<AgentEntry> GetAgentEntries() { 73 List<AgentEntry> agents = new List<AgentEntry>(); 74 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 75 cnn.Open(); 76 SQLiteCommand c = cnn.CreateCommand(); 77 c.CommandText = "Select id, name, status, rawdata from Agent"; 78 SQLiteDataReader r = c.ExecuteReader(); 79 while(r.Read()) { 80 AgentEntry agent = new AgentEntry(r.GetInt32(0), r.GetString(1), (AgentStatus)Enum.Parse(typeof(AgentStatus), r.GetString(2)), (byte[])r.GetValue(3)); 81 agents.Add(agent); 82 } 83 } 84 return agents; 85 } 86 87 public ICollection<AgentEntry> GetAgentEntries(AgentStatus status) { 88 List<AgentEntry> agents = new List<AgentEntry>(); 89 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 90 cnn.Open(); 91 SQLiteCommand c = cnn.CreateCommand(); 92 c.CommandText = "Select id, name, status, rawdata from Agent where Status=@Status"; 93 DbParameter statusParameter = c.CreateParameter(); 94 statusParameter.ParameterName = "@Status"; 95 statusParameter.Value = (int)status; 96 c.Parameters.Add(statusParameter); 97 98 SQLiteDataReader r = c.ExecuteReader(); 99 while(r.Read()) { 100 AgentEntry agent = new AgentEntry(r.GetInt32(0), r.GetString(1), (AgentStatus)Enum.Parse(typeof(AgentStatus), r.GetString(2)), (byte[])r.GetValue(3)); 101 agents.Add(agent); 102 } 103 } 104 return agents; 105 } 106 107 public void Update(AgentEntry entry) { 108 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 109 cnn.Open(); 110 SQLiteCommand c = cnn.CreateCommand(); 111 c.CommandText = "Update Agent set Name=@Name, Status=@Status, RawData=@RawData where id=@Id"; 112 DbParameter nameParam = c.CreateParameter(); 113 DbParameter statusParam = c.CreateParameter(); 114 DbParameter rawDataParam = c.CreateParameter(); 115 DbParameter idParam = c.CreateParameter(); 116 nameParam.ParameterName = "@Name"; 117 nameParam.Value = entry.Name; 118 statusParam.ParameterName = "@Status"; 119 statusParam.Value = entry.Status; 120 rawDataParam.ParameterName = "@RawData"; 121 rawDataParam.Value = entry.RawData; 122 idParam.ParameterName = "@Id"; 123 idParam.Value = entry.Id; 124 c.Parameters.Add(nameParam); 125 c.Parameters.Add(statusParam); 126 c.Parameters.Add(rawDataParam); 127 c.Parameters.Add(idParam); 128 c.ExecuteNonQuery(); 129 } 130 } 131 132 public void Update(ResultEntry result) { 44 lock(bigLock) { 45 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 46 cnn.Open(); 47 using(DbTransaction t = cnn.BeginTransaction()) { 48 using(DbCommand cmd = cnn.CreateCommand()) { 49 cmd.CommandText = "CREATE TABLE Project (ID integer primary key autoincrement, Name text, Description text, CreationTime DateTime)"; 50 cmd.Transaction = t; 51 cmd.ExecuteNonQuery(); 52 } 53 using(DbCommand cmd = cnn.CreateCommand()) { 54 cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, Name text, Status text default 'Unknown', RawData Blob)"; 55 cmd.Transaction = t; 56 cmd.ExecuteNonQuery(); 57 } 58 using(DbCommand cmd = cnn.CreateCommand()) { 59 cmd.CommandText = "CREATE TABLE Run (ID integer primary key autoincrement, AgentId integer, CreationTime DateTime, StartTime DateTime, FinishedTime DateTime, Status text default 'Unknown', RawData Blob)"; 60 cmd.Transaction = t; 61 cmd.ExecuteNonQuery(); 62 } 63 using(DbCommand cmd = cnn.CreateCommand()) { 64 cmd.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, RunId integer, ResultId integer, CreationTime DateTime, RawData Blob)"; 65 cmd.Transaction = t; 66 cmd.ExecuteNonQuery(); 67 } 68 t.Commit(); 69 } 70 } 71 } 72 } 73 #endregion 74 75 #region insert agent/run/result/sub-result 76 public long InsertAgent(string name, byte[] rawData) { 77 lock(bigLock) { 78 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 79 cnn.Open(); 80 long id; 81 using(DbTransaction t = cnn.BeginTransaction()) { 82 using(DbCommand c = cnn.CreateCommand()) { 83 c.Transaction = t; 84 c.CommandText = "Insert into Agent (Name, RawData) values (@Name, @RawData); select last_insert_rowid()"; 85 DbParameter nameParam = c.CreateParameter(); 86 nameParam.ParameterName = "@Name"; 87 nameParam.Value = name; 88 c.Parameters.Add(nameParam); 89 DbParameter dataParam = c.CreateParameter(); 90 dataParam.ParameterName = "@RawData"; 91 dataParam.Value = rawData; 92 c.Parameters.Add(dataParam); 93 id = (long)c.ExecuteScalar(); 94 } 95 t.Commit(); 96 return id; 97 } 98 } 99 } 100 } 101 102 public long InsertRun(long agentId, byte[] rawData) { 103 lock(bigLock) { 104 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 105 cnn.Open(); 106 long id; 107 using(DbTransaction t = cnn.BeginTransaction()) { 108 using(DbCommand c = cnn.CreateCommand()) { 109 c.Transaction = t; 110 c.CommandText = "Insert into Run (AgentId, CreationTime, RawData) values (@AgentId, @CreationTime, @RawData); select last_insert_rowid()"; 111 DbParameter agentIdParam = c.CreateParameter(); 112 agentIdParam.ParameterName = "@AgentId"; 113 agentIdParam.Value = agentId; 114 c.Parameters.Add(agentIdParam); 115 DbParameter creationParam = c.CreateParameter(); 116 creationParam.ParameterName = "@CreationTime"; 117 DateTime now = DateTime.Now; 118 creationParam.Value = now; 119 c.Parameters.Add(creationParam); 120 DbParameter rawDataParam = c.CreateParameter(); 121 rawDataParam.ParameterName = "@RawData"; 122 rawDataParam.Value = rawData; 123 c.Parameters.Add(rawDataParam); 124 id = (long)c.ExecuteScalar(); 125 } 126 t.Commit(); 127 return id; 128 } 129 } 130 } 131 } 132 133 public long InsertResult(long runId, byte[] rawData) { 134 lock(bigLock) { 135 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 136 cnn.Open(); 137 long id; 138 using(DbTransaction t = cnn.BeginTransaction()) { 139 using(DbCommand c = cnn.CreateCommand()) { 140 c.Transaction = t; 141 c.CommandText = "Insert into Result (RunId, CreationTime, RawData) values (@RunId, @CreationTime, @RawData); select last_insert_rowid()"; 142 DbParameter runIdParam = c.CreateParameter(); 143 runIdParam.ParameterName = "@RunId"; 144 runIdParam.Value = runId; 145 c.Parameters.Add(runIdParam); 146 DbParameter creationParam = c.CreateParameter(); 147 creationParam.ParameterName = "@CreationTime"; 148 DateTime now = DateTime.Now; 149 creationParam.Value = now; 150 c.Parameters.Add(creationParam); 151 DbParameter rawDataParam = c.CreateParameter(); 152 rawDataParam.ParameterName = "@RawData"; 153 rawDataParam.Value = rawData; 154 c.Parameters.Add(rawDataParam); 155 id = (long)c.ExecuteScalar(); 156 } 157 t.Commit(); 158 return id; 159 } 160 } 161 } 162 } 163 164 public long InsertSubResult(long resultId, byte[] rawData) { 165 lock(bigLock) { 166 167 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 168 cnn.Open(); 169 long id; 170 using(DbTransaction t = cnn.BeginTransaction()) { 171 using(DbCommand c = cnn.CreateCommand()) { 172 c.Transaction = t; 173 c.CommandText = "Insert into Result (ResultId, CreationTime, RawData) values (@ResultId, @CreationTime, @RawData); select last_insert_rowid()"; 174 DbParameter resultIdParam = c.CreateParameter(); 175 resultIdParam.ParameterName = "@ResultId"; 176 resultIdParam.Value = resultId; 177 c.Parameters.Add(resultIdParam); 178 DbParameter creationParam = c.CreateParameter(); 179 creationParam.ParameterName = "@CreationTime"; 180 DateTime now = DateTime.Now; 181 creationParam.Value = now; 182 c.Parameters.Add(creationParam); 183 DbParameter rawDataParam = c.CreateParameter(); 184 rawDataParam.ParameterName = "@RawData"; 185 rawDataParam.Value = rawData; 186 c.Parameters.Add(rawDataParam); 187 id = (long)c.ExecuteScalar(); 188 } 189 t.Commit(); 190 return id; 191 } 192 } 193 } 194 } 195 #endregion 196 197 #region update agent/run 198 public void UpdateAgent(long id, string name) { 199 lock(bigLock) { 200 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 201 cnn.Open(); 202 using(SQLiteTransaction t = cnn.BeginTransaction()) { 203 using(SQLiteCommand c = cnn.CreateCommand()) { 204 c.Transaction = t; 205 c.CommandText = "Update Agent set Name=@Name where id=@Id"; 206 DbParameter nameParam = c.CreateParameter(); 207 DbParameter idParam = c.CreateParameter(); 208 nameParam.ParameterName = "@Name"; 209 nameParam.Value = name; 210 idParam.ParameterName = "@Id"; 211 idParam.Value = id; 212 c.Parameters.Add(nameParam); 213 c.Parameters.Add(idParam); 214 c.ExecuteNonQuery(); 215 } 216 t.Commit(); 217 } 218 } 219 } 220 } 221 222 public void UpdateAgent(long id, ProcessStatus status) { 223 lock(bigLock) { 224 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 225 cnn.Open(); 226 using(SQLiteTransaction t = cnn.BeginTransaction()) { 227 using(SQLiteCommand c = cnn.CreateCommand()) { 228 c.Transaction = t; 229 c.CommandText = "Update Agent set Status=@Status where id=@Id"; 230 DbParameter statusParam = c.CreateParameter(); 231 DbParameter idParam = c.CreateParameter(); 232 statusParam.ParameterName = "@Status"; 233 statusParam.Value = status; 234 idParam.ParameterName = "@Id"; 235 idParam.Value = id; 236 c.Parameters.Add(statusParam); 237 c.Parameters.Add(idParam); 238 c.ExecuteNonQuery(); 239 } 240 t.Commit(); 241 } 242 } 243 } 244 } 245 246 public void UpdateAgent(long id, byte[] rawData) { 247 lock(bigLock) { 248 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 249 cnn.Open(); 250 using(SQLiteTransaction t = cnn.BeginTransaction()) { 251 using(SQLiteCommand c = cnn.CreateCommand()) { 252 c.Transaction = t; 253 c.CommandText = "Update Agent set RawData=@RawData where id=@Id"; 254 DbParameter rawDataParam = c.CreateParameter(); 255 DbParameter idParam = c.CreateParameter(); 256 rawDataParam.ParameterName = "@RawData"; 257 rawDataParam.Value = rawData; 258 idParam.ParameterName = "@Id"; 259 idParam.Value = id; 260 c.Parameters.Add(rawDataParam); 261 c.Parameters.Add(idParam); 262 c.ExecuteNonQuery(); 263 } 264 t.Commit(); 265 } 266 } 267 } 268 } 269 270 public void UpdateRunStart(long runId, DateTime startTime) { 271 lock(bigLock) { 272 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 273 cnn.Open(); 274 using(SQLiteTransaction t = cnn.BeginTransaction()) { 275 using(SQLiteCommand c = cnn.CreateCommand()) { 276 c.Transaction = t; 277 c.CommandText = "Update Run set StartTime=@StartTime where id=@Id"; 278 DbParameter startTimeParam = c.CreateParameter(); 279 DbParameter idParam = c.CreateParameter(); 280 startTimeParam.ParameterName = "@StartTime"; 281 startTimeParam.Value = startTime; 282 idParam.ParameterName = "@Id"; 283 idParam.Value = runId; 284 c.Parameters.Add(startTimeParam); 285 c.Parameters.Add(idParam); 286 c.ExecuteNonQuery(); 287 } 288 t.Commit(); 289 } 290 } 291 } 292 } 293 294 public void UpdateRunFinished(long runId, DateTime finishedTime) { 295 lock(bigLock) { 296 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 297 cnn.Open(); 298 using(SQLiteTransaction t = cnn.BeginTransaction()) { 299 using(SQLiteCommand c = cnn.CreateCommand()) { 300 c.Transaction = t; 301 c.CommandText = "Update Run set FinishedTime=@FinishedTime where id=@Id"; 302 DbParameter finishedTimeParam = c.CreateParameter(); 303 DbParameter idParam = c.CreateParameter(); 304 finishedTimeParam.ParameterName = "@FinishedTime"; 305 finishedTimeParam.Value = finishedTime; 306 idParam.ParameterName = "@Id"; 307 idParam.Value = runId; 308 c.Parameters.Add(finishedTimeParam); 309 c.Parameters.Add(idParam); 310 c.ExecuteNonQuery(); 311 } 312 t.Commit(); 313 } 314 } 315 } 316 } 317 318 public void UpdateRunStatus(long runId, ProcessStatus status) { 319 lock(bigLock) { 320 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 321 cnn.Open(); 322 using(SQLiteTransaction t = cnn.BeginTransaction()) { 323 using(SQLiteCommand c = cnn.CreateCommand()) { 324 c.Transaction = t; 325 c.CommandText = "Update Run set Status=@Status where id=@Id"; 326 DbParameter statusParam = c.CreateParameter(); 327 DbParameter idParam = c.CreateParameter(); 328 statusParam.ParameterName = "@Status"; 329 statusParam.Value = status; 330 idParam.ParameterName = "@Id"; 331 idParam.Value = runId; 332 c.Parameters.Add(statusParam); 333 c.Parameters.Add(idParam); 334 c.ExecuteNonQuery(); 335 } 336 t.Commit(); 337 } 338 } 339 } 340 } 341 342 343 344 #endregion 345 346 347 #region get agent/run/result/sub-result 348 349 public ICollection<AgentEntry> GetAgents(ProcessStatus status) { 350 lock(bigLock) { 351 List<AgentEntry> agents = new List<AgentEntry>(); 352 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 353 cnn.Open(); 354 SQLiteCommand c = cnn.CreateCommand(); 355 c.CommandText = "Select id, name, status, rawdata from Agent where Status=@Status"; 356 DbParameter statusParameter = c.CreateParameter(); 357 statusParameter.ParameterName = "@Status"; 358 statusParameter.Value = status; 359 c.Parameters.Add(statusParameter); 360 361 SQLiteDataReader r = c.ExecuteReader(); 362 while(r.Read()) { 363 AgentEntry agent = new AgentEntry(); 364 agent.Id = r.GetInt32(0); 365 agent.Name = r.GetString(1); 366 agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2)); 367 agent.RawData = (byte[])r.GetValue(3); 368 agents.Add(agent); 369 } 370 } 371 return agents; 372 } 373 } 374 375 public ICollection<AgentEntry> GetAgents() { 376 lock(bigLock) { 377 List<AgentEntry> agents = new List<AgentEntry>(); 378 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 379 cnn.Open(); 380 using(DbCommand c = cnn.CreateCommand()) { 381 c.CommandText = "Select id, name, status, rawdata from Agent"; 382 using(DbDataReader r = c.ExecuteReader()) { 383 while(r.Read()) { 384 AgentEntry agent = new AgentEntry(); 385 agent.Id = r.GetInt32(0); 386 agent.Name = r.GetString(1); 387 agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2)); 388 agent.RawData = (byte[])r.GetValue(3); 389 agents.Add(agent); 390 } 391 } 392 } 393 } 394 return agents; 395 } 396 } 397 398 //(ID integer primary key autoincrement, AgentId integer, CreationTime DateTime, StartTime DateTime, FinishedTime DateTime, Status text default 'Unknown', RawData Blob)"; 399 400 public ICollection<RunEntry> GetRuns() { 401 lock(bigLock) { 402 List<RunEntry> runs = new List<RunEntry>(); 403 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 404 cnn.Open(); 405 using(DbCommand c = cnn.CreateCommand()) { 406 c.CommandText = "Select Id, AgentId, CreationTime, StartTime, FinishedTime, Status, Rawdata from Run"; 407 using(DbDataReader r = c.ExecuteReader()) { 408 while(r.Read()) { 409 RunEntry run = new RunEntry(); 410 run.Id = r.GetInt32(0); 411 run.AgentId = r.GetInt32(1); 412 run.CreationTime = r.GetDateTime(2); 413 run.StartTime = r.GetDateTime(3); 414 run.FinishedTime = r.GetDateTime(4); 415 run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(5)); 416 run.RawData = (byte[])r.GetValue(6); 417 runs.Add(run); 418 } 419 } 420 } 421 } 422 return runs; 423 } 424 } 425 426 public ICollection<RunEntry> GetRuns(ProcessStatus status) { 427 lock(bigLock) { 428 List<RunEntry> runs = new List<RunEntry>(); 429 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 430 cnn.Open(); 431 using(DbCommand c = cnn.CreateCommand()) { 432 c.CommandText = "Select Id, AgentId, CreationTime, StartTime, FinishedTime, Status, Rawdata from Run where Status=@Status"; 433 DbParameter statusParameter = c.CreateParameter(); 434 statusParameter.ParameterName = "@Status"; 435 statusParameter.Value = status; 436 c.Parameters.Add(statusParameter); 437 438 using(DbDataReader r = c.ExecuteReader()) { 439 while(r.Read()) { 440 RunEntry run = new RunEntry(); 441 run.Id = r.GetInt32(0); 442 run.AgentId = r.GetInt32(1); 443 run.CreationTime = r.GetDateTime(2); 444 run.StartTime = r.IsDBNull(3)? null : new Nullable<DateTime>(r.GetDateTime(3)); 445 run.FinishedTime = r.IsDBNull(4) ? null:new Nullable<DateTime>(r.GetDateTime(4)); 446 run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(5)); 447 run.RawData = (byte[])r.GetValue(6); 448 runs.Add(run); 449 } 450 } 451 } 452 } 453 return runs; 454 } 455 } 456 457 // (ID integer primary key autoincrement, RunId integer, ResultId integer, CreationTime DateTime, RawData Blob)"; 458 public ICollection<ResultEntry> GetResults(long runId) { 459 lock(bigLock) { 460 List<ResultEntry> results = new List<ResultEntry>(); 461 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 462 cnn.Open(); 463 using(DbCommand c = cnn.CreateCommand()) { 464 c.CommandText = "Select Id, RunId, CreationTime, Rawdata from Result"; 465 using(DbDataReader r = c.ExecuteReader()) { 466 while(r.Read()) { 467 ResultEntry result = new ResultEntry(); 468 result.Id = r.GetInt32(0); 469 result.RunId = r.GetInt32(1); 470 result.CreationTime = r.GetDateTime(2); 471 result.RawData = (byte[])r.GetValue(3); 472 results.Add(result); 473 } 474 } 475 } 476 } 477 return results; 478 } 479 } 480 481 public ICollection<ResultEntry> GetSubResults(long resultId) { 133 482 throw new NotImplementedException(); 134 483 } 484 #endregion 135 485 } 136 486 } -
trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj
r352 r375 42 42 <RequiredTargetFramework>3.5</RequiredTargetFramework> 43 43 </Reference> 44 <Reference Include="System.Runtime.Serialization"> 45 <RequiredTargetFramework>3.0</RequiredTargetFramework> 46 </Reference> 47 <Reference Include="System.ServiceModel"> 48 <RequiredTargetFramework>3.0</RequiredTargetFramework> 49 </Reference> 44 50 <Reference Include="System.Xml.Linq"> 45 51 <RequiredTargetFramework>3.5</RequiredTargetFramework> … … 53 59 <ItemGroup> 54 60 <Compile Include="HeuristicLabCedmaOperatorsPlugin.cs" /> 61 <Compile Include="OnGridProcessor.cs" /> 55 62 <Compile Include="Properties\AssemblyInfo.cs" /> 56 63 </ItemGroup> 57 64 <ItemGroup> 58 65 <None Include="HeuristicLab.snk" /> 66 </ItemGroup> 67 <ItemGroup> 68 <ProjectReference Include="..\HeuristicLab.CEDMA.Console\HeuristicLab.CEDMA.Console.csproj"> 69 <Project>{F8880599-F224-4EC7-9288-5C4A6853E7BE}</Project> 70 <Name>HeuristicLab.CEDMA.Console</Name> 71 </ProjectReference> 72 <ProjectReference Include="..\HeuristicLab.CEDMA.DB.Interfaces\HeuristicLab.CEDMA.DB.Interfaces.csproj"> 73 <Project>{4F9BB789-D561-436B-B226-2BF44B7D0804}</Project> 74 <Name>HeuristicLab.CEDMA.DB.Interfaces</Name> 75 </ProjectReference> 76 <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj"> 77 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> 78 <Name>HeuristicLab.Core</Name> 79 </ProjectReference> 80 <ProjectReference Include="..\HeuristicLab.Data\HeuristicLab.Data.csproj"> 81 <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project> 82 <Name>HeuristicLab.Data</Name> 83 </ProjectReference> 59 84 </ItemGroup> 60 85 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs
r373 r375 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Grid;28 27 using System.Threading; 28 using HeuristicLab.CEDMA.DB.Interfaces; 29 using System.ServiceModel; 30 using HeuristicLab.CEDMA.Console; 29 31 30 namespace HeuristicLab. DistributedEngine{32 namespace HeuristicLab.CEDMA.Operators { 31 33 public class OnGridProcessor : OperatorBase { 32 34 public override string Description { … … 36 38 public OnGridProcessor() 37 39 : base() { 40 AddVariableInfo(new VariableInfo("AgentId", "Id of the agent that the run should be associated to.", typeof(IntData), VariableKind.In)); 38 41 AddVariableInfo(new VariableInfo("OperatorGraph", "The operator graph that should be executed on the grid", typeof(IOperatorGraph), VariableKind.In)); 39 AddVariableInfo(new VariableInfo(" GridServerUrl", "Url of the gridserver", typeof(StringData), VariableKind.In));42 AddVariableInfo(new VariableInfo("ServerUrl", "Url of the CEDMA server", typeof(StringData), VariableKind.In)); 40 43 } 41 44 42 45 public override IOperation Apply(IScope scope) { 43 46 IOperatorGraph operatorGraph = scope.GetVariableValue<IOperatorGraph>("OperatorGraph", false); 44 string gridServerUrl = scope.GetVariableValue<StringData>("GridServerUrl", true).Data; 45 JobManager jobManager = new JobManager(gridServerUrl); 46 jobManager.Reset(); 47 Scope globalScope = new Scope(); 48 AtomicOperation operation = new AtomicOperation(operatorGraph.InitialOperator, globalScope); 49 WaitHandle w = jobManager.BeginExecuteOperation(globalScope, operation); 50 51 ThreadPool.QueueUserWorkItem(delegate(object status) { 52 w.WaitOne(); 53 jobManager.EndExecuteOperation(operation); 54 }); 47 string serverUrl = scope.GetVariableValue<StringData>("ServerUrl", true).Data; 48 long agentId = scope.GetVariableValue<IntData>("AgentId", true).Data; 49 50 NetTcpBinding binding = new NetTcpBinding(); 51 binding.MaxReceivedMessageSize = 10000000; // 10Mbytes 52 binding.ReaderQuotas.MaxStringContentLength = 10000000; // also 10M chars 53 binding.ReaderQuotas.MaxArrayLength = 10000000; // also 10M elements; 54 binding.Security.Mode = SecurityMode.None; 55 using(ChannelFactory<IDatabase> factory = new ChannelFactory<IDatabase>(binding)) { 56 IDatabase database = factory.CreateChannel(new EndpointAddress(serverUrl)); 57 long id = database.InsertRun(agentId, DbPersistenceManager.Save(operatorGraph)); 58 database.UpdateRunStatus(id, ProcessStatus.Waiting); 59 } 55 60 return null; 56 61 } -
trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs
r372 r375 59 59 engines.Remove(e); 60 60 AgentEntry entry = agent[e]; 61 entry.Status = AgentStatus.Finished;62 database.Update (entry);61 entry.Status = ProcessStatus.Finished; 62 database.UpdateAgent(entry.Id, entry.Status); 63 63 } 64 64 } 65 65 private void CreateNewEngines() { 66 ICollection<AgentEntry> agents = database.GetAgent Entries(AgentStatus.Waiting);66 ICollection<AgentEntry> agents = database.GetAgents(ProcessStatus.Waiting); 67 67 foreach(AgentEntry a in agents) { 68 68 SequentialEngine.SequentialEngine engine = new HeuristicLab.SequentialEngine.SequentialEngine(); … … 75 75 agent[engine] = a; 76 76 engines.Add(engine); 77 a.Status = AgentStatus.Active;78 database.Update (a);77 a.Status = ProcessStatus.Active; 78 database.UpdateAgent(a.Id, a.Status); 79 79 } 80 80 } … … 84 84 engine.ExecuteStep(); 85 85 } 86 Thread.Sleep(100); // prevent over -load86 Thread.Sleep(100); // prevent overload 87 87 } 88 88 } -
trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj
r372 r375 60 60 <ItemGroup> 61 61 <Compile Include="AgentScheduler.cs" /> 62 <Compile Include="RunScheduler.cs" /> 62 63 <Compile Include="DbPersistenceManager.cs" /> 63 64 <Compile Include="ServerApplication.cs" /> … … 87 88 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> 88 89 <Name>HeuristicLab.Core</Name> 90 </ProjectReference> 91 <ProjectReference Include="..\HeuristicLab.Grid\HeuristicLab.Grid.csproj"> 92 <Project>{545CE756-98D8-423B-AC2E-6E7D70926E5C}</Project> 93 <Name>HeuristicLab.Grid</Name> 89 94 </ProjectReference> 90 95 <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj"> -
trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs
r372 r375 36 36 using System.Data.Common; 37 37 using System.Threading; 38 using HeuristicLab.Grid; 38 39 39 40 namespace HeuristicLab.CEDMA.Server { … … 45 46 public ServerForm() { 46 47 InitializeComponent(); 47 InitDatabase();48 InitAgentScheduler();49 50 48 // windows XP returns the external ip on index 0 while windows vista returns the external ip on index 2 51 49 if (System.Environment.OSVersion.Version.Major >= 6) { … … 54 52 addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/CEDMA/World"; 55 53 } 56 Start();57 54 } 58 55 59 56 private void InitAgentScheduler() { 60 57 AgentScheduler scheduler = new AgentScheduler(database); 58 ThreadPool.QueueUserWorkItem(delegate(object status) { scheduler.Run(); }); 59 } 60 61 private void InitRunScheduler() { 62 JobManager jobManager = new JobManager(gridAddress.Text); 63 RunScheduler scheduler = new RunScheduler(database, jobManager); 61 64 ThreadPool.QueueUserWorkItem(delegate(object status) { scheduler.Run(); }); 62 65 } … … 74 77 75 78 private void Start() { 79 InitDatabase(); 80 InitAgentScheduler(); 81 InitRunScheduler(); 82 76 83 host = new ServiceHost(database, new Uri(addressTextBox.Text)); 77 84 ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior(); … … 95 102 private void statusUpdateTimer_Tick(object sender, EventArgs e) { 96 103 } 104 105 private void startButton_Click(object sender, EventArgs e) { 106 Start(); 107 startButton.Enabled = false; 108 } 97 109 } 98 110 } -
trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.designer.cs
r352 r375 51 51 this.activeAgentsTextBox = new System.Windows.Forms.TextBox(); 52 52 this.statusUpdateTimer = new System.Windows.Forms.Timer(this.components); 53 this.gridAddressLabel = new System.Windows.Forms.Label(); 54 this.gridAddress = new System.Windows.Forms.TextBox(); 55 this.startButton = new System.Windows.Forms.Button(); 53 56 this.SuspendLayout(); 54 57 // … … 73 76 // 74 77 this.activeAgentsLabel.AutoSize = true; 75 this.activeAgentsLabel.Location = new System.Drawing.Point(12, 35);78 this.activeAgentsLabel.Location = new System.Drawing.Point(12, 61); 76 79 this.activeAgentsLabel.Name = "activeAgentsLabel"; 77 80 this.activeAgentsLabel.Size = new System.Drawing.Size(75, 13); … … 81 84 // activeAgentsTextBox 82 85 // 83 this.activeAgentsTextBox.Location = new System.Drawing.Point(106, 32);86 this.activeAgentsTextBox.Location = new System.Drawing.Point(106, 58); 84 87 this.activeAgentsTextBox.Name = "activeAgentsTextBox"; 85 88 this.activeAgentsTextBox.ReadOnly = true; … … 95 98 this.statusUpdateTimer.Tick += new System.EventHandler(this.statusUpdateTimer_Tick); 96 99 // 100 // gridAddressLabel 101 // 102 this.gridAddressLabel.AutoSize = true; 103 this.gridAddressLabel.Location = new System.Drawing.Point(12, 35); 104 this.gridAddressLabel.Name = "gridAddressLabel"; 105 this.gridAddressLabel.Size = new System.Drawing.Size(69, 13); 106 this.gridAddressLabel.TabIndex = 9; 107 this.gridAddressLabel.Text = "&Grid address:"; 108 // 109 // gridAddress 110 // 111 this.gridAddress.Location = new System.Drawing.Point(106, 32); 112 this.gridAddress.Name = "gridAddress"; 113 this.gridAddress.Size = new System.Drawing.Size(229, 20); 114 this.gridAddress.TabIndex = 8; 115 // 116 // startButton 117 // 118 this.startButton.Location = new System.Drawing.Point(15, 84); 119 this.startButton.Name = "startButton"; 120 this.startButton.Size = new System.Drawing.Size(75, 23); 121 this.startButton.TabIndex = 10; 122 this.startButton.Text = "Start"; 123 this.startButton.UseVisualStyleBackColor = true; 124 this.startButton.Click += new System.EventHandler(this.startButton_Click); 125 // 97 126 // ServerForm 98 127 // 99 128 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 100 129 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 101 this.ClientSize = new System.Drawing.Size(347, 62); 130 this.ClientSize = new System.Drawing.Size(347, 119); 131 this.Controls.Add(this.startButton); 132 this.Controls.Add(this.gridAddressLabel); 133 this.Controls.Add(this.gridAddress); 102 134 this.Controls.Add(this.activeAgentsLabel); 103 135 this.Controls.Add(this.activeAgentsTextBox); … … 118 150 private System.Windows.Forms.TextBox activeAgentsTextBox; 119 151 private System.Windows.Forms.Timer statusUpdateTimer; 152 private System.Windows.Forms.Label gridAddressLabel; 153 private System.Windows.Forms.TextBox gridAddress; 154 private System.Windows.Forms.Button startButton; 120 155 } 121 156 } -
trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj
r372 r375 49 49 </ItemGroup> 50 50 <ItemGroup> 51 <Compile Include="OnGridProcessor.cs" />52 51 <Compile Include="HeuristicLabDistributedEnginePlugin.cs" /> 53 52 <Compile Include="Properties\AssemblyInfo.cs" />
Note: See TracChangeset
for help on using the changeset viewer.