Free cookie consent management tool by TermsFeed Policy Generator

Changeset 375


Ignore:
Timestamp:
07/09/08 21:37:36 (16 years ago)
Author:
gkronber
Message:

worked on #188

Location:
trunk/sources
Files:
2 added
16 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs

    r372 r375  
    3333    public long Id { get; set; }
    3434    public string Name { get; set; }
    35     public AgentStatus Status { get; set; }
     35    public ProcessStatus Status { get; set; }
    3636    private OperatorGraph operatorGraph;
    3737
     
    5151
    5252    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));
    5556    }
    5657
    5758    public void Activate() {
    58       Status = AgentStatus.Waiting;
     59      Status = ProcessStatus.Waiting;
    5960      Save();
    6061    }
  • trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs

    r372 r375  
    4646    private void ReloadList() {
    4747      agentList.Clear();
    48       foreach(AgentEntry a in database.GetAgentEntries()) {
     48      foreach(AgentEntry a in database.GetAgents()) {
    4949        Agent newAgent = (Agent)DbPersistenceManager.Restore(a.RawData);
    5050        newAgent.Database = database;
     
    6363
    6464    public void CreateAgent() {
    65       long id = database.CreateAgent();
    66       Agent agent = new Agent(database, id);
     65      Agent agent = new Agent();
    6766      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;
    6971      agentList.Add(agent);
    7072    }
  • trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs

    r372 r375  
    5858        }
    5959
    60         if(Agent.Status == AgentStatus.Unkown) activateButton.Enabled = true;
     60        if(Agent.Status == ProcessStatus.Unkown) activateButton.Enabled = true;
    6161        else activateButton.Enabled = false;
    6262      }
  • trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs

    r372 r375  
    2929
    3030namespace HeuristicLab.CEDMA.Console {
    31   internal static class DbPersistenceManager {
    32     internal static IStorable Restore(byte[] serializedStorable) {
     31  public static class DbPersistenceManager {
     32    public static IStorable Restore(byte[] serializedStorable) {
    3333      GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress);
    3434      return PersistenceManager.Load(stream);
    3535    }
    36     internal static byte[] Save(IStorable storable) {
     36    public static byte[] Save(IStorable storable) {
    3737      MemoryStream memStream = new MemoryStream();
    3838      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
  • trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs

    r372 r375  
    3030  public interface IAgent : IDatabaseItem {
    3131    string Name { get; }
    32     AgentStatus Status { get; }
     32    ProcessStatus Status { get; }
    3333    IOperatorGraph OperatorGraph { get; }
    3434    void Save();
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs

    r372 r375  
    3535    public string Name { get; set; }
    3636    [DataMember]
    37     public AgentStatus Status { get; set; }
     37    public ProcessStatus Status { get; set; }
    3838    [DataMember]
    3939    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     }
    4740  }
    4841}
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj

    r372 r375  
    5959  <ItemGroup>
    6060    <Compile Include="AgentEntry.cs" />
    61     <Compile Include="AgentStatus.cs" />
     61    <Compile Include="ProcessStatus.cs" />
     62    <Compile Include="RunEntry.cs" />
    6263    <Compile Include="ResultEntry.cs" />
    6364    <Compile Include="HeuristicLabCedmaDbInterfacesPlugin.cs" />
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs

    r372 r375  
    3131  public interface IDatabase {
    3232    [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);
    3443
    3544    [OperationContract]
    36     long CreateAgent();
     45    long InsertRun(long agentId, byte[] rawData);
    3746
    38     [OperationContract(Name="UpdateAgent")]
    39     void Update(AgentEntry entry);
     47    [OperationContract]
     48    void UpdateRunStart(long runId, DateTime CreationTime);
    4049
    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
    4376  }
    4477}
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ProcessStatus.cs

    r372 r375  
    2626
    2727namespace HeuristicLab.CEDMA.DB.Interfaces {
    28   public enum AgentStatus { Unkown, Active, Finished, Error, Waiting}
     28  public enum ProcessStatus { Unkown, Active, Finished, Error, Waiting}
    2929}
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs

    r372 r375  
    3131  public class ResultEntry {
    3232    [DataMember]
    33     private long id;
     33    public long Id { get; set; }
    3434    [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; }
    4942  }
    5043}
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r372 r375  
    3232
    3333namespace HeuristicLab.CEDMA.DB {
    34   [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = true)]
     34  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
    3535  public class Database : IDatabase {
    3636    private string connectionString;
     37    private object bigLock = new object();
    3738    public Database(string connectionString) {
    3839      this.connectionString = connectionString;
    3940    }
    4041
     42    #region create empty database
    4143    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) {
    133482      throw new NotImplementedException();
    134483    }
     484    #endregion
    135485  }
    136486}
  • trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj

    r352 r375  
    4242      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    4343    </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>
    4450    <Reference Include="System.Xml.Linq">
    4551      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    5359  <ItemGroup>
    5460    <Compile Include="HeuristicLabCedmaOperatorsPlugin.cs" />
     61    <Compile Include="OnGridProcessor.cs" />
    5562    <Compile Include="Properties\AssemblyInfo.cs" />
    5663  </ItemGroup>
    5764  <ItemGroup>
    5865    <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>
    5984  </ItemGroup>
    6085  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs

    r373 r375  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Grid;
    2827using System.Threading;
     28using HeuristicLab.CEDMA.DB.Interfaces;
     29using System.ServiceModel;
     30using HeuristicLab.CEDMA.Console;
    2931
    30 namespace HeuristicLab.DistributedEngine {
     32namespace HeuristicLab.CEDMA.Operators {
    3133  public class OnGridProcessor : OperatorBase {
    3234    public override string Description {
     
    3638    public OnGridProcessor()
    3739      : base() {
     40      AddVariableInfo(new VariableInfo("AgentId", "Id of the agent that the run should be associated to.", typeof(IntData), VariableKind.In));
    3841      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 grid server", typeof(StringData), VariableKind.In));
     42      AddVariableInfo(new VariableInfo("ServerUrl", "Url of the CEDMA server", typeof(StringData), VariableKind.In));
    4043    }
    4144
    4245    public override IOperation Apply(IScope scope) {
    4346      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      }
    5560      return null;
    5661    }
  • trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs

    r372 r375  
    5959        engines.Remove(e);
    6060        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);
    6363      }
    6464    }
    6565    private void CreateNewEngines() {
    66       ICollection<AgentEntry> agents = database.GetAgentEntries(AgentStatus.Waiting);
     66      ICollection<AgentEntry> agents = database.GetAgents(ProcessStatus.Waiting);
    6767      foreach(AgentEntry a in agents) {
    6868        SequentialEngine.SequentialEngine engine = new HeuristicLab.SequentialEngine.SequentialEngine();
     
    7575        agent[engine] = a;
    7676        engines.Add(engine);
    77         a.Status = AgentStatus.Active;
    78         database.Update(a);
     77        a.Status = ProcessStatus.Active;
     78        database.UpdateAgent(a.Id, a.Status);
    7979      }
    8080    }
     
    8484          engine.ExecuteStep();
    8585        }
    86         Thread.Sleep(100); // prevent over-load
     86        Thread.Sleep(100); // prevent overload
    8787      }
    8888    }
  • trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj

    r372 r375  
    6060  <ItemGroup>
    6161    <Compile Include="AgentScheduler.cs" />
     62    <Compile Include="RunScheduler.cs" />
    6263    <Compile Include="DbPersistenceManager.cs" />
    6364    <Compile Include="ServerApplication.cs" />
     
    8788      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    8889      <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>
    8994    </ProjectReference>
    9095    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
  • trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs

    r372 r375  
    3636using System.Data.Common;
    3737using System.Threading;
     38using HeuristicLab.Grid;
    3839
    3940namespace HeuristicLab.CEDMA.Server {
     
    4546    public ServerForm() {
    4647      InitializeComponent();
    47       InitDatabase();
    48       InitAgentScheduler();
    49 
    5048      // windows XP returns the external ip on index 0 while windows vista returns the external ip on index 2
    5149      if (System.Environment.OSVersion.Version.Major >= 6) {
     
    5452        addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/CEDMA/World";
    5553      }
    56       Start();
    5754    }
    5855
    5956    private void InitAgentScheduler() {
    6057      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);
    6164      ThreadPool.QueueUserWorkItem(delegate(object status) { scheduler.Run(); });
    6265    }
     
    7477
    7578    private void Start() {
     79      InitDatabase();
     80      InitAgentScheduler();
     81      InitRunScheduler();
     82
    7683      host = new ServiceHost(database, new Uri(addressTextBox.Text));
    7784      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
     
    95102    private void statusUpdateTimer_Tick(object sender, EventArgs e) {
    96103    }
     104
     105    private void startButton_Click(object sender, EventArgs e) {
     106      Start();
     107      startButton.Enabled = false;
     108    }
    97109  }
    98110}
  • trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.designer.cs

    r352 r375  
    5151      this.activeAgentsTextBox = new System.Windows.Forms.TextBox();
    5252      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();
    5356      this.SuspendLayout();
    5457      //
     
    7376      //
    7477      this.activeAgentsLabel.AutoSize = true;
    75       this.activeAgentsLabel.Location = new System.Drawing.Point(12, 35);
     78      this.activeAgentsLabel.Location = new System.Drawing.Point(12, 61);
    7679      this.activeAgentsLabel.Name = "activeAgentsLabel";
    7780      this.activeAgentsLabel.Size = new System.Drawing.Size(75, 13);
     
    8184      // activeAgentsTextBox
    8285      //
    83       this.activeAgentsTextBox.Location = new System.Drawing.Point(106, 32);
     86      this.activeAgentsTextBox.Location = new System.Drawing.Point(106, 58);
    8487      this.activeAgentsTextBox.Name = "activeAgentsTextBox";
    8588      this.activeAgentsTextBox.ReadOnly = true;
     
    9598      this.statusUpdateTimer.Tick += new System.EventHandler(this.statusUpdateTimer_Tick);
    9699      //
     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      //
    97126      // ServerForm
    98127      //
    99128      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    100129      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);
    102134      this.Controls.Add(this.activeAgentsLabel);
    103135      this.Controls.Add(this.activeAgentsTextBox);
     
    118150    private System.Windows.Forms.TextBox activeAgentsTextBox;
    119151    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;
    120155  }
    121156}
  • trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj

    r372 r375  
    4949  </ItemGroup>
    5050  <ItemGroup>
    51     <Compile Include="OnGridProcessor.cs" />
    5251    <Compile Include="HeuristicLabDistributedEnginePlugin.cs" />
    5352    <Compile Include="Properties\AssemblyInfo.cs" />
Note: See TracChangeset for help on using the changeset viewer.