Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/09 15:21:33 (15 years ago)
Author:
gkronber
Message:

Fixed bugs in preparation of engines for execution on hive. Used HL.Tracing instead of trace statements. #642 (Hive backend for CEDMA)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Grid.HiveBridge/3.2/HiveGridServerWrapper.cs

    r2064 r2073  
    3232using HeuristicLab.PluginInfrastructure;
    3333using HeuristicLab.Hive.Contracts.BusinessObjects;
     34using System.ServiceModel;
     35using HeuristicLab.Tracing;
    3436
    3537namespace HeuristicLab.Grid.HiveBridge {
    3638  public class HiveGridServerWrapper : IGridServer {
     39    private const int MAX_CONNECTION_RETRIES = 10;
     40    private const int RETRY_TIMEOUT_SEC = 60;
    3741    private string address;
     42    private IExecutionEngineFacade executionEngine;
     43    private object connectionLock = new object();
    3844
    3945    public HiveGridServerWrapper(string address) {
     
    4248
    4349    public JobState JobState(Guid guid) {
    44       IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(address);
    45       ResponseObject<JobResult> response = executionEngineFacade.GetLastResult(guid, false);
    46       if (response.Success == true &&
     50      ResponseObject<JobResult> response = SavelyExecute(() => executionEngine.GetLastResult(guid, false));
     51      if (response != null && response.Success == true &&
    4752        (response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE ||
    4853          response.StatusMessage == ApplicationConstants.RESPONSE_JOB_REQUEST_SET ||
    4954          response.StatusMessage == ApplicationConstants.RESPONSE_JOB_REQUEST_ALLREADY_SET ||
    5055          response.StatusMessage == ApplicationConstants.RESPONSE_JOB_JOB_RESULT_SENT)) {
    51           return HeuristicLab.Grid.JobState.Busy;
     56        return HeuristicLab.Grid.JobState.Busy;
    5257      } else return HeuristicLab.Grid.JobState.Unknown;
    5358    }
     
    5661      var jobObj = CreateJobObj(engine);
    5762
    58       IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(address);
    59       ResponseObject<HeuristicLab.Hive.Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
    60       return res.Obj.Id;
     63      ResponseObject<HeuristicLab.Hive.Contracts.BusinessObjects.Job> res = SavelyExecute(() => executionEngine.AddJob(jobObj));
     64      return res == null ? Guid.Empty : res.Obj.Id;
    6165    }
    6266
    6367    public byte[] TryEndExecuteEngine(Guid guid) {
    64       IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(address);
    65       ResponseObject<JobResult> response = executionEngineFacade.GetLastResult(guid, false);
    66       if (response.Success && response.Obj != null) {
     68      ResponseObject<JobResult> response = SavelyExecute(() => executionEngine.GetLastResult(guid, false));
     69      if (response != null &&
     70        response.Success && response.Obj != null) {
    6771        HeuristicLab.Hive.Engine.Job restoredJob = (HeuristicLab.Hive.Engine.Job)PersistenceManager.RestoreFromGZip(response.Obj.Result);
    6872        // Serialize the engine
     
    8993      job.Engine.OperatorGraph.AddOperator(engine.OperatorGraph.InitialOperator);
    9094      job.Engine.OperatorGraph.InitialOperator = engine.OperatorGraph.InitialOperator;
     95      job.Engine.Reset();
    9196
    9297      // Serialize the job
     
    143148      return engine;
    144149    }
     150
     151    private TResult SavelyExecute<TResult>(Func<TResult> a) where TResult : Response {
     152      int retries = 0;
     153      if (executionEngine == null)
     154        executionEngine = ServiceLocator.CreateExecutionEngineFacade(address);
     155
     156      do {
     157        try {
     158          lock (connectionLock) {
     159            return a();
     160          }
     161        }
     162        catch (TimeoutException) {
     163          retries++;
     164          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
     165        }
     166        catch (CommunicationException) {
     167          executionEngine = ServiceLocator.CreateExecutionEngineFacade(address);
     168          retries++;
     169          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
     170        }
     171      } while (retries < MAX_CONNECTION_RETRIES);
     172      Logger.Warn("Reached max connection retries");
     173      return null;
     174    }
    145175  }
    146176}
Note: See TracChangeset for help on using the changeset viewer.