Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/21/11 17:35:42 (14 years ago)
Author:
cneumuel
Message:

#1233

  • fixed handling of StateLog in DataLayer
  • extended unit tests
  • changed style of service calls to OKB-like style (using delegates)
  • added possibility that parent jobs can be finished immediately when child jobs are finished
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs

    r5512 r5526  
    371371        }
    372372        Job cJob = jobs[jobId];
    373         cJob.State = JobState.Finished;//TODO: what if failed?
     373        cJob.State = JobState.Finished; // TODO: what if failed?
    374374        cJob.ExecutionTime = engines[jobId].ExecutionTime;
    375375
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs

    r5511 r5526  
    2222using System;
    2323using System.Collections.Generic;
    24 using HeuristicLab.Clients.Common;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Services.Hive.Common;
     
    4342        if (instance == null) {
    4443          instance = new WcfService();
     44          ServiceLocator.Instance.Username = "hiveslave";
     45          ServiceLocator.Instance.Password = "hiveslave";
    4546        }
    4647        return instance;
     
    7475    /// </summary>
    7576    public void Connect(HeuristicLab.Services.Hive.Common.DataTransfer.Slave slaveInfo) {
    76       using (Disposable<IHiveService> service = GetSlaveService()) {
    77         try {
    78           ConnState = NetworkEnum.WcfConnState.Connected;
    79           ConnectedSince = DateTime.Now;
    80           service.Obj.Hello(slaveInfo);
    81           OnConnected();
    82         }
    83         catch (Exception ex) {
    84           HandleNetworkError(ex);
    85         }
    86       }
     77      CallHiveService(service => {
     78        ConnState = NetworkEnum.WcfConnState.Connected;
     79        ConnectedSince = DateTime.Now;
     80        service.Hello(slaveInfo);
     81        OnConnected();
     82      });
    8783    }
    8884
     
    9187    /// </summary>
    9288    public void Disconnect() {
    93       using (Disposable<IHiveService> service = GetSlaveService()) {
    94         try {
    95           service.Obj.GoodBye(ConfigManager.Instance.GetClientInfo().Id);
    96           ConnState = NetworkEnum.WcfConnState.Disconnected;
    97         }
    98         catch (Exception ex) {
    99           HandleNetworkError(ex);
    100         }
    101       }
     89      CallHiveService(service => {
     90        service.GoodBye(ConfigManager.Instance.GetClientInfo().Id);
     91        ConnState = NetworkEnum.WcfConnState.Disconnected;
     92      });
    10293    }
    10394
     
    115106    /// </summary>
    116107    public Job GetJob(Guid jobId) {
    117       using (Disposable<IHiveService> service = GetSlaveService()) {
    118         try {
    119           Job job = service.Obj.GetJob(jobId);
    120           return job;
    121         }
    122         catch (Exception ex) {
    123           HandleNetworkError(ex);
    124           return null;
    125         }
    126       }
     108      return CallHiveService(s => s.GetJob(jobId));
    127109    }
    128110
    129111    public JobData GetJobData(Guid jobId) {
    130       using (Disposable<IHiveService> service = GetSlaveService()) {
    131         try {
    132           JobData jobData = service.Obj.GetJobData(jobId);
    133           return jobData;
    134         }
    135         catch (Exception ex) {
    136           HandleNetworkError(ex);
    137           return null;
    138         }
    139       }
     112      return CallHiveService(s => s.GetJobData(jobId));
    140113    }
    141114
    142115    public void UpdateJob(Job job) {
    143       using (Disposable<IHiveService> service = GetSlaveService()) {
    144         try {
    145           service.Obj.UpdateJob(job);
    146         }
    147         catch (Exception ex) {
    148           HandleNetworkError(ex);
    149         }
    150       }
     116      CallHiveService(s => s.UpdateJob(job));
    151117    }
    152118
     
    157123    /// <param name="jobData"></param>   
    158124    public void UpdateJobData(Job job, JobData jobData, Guid slaveId) {
    159       using (Disposable<IHiveService> service = GetSlaveService()) {
    160         try {
    161           JobState before = job.State;
    162           job.SetState(JobState.Transferring, slaveId, "");
    163           service.Obj.UpdateJob(job);
     125      CallHiveService(service => {
     126        JobState before = job.State;
     127        job.SetState(JobState.Transferring, slaveId, "");
     128        service.UpdateJob(job);
    164129
    165           service.Obj.UpdateJobData(job, jobData);
     130        service.UpdateJobData(job, jobData);
    166131
    167           job.SetState(before, slaveId, "");
    168           service.Obj.UpdateJob(job);
    169         }
    170         catch (Exception ex) {
    171           HandleNetworkError(ex);
    172         }
     132        job.SetState(before, slaveId, "");
     133        service.UpdateJob(job);
     134      });
     135    }
     136
     137    public List<MessageContainer> SendHeartbeat(Heartbeat heartbeat) {
     138      return CallHiveService(s => s.Heartbeat(heartbeat));
     139    }
     140
     141    public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) {
     142      return CallHiveService(s => s.GetPluginDatas(pluginIds));
     143    }
     144
     145    public IEnumerable<Plugin> GetPlugins() {
     146      return CallHiveService(s => s.GetPlugins());
     147    }
     148
     149    public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
     150      return CallHiveService(s => s.AddChildJob(parentJobId, job, jobData));
     151    }
     152
     153    public IEnumerable<JobData> GetChildJobs(Guid? parentJobId) {
     154      return CallHiveService(service => {
     155        IEnumerable<LightweightJob> msg = service.GetLightweightChildJobs(parentJobId, false, false);
     156
     157        List<JobData> jobs = new List<JobData>();
     158        foreach (LightweightJob ljob in msg)
     159          jobs.Add(service.GetJobData(ljob.Id));
     160
     161        return jobs;
     162      });
     163    }
     164
     165    public void DeleteChildJobs(Guid jobId) {
     166      CallHiveService(s => s.DeleteChildJobs(jobId));
     167    }
     168
     169    public void CallHiveService(Action<IHiveService> call) {
     170      try {
     171        ServiceLocator.Instance.CallHiveService(call);
    173172      }
    174     }
    175    
    176     public List<MessageContainer> SendHeartbeat(Heartbeat heartbeat) {
    177       using (Disposable<IHiveService> service = GetSlaveService()) {
    178         try {
    179           List<MessageContainer> msg = service.Obj.Heartbeat(heartbeat);
    180           return msg;
    181         }
    182         catch (Exception ex) {
    183           HandleNetworkError(ex);
    184           return null;
    185         }
     173      catch (Exception ex) {
     174        HandleNetworkError(ex);
    186175      }
    187176    }
    188177
    189     public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) {
    190       using (Disposable<IHiveService> service = GetSlaveService()) {
    191         try {
    192           IEnumerable<PluginData> msg = service.Obj.GetPluginDatas(pluginIds);
    193           return msg;
    194         }
    195         catch (Exception ex) {
    196           HandleNetworkError(ex);
    197           return null;
    198         }
     178    private T CallHiveService<T>(Func<IHiveService, T> call) {
     179      try {
     180        return ServiceLocator.Instance.CallHiveService(call);
    199181      }
    200     }
    201 
    202     public IEnumerable<Plugin> GetPlugins() {
    203       using (Disposable<IHiveService> service = GetSlaveService()) {
    204         try {
    205           IEnumerable<Plugin> msg = service.Obj.GetPlugins();
    206           return msg;
    207         }
    208         catch (Exception ex) {
    209           HandleNetworkError(ex);
    210           return null;
    211         }
     182      catch (Exception ex) {
     183        HandleNetworkError(ex);
     184        return default(T);
    212185      }
    213     }
    214 
    215     public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
    216       using (Disposable<IHiveService> service = GetSlaveService()) {
    217         try {
    218           Guid msg = service.Obj.AddChildJob(parentJobId, job, jobData);
    219           return msg;
    220         }
    221         catch (Exception ex) {
    222           HandleNetworkError(ex);
    223           return new Guid();
    224         }
    225       }
    226     }
    227 
    228     public IEnumerable<JobData> GetChildJobs(Guid? parentJobId) {
    229       using (Disposable<IHiveService> service = GetSlaveService()) {
    230         try {
    231           IEnumerable<LightweightJob> msg = service.Obj.GetLightweightChildJobs(parentJobId, false, false);
    232 
    233           List<JobData> jobs = new List<JobData>();
    234           foreach (LightweightJob ljob in msg)
    235             jobs.Add(service.Obj.GetJobData(ljob.Id));
    236 
    237           return jobs;
    238         }
    239         catch (Exception ex) {
    240           HandleNetworkError(ex);
    241           return null;
    242         }
    243       }
    244     }
    245 
    246     public void DeleteChildJobs(Guid jobId) {
    247       using (Disposable<IHiveService> service = GetSlaveService()) {
    248         try {
    249           service.Obj.DeleteChildJobs(jobId);
    250         }
    251         catch (Exception ex) {
    252           HandleNetworkError(ex);
    253         }
    254       }
    255     }
    256 
    257     private static Disposable<IHiveService> GetSlaveService() {
    258       return ServiceLocator.Instance.GetService("hiveslave", "hiveslave");
    259186    }
    260187  }
Note: See TracChangeset for help on using the changeset viewer.