- Timestamp:
- 01/02/12 11:40:31 (12 years ago)
- Location:
- branches/RegressionBenchmarks
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RegressionBenchmarks
-
branches/RegressionBenchmarks/HeuristicLab.Clients.Hive/3.3
- Property svn:ignore
-
old new 1 1 obj 2 2 Plugin.cs 3 bin
-
- Property svn:ignore
-
branches/RegressionBenchmarks/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r7059 r7255 82 82 83 83 try { 84 this.IsAllowedPrivileged = ServiceLocator.Instance.CallHiveService((s) => s.IsAllowedPrivileged());84 this.IsAllowedPrivileged = HiveServiceLocator.Instance.CallHiveService((s) => s.IsAllowedPrivileged()); 85 85 86 86 var oldJobs = jobs ?? new ItemCollection<RefreshableJob>(); 87 87 jobs = new HiveItemCollection<RefreshableJob>(); 88 var jobsLoaded = ServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());88 var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs()); 89 89 90 90 foreach (var j in jobsLoaded) { … … 113 113 jobs = null; 114 114 throw; 115 } 116 finally { 115 } finally { 117 116 OnRefreshed(); 118 117 } … … 143 142 if (item is JobPermission) { 144 143 var hep = (JobPermission)item; 145 hep.GrantedUserId = ServiceLocator.Instance.CallHiveService((s) => s.GetUserIdByUsername(hep.GrantedUserName));144 hep.GrantedUserId = HiveServiceLocator.Instance.CallHiveService((s) => s.GetUserIdByUsername(hep.GrantedUserName)); 146 145 if (hep.GrantedUserId == Guid.Empty) { 147 146 throw new ArgumentException(string.Format("The user {0} was not found.", hep.GrantedUserName)); 148 147 } 149 ServiceLocator.Instance.CallHiveService((s) => s.GrantPermission(hep.JobId, hep.GrantedUserId, hep.Permission));148 HiveServiceLocator.Instance.CallHiveService((s) => s.GrantPermission(hep.JobId, hep.GrantedUserId, hep.Permission)); 150 149 } 151 150 } else { 152 151 if (item is Job) 153 ServiceLocator.Instance.CallHiveService(s => s.UpdateJob((Job)item));152 HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJob((Job)item)); 154 153 } 155 154 } … … 177 176 178 177 if (item is Job) 179 ServiceLocator.Instance.CallHiveService(s => s.DeleteJob(item.Id)); 180 if (item is RefreshableJob) 181 ServiceLocator.Instance.CallHiveService(s => s.DeleteJob(item.Id)); 178 HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(item.Id)); 179 if (item is RefreshableJob) { 180 RefreshableJob job = (RefreshableJob)item; 181 if (job.RefreshAutomatically) { 182 job.StopResultPolling(); 183 } 184 HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(item.Id)); 185 } 182 186 if (item is JobPermission) { 183 187 var hep = (JobPermission)item; 184 ServiceLocator.Instance.CallHiveService(s => s.RevokePermission(hep.JobId, hep.GrantedUserId));188 HiveServiceLocator.Instance.CallHiveService(s => s.RevokePermission(hep.JobId, hep.GrantedUserId)); 185 189 } 186 190 item.Id = Guid.Empty; … … 216 220 217 221 public static void PauseJob(RefreshableJob refreshableJob) { 218 ServiceLocator.Instance.CallHiveService(service => {222 HiveServiceLocator.Instance.CallHiveService(service => { 219 223 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { 220 224 if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed) … … 226 230 227 231 public static void StopJob(RefreshableJob refreshableJob) { 228 ServiceLocator.Instance.CallHiveService(service => {232 HiveServiceLocator.Instance.CallHiveService(service => { 229 233 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { 230 234 if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed) … … 232 236 } 233 237 }); 234 // execution state does not need to be set. it will be set to Stopped, when all jobs have been downloaded 238 refreshableJob.ExecutionState = ExecutionState.Stopped; 239 } 240 241 public static void ResumeJob(RefreshableJob refreshableJob) { 242 HiveServiceLocator.Instance.CallHiveService(service => { 243 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { 244 if (task.Task.State == TaskState.Paused) { 245 service.RestartTask(task.Task.Id); 246 } 247 } 248 }); 249 refreshableJob.ExecutionState = ExecutionState.Started; 235 250 } 236 251 … … 247 262 var resourceIds = new List<Guid>(); 248 263 foreach (var resourceName in resourceNames) { 249 Guid resourceId = ServiceLocator.Instance.CallHiveService((s) => s.GetResourceId(resourceName));264 Guid resourceId = HiveServiceLocator.Instance.CallHiveService((s) => s.GetResourceId(resourceName)); 250 265 if (resourceId == Guid.Empty) { 251 266 throw new ResourceNotFoundException(string.Format("Could not find the resource '{0}'", resourceName)); … … 260 275 // upload Job 261 276 refreshableJob.Progress.Status = "Uploading Job..."; 262 refreshableJob.Job.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job));277 refreshableJob.Job.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job)); 263 278 bool isPrivileged = refreshableJob.Job.IsPrivileged; 264 refreshableJob.Job = ServiceLocator.Instance.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions279 refreshableJob.Job = HiveServiceLocator.Instance.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions 265 280 refreshableJob.Job.IsPrivileged = isPrivileged; 266 281 cancellationToken.ThrowIfCancellationRequested(); … … 272 287 // upload plugins 273 288 refreshableJob.Progress.Status = "Uploading plugins..."; 274 this.OnlinePlugins = ServiceLocator.Instance.CallHiveService((s) => s.GetPlugins());289 this.OnlinePlugins = HiveServiceLocator.Instance.CallHiveService((s) => s.GetPlugins()); 275 290 this.AlreadyUploadedPlugins = new List<Plugin>(); 276 Plugin configFilePlugin = ServiceLocator.Instance.CallHiveService((s) => UploadConfigurationFile(s, onlinePlugins));291 Plugin configFilePlugin = HiveServiceLocator.Instance.CallHiveService((s) => UploadConfigurationFile(s, onlinePlugins)); 277 292 this.alreadyUploadedPlugins.Add(configFilePlugin); 278 293 cancellationToken.ThrowIfCancellationRequested(); … … 297 312 } 298 313 refreshableJob.Job.Modified = false; 299 } 300 finally { 314 } finally { 301 315 refreshableJob.IsProgressing = false; 302 316 } … … 359 373 if (!cancellationToken.IsCancellationRequested) { 360 374 lock (pluginLocker) { 361 ServiceLocator.Instance.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins));375 HiveServiceLocator.Instance.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins)); 362 376 } 363 377 } 364 }, -1, "Failed to upload plugins");378 }, Settings.Default.MaxRepeatServiceCalls, "Failed to upload plugins"); 365 379 cancellationToken.ThrowIfCancellationRequested(); 366 380 hiveTask.Task.PluginsNeededIds.Add(configPluginId); … … 372 386 if (!cancellationToken.IsCancellationRequested) { 373 387 if (parentHiveTask != null) { 374 hiveTask.Task.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData));388 hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData)); 375 389 } else { 376 hiveTask.Task.Id = ServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData, groups.ToList()));390 hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData, groups.ToList())); 377 391 } 378 392 } 379 }, 50, "Failed to add task", log);393 }, Settings.Default.MaxRepeatServiceCalls, "Failed to add task", log); 380 394 cancellationToken.ThrowIfCancellationRequested(); 381 395 … … 400 414 if (!ae.InnerExceptions.All(e => e is TaskCanceledException)) throw ae; // for some reason the WaitAll throws a AggregateException containg a TaskCanceledException. i don't know where it comes from, however the tasks all finish properly, so for now just ignore it 401 415 } 402 } 403 finally { 416 } finally { 404 417 if (!semaphoreReleased) taskUploadSemaphore.Release(); 405 418 } … … 420 433 // fetch all task objects to create the full tree of tree of HiveTask objects 421 434 refreshableJob.Progress.Status = "Downloading list of tasks..."; 422 allTasks = ServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasks(hiveExperiment.Id));435 allTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasks(hiveExperiment.Id)); 423 436 totalJobCount = allTasks.Count(); 424 437 438 refreshableJob.Progress.Status = "Downloading tasks..."; 425 439 TaskDownloader downloader = new TaskDownloader(allTasks.Select(x => x.Id)); 426 440 downloader.StartAsync(); … … 436 450 } 437 451 IDictionary<Guid, HiveTask> allHiveTasks = downloader.Results; 438 439 refreshableJob.HiveTasks = new ItemCollection<HiveTask>(allHiveTasks.Values.Where(x => !x.Task.ParentTaskId.HasValue)); 440 452 var parents = allHiveTasks.Values.Where(x => !x.Task.ParentTaskId.HasValue); 453 454 refreshableJob.Progress.Status = "Downloading/deserializing complete. Displaying tasks..."; 455 // build child-task tree 456 foreach (HiveTask hiveTask in parents) { 457 BuildHiveJobTree(hiveTask, allTasks, allHiveTasks); 458 } 459 460 refreshableJob.HiveTasks = new ItemCollection<HiveTask>(parents); 441 461 if (refreshableJob.IsFinished()) { 442 462 refreshableJob.ExecutionState = Core.ExecutionState.Stopped; … … 444 464 refreshableJob.ExecutionState = Core.ExecutionState.Started; 445 465 } 446 447 // build child-task tree448 foreach (HiveTask hiveTask in refreshableJob.HiveTasks) {449 BuildHiveJobTree(hiveTask, allTasks, allHiveTasks);450 }451 452 466 refreshableJob.OnLoaded(); 453 } 454 finally { 467 } finally { 455 468 refreshableJob.IsProgressing = false; 456 469 } 457 470 } 458 471 459 private static void BuildHiveJobTree(HiveTask parentHive Job, IEnumerable<LightweightTask> allJobs, IDictionary<Guid, HiveTask> allHiveJobs) {460 IEnumerable<LightweightTask> childTasks = from job in all Jobs461 where job.ParentTaskId.HasValue && job.ParentTaskId.Value == parentHive Job.Task.Id472 private static void BuildHiveJobTree(HiveTask parentHiveTask, IEnumerable<LightweightTask> allTasks, IDictionary<Guid, HiveTask> allHiveTasks) { 473 IEnumerable<LightweightTask> childTasks = from job in allTasks 474 where job.ParentTaskId.HasValue && job.ParentTaskId.Value == parentHiveTask.Task.Id 462 475 orderby job.DateCreated ascending 463 476 select job; 464 477 foreach (LightweightTask task in childTasks) { 465 HiveTask childHiveTask = allHive Jobs[task.Id];466 parentHive Job.AddChildHiveJob(childHiveTask);467 BuildHiveJobTree(childHiveTask, all Jobs, allHiveJobs);478 HiveTask childHiveTask = allHiveTasks[task.Id]; 479 parentHiveTask.AddChildHiveTask(childHiveTask); 480 BuildHiveJobTree(childHiveTask, allTasks, allHiveTasks); 468 481 } 469 482 } … … 482 495 483 496 public static ItemTask LoadItemJob(Guid jobId) { 484 TaskData taskData = ServiceLocator.Instance.CallHiveService(s => s.GetTaskData(jobId));497 TaskData taskData = HiveServiceLocator.Instance.CallHiveService(s => s.GetTaskData(jobId)); 485 498 try { 486 499 return PersistenceUtil.Deserialize<ItemTask>(taskData.Data); … … 507 520 508 521 public static HiveItemCollection<JobPermission> GetJobPermissions(Guid jobId) { 509 return ServiceLocator.Instance.CallHiveService((service) => {522 return HiveServiceLocator.Instance.CallHiveService((service) => { 510 523 IEnumerable<JobPermission> jps = service.GetJobPermissions(jobId); 511 524 foreach (var hep in jps) {
Note: See TracChangeset
for help on using the changeset viewer.