use of gov.sandia.n2a.host.Host in project n2a by frothga.
the class PanelEquations method launchJob.
public void launchJob() {
if (record == null)
return;
prepareForTabChange();
String jobKey = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.ROOT).format(new Date());
MDoc job = (MDoc) AppData.runs.childOrCreate(jobKey);
NodeJob.collectJobParameters(root.source, record.key(), job);
// Force directory (and job file) to exist, so Backends can work with the dir.
job.save();
NodeJob.saveSnapshot(record, job);
MainTabbedPane mtp = (MainTabbedPane) MainFrame.instance.tabs;
mtp.setPreferredFocus(PanelRun.instance, PanelRun.instance.tree);
mtp.selectTab("Runs");
NodeJob node = PanelRun.instance.addNewRun(job, true);
// Hack to allow local jobs to bypass the wait-for-host queue.
// It would be better for all jobs to check for resources before starting.
// However, the time cost for the local check could be as long as the job itself
// (for very simple models). There is some expectation that the user knows
// the state of their own system when they choose to hit the play button.
Backend backend = Backend.getBackend(job.get("backend"));
String backendName = backend.getName().toLowerCase();
Host h = Host.get(job);
boolean internal = backend instanceof InternalBackend;
boolean localhost = !(h instanceof Remote);
boolean forbidden = h.config.get("backend", backendName).equals("0");
if (// use of Internal overrides host selection
internal || (localhost && !forbidden)) {
// In case it was "internal" but not "localhost", set host to correct value.
job.set("localhost", "host");
backend.start(job);
h.monitor(node);
return;
}
Host.waitForHost(node);
}
use of gov.sandia.n2a.host.Host in project n2a by frothga.
the class XyceBackend method start.
@Override
public void start(final MNode job) {
Thread t = new Thread() {
@Override
public void run() {
Path localJobDir = Host.getJobDir(Host.getLocalResourceDir(), job);
Path errPath = localJobDir.resolve("err");
try {
err.set(new PrintStream(new FileOutputStream(errPath.toFile(), true), false, "UTF-8"));
} catch (Exception e) {
}
try {
Files.createFile(localJobDir.resolve("started"));
MNode model = NodeJob.getModel(job);
// set up job info
Host env = Host.get(job);
String xyce = env.config.getOrDefault("Xyce", "backend", "xyce", "path");
// local or remote
Path jobDir = Host.getJobDir(env.getResourceDir(), job);
Path cirFile = jobDir.resolve("model.cir");
// "prn" doesn't work, at least on Windows
Path prnFile = jobDir.resolve("out");
EquationSet digestedModel = new EquationSet(model);
Simulator simulator = InternalBackend.constructStaticNetwork(digestedModel, null);
analyze(digestedModel);
String duration = digestedModel.metadata.getOrDefault("1.0", "duration");
job.set(duration, "duration");
long seed = digestedModel.metadata.getOrDefault(System.currentTimeMillis(), "seed");
job.set(seed, "seed");
MNode integrator = digestedModel.metadata.child("backend", "xyce", "integrator");
job.set(integrator, "integrator");
try (BufferedWriter writer = Files.newBufferedWriter(cirFile)) {
generateNetlist(job, simulator, writer);
}
PrintStream ps = Backend.err.get();
if (ps != System.err) {
ps.close();
Backend.err.remove();
job.set(Host.size(errPath), "errSize");
}
env.submitJob(job, false, xyce, env.quote(cirFile), "-o", env.quote(prnFile));
} catch (AbortRun a) {
} catch (Exception e) {
e.printStackTrace(Backend.err.get());
}
PrintStream ps = err.get();
if (ps != System.err)
ps.close();
}
};
t.setDaemon(true);
t.start();
}
use of gov.sandia.n2a.host.Host in project n2a by frothga.
the class NodeJob method distribute.
/**
* Load job data in and decide which host thread should monitor it.
*/
public synchronized void distribute() {
MNode source = getSource();
if (// TODO: remove this conversion by 3/17/2022 (one-year sunset date)
source.size() == 0) {
// Convert old-format job directories to new format, which has separate "job" and "model" files.
System.err.println("converting to new job format: " + source.key());
Path jobDir = Host.getJobDir(Host.getLocalResourceDir(), source);
MDoc model = new MDoc(jobDir.resolve("model"));
collectJobParameters(model, model.get("$inherit"), source);
String temp = model.get("$metadata", "pid");
if (!temp.isEmpty())
source.set(temp, "pid");
}
inherit = source.getOrDefault(key, "$inherit").split(",", 2)[0].replace("\"", "");
setUserObject(inherit);
// Lightweight evaluation of local "finished" file.
// This slows down the initial load, but also makes the user more comfortable by showing
// status as soon as possible on the first screenful of the Runs tab.
Path localJobDir = Host.getJobDir(Host.getLocalResourceDir(), source);
Path finished = localJobDir.resolve("finished");
if (Files.exists(finished))
checkFinished(finished);
EventQueue.invokeLater(new Runnable() {
public void run() {
PanelRun panel = PanelRun.instance;
panel.model.nodeChanged(NodeJob.this);
}
});
Path started = localJobDir.resolve("started");
if (Files.exists(started)) {
dateStarted = new Date(Host.lastModified(started));
Host env = Host.get(source);
env.monitor(this);
} else // Not started yet, so send to wait-for-host queue.
{
// However, only try to start jobs that still have enough info to actually run.
// Sometimes a directory might be lingering from an incomplete delete,
// so don't try to start a job in that case.
Path model = localJobDir.resolve("model");
if (Files.exists(model))
Host.waitForHost(this);
}
}
use of gov.sandia.n2a.host.Host in project n2a by frothga.
the class NodeJob method build.
/**
* Construct the list of resources under this job node.
* This only called if this job node is actively monitored and open in the tree,
* or if this job node is about to be opened regardless of monitoring.
*
* This function may make blocking remote calls, so should not run on the EDT.
* It queues changes and inserts an EDT event to apply them.
*/
public synchronized void build(JTree tree) {
NodeBase selected = null;
TreePath path = tree.getLeadSelectionPath();
if (path != null)
selected = (NodeBase) path.getLastPathComponent();
TreeMap<String, NodeFile> existing = new TreeMap<String, NodeFile>();
if (children != null) {
for (Object c : children) {
NodeFile nf = (NodeFile) c;
nf.found = false;
existing.put(nf.path.getFileName().toString(), nf);
}
}
// Scan local job dir
boolean changed = false;
MNode source = getSource();
Path localJobDir = Host.getJobDir(Host.getLocalResourceDir(), source);
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(localJobDir)) {
for (Path file : dirStream) if (buildChild(file, existing))
changed = true;
} catch (IOException e) {
}
// Update display immediately, before waiting on remote.
if (changed)
applyChanges(tree, selected, existing);
changed = false;
// Scan remote job dir. Because this is done second, remote files take lower precedence than local files.
Host env = Host.get(source);
if (env instanceof Remote) {
try {
// To get here, the use had to expand the node. This implies permission to prompt for login.
((Remote) env).enable();
Path remoteJobDir = Host.getJobDir(env.getResourceDir(), source);
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(remoteJobDir)) {
for (Path file : dirStream) if (buildChild(file, existing))
changed = true;
}
} catch (Exception e) {
}
}
List<String> keys = new ArrayList<String>(existing.keySet());
for (String key : keys) {
NodeFile nf = existing.get(key);
if (!nf.found) {
changed = true;
existing.remove(key);
}
}
if (changed)
applyChanges(tree, selected, existing);
}
use of gov.sandia.n2a.host.Host in project n2a by frothga.
the class SettingsHost method displayRecord.
// Update editor side with currently-selected item in list.
public void displayRecord() {
Host h = list.getSelectedValue();
editorHolder.removeAll();
if (// This can happen during delete.
h == null) {
fieldName.bind(null, null);
return;
}
fieldName.bind(h.config.parent(), h.name);
comboClass.setSelectedItem(h.getClassName());
editor = h.getEditor();
editorHolder.add(editor, BorderLayout.CENTER);
editor.revalidate();
editor.repaint();
}
Aggregations