public void Run(string[] args) { SubmissionWorker w = new SubmissionWorker(IntPtr.Zero, 0); w.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); w.WorkerReportsProgress = true; w.WorkerSupportsCancellation = false; Configuration config; if (args.Count() == 1) { if (args[0] == "-h" || args[0] == "--help" || args[0] == "/?") { Console.WriteLine("Usage: ClusterSubmit [config-file]"); return; } else config = new Configuration(args[0]); } else config = new Configuration("config.xml"); string executable = findBinary(config.z3_drop_dir, config.z3_release_dir, config.z3_exe); if (executable == "") { Console.WriteLine(now() + ": Z3 not found."); return; } else if (File.Exists("last_binary")) { FileStream lf = File.OpenRead("last_binary"); StreamReader sr = new StreamReader(lf); long last = Convert.ToInt64(sr.ReadLine()); if (last >= File.GetLastWriteTime(executable).ToFileTimeUtc()) { Console.WriteLine(now() + ": No new binary."); return; } sr.Close(); lf.Close(); } bool haveBinId = false; int binId = 0; try { string bestCluster = SubmissionWorker.FindCluster(config.cluster, config.alternativeClusters); Console.WriteLine(now() + ": Submitting job to " + bestCluster + " with the following binary: " + executable); w.UploadBinary(config.db, executable, ref haveBinId, ref binId); string sExecutor = ""; int jid = w.SetupExperiment(config.db, config.category, config.sharedDir, config.memout, config.timeout, config.executor, config.parameters, bestCluster, config.nodegroup, config.locality, config.minResources, config.maxResources, config.username, config.priority, config.extension, config.note, ref haveBinId, ref binId, ref sExecutor); w.SubmitHPCJob(config.db, true, jid, config.cluster, config.nodegroup, config.priority, config.locality, config.minResources, config.maxResources, config.sharedDir, sExecutor); saveBinaryDate(executable); uint retries = 0; if (File.Exists(config.fuzzer_target)) { retry: if (File.GetLastWriteTime(executable) > File.GetLastWriteTime(config.fuzzer_target)) { try { File.Copy(executable, config.fuzzer_target, true); } catch (Exception ex) { retries++; if (retries < config.fuzzer_max_retries) goto retry; else throw ex; } } } } catch (Exception ex) { Console.WriteLine(now() + ": Exception caught: " + ex.Message); } }
private void showRestartCommand(object sender, ExecutedRoutedEventArgs e) { Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; try { Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; double total = (double)dataGrid.SelectedItems.Count; IList drviews = dataGrid.SelectedItems; bool stop = false; for (int i = 0; i < total && !stop; i++) { Progress p = new Progress(this, dataGrid.SelectedItems.Count, "Restarting", (sndr, ea) => { ProgressWorker w = (ProgressWorker)sndr; Object[] args = (Object[])ea.Argument; DataRowView drv = (DataRowView)drviews[i]; int eid = (int)drv["ID"]; string sharedDir = null; string cluster = null; string nodegroup = null; string locality = null; int clusterJobID = 0; string executor = null; string jobTemplate = null; int jobTimeout = 0; int taskTimeout = 0; int priority = 2; int min = 1, max = 100; SqlCommand cmd = new SqlCommand("SELECT SharedDir, Cluster, Nodegroup, Locality, ClusterJobID, Executor, JobTemplate, JobTimeout, TaskTimeout FROM Experiments WHERE ID=" + eid + ";", sql); cmd.CommandTimeout = 0; SqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { sharedDir = (string)r[0]; cluster = (string)r[1]; nodegroup = (string)r[2]; locality = (string)r[3]; clusterJobID = (int)r[4]; executor = (string)r[5]; jobTemplate = (string)r[6]; jobTimeout = (int)r[7]; taskTimeout = (int)r[8]; } r.Close(); Scheduler scheduler = new Scheduler(); scheduler.Connect(cluster); try { ISchedulerJob job = scheduler.OpenJob(clusterJobID); switch (job.Priority) { case JobPriority.Lowest: priority = 0; break; case JobPriority.BelowNormal: priority = 1; break; case JobPriority.Normal: priority = 2; break; case JobPriority.AboveNormal: priority = 3; break; case JobPriority.Highest: priority = 4; break; } if (locality == "Socket") { min = job.MinimumNumberOfSockets; max = job.MaximumNumberOfSockets; } else if (locality == "Core") { min = job.MinimumNumberOfCores; max = job.MaximumNumberOfCores; } else if (locality == "Node") { min = job.MinimumNumberOfNodes; max = job.MaximumNumberOfNodes; } JobState state = job.State; if (state == JobState.Running || state == JobState.Queued || state == JobState.Validating || state == JobState.Submitted || state == JobState.ExternalValidation) scheduler.CancelJob(clusterJobID, "", true); } catch (SchedulerException) { // OK, job doesn't exist anymore. } catch (Exception ex) { Dispatcher.Invoke(new Action(() => System.Windows.MessageBox.Show(this, "Exception: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error))); return; } cmd = new SqlCommand("DELETE FROM Data WHERE ExperimentID=" + eid + ";" + "DELETE FROM JobQueue WHERE ExperimentID=" + eid + ";", sql); cmd.CommandTimeout = 0; cmd.ExecuteNonQuery(); scheduler.Close(); string wrkrpath = System.IO.Path.Combine(sharedDir, executor); if (!File.Exists(wrkrpath)) { string exc = (string)Registry.GetValue(keyName, "Executor", ""); File.Copy(exc, wrkrpath, true); } if (w.CancellationPending == true) { stop = true; } Dispatcher.Invoke(new Action(() => { WindowInteropHelper helper = new WindowInteropHelper(this); SubmissionWorker sw = new SubmissionWorker(helper.Handle, 0); sw.SubmitHPCJob(txtDatabase.Text, true, eid, cluster, nodegroup, priority, locality, min.ToString(), max.ToString(), sharedDir, executor, jobTemplate, jobTimeout, taskTimeout); })); if (w.WorkerReportsProgress) w.ReportProgress((int)(100.0 * ((double)i / (double)total))); }); p.Go(); } } catch (Exception ex) { System.Windows.MessageBox.Show(this, "Exception: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } Mouse.OverrideCursor = null; }