public override void Execute() { IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView; var content = (IItem)activeView.Content; var clonedConent = (IItem)content.Clone(); //IOptimizer and IExecutables need some special care if (clonedConent is IOptimizer) { ((IOptimizer)clonedConent).Runs.Clear(); } if (clonedConent is IExecutable) { IExecutable exec = clonedConent as IExecutable; if (exec.ExecutionState != ExecutionState.Prepared) { exec.Prepare(); } } HiveClient.Instance.Refresh(); ItemTask hiveTask = ItemTask.GetItemTaskForItem(clonedConent); HiveTask task = hiveTask.CreateHiveTask(); RefreshableJob rJob = new RefreshableJob(); rJob.Job.Name = clonedConent.ToString(); rJob.HiveTasks.Add(task); task.ItemTask.ComputeInParallel = clonedConent is Experiment || clonedConent is BatchRun; MainFormManager.MainForm.ShowContent(rJob); }
public override void Execute() { IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; content = activeView.Content as IItem; //IOptimizer and IExecutables need some special care if (content is IOptimizer) { ((IOptimizer)content).Runs.Clear(); } if (content is IExecutable) { IExecutable exec = content as IExecutable; if (exec.ExecutionState != ExecutionState.Prepared) { exec.Prepare(); } } HiveClient.Instance.Refresh(); ItemTask hiveTask = ItemTask.GetItemTaskForItem(content); HiveTask task = hiveTask.CreateHiveTask(); RefreshableJob rJob = new RefreshableJob(); rJob.Job.Name = content.ToString(); rJob.HiveTasks.Add(task); task.ItemTask.ComputeInParallel = content is Experiment || content is BatchRun; var hiveResourceSelectorDialog = new HiveResourceSelectorDialog(rJob.Job.Id, rJob.Job.ProjectId); if (HiveClient.Instance.Projects.Count == 1) { var project = HiveClient.Instance.Projects.FirstOrDefault(); if (project != null && project.Id != Guid.Empty) { hiveResourceSelectorDialog.SelectedProjectId = project.Id; } } if (hiveResourceSelectorDialog.ShowDialog((UserControl)activeView) == DialogResult.OK) { var selectedProject = hiveResourceSelectorDialog.SelectedProject; if (selectedProject != null) { rJob.Job.ProjectId = selectedProject.Id; rJob.Job.ResourceIds = hiveResourceSelectorDialog.SelectedResources.Select(x => x.Id).ToList(); progress = Progress.Show(this.content, "Uploading to Hive...", ProgressMode.Indeterminate); rJob.Progress = progress; progress.ProgressStateChanged += progress_ProgressStateChanged; HiveClient.StartJob(new Action <Exception>(HandleEx), rJob, new CancellationToken()); } } }
protected virtual void Content_StateLogChanged(object sender, EventArgs e) { if (Content != null) { if (Content.ItemTask.ComputeInParallel) { this.stateLogViewHost.Content = Content.ChildStateLogList; } else { this.stateLogViewHost.Content = Content.StateLog; } } else { this.stateLogViewHost.Content = null; } }
public override void Execute() { IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; content = activeView.Content as IItem; //IOptimizer and IExecutables need some special care if (content is IOptimizer) { ((IOptimizer)content).Runs.Clear(); } if (content is IExecutable) { IExecutable exec = content as IExecutable; if (exec.ExecutionState != ExecutionState.Prepared) { exec.Prepare(); } } HiveClient.Instance.Refresh(); ItemTask hiveTask = ItemTask.GetItemTaskForItem(content); HiveTask task = hiveTask.CreateHiveTask(); RefreshableJob rJob = new RefreshableJob(); rJob.Job.Name = content.ToString(); rJob.HiveTasks.Add(task); task.ItemTask.ComputeInParallel = content is Experiment || content is BatchRun; progress = MainFormManager.GetMainForm <MainForm.WindowsForms.MainForm>().AddOperationProgressToContent(this.content, "Uploading to Hive..."); rJob.Progress = progress; progress.ProgressStateChanged += progress_ProgressStateChanged; HiveClient.StartJob(new Action <Exception>(HandleEx), rJob, new CancellationToken()); }
private static void BuildHiveJobTree(HiveTask parentHiveTask, IEnumerable<LightweightTask> allTasks, IDictionary<Guid, HiveTask> allHiveTasks) { IEnumerable<LightweightTask> childTasks = from job in allTasks where job.ParentTaskId.HasValue && job.ParentTaskId.Value == parentHiveTask.Task.Id orderby job.DateCreated ascending select job; foreach (LightweightTask task in childTasks) { HiveTask childHiveTask = allHiveTasks[task.Id]; BuildHiveJobTree(childHiveTask, allTasks, allHiveTasks); parentHiveTask.AddChildHiveTask(childHiveTask); } }
/// <summary> /// Uploads the given task and all its child-jobs while setting the proper parentJobId values for the childs /// </summary> /// <param name="parentHiveTask">shall be null if its the root task</param> private void UploadTaskWithChildren(IProgress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, CancellationToken cancellationToken) { taskUploadSemaphore.WaitOne(); bool semaphoreReleased = false; try { cancellationToken.ThrowIfCancellationRequested(); lock (jobCountLocker) { taskCount[0]++; } TaskData taskData; List<IPluginDescription> plugins; if (hiveTask.ItemTask.ComputeInParallel) { hiveTask.Task.IsParentTask = true; hiveTask.Task.FinishWhenChildJobsFinished = true; taskData = hiveTask.GetAsTaskData(true, out plugins); } else { hiveTask.Task.IsParentTask = false; hiveTask.Task.FinishWhenChildJobsFinished = false; taskData = hiveTask.GetAsTaskData(false, out plugins); } cancellationToken.ThrowIfCancellationRequested(); TryAndRepeat(() => { if (!cancellationToken.IsCancellationRequested) { lock (pluginLocker) { HiveServiceLocator.Instance.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins)); } } }, Settings.Default.MaxRepeatServiceCalls, "Failed to upload plugins"); cancellationToken.ThrowIfCancellationRequested(); hiveTask.Task.PluginsNeededIds.Add(configPluginId); hiveTask.Task.JobId = jobId; log.LogMessage(string.Format("Uploading task ({0} kb, {1} objects)", taskData.Data.Count() / 1024, hiveTask.ItemTask.GetObjectGraphObjects().Count())); TryAndRepeat(() => { if (!cancellationToken.IsCancellationRequested) { if (parentHiveTask != null) { hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData)); } else { hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData, groups.ToList())); } } }, Settings.Default.MaxRepeatServiceCalls, "Failed to add task", log); cancellationToken.ThrowIfCancellationRequested(); lock (jobCountLocker) { progress.ProgressValue = (double)taskCount[0] / totalJobCount; progress.Status = string.Format("Uploaded task ({0} of {1})", taskCount[0], totalJobCount); } var tasks = new List<TS.Task>(); foreach (HiveTask child in hiveTask.ChildHiveTasks) { var task = TS.Task.Factory.StartNew((tuple) => { var arguments = (Tuple<HiveTask, HiveTask>)tuple; UploadTaskWithChildren(progress, arguments.Item1, arguments.Item2, groups, taskCount, totalJobCount, configPluginId, jobId, log, cancellationToken); }, new Tuple<HiveTask, HiveTask>(child, hiveTask)); task.ContinueWith((x) => log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted); tasks.Add(task); } taskUploadSemaphore.Release(); semaphoreReleased = true; // the semaphore has to be release before waitall! TS.Task.WaitAll(tasks.ToArray()); } finally { if (!semaphoreReleased) taskUploadSemaphore.Release(); } }