- Timestamp:
- 02/21/11 17:35:42 (14 years ago)
- 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 371 371 } 372 372 Job cJob = jobs[jobId]; 373 cJob.State = JobState.Finished; //TODO: what if failed?373 cJob.State = JobState.Finished; // TODO: what if failed? 374 374 cJob.ExecutionTime = engines[jobId].ExecutionTime; 375 375 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs
r5511 r5526 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Clients.Common;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Services.Hive.Common; … … 43 42 if (instance == null) { 44 43 instance = new WcfService(); 44 ServiceLocator.Instance.Username = "hiveslave"; 45 ServiceLocator.Instance.Password = "hiveslave"; 45 46 } 46 47 return instance; … … 74 75 /// </summary> 75 76 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 }); 87 83 } 88 84 … … 91 87 /// </summary> 92 88 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 }); 102 93 } 103 94 … … 115 106 /// </summary> 116 107 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)); 127 109 } 128 110 129 111 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)); 140 113 } 141 114 142 115 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)); 151 117 } 152 118 … … 157 123 /// <param name="jobData"></param> 158 124 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); 164 129 165 service.Obj.UpdateJobData(job, jobData);130 service.UpdateJobData(job, jobData); 166 131 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); 173 172 } 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); 186 175 } 187 176 } 188 177 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); 199 181 } 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); 212 185 } 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");259 186 } 260 187 }
Note: See TracChangeset
for help on using the changeset viewer.