Free cookie consent management tool by TermsFeed Policy Generator

Changeset 390


Ignore:
Timestamp:
07/22/08 19:15:29 (16 years ago)
Author:
gkronber
Message:

unified runs and agents (are actually the same with the minor difference that agents can create new agents (runs)) (ticket #188)

Location:
trunk/sources
Files:
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/AgentList.cs

    r383 r390  
    6464      Agent agent = new Agent();
    6565      agent.Name = DateTime.Now.ToString();
    66       agent.Status = ProcessStatus.Unkown;
     66      agent.Status = ProcessStatus.Unknown;
    6767      agent.Database = database;
    68       long id = database.InsertAgent(agent.Name, DbPersistenceManager.Save(agent));
     68      long id = database.InsertAgent(null, agent.Name, true, DbPersistenceManager.Save(agent));
    6969      agent.Id = id;
    7070      agentList.Add(agent);
  • trunk/sources/HeuristicLab.CEDMA.Core/AgentListView.Designer.cs

    r389 r390  
    119119      this.agentTreeView.TabIndex = 0;
    120120      this.agentTreeView.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.agentTreeView_BeforeExpand);
     121      this.agentTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.agentTreeView_AfterSelect);
    121122      //
    122123      // AgentListView
  • trunk/sources/HeuristicLab.CEDMA.Core/AgentListView.cs

    r389 r390  
    6969    }
    7070
    71     private void variablesListView_SelectedIndexChanged(object sender, EventArgs e) {
    72       if(detailsGroupBox.Controls.Count > 0)
    73         detailsGroupBox.Controls[0].Dispose();
    74       detailsGroupBox.Controls.Clear();
    75       detailsGroupBox.Enabled = false;
    76       if(agentTreeView.SelectedNode!=null) {
    77         IAgent agent = (IAgent)agentTreeView.SelectedNode.Tag;
    78         Control control = (Control)new AgentView(agent);
    79         detailsGroupBox.Controls.Add(control);
    80         control.Dock = DockStyle.Fill;
    81         detailsGroupBox.Enabled = true;
    82       }
    83     }
    84 
    8571    #region Button Events
    8672    private void addButton_Click(object sender, EventArgs e) {
     
    9278    private void agentTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) {
    9379    }
     80
     81    private void agentTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
     82      if(detailsGroupBox.Controls.Count > 0)
     83        detailsGroupBox.Controls[0].Dispose();
     84      detailsGroupBox.Controls.Clear();
     85      detailsGroupBox.Enabled = false;
     86      if(agentTreeView.SelectedNode != null) {
     87        IAgent agent = (IAgent)agentTreeView.SelectedNode.Tag;
     88        Control control = (Control)new AgentView(agent);
     89        detailsGroupBox.Controls.Add(control);
     90        control.Dock = DockStyle.Fill;
     91        detailsGroupBox.Enabled = true;
     92      }
     93    }
    9494  }
    9595}
  • trunk/sources/HeuristicLab.CEDMA.Core/AgentView.cs

    r389 r390  
    5858        }
    5959
    60         if(Agent.Status == ProcessStatus.Unkown) activateButton.Enabled = true;
     60        if(Agent.Status == ProcessStatus.Unknown) activateButton.Enabled = true;
    6161        else activateButton.Enabled = false;
    6262      }
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs

    r375 r390  
    3333    public long Id { get; set; }
    3434    [DataMember]
     35    public long? ParentAgentId { get; set; }
     36    [DataMember]
    3537    public string Name { get; set; }
    3638    [DataMember]
    3739    public ProcessStatus Status { get; set; }
    3840    [DataMember]
     41    public bool ControllerAgent { get; set; }
     42    [DataMember]
    3943    public byte[] RawData { get; set; }
    4044  }
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj

    r382 r390  
    5656    <Compile Include="AgentEntry.cs" />
    5757    <Compile Include="ProcessStatus.cs" />
    58     <Compile Include="RunEntry.cs" />
    5958    <Compile Include="ResultEntry.cs" />
    6059    <Compile Include="HeuristicLabCedmaDbInterfacesPlugin.cs" />
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs

    r389 r390  
    3131  public interface IDatabase {
    3232    [OperationContract]
    33     long InsertAgent(string name, byte[] rawData);
     33    long InsertAgent(long? parentAgentId, string name, bool controllerAgent, byte[] rawData);
    3434
    3535    [OperationContract(Name = "UpdateAgentName")]
     
    4343
    4444    [OperationContract]
    45     long InsertRun(long agentId, byte[] rawData);
     45    long InsertResult(long agentId, string summary, string description, byte[] rawData);
    4646
    4747    [OperationContract]
    48     void UpdateRunStart(long runId, DateTime CreationTime);
    49 
    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 
     48    long InsertSubResult(long resultId, string summary, string description, byte[] rawData);
    6249
    6350    // should be replaced by more powerful querying interface (LINQ provider?)
     
    6653
    6754    [OperationContract]
    68     ICollection<RunEntry> GetRuns(long agentId);
     55    ICollection<AgentEntry> GetSubAgents(long parentAgentId);
    6956
    7057    [OperationContract]
    71     ICollection<ResultEntry> GetResults(long runId);
     58    ICollection<ResultEntry> GetResults(long agentId);
    7259
    7360    [OperationContract]
    74     ICollection<ResultEntry> GetSubResults(long resultId);
     61    ICollection<ResultEntry> GetSubResults(long parentResultId);
    7562
    7663  }
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ProcessStatus.cs

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

    r389 r390  
    3333    public long Id { get; set; }
    3434    [DataMember]
    35     public long RunId { get; set; }
     35    public long? AgentId { get; set; }
    3636    [DataMember]
    37     public long ResultId { get; set; }
     37    public long? ParentResultId { get; set; }
    3838    [DataMember]
    3939    public string Summary { get; set; }
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r389 r390  
    5555            }
    5656            using(DbCommand cmd = cnn.CreateCommand()) {
    57               cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, Name text, Status text default 'Unknown', RawData Blob)";
     57              cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, ParentAgentId integer, Name text, Status text default 'Unknown', ControllerAgent integer, RawData Blob)";
    5858              cmd.Transaction = t;
    5959              cmd.ExecuteNonQuery();
    6060            }
    6161            using(DbCommand cmd = cnn.CreateCommand()) {
    62               cmd.CommandText = "CREATE TABLE Run (ID integer primary key autoincrement, AgentId integer, CreationTime DateTime, StartTime DateTime, FinishedTime DateTime, Status text default 'Unknown', RawData Blob)";
     62              cmd.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, AgentId integer, ParentResultId integer, Summary text, Description text, CreationTime DateTime, RawData Blob)";
    6363              cmd.Transaction = t;
    6464              cmd.ExecuteNonQuery();
    6565            }
    66             using(DbCommand cmd = cnn.CreateCommand()) {
    67               cmd.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, RunId integer, ResultId integer, CreationTime DateTime, RawData Blob)";
    68               cmd.Transaction = t;
    69               cmd.ExecuteNonQuery();
    70             }
    7166            t.Commit();
    7267          }
     
    7974
    8075    #region insert agent/run/result/sub-result
    81     public long InsertAgent(string name, byte[] rawData) {
     76    public long InsertAgent(long? parentAgentId, string name, bool controllerAgent, byte[] rawData) {
    8277      rwLock.EnterWriteLock();
    8378      try {
     
    8883            using(DbCommand c = cnn.CreateCommand()) {
    8984              c.Transaction = t;
    90               c.CommandText = "Insert into Agent (Name, RawData) values (@Name, @RawData); select last_insert_rowid()";
     85              c.CommandText = "Insert into Agent (Name, ParentAgentId, ControllerAgent, RawData) values (@Name, @ParentAgentId, @ControllerAgent, @RawData); select last_insert_rowid()";
    9186              DbParameter nameParam = c.CreateParameter();
    9287              nameParam.ParameterName = "@Name";
    9388              nameParam.Value = name;
    9489              c.Parameters.Add(nameParam);
     90              DbParameter parentParam = c.CreateParameter();
     91              parentParam.ParameterName = "@ParentAgentId";
     92              parentParam.Value = parentAgentId;
     93              c.Parameters.Add(parentParam);
     94              DbParameter controllerParam = c.CreateParameter();
     95              controllerParam.ParameterName = "@ControllerAgent";
     96              controllerParam.Value = controllerAgent;
     97              c.Parameters.Add(controllerParam);
    9598              DbParameter dataParam = c.CreateParameter();
    9699              dataParam.ParameterName = "@RawData";
     
    108111    }
    109112
    110     public long InsertRun(long agentId, byte[] rawData) {
     113    public long InsertResult(long agentId, string summary, string description, byte[] rawData) {
    111114      rwLock.EnterWriteLock();
    112115      try {
     
    117120            using(DbCommand c = cnn.CreateCommand()) {
    118121              c.Transaction = t;
    119               c.CommandText = "Insert into Run (AgentId, CreationTime, RawData) values (@AgentId, @CreationTime, @RawData); select last_insert_rowid()";
     122              c.CommandText = "Insert into Result (AgentId, CreationTime, Summary, Description, RawData) values (@AgentId, @CreationTime, @Summary, @Description, @RawData); select last_insert_rowid()";
    120123              DbParameter agentIdParam = c.CreateParameter();
    121124              agentIdParam.ParameterName = "@AgentId";
     
    127130              creationParam.Value = now;
    128131              c.Parameters.Add(creationParam);
     132              DbParameter summaryParam = c.CreateParameter();
     133              summaryParam.ParameterName = "@Summary";
     134              summaryParam.Value = summary;
     135              c.Parameters.Add(summaryParam);
     136              DbParameter descParam = c.CreateParameter();
     137              descParam.ParameterName = "@Description";
     138              descParam.Value = description;
     139              c.Parameters.Add(descParam);
    129140              DbParameter rawDataParam = c.CreateParameter();
    130141              rawDataParam.ParameterName = "@RawData";
     
    142153    }
    143154
    144     public long InsertResult(long runId, byte[] rawData) {
     155    public long InsertSubResult(long resultId, string summary, string description, byte[] rawData) {
    145156      rwLock.EnterWriteLock();
    146157      try {
     
    151162            using(DbCommand c = cnn.CreateCommand()) {
    152163              c.Transaction = t;
    153               c.CommandText = "Insert into Result (RunId, CreationTime, RawData) values (@RunId, @CreationTime, @RawData); select last_insert_rowid()";
    154               DbParameter runIdParam = c.CreateParameter();
    155               runIdParam.ParameterName = "@RunId";
    156               runIdParam.Value = runId;
    157               c.Parameters.Add(runIdParam);
    158               DbParameter creationParam = c.CreateParameter();
    159               creationParam.ParameterName = "@CreationTime";
    160               DateTime now = DateTime.Now;
    161               creationParam.Value = now;
    162               c.Parameters.Add(creationParam);
    163               DbParameter rawDataParam = c.CreateParameter();
    164               rawDataParam.ParameterName = "@RawData";
    165               rawDataParam.Value = rawData;
    166               c.Parameters.Add(rawDataParam);
    167               id = (long)c.ExecuteScalar();
    168             }
    169             t.Commit();
    170             return id;
    171           }
    172         }
    173       } finally {
    174         rwLock.ExitWriteLock();
    175       }
    176     }
    177 
    178     public long InsertSubResult(long resultId, byte[] rawData) {
    179       rwLock.EnterWriteLock();
    180       try {
    181         using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    182           cnn.Open();
    183           long id;
    184           using(DbTransaction t = cnn.BeginTransaction()) {
    185             using(DbCommand c = cnn.CreateCommand()) {
    186               c.Transaction = t;
    187               c.CommandText = "Insert into Result (ResultId, CreationTime, RawData) values (@ResultId, @CreationTime, @RawData); select last_insert_rowid()";
     164              c.CommandText = "Insert into Result (ParentResultId, CreationTime, Summary, Description, RawData) values (@ParentResultId, @CreationTime, @Summary, @Description, @RawData); select last_insert_rowid()";
    188165              DbParameter resultIdParam = c.CreateParameter();
    189               resultIdParam.ParameterName = "@ResultId";
     166              resultIdParam.ParameterName = "@ParentResultId";
    190167              resultIdParam.Value = resultId;
    191168              c.Parameters.Add(resultIdParam);
     
    195172              creationParam.Value = now;
    196173              c.Parameters.Add(creationParam);
     174              DbParameter summaryParam = c.CreateParameter();
     175              summaryParam.ParameterName = "@Summary";
     176              summaryParam.Value = summary;
     177              c.Parameters.Add(summaryParam);
     178              DbParameter descParam = c.CreateParameter();
     179              descParam.ParameterName = "@Description";
     180              descParam.Value = description;
     181              c.Parameters.Add(descParam);
    197182              DbParameter rawDataParam = c.CreateParameter();
    198183              rawDataParam.ParameterName = "@RawData";
     
    293278    }
    294279
    295     public void UpdateRunStart(long runId, DateTime startTime) {
    296       rwLock.EnterWriteLock();
    297       try {
    298         using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    299           cnn.Open();
    300           using(SQLiteTransaction t = cnn.BeginTransaction()) {
    301             using(SQLiteCommand c = cnn.CreateCommand()) {
    302               c.Transaction = t;
    303               c.CommandText = "Update Run set StartTime=@StartTime where id=@Id";
    304               DbParameter startTimeParam = c.CreateParameter();
    305               DbParameter idParam = c.CreateParameter();
    306               startTimeParam.ParameterName = "@StartTime";
    307               startTimeParam.Value = startTime;
    308               idParam.ParameterName = "@Id";
    309               idParam.Value = runId;
    310               c.Parameters.Add(startTimeParam);
    311               c.Parameters.Add(idParam);
    312               c.ExecuteNonQuery();
    313             }
    314             t.Commit();
    315           }
    316         }
    317       } finally {
    318         rwLock.ExitWriteLock();
    319       }
    320     }
    321 
    322     public void UpdateRunFinished(long runId, DateTime finishedTime) {
    323       rwLock.EnterWriteLock();
    324       try {
    325         using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    326           cnn.Open();
    327           using(SQLiteTransaction t = cnn.BeginTransaction()) {
    328             using(SQLiteCommand c = cnn.CreateCommand()) {
    329               c.Transaction = t;
    330               c.CommandText = "Update Run set FinishedTime=@FinishedTime where id=@Id";
    331               DbParameter finishedTimeParam = c.CreateParameter();
    332               DbParameter idParam = c.CreateParameter();
    333               finishedTimeParam.ParameterName = "@FinishedTime";
    334               finishedTimeParam.Value = finishedTime;
    335               idParam.ParameterName = "@Id";
    336               idParam.Value = runId;
    337               c.Parameters.Add(finishedTimeParam);
    338               c.Parameters.Add(idParam);
    339               c.ExecuteNonQuery();
    340             }
    341             t.Commit();
    342           }
    343         }
    344       } finally {
    345         rwLock.ExitWriteLock();
    346       }
    347     }
    348 
    349     public void UpdateRunStatus(long runId, ProcessStatus status) {
    350       rwLock.EnterWriteLock();
    351       try {
    352         using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    353           cnn.Open();
    354           using(SQLiteTransaction t = cnn.BeginTransaction()) {
    355             using(SQLiteCommand c = cnn.CreateCommand()) {
    356               c.Transaction = t;
    357               c.CommandText = "Update Run set Status=@Status where id=@Id";
    358               DbParameter statusParam = c.CreateParameter();
    359               DbParameter idParam = c.CreateParameter();
    360               statusParam.ParameterName = "@Status";
    361               statusParam.Value = status;
    362               idParam.ParameterName = "@Id";
    363               idParam.Value = runId;
    364               c.Parameters.Add(statusParam);
    365               c.Parameters.Add(idParam);
    366               c.ExecuteNonQuery();
    367             }
    368             t.Commit();
    369           }
    370         }
    371       } finally {
    372         rwLock.ExitWriteLock();
    373       }
    374     }
     280    //public void UpdateRunStart(long runId, DateTime startTime) {
     281    //  rwLock.EnterWriteLock();
     282    //  try {
     283    //    using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     284    //      cnn.Open();
     285    //      using(SQLiteTransaction t = cnn.BeginTransaction()) {
     286    //        using(SQLiteCommand c = cnn.CreateCommand()) {
     287    //          c.Transaction = t;
     288    //          c.CommandText = "Update Run set StartTime=@StartTime where id=@Id";
     289    //          DbParameter startTimeParam = c.CreateParameter();
     290    //          DbParameter idParam = c.CreateParameter();
     291    //          startTimeParam.ParameterName = "@StartTime";
     292    //          startTimeParam.Value = startTime;
     293    //          idParam.ParameterName = "@Id";
     294    //          idParam.Value = runId;
     295    //          c.Parameters.Add(startTimeParam);
     296    //          c.Parameters.Add(idParam);
     297    //          c.ExecuteNonQuery();
     298    //        }
     299    //        t.Commit();
     300    //      }
     301    //    }
     302    //  } finally {
     303    //    rwLock.ExitWriteLock();
     304    //  }
     305    //}
     306
     307    //public void UpdateRunFinished(long runId, DateTime finishedTime) {
     308    //  rwLock.EnterWriteLock();
     309    //  try {
     310    //    using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     311    //      cnn.Open();
     312    //      using(SQLiteTransaction t = cnn.BeginTransaction()) {
     313    //        using(SQLiteCommand c = cnn.CreateCommand()) {
     314    //          c.Transaction = t;
     315    //          c.CommandText = "Update Run set FinishedTime=@FinishedTime where id=@Id";
     316    //          DbParameter finishedTimeParam = c.CreateParameter();
     317    //          DbParameter idParam = c.CreateParameter();
     318    //          finishedTimeParam.ParameterName = "@FinishedTime";
     319    //          finishedTimeParam.Value = finishedTime;
     320    //          idParam.ParameterName = "@Id";
     321    //          idParam.Value = runId;
     322    //          c.Parameters.Add(finishedTimeParam);
     323    //          c.Parameters.Add(idParam);
     324    //          c.ExecuteNonQuery();
     325    //        }
     326    //        t.Commit();
     327    //      }
     328    //    }
     329    //  } finally {
     330    //    rwLock.ExitWriteLock();
     331    //  }
     332    //}
     333
     334    //public void UpdateRunStatus(long runId, ProcessStatus status) {
     335    //  rwLock.EnterWriteLock();
     336    //  try {
     337    //    using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     338    //      cnn.Open();
     339    //      using(SQLiteTransaction t = cnn.BeginTransaction()) {
     340    //        using(SQLiteCommand c = cnn.CreateCommand()) {
     341    //          c.Transaction = t;
     342    //          c.CommandText = "Update Run set Status=@Status where id=@Id";
     343    //          DbParameter statusParam = c.CreateParameter();
     344    //          DbParameter idParam = c.CreateParameter();
     345    //          statusParam.ParameterName = "@Status";
     346    //          statusParam.Value = status;
     347    //          idParam.ParameterName = "@Id";
     348    //          idParam.Value = runId;
     349    //          c.Parameters.Add(statusParam);
     350    //          c.Parameters.Add(idParam);
     351    //          c.ExecuteNonQuery();
     352    //        }
     353    //        t.Commit();
     354    //      }
     355    //    }
     356    //  } finally {
     357    //    rwLock.ExitWriteLock();
     358    //  }
     359    //}
    375360    #endregion
    376361
     
    384369          cnn.Open();
    385370          SQLiteCommand c = cnn.CreateCommand();
    386           c.CommandText = "Select id, name, status, rawdata from Agent where Status=@Status";
     371          c.CommandText = "Select id, name, ControllerAgent, rawdata from Agent where Status=@Status";
    387372          DbParameter statusParameter = c.CreateParameter();
    388373          statusParameter.ParameterName = "@Status";
     
    393378          while(r.Read()) {
    394379            AgentEntry agent = new AgentEntry();
     380            agent.ParentAgentId = null;
     381            agent.Status = status;
    395382            agent.Id = r.GetInt32(0);
    396             agent.Name = r.GetString(1);
    397             agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
     383            agent.Name = r.IsDBNull(1)?"":r.GetString(1);
     384            agent.ControllerAgent = r.GetBoolean(2);
    398385            agent.RawData = (byte[])r.GetValue(3);
    399386            agents.Add(agent);
     
    413400          cnn.Open();
    414401          using(DbCommand c = cnn.CreateCommand()) {
    415             c.CommandText = "Select id, name, status, rawdata from Agent";
     402            c.CommandText = "Select id, ParentAgentId, name, status, ControllerAgent, rawdata from Agent";
    416403            using(DbDataReader r = c.ExecuteReader()) {
    417404              while(r.Read()) {
    418405                AgentEntry agent = new AgentEntry();
    419406                agent.Id = r.GetInt32(0);
     407                agent.ParentAgentId = r.IsDBNull(1) ? null : new Nullable<long>(r.GetInt32(1));
     408                agent.Name = r.GetString(2);
     409                agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
     410                agent.ControllerAgent = r.GetBoolean(4);
     411                agent.RawData = (byte[])r.GetValue(5);
     412                agents.Add(agent);
     413              }
     414            }
     415          }
     416        }
     417      } finally {
     418        rwLock.ExitReadLock();
     419      }
     420      return agents;
     421    }
     422
     423    public ICollection<AgentEntry> GetSubAgents(long parentAgentId) {
     424      rwLock.EnterReadLock();
     425      List<AgentEntry> agents = new List<AgentEntry>();
     426      try {
     427        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     428          cnn.Open();
     429          using(DbCommand c = cnn.CreateCommand()) {
     430            c.CommandText = "Select id, name, status, controllerAgent, rawdata from Agent where ParentAgentId=@ParentAgentId";
     431            using(DbDataReader r = c.ExecuteReader()) {
     432              while(r.Read()) {
     433                AgentEntry agent = new AgentEntry();
     434                agent.ParentAgentId = parentAgentId;
     435                agent.Id = r.GetInt32(0);
    420436                agent.Name = r.GetString(1);
    421437                agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
    422                 agent.RawData = (byte[])r.GetValue(3);
     438                agent.ControllerAgent = r.GetBoolean(3);
     439                agent.RawData = (byte[])r.GetValue(4);
    423440                agents.Add(agent);
    424441              }
     
    432449    }
    433450
    434     public ICollection<RunEntry> GetRuns(long agentId) {
    435       List<RunEntry> runs = new List<RunEntry>();
    436       rwLock.EnterReadLock();
    437       try {
    438         using(DbConnection cnn = new SQLiteConnection(connectionString)) {
    439           cnn.Open();
    440           using(DbCommand c = cnn.CreateCommand()) {
    441             c.CommandText = "Select Id, AgentId, CreationTime, Status, Rawdata from Run where AgentId=@AgentId";
    442             DbParameter agentParameter = c.CreateParameter();
    443             agentParameter.ParameterName = "@AgentId";
    444             agentParameter.Value = agentId;
    445             c.Parameters.Add(agentParameter);
    446 
    447             using(DbDataReader r = c.ExecuteReader()) {
    448               while(r.Read()) {
    449                 RunEntry run = new RunEntry();
    450                 run.Id = r.GetInt32(0);
    451                 run.AgentId = r.GetInt32(1);
    452                 run.CreationTime = r.GetDateTime(2);
    453                 run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
    454                 run.RawData = (byte[])r.GetValue(4);
    455                 runs.Add(run);
    456               }
    457             }
    458           }
    459         }
    460       } finally {
    461         rwLock.ExitReadLock();
    462       }
    463       return runs;
    464     }
    465 
    466     public ICollection<RunEntry> GetRuns(ProcessStatus status) {
    467       List<RunEntry> runs = new List<RunEntry>();
    468       rwLock.EnterReadLock();
    469       try {
    470         using(DbConnection cnn = new SQLiteConnection(connectionString)) {
    471           cnn.Open();
    472           using(DbCommand c = cnn.CreateCommand()) {
    473             c.CommandText = "Select Id, AgentId, CreationTime, Status, Rawdata from Run where Status=@Status";
    474             DbParameter statusParameter = c.CreateParameter();
    475             statusParameter.ParameterName = "@Status";
    476             statusParameter.Value = status;
    477             c.Parameters.Add(statusParameter);
    478 
    479             using(DbDataReader r = c.ExecuteReader()) {
    480               while(r.Read()) {
    481                 RunEntry run = new RunEntry();
    482                 run.Id = r.GetInt32(0);
    483                 run.AgentId = r.GetInt32(1);
    484                 run.CreationTime = r.GetDateTime(2);
    485                 run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
    486                 run.RawData = (byte[])r.GetValue(4);
    487                 runs.Add(run);
    488               }
    489             }
    490           }
    491         }
    492       } finally {
    493         rwLock.ExitReadLock();
    494       }
    495       return runs;
    496     }
    497 
    498     public ICollection<ResultEntry> GetResults(long runId) {
     451    //public ICollection<RunEntry> GetRuns(long agentId) {
     452    //  List<RunEntry> runs = new List<RunEntry>();
     453    //  rwLock.EnterReadLock();
     454    //  try {
     455    //    using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     456    //      cnn.Open();
     457    //      using(DbCommand c = cnn.CreateCommand()) {
     458    //        c.CommandText = "Select Id, AgentId, CreationTime, Status, Rawdata from Run where AgentId=@AgentId";
     459    //        DbParameter agentParameter = c.CreateParameter();
     460    //        agentParameter.ParameterName = "@AgentId";
     461    //        agentParameter.Value = agentId;
     462    //        c.Parameters.Add(agentParameter);
     463
     464    //        using(DbDataReader r = c.ExecuteReader()) {
     465    //          while(r.Read()) {
     466    //            RunEntry run = new RunEntry();
     467    //            run.Id = r.GetInt32(0);
     468    //            run.AgentId = r.GetInt32(1);
     469    //            run.CreationTime = r.GetDateTime(2);
     470    //            run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
     471    //            run.RawData = (byte[])r.GetValue(4);
     472    //            runs.Add(run);
     473    //          }
     474    //        }
     475    //      }
     476    //    }
     477    //  } finally {
     478    //    rwLock.ExitReadLock();
     479    //  }
     480    //  return runs;
     481    //}
     482
     483    //public ICollection<RunEntry> GetRuns(ProcessStatus status) {
     484    //  List<RunEntry> runs = new List<RunEntry>();
     485    //  rwLock.EnterReadLock();
     486    //  try {
     487    //    using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     488    //      cnn.Open();
     489    //      using(DbCommand c = cnn.CreateCommand()) {
     490    //        c.CommandText = "Select Id, AgentId, CreationTime, Status, Rawdata from Run where Status=@Status";
     491    //        DbParameter statusParameter = c.CreateParameter();
     492    //        statusParameter.ParameterName = "@Status";
     493    //        statusParameter.Value = status;
     494    //        c.Parameters.Add(statusParameter);
     495
     496    //        using(DbDataReader r = c.ExecuteReader()) {
     497    //          while(r.Read()) {
     498    //            RunEntry run = new RunEntry();
     499    //            run.Id = r.GetInt32(0);
     500    //            run.AgentId = r.GetInt32(1);
     501    //            run.CreationTime = r.GetDateTime(2);
     502    //            run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
     503    //            run.RawData = (byte[])r.GetValue(4);
     504    //            runs.Add(run);
     505    //          }
     506    //        }
     507    //      }
     508    //    }
     509    //  } finally {
     510    //    rwLock.ExitReadLock();
     511    //  }
     512    //  return runs;
     513    //}
     514
     515    public ICollection<ResultEntry> GetResults(long agentId) {
    499516      List<ResultEntry> results = new List<ResultEntry>();
    500517      rwLock.EnterReadLock();
     
    503520          cnn.Open();
    504521          using(DbCommand c = cnn.CreateCommand()) {
    505             c.CommandText = "Select Id, RunId, CreationTime, Rawdata from Result";
     522            c.CommandText = "Select Id, CreationTime, Summary, Description, Rawdata from Result where AgentId=@AgentId";
     523            DbParameter agentParam = c.CreateParameter();
     524            agentParam.ParameterName = "@AgentId";
     525            agentParam.Value = agentId;
     526            c.Parameters.Add(agentParam);
    506527            using(DbDataReader r = c.ExecuteReader()) {
    507528              while(r.Read()) {
    508529                ResultEntry result = new ResultEntry();
     530                result.AgentId = agentId;
    509531                result.Id = r.GetInt32(0);
    510                 result.RunId = r.GetInt32(1);
    511                 result.CreationTime = r.GetDateTime(2);
    512                 result.RawData = (byte[])r.GetValue(3);
     532                result.CreationTime = r.GetDateTime(1);
     533                result.Summary = r.GetString(2);
     534                result.Description = r.GetString(3);
     535                result.RawData = (byte[])r.GetValue(4);
    513536                results.Add(result);
    514537              }
     
    523546
    524547    public ICollection<ResultEntry> GetSubResults(long resultId) {
    525       throw new NotImplementedException();
     548      List<ResultEntry> results = new List<ResultEntry>();
     549      rwLock.EnterReadLock();
     550      try {
     551        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     552          cnn.Open();
     553          using(DbCommand c = cnn.CreateCommand()) {
     554            c.CommandText = "Select Id, CreationTime, Summary, Description, Rawdata from Result where ParentResultId=@ParentResultId";
     555            DbParameter parentParam = c.CreateParameter();
     556            parentParam.ParameterName = "@ParentResultId";
     557            parentParam.Value = resultId;
     558            c.Parameters.Add(parentParam);
     559            using(DbDataReader r = c.ExecuteReader()) {
     560              while(r.Read()) {
     561                ResultEntry result = new ResultEntry();
     562                result.ParentResultId = resultId;
     563                result.Id = r.GetInt32(0);
     564                result.CreationTime = r.GetDateTime(1);
     565                result.Summary = r.GetString(2);
     566                result.Description = r.GetString(3);
     567                result.RawData = (byte[])r.GetValue(4);
     568                results.Add(result);
     569              }
     570            }
     571          }
     572        }
     573      } finally {
     574        rwLock.ExitReadLock();
     575      }
     576      return results;
    526577    }
    527578    #endregion
  • trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs

    r377 r390  
    4444
    4545    public override IOperation Apply(IScope scope) {
     46     
    4647      IOperatorGraph operatorGraph = scope.GetVariableValue<IOperatorGraph>("OperatorGraph", false);
    4748      string serverUrl = scope.GetVariableValue<StringData>("ServerUrl", true).Data;
     
    5556      using(ChannelFactory<IDatabase> factory = new ChannelFactory<IDatabase>(binding)) {
    5657        IDatabase database = factory.CreateChannel(new EndpointAddress(serverUrl));
    57         long id = database.InsertRun(agentId, DbPersistenceManager.Save(operatorGraph));
    58         database.UpdateRunStatus(id, ProcessStatus.Waiting);
     58        long id = database.InsertAgent(agentId, null, false, DbPersistenceManager.Save(operatorGraph));
     59        database.UpdateAgent(id, ProcessStatus.Waiting);
    5960      }
    6061      return null;
  • trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs

    r388 r390  
    6565    }
    6666    private void CreateNewEngines() {
    67       ICollection<AgentEntry> agents = database.GetAgents(ProcessStatus.Waiting);
     67      IEnumerable<AgentEntry> agents = database.GetAgents(ProcessStatus.Waiting).Where(a=>a.ControllerAgent);
    6868      foreach(AgentEntry a in agents) {
    6969        SequentialEngine.SequentialEngine engine = new HeuristicLab.SequentialEngine.SequentialEngine();
  • trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs

    r380 r390  
    3030using HeuristicLab.CEDMA.Core;
    3131using HeuristicLab.Grid;
     32using System.Diagnostics;
    3233
    3334namespace HeuristicLab.CEDMA.Server {
    3435  public class RunScheduler {
     36    private class Job {
     37      public long AgentId;
     38      public WaitHandle WaitHandle;
     39      public AtomicOperation Operation;
     40    }
    3541    private Database database;
    3642    private JobManager jobManager;
    3743    private const int RELEASE_INTERVAL = 5;
    3844    private object remoteCommLock = new object();
    39     private object collectionsLock = new object();
    40     private Queue<WaitHandle> waithandles;
    41     private Dictionary<WaitHandle, AtomicOperation> runningOperations;
    42     private Dictionary<WaitHandle, long> runningEntries;
     45    private object queueLock = new object();
     46    private Queue<Job> jobQueue;
    4347
    4448    public RunScheduler(Database database, JobManager jobManager) {
    4549      this.database = database;
    4650      this.jobManager = jobManager;
    47       runningOperations = new Dictionary<WaitHandle, AtomicOperation>();
    48       runningEntries = new Dictionary<WaitHandle, long>();
    49       waithandles = new Queue<WaitHandle>();
     51      jobQueue = new Queue<Job>();
    5052      Thread resultsGatheringThread = new Thread(GatherResults);
    5153      resultsGatheringThread.Start();
     
    5860    }
    5961    private void ReleaseWaitingRuns() {
    60       ICollection<RunEntry> runs;
     62      IEnumerable<AgentEntry> agents;
    6163      lock(remoteCommLock) {
    62         runs = database.GetRuns(ProcessStatus.Waiting);
     64        agents = database.GetAgents(ProcessStatus.Waiting).Where(a=>!a.ControllerAgent);
    6365      }
    64       foreach(RunEntry entry in runs) {
     66      foreach(AgentEntry entry in agents) {
    6567        IOperatorGraph opGraph = (IOperatorGraph)DbPersistenceManager.Restore(entry.RawData);
    66         Scope scope = new Scope();
    67         AtomicOperation op = new AtomicOperation(opGraph.InitialOperator, scope);
     68        AtomicOperation op = new AtomicOperation(opGraph.InitialOperator, new Scope());
    6869        WaitHandle wHandle;
    6970        lock(remoteCommLock) {
    70           wHandle = jobManager.BeginExecuteOperation(scope, op);
    71           database.UpdateRunStatus(entry.Id, ProcessStatus.Active);
    72           database.UpdateRunStart(entry.Id, DateTime.Now);
     71          wHandle = jobManager.BeginExecuteOperation(op.Scope, op);
     72          database.UpdateAgent(entry.Id, ProcessStatus.Active);
    7373        }
    7474
    75         lock(collectionsLock) {
    76           waithandles.Enqueue(wHandle);
    77           runningOperations[wHandle] = op;
    78           runningEntries[wHandle] = entry.Id;
     75        Job job = new Job();
     76        job.AgentId = entry.Id;
     77        job.Operation = op;
     78        job.WaitHandle = wHandle;
     79
     80        lock(queueLock) {
     81          jobQueue.Enqueue(job);
    7982        }
    8083      }
     
    8285
    8386    private void GatherResults() {
    84       while(true) {
    85         if(waithandles.Count == 0) Thread.Sleep(1000);
    86         else {
    87           WaitHandle w;
    88           lock(collectionsLock) {
    89             w = waithandles.Dequeue();
    90           }
    91           w.WaitOne();
    92           long id;
    93           AtomicOperation op;
    94           lock(collectionsLock) {
    95             id = runningEntries[w];
    96             runningEntries.Remove(w);
    97             op = runningOperations[w];
    98             runningOperations.Remove(w);
    99           }
    100           w.Close();
    101           lock(remoteCommLock) {
    102             jobManager.EndExecuteOperation(op);
    103             database.UpdateRunStatus(id, ProcessStatus.Finished);
    104             database.UpdateRunFinished(id, DateTime.Now);
     87      try {
     88        while(true) {
     89          int runningJobs;
     90          lock(queueLock) runningJobs = jobQueue.Count;
     91          if(runningJobs==0) Thread.Sleep(1000); // TASK: replace with waithandle
     92          else {
     93            Job job;
     94            lock(queueLock) {
     95              job = jobQueue.Dequeue();
     96            }
     97            job.WaitHandle.WaitOne();
     98            job.WaitHandle.Close();
     99            lock(remoteCommLock) {
     100              jobManager.EndExecuteOperation(job.Operation);
     101              database.UpdateAgent(job.AgentId, ProcessStatus.Finished);
     102            }
    105103          }
    106104        }
     105      } finally {
     106        Debug.Assert(false); // make sure we are notified when this thread is killed while debugging
    107107      }
    108108    }
Note: See TracChangeset for help on using the changeset viewer.