public static void Delete(IHiveItem item) { if (item.Id == Guid.Empty && item.GetType() != typeof(JobPermission)) { return; } if (item is Job) { HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJobState(item.Id, JobState.StatisticsPending)); } if (item is RefreshableJob) { RefreshableJob job = (RefreshableJob)item; if (job.RefreshAutomatically) { job.StopResultPolling(); } HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJobState(item.Id, JobState.StatisticsPending)); } if (item is JobPermission) { var hep = (JobPermission)item; HiveServiceLocator.Instance.CallHiveService(s => s.RevokePermission(hep.JobId, hep.GrantedUserId)); } item.Id = Guid.Empty; }
private void UploadJob(RefreshableJob refreshableJob, CancellationToken cancellationToken) { try { refreshableJob.IsProgressing = true; refreshableJob.Progress.Start("Connecting to server..."); IEnumerable <string> resourceNames = ToResourceNameList(refreshableJob.Job.ResourceNames); var resourceIds = new List <Guid>(); foreach (var resourceName in resourceNames) { Guid resourceId = HiveServiceLocator.Instance.CallHiveService((s) => s.GetResourceId(resourceName)); if (resourceId == Guid.Empty) { throw new ResourceNotFoundException(string.Format("Could not find the resource '{0}'", resourceName)); } resourceIds.Add(resourceId); } foreach (OptimizerHiveTask hiveJob in refreshableJob.HiveTasks.OfType <OptimizerHiveTask>()) { hiveJob.SetIndexInParentOptimizerList(null); } // upload Job refreshableJob.Progress.Status = "Uploading Job..."; refreshableJob.Job.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job)); refreshableJob.Job = HiveServiceLocator.Instance.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions cancellationToken.ThrowIfCancellationRequested(); int totalJobCount = refreshableJob.GetAllHiveTasks().Count(); int[] jobCount = new int[1]; // use a reference type (int-array) instead of value type (int) in order to pass the value via a delegate to task-parallel-library cancellationToken.ThrowIfCancellationRequested(); // upload plugins refreshableJob.Progress.Status = "Uploading plugins..."; this.OnlinePlugins = HiveServiceLocator.Instance.CallHiveService((s) => s.GetPlugins()); this.AlreadyUploadedPlugins = new List <Plugin>(); Plugin configFilePlugin = HiveServiceLocator.Instance.CallHiveService((s) => UploadConfigurationFile(s, onlinePlugins)); this.alreadyUploadedPlugins.Add(configFilePlugin); cancellationToken.ThrowIfCancellationRequested(); // upload tasks refreshableJob.Progress.Status = "Uploading tasks..."; var tasks = new List <TS.Task>(); foreach (HiveTask hiveTask in refreshableJob.HiveTasks) { var task = TS.Task.Factory.StartNew((hj) => { UploadTaskWithChildren(refreshableJob.Progress, (HiveTask)hj, null, resourceIds, jobCount, totalJobCount, configFilePlugin.Id, refreshableJob.Job.Id, refreshableJob.Log, cancellationToken); }, hiveTask); task.ContinueWith((x) => refreshableJob.Log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted); tasks.Add(task); } TS.Task.WaitAll(tasks.ToArray()); } finally { refreshableJob.Job.Modified = false; refreshableJob.IsProgressing = false; refreshableJob.Progress.Finish(); } }
public static void StartJob(Action <Exception> exceptionCallback, RefreshableJob refreshableJob, CancellationToken cancellationToken) { HiveClient.StoreAsync( new Action <Exception>((Exception ex) => { refreshableJob.ExecutionState = ExecutionState.Prepared; exceptionCallback(ex); }), refreshableJob, cancellationToken); refreshableJob.ExecutionState = ExecutionState.Started; }
public static void UpdateJob(Action <Exception> exceptionCallback, RefreshableJob refreshableJob, CancellationToken cancellationToken) { refreshableJob.IsProgressing = true; refreshableJob.Progress.Message = "Saving Job..."; HiveClient.StoreAsync( new Action <Exception>((Exception ex) => { exceptionCallback(ex); }), refreshableJob.Job, cancellationToken); refreshableJob.IsProgressing = false; refreshableJob.Progress.Finish(); }
public static void ResumeJob(RefreshableJob refreshableJob) { HiveServiceLocator.Instance.CallHiveService(service => { foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { if (task.Task.State == TaskState.Paused) { service.RestartTask(task.Task.Id); } } }); refreshableJob.ExecutionState = ExecutionState.Started; }
public static void StopJob(RefreshableJob refreshableJob) { HiveServiceLocator.Instance.CallHiveService(service => { foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed) { service.StopTask(task.Task.Id); } } }); refreshableJob.ExecutionState = ExecutionState.Stopped; }
public static void UpdateJob(RefreshableJob refreshableJob) { refreshableJob.IsProgressing = true; try { refreshableJob.Progress.Start("Saving Job...", ProgressMode.Indeterminate); HiveClient.StoreAsync(new Action <Exception>((Exception ex) => { throw new Exception("Update failed.", ex); }), refreshableJob.Job, new CancellationToken()); } finally { refreshableJob.IsProgressing = false; refreshableJob.Progress.Finish(); } }
public static void StopJob(RefreshableJob refreshableJob) { HiveServiceLocator.Instance.CallHiveService(service => { var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); foreach (var task in tasks) { if (task.State != TaskState.Finished && task.State != TaskState.Aborted && task.State != TaskState.Failed) { service.StopTask(task.Id); } } }); refreshableJob.ExecutionState = ExecutionState.Stopped; }
public static void ResumeJob(RefreshableJob refreshableJob) { HiveServiceLocator.Instance.CallHiveService(service => { var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); foreach (var task in tasks) { if (task.State == TaskState.Paused) { service.RestartTask(task.Id); } } }); refreshableJob.ExecutionState = ExecutionState.Started; }
public void LoadLightweightJob(RefreshableJob refreshableJob) { var job = refreshableJob.Job; var lightweightTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(job.Id)); if (tasks.ContainsKey(job.Id)) { tasks[job.Id].Clear(); tasks[job.Id].AddRange(lightweightTasks); } else { tasks.Add(job.Id, new List <LightweightTask>(lightweightTasks)); } if (lightweightTasks != null && lightweightTasks.Count > 0 && lightweightTasks.All(x => x.Id != Guid.Empty)) { if (lightweightTasks.All(x => x.State == TaskState.Finished || x.State == TaskState.Aborted || x.State == TaskState.Failed)) { refreshableJob.ExecutionState = ExecutionState.Stopped; refreshableJob.RefreshAutomatically = false; } else if ( lightweightTasks .Where(x => x.ParentTaskId != null) .All(x => x.State != TaskState.Waiting || x.State != TaskState.Transferring || x.State != TaskState.Calculating) && lightweightTasks .Where(x => x.ParentTaskId != null) .Any(x => x.State == TaskState.Paused)) { refreshableJob.ExecutionState = ExecutionState.Paused; refreshableJob.RefreshAutomatically = false; } else if (lightweightTasks.Any(x => x.State == TaskState.Calculating || x.State == TaskState.Transferring || x.State == TaskState.Waiting)) { refreshableJob.ExecutionState = ExecutionState.Started; } refreshableJob.ExecutionTime = TimeSpan.FromMilliseconds(lightweightTasks.Sum(x => x.ExecutionTime.TotalMilliseconds)); } }
public static void LoadJob(RefreshableJob refreshableJob) { var hiveExperiment = refreshableJob.Job; refreshableJob.IsProgressing = true; TaskDownloader downloader = null; try { int totalJobCount = 0; IEnumerable <LightweightTask> allTasks; // fetch all task objects to create the full tree of tree of HiveTask objects refreshableJob.Progress.Start("Downloading list of tasks...", ProgressMode.Indeterminate); allTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(hiveExperiment.Id)); totalJobCount = allTasks.Count(); refreshableJob.Progress.Message = "Downloading tasks..."; refreshableJob.Progress.ProgressMode = ProgressMode.Determinate; refreshableJob.Progress.ProgressValue = 0.0; downloader = new TaskDownloader(allTasks.Select(x => x.Id)); downloader.StartAsync(); while (!downloader.IsFinished) { refreshableJob.Progress.ProgressValue = downloader.FinishedCount / (double)totalJobCount; refreshableJob.Progress.Message = string.Format("Downloading/deserializing tasks... ({0}/{1} finished)", downloader.FinishedCount, totalJobCount); Thread.Sleep(500); if (downloader.IsFaulted) { throw downloader.Exception; } } IDictionary <Guid, HiveTask> allHiveTasks = downloader.Results; var parents = allHiveTasks.Values.Where(x => !x.Task.ParentTaskId.HasValue); refreshableJob.Progress.Message = "Downloading/deserializing complete. Displaying tasks..."; refreshableJob.Progress.ProgressMode = ProgressMode.Indeterminate; // build child-task tree foreach (HiveTask hiveTask in parents) { BuildHiveJobTree(hiveTask, allTasks, allHiveTasks); } refreshableJob.HiveTasks = new ItemCollection <HiveTask>(parents); if (refreshableJob.IsFinished()) { refreshableJob.ExecutionState = Core.ExecutionState.Stopped; } else if (refreshableJob.IsPaused()) { refreshableJob.ExecutionState = Core.ExecutionState.Paused; } else { refreshableJob.ExecutionState = Core.ExecutionState.Started; } refreshableJob.OnLoaded(); } finally { refreshableJob.IsProgressing = false; refreshableJob.Progress.Finish(); if (downloader != null) { downloader.Dispose(); } } }
public static void RemoveJob(RefreshableJob refreshableJob) { HiveServiceLocator.Instance.CallHiveService((service) => { service.UpdateJobState(refreshableJob.Id, JobState.StatisticsPending); }); }