Search in sources :

Example 6 with NodeJob

use of gov.sandia.n2a.ui.jobs.NodeJob in project n2a by frothga.

the class Main method studyHeadless.

/**
 *        Run a study from the command line.
 *        Unlike runHeadless(), this function uses all the usual job management machinery.
 */
public static void studyHeadless(MNode record) {
    String key = record.key();
    MNode doc = AppData.models.childOrEmpty(key);
    record.mergeUnder(doc);
    MPart collated = new MPart(record);
    if (!collated.containsKey("study"))
        return;
    // Start host monitor threads (see PanelRun constructor for non-headless procedure)
    Host.restartAssignmentThread();
    for (Host h : Host.getHosts()) h.restartMonitorThread();
    MNode studyNode = PanelEquations.createStudy(collated);
    // constructed in paused state
    Study study = new Study(studyNode);
    // start
    study.togglePause();
    study.waitForCompletion();
    // Output CSV files, if requested.
    if (record.getFlag("$metadata", "csv")) {
        Path studyDir = study.getDir();
        try (BufferedWriter parms = Files.newBufferedWriter(studyDir.resolve("study.csv"))) {
            SampleTableModel samples = new SampleTableModel();
            samples.update(study);
            int rows = samples.getRowCount();
            int cols = samples.getColumnCount();
            int lastCol = cols - 1;
            // Header for study.csv file
            for (// first column is job status, so skip it
            int c = 1; // first column is job status, so skip it
            c < cols; // first column is job status, so skip it
            c++) {
                parms.write(samples.getColumnName(c));
                if (c < lastCol)
                    parms.write(",");
            }
            parms.newLine();
            // Rows for study.csv file, along with converted output of each job.
            for (int r = 0; r < rows; r++) {
                for (int c = 1; c < cols; c++) {
                    parms.write(samples.getValueAt(r, c).toString());
                    if (c < lastCol)
                        parms.write(",");
                }
                parms.newLine();
                NodeJob jobNode = study.getJob(r);
                Path jobDir = Host.getJobDir(Host.getLocalResourceDir(), jobNode.getSource());
                try {
                    Table table = new Table(jobDir.resolve("out"), false);
                    table.dumpCSV(studyDir.resolve(r + ".csv"));
                } catch (IOException e) {
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // See MainFrame window close listener
    // Save any modified data, particularly the study record.
    AppData.quit();
    // Close down any ssh sessions.
    Host.quit();
}
Also used : Path(java.nio.file.Path) Study(gov.sandia.n2a.ui.studies.Study) MPart(gov.sandia.n2a.eqset.MPart) Table(gov.sandia.n2a.ui.jobs.Table) SampleTableModel(gov.sandia.n2a.ui.studies.PanelStudy.SampleTableModel) Host(gov.sandia.n2a.host.Host) NodeJob(gov.sandia.n2a.ui.jobs.NodeJob) IOException(java.io.IOException) MNode(gov.sandia.n2a.db.MNode) BufferedWriter(java.io.BufferedWriter)

Aggregations

NodeJob (gov.sandia.n2a.ui.jobs.NodeJob)6 Host (gov.sandia.n2a.host.Host)3 Path (java.nio.file.Path)3 MDoc (gov.sandia.n2a.db.MDoc)2 MNode (gov.sandia.n2a.db.MNode)2 MPart (gov.sandia.n2a.eqset.MPart)2 Remote (gov.sandia.n2a.host.Remote)2 Backend (gov.sandia.n2a.plugins.extpoints.Backend)2 OutputParser (gov.sandia.n2a.ui.jobs.OutputParser)2 Table (gov.sandia.n2a.ui.jobs.Table)2 BufferedWriter (java.io.BufferedWriter)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 InternalBackend (gov.sandia.n2a.backend.internal.InternalBackend)1 MainTabbedPane (gov.sandia.n2a.ui.MainTabbedPane)1 Column (gov.sandia.n2a.ui.jobs.OutputParser.Column)1 SampleTableModel (gov.sandia.n2a.ui.studies.PanelStudy.SampleTableModel)1 Study (gov.sandia.n2a.ui.studies.Study)1 Point (java.awt.Point)1