- Timestamp:
- 03/16/11 13:32:39 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.LifecycleClient/Program.cs
r5636 r5708 6 6 private static void Main(string[] args) { 7 7 using (var factory = ClientFactory.CreateChannelFactory<IHiveService>("wsHttpBinding_IHiveService", null, "hiveslave", "hiveslave")) { 8 IHiveService client = factory. Obj.CreateChannel();8 IHiveService client = factory.CreateChannel(); 9 9 client.TriggerLifecycle(true); 10 10 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/TransactionManager.cs
r5055 r5708 1 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 2 using System.Transactions; 5 3 using HeuristicLab.Services.Hive.Common; 6 using System.Transactions;7 using HeuristicLab.Common;8 using HeuristicLab.Clients.Common;9 4 10 5 namespace HeuristicLab.Services.Hive.DataAccess { 11 6 public class TransactionManager { 12 public Disposable<TransactionScope> OpenTransaction() { 13 TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope }); 14 var disposable = new Disposable<TransactionScope>(transaction); 15 disposable.OnDisposing += new EventHandler<EventArgs<object>>(disposable_OnDisposing); 16 return disposable; 7 public void UseTransaction(Action call) { 8 TransactionScope transaction = CreateTransaction(); 9 try { 10 call(); 11 transaction.Complete(); 12 } 13 finally { 14 transaction.Dispose(); 15 } 17 16 } 18 17 19 void disposable_OnDisposing(object sender, EventArgs<object> e) { 20 TransactionScope scope = (TransactionScope)e.Value; 21 scope.Complete(); 22 scope.Dispose(); 18 public T UseTransaction<T>(Func<T> call) { 19 TransactionScope transaction = CreateTransaction(); 20 try { 21 T result = call(); 22 transaction.Complete(); 23 return result; 24 } 25 finally { 26 transaction.Dispose(); 27 } 28 } 29 30 private static TransactionScope CreateTransaction() { 31 return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope }); 23 32 } 24 33 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs
r5636 r5708 35 35 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 36 36 public Guid AddJob(Job job, JobData jobData, IEnumerable<Guid> resourceIds) { 37 using (trans.OpenTransaction()){37 return trans.UseTransaction(() => { 38 38 job.Id = dao.AddJob(job); 39 39 jobData.JobId = job.Id; … … 49 49 dao.UpdateJobState(job.Id, JobState.Waiting, null, auth.UserId, null); 50 50 return jobData.JobId; 51 } 51 }); 52 52 } 53 53 … … 55 55 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 56 56 public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) { 57 using (trans.OpenTransaction()){57 return trans.UseTransaction(() => { 58 58 job.ParentJobId = parentJobId; 59 59 return AddJob(job, jobData, dao.GetAssignedResources(parentJobId).Select(x => x.Id)); 60 } 60 }); 61 61 } 62 62 … … 97 97 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 98 98 public void UpdateJob(Job job) { 99 using (trans.OpenTransaction()){99 trans.UseTransaction(() => { 100 100 dao.UpdateJob(job); 101 } 101 }); 102 102 } 103 103 … … 106 106 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 107 107 public void UpdateJobData(Job job, JobData jobData) { 108 using (trans.OpenTransaction()){108 trans.UseTransaction(() => { 109 109 jobData.LastUpdate = DateTime.Now; 110 110 dao.UpdateJob(job); 111 111 dao.UpdateJobData(jobData); 112 } 112 }); 113 113 } 114 114 … … 117 117 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 118 118 public void DeleteJob(Guid jobId) { 119 using (trans.OpenTransaction()){119 trans.UseTransaction(() => { 120 120 dao.DeleteJob(jobId); 121 } 121 }); 122 122 } 123 123 … … 126 126 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 127 127 public void DeleteChildJobs(Guid parentJobId) { 128 using (trans.OpenTransaction()){128 trans.UseTransaction(() => { 129 129 var jobs = GetChildJobs(parentJobId, true, false); 130 130 foreach (var job in jobs) { … … 132 132 dao.DeleteJobData(job.Id); 133 133 }; 134 } 134 }); 135 135 } 136 136 … … 139 139 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 140 140 public Job UpdateJobState(Guid jobId, JobState jobState, Guid? slaveId, Guid? userId, string exception) { 141 using (trans.OpenTransaction()) { 142 return dao.UpdateJobState(jobId, jobState, slaveId, userId, exception); 143 } 141 return trans.UseTransaction(() => dao.UpdateJobState(jobId, jobState, slaveId, userId, exception)); 144 142 } 145 143 #endregion … … 150 148 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 151 149 public void StopJob(Guid jobId) { 152 using (trans.OpenTransaction()){150 trans.UseTransaction(() => { 153 151 throw new NotImplementedException(); 154 } 152 }); 155 153 } 156 154 … … 159 157 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 160 158 public void PauseJob(Guid jobId) { 161 using (trans.OpenTransaction()){159 trans.UseTransaction(() => { 162 160 throw new NotImplementedException(); 163 } 161 }); 164 162 } 165 163 #endregion … … 189 187 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 190 188 public Guid AddHiveExperiment(HiveExperiment hiveExperimentDto) { 191 using (trans.OpenTransaction()){189 return trans.UseTransaction(() => { 192 190 hiveExperimentDto.OwnerUserId = auth.UserId; 193 191 hiveExperimentDto.DateCreated = DateTime.Now; 194 192 return dao.AddHiveExperiment(hiveExperimentDto); 195 } 193 }); 196 194 } 197 195 … … 199 197 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 200 198 public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) { 201 using (trans.OpenTransaction()){199 trans.UseTransaction(() => { 202 200 dao.UpdateHiveExperiment(hiveExperimentDto); 203 } 201 }); 204 202 } 205 203 … … 207 205 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 208 206 public void DeleteHiveExperiment(Guid hiveExperimentId) { 209 using (trans.OpenTransaction()){207 trans.UseTransaction(() => { 210 208 HiveExperiment he = dao.GetHiveExperiment(hiveExperimentId); 211 209 dao.DeleteHiveExperiment(hiveExperimentId); // child jobs will be deleted by db-trigger 212 } 210 }); 213 211 } 214 212 #endregion … … 217 215 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 218 216 public void Hello(Slave slaveInfo) { 219 using (trans.OpenTransaction()){217 trans.UseTransaction(() => { 220 218 var slave = dao.GetSlave(slaveInfo.Id); 221 219 … … 225 223 dao.UpdateSlave(slaveInfo); 226 224 } 227 } 225 }); 228 226 } 229 227 230 228 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 231 229 public void GoodBye(Guid slaveId) { 232 using (trans.OpenTransaction()){230 trans.UseTransaction(() => { 233 231 var slave = dao.GetSlave(slaveId); 234 232 if (slave != null) { … … 236 234 dao.UpdateSlave(slave); 237 235 } 238 } 236 }); 239 237 } 240 238 #endregion … … 244 242 public List<MessageContainer> Heartbeat(Heartbeat heartbeat) { 245 243 TriggerLifecycle(false); 246 247 using (trans.OpenTransaction()) { 248 return heartbeatManager.ProcessHeartbeat(heartbeat); 249 } 244 return trans.UseTransaction(() => heartbeatManager.ProcessHeartbeat(heartbeat)); 250 245 } 251 246 #endregion … … 255 250 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 256 251 public Guid AddPlugin(Plugin plugin, List<PluginData> pluginDatas) { 257 using (trans.OpenTransaction()){252 return trans.UseTransaction(() => { 258 253 plugin.UserId = auth.UserId; 259 254 plugin.DateCreated = DateTime.Now; … … 264 259 } 265 260 return pluginId; 266 } 261 }); 267 262 } 268 263 … … 280 275 List<PluginData> pluginDatas = new List<PluginData>(); 281 276 282 using (trans.OpenTransaction()){277 return trans.UseTransaction(() => { 283 278 foreach (Guid guid in pluginIds) { 284 279 List<PluginData> pluginData = dao.GetPluginDatas(x => x.PluginId == guid).ToList(); … … 290 285 } 291 286 return pluginDatas; 292 } 287 }); 293 288 } 294 289 … … 299 294 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 300 295 public Guid AddSlave(Slave slave) { 301 using (trans.OpenTransaction()) { 302 return dao.AddSlave(slave); 303 } 296 return trans.UseTransaction(() => dao.AddSlave(slave)); 304 297 } 305 298 … … 307 300 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 308 301 public Guid AddSlaveGroup(SlaveGroup slaveGroup) { 309 using (trans.OpenTransaction()) { 310 return dao.AddSlaveGroup(slaveGroup); 311 } 302 return trans.UseTransaction(() => dao.AddSlaveGroup(slaveGroup)); 312 303 } 313 304 … … 337 328 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 338 329 public void UpdateSlave(Slave slave) { 339 using (trans.OpenTransaction()){330 trans.UseTransaction(() => { 340 331 dao.UpdateSlave(slave); 341 } 332 }); 342 333 } 343 334 … … 345 336 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 346 337 public void UpdateSlaveGroup(SlaveGroup slaveGroup) { 347 using (trans.OpenTransaction()){338 trans.UseTransaction(() => { 348 339 dao.UpdateSlaveGroup(slaveGroup); 349 } 340 }); 350 341 } 351 342 … … 353 344 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 354 345 public void DeleteSlave(Guid slaveId) { 355 using (trans.OpenTransaction()){346 trans.UseTransaction(() => { 356 347 dao.DeleteSlave(slaveId); 357 } 348 }); 358 349 } 359 350 … … 361 352 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 362 353 public void DeleteSlaveGroup(Guid slaveGroupId) { 363 using (trans.OpenTransaction()){354 trans.UseTransaction(() => { 364 355 dao.DeleteSlaveGroup(slaveGroupId); 365 } 356 }); 366 357 } 367 358 … … 369 360 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 370 361 public void AddResourceToGroup(Guid slaveGroupId, Guid resourceId) { 371 using (trans.OpenTransaction()){362 trans.UseTransaction(() => { 372 363 var resource = dao.GetResource(resourceId); 373 364 resource.ParentResourceId = slaveGroupId; 374 365 dao.UpdateResource(resource); 375 } 366 }); 376 367 } 377 368 … … 379 370 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 380 371 public void RemoveResourceFromGroup(Guid slaveGroupId, Guid resourceId) { 381 using (trans.OpenTransaction()){372 trans.UseTransaction(() => { 382 373 var resource = dao.GetResource(resourceId); 383 374 resource.ParentResourceId = null; 384 375 dao.UpdateResource(resource); 385 } 376 }); 386 377 } 387 378 … … 389 380 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 390 381 public Guid GetResourceId(string resourceName) { 391 using (trans.OpenTransaction()){382 return trans.UseTransaction(() => { 392 383 var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault(); 393 384 if (resource != null) { … … 396 387 return Guid.Empty; 397 388 } 398 } 389 }); 399 390 } 400 391 401 392 public void TriggerLifecycle(bool force) { 402 using (trans.OpenTransaction()){393 trans.UseTransaction(() => { 403 394 DateTime lastCleanup = dao.GetLastCleanup(); 404 395 if (force || DateTime.Now - lastCleanup > TimeSpan.FromSeconds(59)) { … … 406 397 lifecycleManager.Cleanup(); 407 398 } 408 } 399 }); 409 400 } 410 401 #endregion … … 433 424 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 434 425 public Guid AddAppointment(Appointment appointment) { 435 using (trans.OpenTransaction()) { 436 return dao.AddAppointment(appointment); 437 } 426 return trans.UseTransaction(() => dao.AddAppointment(appointment)); 438 427 } 439 428 440 429 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 441 430 public void DeleteAppointment(Guid appointmentId) { 442 using (trans.OpenTransaction()){431 trans.UseTransaction(() => { 443 432 dao.DeleteAppointment(appointmentId); 444 } 433 }); 445 434 } 446 435 447 436 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 448 437 public void UpdateAppointment(Appointment appointment) { 449 using (trans.OpenTransaction()){438 trans.UseTransaction(() => { 450 439 dao.UpdateAppointment(appointment); 451 } 440 }); 452 441 } 453 442 454 443 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 455 444 public IEnumerable<Appointment> GetScheduleForResource(Guid resourceId) { 456 using (trans.OpenTransaction()) { 457 return dao.GetAppointments(x => x.ResourceId == resourceId); 458 } 445 return trans.UseTransaction(() => dao.GetAppointments(x => x.ResourceId == resourceId)); 459 446 } 460 447 #endregion
Note: See TracChangeset
for help on using the changeset viewer.