diff --git a/src/com/xilinx/rapidwright/util/Job.java b/src/com/xilinx/rapidwright/util/Job.java index 3f3be0345..b55579884 100644 --- a/src/com/xilinx/rapidwright/util/Job.java +++ b/src/com/xilinx/rapidwright/util/Job.java @@ -57,6 +57,11 @@ public abstract class Job { public static final String DEFAULT_COMMAND_LOG_FILE = DEFAULT_COMMAND_NAME + DEFAULT_LOG_EXTENSION; + private String scriptBaseName=DEFAULT_SCRIPT_NAME; + private String scriptLogFile = DEFAULT_SCRIPT_LOG_FILE; + private String cmdLogFile = DEFAULT_COMMAND_LOG_FILE; + + public abstract long launchJob(); public abstract JobState getJobState(); @@ -78,14 +83,26 @@ public Pair createLaunchScript() { FileTools.makeDirs(dir); startupScript.add("cd " + dir); - startupScript.add(getCommand() + " > " + DEFAULT_COMMAND_LOG_FILE + " 2>&1"); + startupScript.add(getCommand() + " > " + cmdLogFile + " 2>&1"); - String startupScriptName = dir + File.separator + DEFAULT_SCRIPT_NAME + scriptExt; + String startupScriptName = dir + File.separator + scriptBaseName + scriptExt; FileTools.writeLinesToTextFile(startupScript, startupScriptName); new File(startupScriptName).setExecutable(true); - String startupScriptLog = dir + File.separator + DEFAULT_SCRIPT_LOG_FILE; + String startupScriptLog = dir + File.separator + scriptLogFile; return new Pair(startupScriptName,startupScriptLog); } + + /** + * @param scriptBaseName the script's base name to set + */ + public void setScriptBaseName(String scriptBaseName) {this.scriptBaseName = scriptBaseName;} + + + /** + * @return the path to the command logfile + */ + public String getCommandLogFileName(){return cmdLogFile;} + /** * @return the command */ @@ -157,6 +174,6 @@ public Optional> getLastLogLines() { } public String getLogFilename() { - return getRunDir() + File.separator + Job.DEFAULT_COMMAND_LOG_FILE; + return getRunDir() + File.separator + this.cmdLogFile; } } diff --git a/src/com/xilinx/rapidwright/util/JobQueue.java b/src/com/xilinx/rapidwright/util/JobQueue.java index 75f6c942e..46101167e 100644 --- a/src/com/xilinx/rapidwright/util/JobQueue.java +++ b/src/com/xilinx/rapidwright/util/JobQueue.java @@ -80,33 +80,52 @@ public boolean addRunningJob(Job j) { return running.add(j); } + public int getRunningCount() { + return running.size(); + } + + private Map> getJobsByState() { + return running.stream().collect(Collectors.groupingBy(Job::getJobState, () -> new EnumMap<>(JobState.class), Collectors.toList())); + } + + public boolean refreshQueue() { + return refreshQueue(isLSFAvailable() ? JobQueue.MAX_LSF_CONCURRENT_JOBS : JobQueue.MAX_LOCAL_CONCURRENT_JOBS); + } + public boolean refreshQueue(int maxNumRunningJobs) { + return refreshQueue(maxNumRunningJobs, getJobsByState()); + } + + private boolean refreshQueue(int maxNumRunningJobs, final Map> jobsByState) { + final List exited = jobsByState.get(JobState.EXITED); + if (exited != null) { + for (Job job : exited) { + running.remove(job); + finished.add(job); + } + //Removing from map so they don't show up in our printout + jobsByState.remove(JobState.EXITED); + } + boolean launched = false; + while (!waitingToRun.isEmpty() && maxNumRunningJobs > running.size()) { + Job j = waitingToRun.poll(); + long pid = j.launchJob(); + running.add(j); + if (printJobStart) { + System.out.println("Running job [" + pid + "] " + j.getCommand() + " in " + j.getRunDir()); + } + launched = true; + } + return launched; + } + public boolean runAllToCompletion() { return runAllToCompletion(isLSFAvailable() ? JobQueue.MAX_LSF_CONCURRENT_JOBS : JobQueue.MAX_LOCAL_CONCURRENT_JOBS); } public boolean runAllToCompletion(int maxNumRunningJobs) { while (!waitingToRun.isEmpty() || !running.isEmpty()) { - - final Map> jobsByState = running.stream().collect(Collectors.groupingBy(Job::getJobState, ()->new EnumMap<>(JobState.class), Collectors.toList())); - final List exited = jobsByState.get(JobState.EXITED); - if (exited != null) { - for (Job job : exited) { - running.remove(job); - finished.add(job); - } - //Removing from map so they don't show up in our printout - jobsByState.remove(JobState.EXITED); - } - boolean launched = false; - while (!waitingToRun.isEmpty() && maxNumRunningJobs > running.size()) { - Job j = waitingToRun.poll(); - long pid = j.launchJob(); - running.add(j); - if (printJobStart) { - System.out.println("Running job [" + pid + "] " + j.getCommand() + " in " + j.getRunDir()); - } - launched = true; - } + final Map> jobsByState = getJobsByState(); + boolean launched = refreshQueue(maxNumRunningJobs, getJobsByState()); if (!launched || !printJobStart) { System.out.print("Waiting on ");