Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2082


Ignore:
Timestamp:
06/23/09 11:35:41 (16 years ago)
Author:
svonolfe
Message:

Avoid out of memory exceptions related to job objects (#372)

Location:
trunk/sources
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/DataAdapterBase.cs

    r2004 r2082  
    8282
    8383    protected delegate IEnumerable<RowT> Selector();
     84    protected delegate object TransactionalAction();
    8485
    8586    protected ObjT Convert(RowT row, ObjT obj) {
     
    109110
    110111    protected ObjT FindSingle(Selector selector) {
    111       ITransaction trans =
    112        session.GetCurrentTransaction();
    113       bool transactionExists = trans != null;
    114       if (!transactionExists) {
    115         trans = session.BeginTransaction();
    116       }
    117 
    118       try {
    119         RowT row = FindSingleRow(selector);
    120 
    121         ObjT result;
    122         if (row != null) {
    123           ObjT obj = new ObjT();
    124           obj = Convert(row, obj);
    125 
    126           result = obj;
    127         } else {
    128           result = default(ObjT);
    129         }
    130 
    131         return result;
    132       }
    133       finally {
    134         if (!transactionExists && trans != null) {
    135           trans.Commit();
    136         }
    137       }
     112      return
     113        (ObjT)doInTransaction(
     114         delegate() {
     115          RowT row = FindSingleRow(selector);
     116
     117          ObjT result;
     118          if (row != null) {
     119            ObjT obj = new ObjT();
     120            obj = Convert(row, obj);
     121
     122            result = obj;
     123          } else {
     124            result = default(ObjT);
     125          }
     126
     127          return result;
     128        });
    138129    }
    139130
    140131    private ICollection<ObjT> FindMultiple(Selector selector,
    141132      int from, int size) {
    142       ITransaction trans =
    143        session.GetCurrentTransaction();
    144       bool transactionExists = trans != null;
    145       if (!transactionExists) {
    146         trans = session.BeginTransaction();
    147       }
    148 
    149       try {
    150         IEnumerable<RowT> found =
    151           selector();
    152 
    153         if (from > 0 && size > 0)
    154           found = found.Skip<RowT>(from).Take<RowT>(size);
    155 
    156         IList<ObjT> result =
    157           new List<ObjT>();
    158 
    159         foreach (RowT row in found) {
    160           ObjT obj = new ObjT();
    161           obj = Convert(row, obj);
    162           if (obj != null)
    163             result.Add(obj);
    164         }
    165 
    166         return result;
    167       }
    168       finally {
    169         if (!transactionExists && trans != null) {
    170           trans.Commit();
    171         }
    172       }     
     133      return (ICollection<ObjT>)doInTransaction(
     134        delegate() {
     135          IEnumerable<RowT> found =
     136            selector();
     137
     138          if (from > 0 && size > 0)
     139            found = found.Skip<RowT>(from).Take<RowT>(size);
     140
     141          IList<ObjT> result =
     142            new List<ObjT>();
     143
     144          foreach (RowT row in found) {
     145            ObjT obj = new ObjT();
     146            obj = Convert(row, obj);
     147            if (obj != null)
     148              result.Add(obj);
     149          }
     150
     151          return result;
     152        });   
    173153    }
    174154
     
    185165    }
    186166
    187     protected virtual void doUpdate(ObjT obj) {
    188       if (obj != null) {
    189         RowT row = null;
    190 
    191         if (obj.Id != Guid.Empty) {
    192           row = GetRowById(obj.Id);
    193         } else {
    194           obj.Id = Guid.NewGuid();
    195         }
    196 
    197         if (row == null) {
    198           row = dataAdapter.InsertNewRow(obj);
    199         }
    200 
    201         ConvertObj(obj, row);
    202         dataAdapter.UpdateRow(row);
    203       }
    204     }
    205 
    206     public void Update(ObjT obj) {
     167    protected object doInTransaction(TransactionalAction action) {
    207168      ITransaction trans =
    208169        session.GetCurrentTransaction();
     
    213174
    214175      try {
    215         doUpdate(obj);
     176        bool result = (bool)action();
     177
     178        if (!transactionExists && trans != null) {
     179            trans.Commit();
     180        }
     181
     182        return result;
     183      }
     184      catch (Exception e) {
     185        if (!transactionExists && trans != null) {
     186          trans.Rollback();
     187        }
     188
     189        throw e;
     190      }
     191    }
     192
     193    protected virtual void doUpdate(ObjT obj) {
     194      if (obj != null) {
     195        RowT row = null;
     196
     197        if (obj.Id != Guid.Empty) {
     198          row = GetRowById(obj.Id);
     199        } else {
     200          obj.Id = Guid.NewGuid();
     201        }
     202
     203        if (row == null) {
     204          row = dataAdapter.InsertNewRow(obj);
     205        }
     206
     207        ConvertObj(obj, row);
     208        dataAdapter.UpdateRow(row);
     209      }
     210    }
     211
     212    public void Update(ObjT obj) {
     213      try {
     214        doInTransaction(
     215          delegate() {
     216            doUpdate(obj);
     217            return true;
     218          });       
    216219      }
    217220      catch (DBConcurrencyException ex) {
     
    234237        //otherwise: row was deleted in the meantime - nothing to do
    235238      }
    236       finally {
    237         if (!transactionExists && trans != null) {
    238           trans.Commit();
    239         }
    240       }
    241239    }
    242240
     
    282280
    283281    public bool Delete(ObjT obj) {
    284       ITransaction trans =
    285         session.GetCurrentTransaction();
    286       bool transactionExists = trans != null;
    287       if (!transactionExists) {
    288         trans = session.BeginTransaction();
    289       }
    290 
    291282      try {
    292         return doDelete(obj);
     283        return (bool)doInTransaction(
     284          delegate() {
     285            return doDelete(obj);
     286          });
    293287      }
    294288      catch (DBConcurrencyException) {
     
    303297        }
    304298      }
    305       finally {
    306         if (!transactionExists && trans != null) {
    307           trans.Commit();
    308         }
    309       } 
    310299    }
    311300  }
  • TabularUnified trunk/sources/HeuristicLab.Grid.HiveBridge/3.2/HiveGridServerWrapper.cs

    r2078 r2082  
    8989    }
    9090
    91     private HeuristicLab.Hive.Contracts.BusinessObjects.Job CreateJobObj(byte[] serializedEngine) {
     91    private HeuristicLab.Hive.Contracts.BusinessObjects.ComputableJob CreateJobObj(byte[] serializedEngine) {
    9292      HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
    9393
     
    111111      stream.Close();
    112112
    113       jobObj.SerializedJob = memStream.ToArray();
     113      ComputableJob computableJob =
     114        new ComputableJob();
     115      computableJob.SerializedJob = memStream.ToArray();
    114116      jobObj.CoresNeeded = 1;
    115117      jobObj.PluginsNeeded = requiredPlugins;
    116118      jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
    117       return jobObj;
     119
     120      computableJob.JobInfo = jobObj;
     121
     122      return computableJob;
    118123    }
    119124
  • TabularUnified trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs

    r2068 r2082  
    297297        bool sandboxed = false;
    298298        List<byte[]> files = new List<byte[]>();
    299         foreach (CachedHivePluginInfo plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded))
     299        foreach (CachedHivePluginInfo plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.JobInfo.PluginsNeeded))
    300300          files.AddRange(plugininfo.PluginFiles);
    301        
    302         AppDomain appDomain = PluginManager.Manager.CreateAndInitAppDomainWithSandbox(e.Result.Job.Id.ToString(), sandboxed, null, files);
     301
     302        AppDomain appDomain = PluginManager.Manager.CreateAndInitAppDomainWithSandbox(e.Result.Job.JobInfo.Id.ToString(), sandboxed, null, files);
    303303        appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException);
    304         lock (engines) {                   
    305           if (!jobs.ContainsKey(e.Result.Job.Id)) {
    306             jobs.Add(e.Result.Job.Id, e.Result.Job);
    307             appDomains.Add(e.Result.Job.Id, appDomain);
     304        lock (engines) {
     305          if (!jobs.ContainsKey(e.Result.Job.JobInfo.Id)) {
     306            jobs.Add(e.Result.Job.JobInfo.Id, e.Result.Job.JobInfo);
     307            appDomains.Add(e.Result.Job.JobInfo.Id, appDomain);
    308308
    309309            Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    310             engine.JobId = e.Result.Job.Id;
     310            engine.JobId = e.Result.Job.JobInfo.Id;
    311311            engine.Queue = MessageQueue.GetInstance();           
    312312            engine.Start(e.Result.Job.SerializedJob);
    313             engines.Add(e.Result.Job.Id, engine);
     313            engines.Add(e.Result.Job.JobInfo.Id, engine);
    314314
    315315            ClientStatusInfo.JobsFetched++;
  • TabularUnified trunk/sources/HeuristicLab.Hive.Contracts/3.2/BusinessObjects/Job.cs

    r1951 r2082  
    4444    public double Percentage { get; set; }
    4545    [DataMember]
    46     public byte[] SerializedJob { get; set; }
    47     [DataMember]
    4846    public DateTime DateCreated { get; set; }
    4947    [DataMember]
  • TabularUnified trunk/sources/HeuristicLab.Hive.Contracts/3.2/HeuristicLab.Hive.Contracts-3.2.csproj

    r1939 r2082  
    8989    <Compile Include="BusinessObjects\CachedHivePluginInfo.cs" />
    9090    <Compile Include="BusinessObjects\ClientGroup.cs" />
     91    <Compile Include="BusinessObjects\ComputableJob.cs" />
    9192    <Compile Include="BusinessObjects\Project.cs" />
    9293    <Compile Include="BusinessObjects\HivePluginInfo.cs" />
  • TabularUnified trunk/sources/HeuristicLab.Hive.Contracts/3.2/Interfaces/IExecutionEngineFacade.cs

    r1509 r2082  
    3131  public interface IExecutionEngineFacade {
    3232    [OperationContract]
    33     ResponseObject<Job> AddJob(Job job);
     33    ResponseObject<Job> AddJob(ComputableJob job);
    3434    [OperationContract]
    3535    Response RequestSnapshot(Guid jobId);
  • TabularUnified trunk/sources/HeuristicLab.Hive.Contracts/3.2/Interfaces/IJobManager.cs

    r2005 r2082  
    3838    ResponseObject<Job> GetJobById(Guid jobId);
    3939    [OperationContract]
    40     ResponseObject<Job> AddNewJob(Job job);
     40    ResponseObject<Job> AddNewJob(ComputableJob job);
    4141    [OperationContract]
    4242    Response RemoveJob(Guid jobId);
  • TabularUnified trunk/sources/HeuristicLab.Hive.Contracts/3.2/ResponseJob.cs

    r1939 r2082  
    3737  public class ResponseJob : Response {
    3838    [DataMember]
    39     public Job Job { get; set; }
     39    public ComputableJob Job { get; set; }
    4040  }
    4141}
  • TabularUnified trunk/sources/HeuristicLab.Hive.Contracts/3.2/WcfSettings.cs

    r2071 r2082  
    2525      NetTcpBinding binding = new NetTcpBinding();
    2626#endif
    27       binding.MaxBufferSize = int.MaxValue;
     27      /*binding.MaxBufferSize = int.MaxValue;
    2828      binding.MaxReceivedMessageSize = int.MaxValue;
    2929      binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
    30       binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
     30      binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;*/
    3131      binding.CloseTimeout = new TimeSpan(0, 5, 0);
    3232      binding.ReceiveTimeout = new TimeSpan(0, 5, 0);
  • TabularUnified trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs

    r2032 r2082  
    193193    }
    194194
    195     private HeuristicLab.Hive.Contracts.BusinessObjects.Job CreateJobObj() {
    196       HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
     195    private HeuristicLab.Hive.Contracts.BusinessObjects.ComputableJob CreateJobObj() {
     196      HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj =
     197        new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
    197198
    198199      MemoryStream memStream = new MemoryStream();
     
    205206      document.Save(stream);
    206207      stream.Close();
    207       jobObj.SerializedJob = memStream.ToArray();
     208
     209      HeuristicLab.Hive.Contracts.BusinessObjects.ComputableJob executableJobObj =
     210        new HeuristicLab.Hive.Contracts.BusinessObjects.ComputableJob();
     211      executableJobObj.JobInfo = jobObj;
     212      executableJobObj.SerializedJob = memStream.ToArray();
    208213
    209214      DiscoveryService service = new DiscoveryService();
     
    234239      jobObj.PluginsNeeded = pluginsNeeded;
    235240      jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
    236       return jobObj;
     241      return executableJobObj;
    237242    }
    238243
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/ClientAdapter.cs

    r1999 r2082  
    189189
    190190    public ClientInfo GetByName(string name) {
    191       ClientInfo client = new ClientInfo();
    192       Resource res =
    193         ResAdapter.GetByName(name);
    194 
    195       return GetById(res.Id);
     191      return (ClientInfo)
     192        base.doInTransaction(
     193        delegate() {
     194          ClientInfo client = new ClientInfo();
     195          Resource res =
     196            ResAdapter.GetByName(name);
     197
     198          return GetById(res.Id);
     199        });
    196200    }
    197201
    198202    protected override bool doDelete(ClientInfo client) {
    199       bool success = false;
    200      
    201       if (client != null) {
    202         dsHiveServer.ClientRow row =
    203           GetRowById(client.Id);
    204 
    205         if (row != null) {
    206           success = base.doDelete(client) &&
    207             ResAdapter.Delete(client);
    208         }
    209       }
    210 
    211       return success;
     203      return (bool)base.doInTransaction(
     204        delegate() {
     205          bool success = false;
     206
     207          if (client != null) {
     208            dsHiveServer.ClientRow row =
     209              GetRowById(client.Id);
     210
     211            if (row != null) {
     212              success = base.doDelete(client) &&
     213                ResAdapter.Delete(client);
     214            }
     215          }
     216
     217          return success;
     218        });
    212219    }
    213220
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/JobAdapter.cs

    r2066 r2082  
    166166          job.Percentage = 0.0;
    167167
    168         if (!row.IsSerializedJobNull())
    169           job.SerializedJob = row.SerializedJob;
    170         else
    171           job.SerializedJob = null;
    172 
    173168        if (!row.IsDateCreatedNull())
    174169          job.DateCreated = row.DateCreated;
     
    255250
    256251        row.Percentage = job.Percentage;
    257 
    258         row.SerializedJob = job.SerializedJob;
    259252
    260253        if (job.DateCreated != DateTime.MinValue)
     
    422415    }
    423416
     417    /// <summary>
     418    /// Gets the computable job with the secified jobId
     419    /// </summary>
     420    /// <param name="jobId"></param>
     421    /// <returns></returns>
     422    public ComputableJob GetComputableJob(Guid jobId) {
     423      return (ComputableJob)base.doInTransaction(
     424        delegate() {
     425          ComputableJob job =
     426            new ComputableJob();
     427
     428          job.JobInfo = GetById(jobId);
     429          dsHiveServer.JobRow row
     430            = GetRowById(jobId);
     431
     432          if (job.JobInfo != null && row != null &&
     433            !row.IsSerializedJobNull()) {
     434
     435            job.SerializedJob =
     436              row.SerializedJob;
     437
     438            return job;
     439          } else {
     440            return null;
     441          }
     442        });
     443    }
     444
     445    /// <summary>
     446    /// Saves or update the computable job
     447    /// </summary>
     448    /// <param name="jobId"></param>
     449    public void UpdateComputableJob(ComputableJob job) {
     450      if(job != null &&
     451        job.JobInfo != null) {
     452        base.doInTransaction(
     453          delegate() {
     454            dsHiveServer.JobRow row
     455              = GetRowById(job.JobInfo.Id);
     456
     457            if (row != null) {
     458              Update(job.JobInfo);
     459              row.SerializedJob =
     460                job.SerializedJob;
     461
     462              base.Adapter.Update(row);
     463            }
     464
     465            return true;
     466          });
     467      }
     468     
     469    }
     470
    424471    #endregion
    425472  }
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.Console/3.2/AddJobForm.cs

    r2026 r2082  
    128128              job.AssignedResourceIds = groupsToCalculate;
    129129            }
    130             job.SerializedJob = PersistenceManager.SaveToGZip(new TestJob());
    131             Response resp = jobManager.AddNewJob(job);
     130
     131            ComputableJob computableJob =
     132              new ComputableJob();
     133            computableJob.JobInfo = job;
     134            computableJob.SerializedJob = PersistenceManager.SaveToGZip(new TestJob());
     135            Response resp = jobManager.AddNewJob(computableJob);
    132136          }
    133137          if (addJobEvent != null) {
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs

    r2022 r2082  
    371371    /// <returns></returns>
    372372    public ResponseJob SendJob(Guid clientId) {
    373       ResponseJob response = new ResponseJob();
    374 
    375       Job job2Calculate = scheduler.GetNextJobForClient(clientId);
    376       if (job2Calculate != null) {
    377         response.Job = job2Calculate;
    378         response.Success = true;
    379         response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_PULLED;
    380         lock (newAssignedJobs) {
    381           newAssignedJobs.Add(job2Calculate.Id, ApplicationConstants.JOB_TIME_TO_LIVE);
    382         }
    383       } else {
    384         response.Success = false;
    385         response.Job = null;
    386         response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT;
    387       }
    388       return response;
     373       ISession session = factory.GetSessionForCurrentThread();
     374      ITransaction tx = null;
     375
     376      try {
     377        IJobAdapter jobAdapter =
     378          session.GetDataAdapter<Job, IJobAdapter>();
     379
     380        tx = session.BeginTransaction();
     381
     382        ResponseJob response = new ResponseJob();
     383
     384        Job job2Calculate = scheduler.GetNextJobForClient(clientId);
     385        if (job2Calculate != null) {
     386          ComputableJob computableJob =
     387            jobAdapter.GetComputableJob(job2Calculate.Id);
     388
     389          response.Job = computableJob;
     390          response.Success = true;
     391          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_PULLED;
     392          lock (newAssignedJobs) {
     393            newAssignedJobs.Add(job2Calculate.Id, ApplicationConstants.JOB_TIME_TO_LIVE);
     394          }
     395        } else {
     396          response.Success = false;
     397          response.Job = null;
     398          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT;
     399        }
     400
     401        return response;
     402      }
     403      catch (Exception ex) {
     404        if (tx != null)
     405          tx.Rollback();
     406        throw ex;
     407      }
     408      finally {
     409        if (session != null)
     410          session.EndSession();
     411      }
    389412    }
    390413
     
    412435          clientAdapter.GetById(clientId);
    413436
    414         Job job =
    415           jobAdapter.GetById(jobId);
     437        ComputableJob job =
     438          new ComputableJob();
     439
     440        if (job != null) {
     441          job.JobInfo =
     442            jobAdapter.GetById(jobId);
     443        }
    416444       
    417         if (job == null) {
     445        if (job == null && job.JobInfo != null) {
    418446          response.Success = false;
    419447          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID;
     
    421449          return response;
    422450        }
    423         if (job.State == State.abort) {
     451        if (job.JobInfo.State == State.abort) {
    424452          response.Success = false;
    425453          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_WAS_ABORTED;
    426454        }
    427         if (job.Client == null) {
     455        if (job.JobInfo.Client == null) {
    428456          response.Success = false;
    429457          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
     
    431459          return response;
    432460        }
    433         if (job.Client.Id != clientId) {
     461        if (job.JobInfo.Client.Id != clientId) {
    434462          response.Success = false;
    435463          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB;
     
    437465          return response;
    438466        }
    439         if (job.State == State.finished) {
     467        if (job.JobInfo.State == State.finished) {
    440468          response.Success = true;
    441469          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED;
     
    443471          return response;
    444472        }
    445         if (job.State == State.requestSnapshotSent) {
    446           job.State = State.calculating;
    447         }
    448         if (job.State != State.calculating && job.State != State.pending) {
     473        if (job.JobInfo.State == State.requestSnapshotSent) {
     474          job.JobInfo.State = State.calculating;
     475        }
     476        if (job.JobInfo.State != State.calculating &&
     477          job.JobInfo.State != State.pending) {
    449478          response.Success = false;
    450479          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_JOB_STATE;
     
    453482        }
    454483        job.SerializedJob = result;
    455         job.Percentage = percentage;
     484        job.JobInfo.Percentage = percentage;
    456485
    457486        if (finished) {
    458           job.State = State.finished;
    459           jobAdapter.Update(job);
    460         }
    461         List<JobResult> jobResults = new List<JobResult>(jobResultAdapter.GetResultsOf(job));
     487          job.JobInfo.State = State.finished;
     488          job.SerializedJob = result;
     489        }
     490
     491        jobAdapter.UpdateComputableJob(job);
     492
     493        List<JobResult> jobResults = new List<JobResult>(
     494          jobResultAdapter.GetResultsOf(job.JobInfo));
    462495        foreach (JobResult currentResult in jobResults)
    463496          jobResultAdapter.Delete(currentResult);
     
    466499          new JobResult();
    467500        jobResult.ClientId = client.Id;
    468         jobResult.JobId = job.Id;
     501        jobResult.JobId = job.JobInfo.Id;
    469502        jobResult.Result = result;
    470503        jobResult.Percentage = percentage;
     
    473506
    474507        jobResultAdapter.Update(jobResult);
    475         jobAdapter.Update(job);
     508        jobAdapter.Update(job.JobInfo);
    476509
    477510        response.Success = true;
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ExecutionEngineFacade.cs

    r1530 r2082  
    3636    #region IExecutionEngineFacade Members
    3737
    38     public ResponseObject<Job> AddJob(Job job) {
     38    public ResponseObject<Job> AddJob(ComputableJob job) {
    3939      return jobManager.AddNewJob(job);
    4040    }
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.Core/3.2/JobManager.cs

    r2005 r2082  
    7373    public void ResetJobsDependingOnResults(Job job) {
    7474      ISession session = factory.GetSessionForCurrentThread();
     75      ITransaction tx = null;
    7576
    7677      try {
     
    7879            session.GetDataAdapter<Job, IJobAdapter>();
    7980
    80         JobResult lastJobResult = GetLastJobResult(job);
    81         if (lastJobResult != null) {
    82           job.Percentage = lastJobResult.Percentage;
    83           job.SerializedJob = lastJobResult.Result;
    84         } else {
    85           job.Percentage = 0;
    86         }
    87 
    88         job.Client = null;
    89         job.State = State.offline;
    90 
    91         jobAdapter.Update(job);
     81        tx = session.BeginTransaction();
     82
     83        if (job != null) {
     84          ComputableJob computableJob =
     85              new ComputableJob();
     86          computableJob.JobInfo =
     87            job;
     88
     89          JobResult lastJobResult = GetLastJobResult(job);
     90          if (lastJobResult != null) {
     91            computableJob.JobInfo.Percentage = lastJobResult.Percentage;
     92            computableJob.SerializedJob = lastJobResult.Result;
     93
     94            jobAdapter.UpdateComputableJob(computableJob);
     95          } else {
     96            computableJob.JobInfo.Percentage = 0;
     97          }
     98
     99          computableJob.JobInfo.Client = null;
     100          computableJob.JobInfo.State = State.offline;
     101
     102          jobAdapter.Update(computableJob.JobInfo);
     103        }
     104
     105        tx.Commit();
     106      }
     107      catch (Exception ex) {
     108        if (tx != null)
     109          tx.Rollback();
     110        throw ex;
    92111      }
    93112      finally {
     
    185204    /// <param name="job"></param>
    186205    /// <returns></returns>
    187     public ResponseObject<Job> AddNewJob(Job job) {
     206    public ResponseObject<Job> AddNewJob(ComputableJob job) {
    188207      ISession session = factory.GetSessionForCurrentThread();
    189208
     
    194213        ResponseObject<Job> response = new ResponseObject<Job>();
    195214
    196         if (job != null) {
    197           if (job.State != State.offline) {
     215        if (job != null && job.JobInfo != null) {
     216          if (job.JobInfo.State != State.offline) {
    198217            response.Success = false;
    199218            response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE;
    200219            return response;
    201220          }
    202           if (job.Id != Guid.Empty) {
     221          if (job.JobInfo.Id != Guid.Empty) {
    203222            response.Success = false;
    204223            response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET;
     
    211230          }
    212231
    213           job.DateCreated = DateTime.Now;
    214           jobAdapter.Update(job);
     232          job.JobInfo.DateCreated = DateTime.Now;
     233          jobAdapter.UpdateComputableJob(job);
    215234          response.Success = true;
    216           response.Obj = job;
     235          response.Obj = job.JobInfo;
    217236          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED;
    218237        } else {
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs

    r2067 r2082  
    9999    }
    100100
    101     public ResponseObject<Job> AddNewJob(Job job) {
    102       secMan.Authorize("AddJob", sessionID, job.Id);
     101    public ResponseObject<Job> AddNewJob(ComputableJob job) {
     102      secMan.Authorize("AddJob", sessionID, job.JobInfo.Id);
    103103      return jobManager.AddNewJob(job);
    104104    }
  • TabularUnified trunk/sources/HeuristicLab.Hive.Server.DataAccess/3.2/IJobAdapter.cs

    r2066 r2082  
    8080    /// <returns></returns>
    8181    ICollection<Job> GetJobsByProject(Guid projectId);
     82
     83    /// <summary>
     84    /// Gets the computable job with the secified jobId
     85    /// </summary>
     86    /// <param name="jobId"></param>
     87    /// <returns></returns>
     88    ComputableJob GetComputableJob(Guid jobId);
     89
     90    /// <summary>
     91    /// Saves or update the computable job
     92    /// </summary>
     93    /// <param name="jobId"></param>
     94    void UpdateComputableJob(ComputableJob job);
    8295  }
    8396}
Note: See TracChangeset for help on using the changeset viewer.