public override void Execute() {
      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
      var 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;

      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;

      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());
    }
        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);
        }
        private RunCollection GetAllRunsFromJob(RefreshableJob job)
        {
            if (job != null)
            {
                RunCollection runs = new RunCollection()
                {
                    OptimizerName = job.ItemName
                };

                foreach (HiveTask subTask in job.HiveTasks)
                {
                    if (subTask is OptimizerHiveTask)
                    {
                        OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
                        ohTask.ExecuteReadActionOnItemTask(new Action(delegate() {
                            runs.AddRange(ohTask.ItemTask.Item.Runs);
                        }));
                    }
                }
                return(runs);
            }
            else
            {
                return(null);
            }
        }
Beispiel #5
0
        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());
                }
            }
        }
Beispiel #6
0
        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 RunCollection GetAllRunsFromJob(RefreshableJob job) {
      if (job != null) {
        RunCollection runs = new RunCollection() { OptimizerName = job.ItemName };

        foreach (HiveTask subTask in job.HiveTasks) {
          if (subTask is OptimizerHiveTask) {
            OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
            ohTask.ExecuteReadActionOnItemTask(new Action(delegate() {
              runs.AddRange(ohTask.ItemTask.Item.Runs);
            }));
          }
        }
        return runs;
      } else {
        return null;
      }
    }
Beispiel #8
0
    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...");
        allTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(hiveExperiment.Id));
        totalJobCount = allTasks.Count();

        refreshableJob.Progress.Status = "Downloading tasks...";
        downloader = new TaskDownloader(allTasks.Select(x => x.Id));
        downloader.StartAsync();

        while (!downloader.IsFinished) {
          refreshableJob.Progress.ProgressValue = downloader.FinishedCount / (double)totalJobCount;
          refreshableJob.Progress.Status = 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.Status = "Downloading/deserializing complete. Displaying tasks...";
        // 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 {
          refreshableJob.ExecutionState = Core.ExecutionState.Started;
        }
        refreshableJob.OnLoaded();
      }
      finally {
        refreshableJob.IsProgressing = false;
        refreshableJob.Progress.Finish();
        if (downloader != null) {
          downloader.Dispose();
        }
      }
    }
Beispiel #9
0
    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();
      }
    }
Beispiel #10
0
 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;
 }
Beispiel #11
0
 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;
 }
Beispiel #12
0
 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;
 }