Search in sources :

Example 16 with HpcJobInfo

use of edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo in project tetrad by cmu-phil.

the class KillHpcJobAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JTable table = (JTable) e.getSource();
    int modelRow = Integer.valueOf(e.getActionCommand());
    DefaultTableModel activeJobTableModel = (DefaultTableModel) table.getModel();
    long jobId = Long.valueOf(activeJobTableModel.getValueAt(modelRow, HpcJobActivityEditor.ID_COLUMN).toString()).longValue();
    int answer = JOptionPane.showConfirmDialog(parentComp, "Would you like to cancel this HPC job id: " + jobId + "?", "Cancel HPC job", JOptionPane.YES_NO_OPTION);
    if (answer == JOptionPane.NO_OPTION)
        return;
    TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
    final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
    HpcJobInfo hpcJobInfo = hpcJobManager.findHpcJobInfoById(Long.valueOf(activeJobTableModel.getValueAt(modelRow, HpcJobActivityEditor.ID_COLUMN).toString()).longValue());
    if (hpcJobInfo != null) {
        try {
            if (hpcJobInfo.getPid() != null) {
                // Update table
                activeJobTableModel.setValueAt("Kill Request", modelRow, 1);
                table.updateUI();
                hpcJobInfo = hpcJobManager.requestHpcJobKilled(hpcJobInfo);
                // Update hpcJobInfo instance
                hpcJobManager.updateHpcJobInfo(hpcJobInfo);
                // Update hpcJobLog instance
                HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
                if (hpcJobLog != null) {
                    hpcJobLog.setLastUpdatedTime(new Date(System.currentTimeMillis()));
                    hpcJobManager.updateHpcJobLog(hpcJobLog);
                    // Update hpcJobLogDetail instance
                    String log = "Requested job id " + hpcJobLog.getId() + " killed";
                    hpcJobManager.logHpcJobLogDetail(hpcJobLog, 2, log);
                }
            } else {
                // Update table
                activeJobTableModel.removeRow(modelRow);
                table.updateUI();
                hpcJobManager.removePendingHpcJob(hpcJobInfo);
                // Killed
                hpcJobInfo.setStatus(4);
                // Update hpcJobInfo instance
                hpcJobManager.updateHpcJobInfo(hpcJobInfo);
                // Update hpcJobLog instance
                HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
                if (hpcJobLog != null) {
                    hpcJobLog.setCanceledTime(new Date(System.currentTimeMillis()));
                    hpcJobLog.setLastUpdatedTime(new Date(System.currentTimeMillis()));
                    hpcJobManager.updateHpcJobLog(hpcJobLog);
                    // Update hpcJobLogDetail instance
                    String log = "Killed job id " + hpcJobLog.getId();
                    hpcJobManager.logHpcJobLogDetail(hpcJobLog, 4, log);
                }
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}
Also used : HpcJobManager(edu.cmu.tetradapp.app.hpc.manager.HpcJobManager) JTable(javax.swing.JTable) DefaultTableModel(javax.swing.table.DefaultTableModel) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo) HpcJobLog(edu.pitt.dbmi.tetrad.db.entity.HpcJobLog) Date(java.util.Date) TetradDesktop(edu.cmu.tetradapp.app.TetradDesktop)

Example 17 with HpcJobInfo

use of edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo in project tetrad by cmu-phil.

the class PendingHpcJobUpdaterTask method run.

@Override
public void run() {
    if (hpcJobActivityEditor.selectedTabbedPaneIndex() != 0)
        return;
    final DefaultTableModel model = (DefaultTableModel) hpcJobActivityEditor.getJobsTableModel();
    Set<HpcJobInfo> pendingDisplayHpcJobInfoSet = hpcJobActivityEditor.getPendingDisplayHpcJobInfoSet();
    Set<HpcJobInfo> notPendingJobAnymoreSet = monitorDataUploadProgress(pendingDisplayHpcJobInfoSet, model);
    hpcJobActivityEditor.addSubmittedDisplayHpcJobInfo(notPendingJobAnymoreSet);
    hpcJobActivityEditor.removePendingDisplayHpcJobInfo(notPendingJobAnymoreSet);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo)

Example 18 with HpcJobInfo

use of edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo in project tetrad by cmu-phil.

the class PendingHpcJobUpdaterTask method monitorDataUploadProgress.

private synchronized Set<HpcJobInfo> monitorDataUploadProgress(final Set<HpcJobInfo> pendingDisplayHpcJobInfoSet, final DefaultTableModel model) {
    Map<Long, Integer> rowMap = new HashMap<>();
    for (int row = 0; row < model.getRowCount(); row++) {
        rowMap.put(Long.valueOf(model.getValueAt(row, HpcJobActivityEditor.ID_COLUMN).toString()), row);
    }
    Set<HpcJobInfo> notPendingJobAnymoreSet = new HashSet<>();
    for (HpcJobInfo hpcJobInfo : pendingDisplayHpcJobInfoSet) {
        int status = hpcJobInfo.getStatus();
        if (!rowMap.containsKey(hpcJobInfo.getId())) {
            continue;
        }
        int modelRow = rowMap.get(hpcJobInfo.getId());
        // request was issued
        if (status != -1) {
            notPendingJobAnymoreSet.add(hpcJobInfo);
        } else {
            // Dataset uploading progress
            AlgorithmParamRequest algorParamReq = hpcJobInfo.getAlgorithmParamRequest();
            String datasetPath = algorParamReq.getDatasetPath();
            int dataUploadProgress = hpcJobManager.getUploadFileProgress(datasetPath);
            if (dataUploadProgress > -1 && dataUploadProgress < 100) {
                model.setValueAt("" + dataUploadProgress + "%", modelRow, HpcJobActivityEditor.DATA_UPLOAD_COLUMN);
            } else if (dataUploadProgress == -1) {
                model.setValueAt("Skipped", modelRow, HpcJobActivityEditor.DATA_UPLOAD_COLUMN);
            } else {
                model.setValueAt("Done", modelRow, HpcJobActivityEditor.DATA_UPLOAD_COLUMN);
            }
            // Prior Knowledge uploading progress
            String priorKnowledgePath = algorParamReq.getPriorKnowledgePath();
            int priorKnowledgeUploadProgress = -1;
            if (priorKnowledgePath != null) {
                LOGGER.debug("priorKnowledgePath: " + priorKnowledgePath);
                priorKnowledgeUploadProgress = hpcJobManager.getUploadFileProgress(priorKnowledgePath);
                if (priorKnowledgeUploadProgress > -1 && priorKnowledgeUploadProgress < 100) {
                    model.setValueAt("" + priorKnowledgeUploadProgress + "%", modelRow, HpcJobActivityEditor.KNOWLEDGE_UPLOAD_COLUMN);
                } else {
                    model.setValueAt("Done", modelRow, HpcJobActivityEditor.KNOWLEDGE_UPLOAD_COLUMN);
                }
            } else {
                model.setValueAt("Skipped", modelRow, HpcJobActivityEditor.KNOWLEDGE_UPLOAD_COLUMN);
            }
            if (dataUploadProgress == 100 && (priorKnowledgeUploadProgress == -1 || priorKnowledgeUploadProgress == 100)) {
                LOGGER.debug("HpcJobInfo Id: " + hpcJobInfo.getId() + " done with both uploading");
                Map<HpcAccount, Set<HpcJobInfo>> pendingHpcJobInfoMap = hpcJobManager.getPendingHpcJobInfoMap();
                Map<HpcAccount, Set<HpcJobInfo>> submittedHpcJobInfoMap = hpcJobManager.getSubmittedHpcJobInfoMap();
                if (pendingHpcJobInfoMap != null) {
                    Set<HpcJobInfo> pendingJobSet = pendingHpcJobInfoMap.get(hpcJobInfo.getHpcAccount());
                    // Is the job still stuck in the pre-processed schedule
                    // task?
                    long id = -1;
                    for (HpcJobInfo pendingJob : pendingJobSet) {
                        if (pendingJob.getId() == hpcJobInfo.getId()) {
                            id = pendingJob.getId();
                            continue;
                        }
                    }
                    // The job is not in the pre-processed schedule task
                    if (id == -1 && submittedHpcJobInfoMap != null) {
                        Set<HpcJobInfo> submittedJobSet = submittedHpcJobInfoMap.get(hpcJobInfo.getHpcAccount());
                        // Is the job in the submitted schedule task?
                        for (HpcJobInfo submittedJob : submittedJobSet) {
                            if (submittedJob.getId() == hpcJobInfo.getId()) {
                                // Status
                                switch(submittedJob.getStatus()) {
                                    case -1:
                                        model.setValueAt("Pending", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                                        break;
                                    case 0:
                                        model.setValueAt("Submitted", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                                        break;
                                    case 1:
                                        model.setValueAt("Running", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                                        break;
                                    case 2:
                                        model.setValueAt("Kill Request", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                                        break;
                                }
                                // Submitted time
                                if (submittedJob.getSubmittedTime() != null) {
                                    model.setValueAt(FilePrint.fileTimestamp(hpcJobInfo.getSubmittedTime().getTime()), modelRow, HpcJobActivityEditor.ACTIVE_SUBMITTED_COLUMN);
                                }
                                // Hpc Pid
                                model.setValueAt(submittedJob.getPid(), modelRow, HpcJobActivityEditor.ACTIVE_HPC_JOB_ID_COLUMN);
                                // last update
                                HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(submittedJob);
                                model.setValueAt(FilePrint.fileTimestamp(hpcJobLog.getLastUpdatedTime().getTime()), modelRow, HpcJobActivityEditor.ACTIVE_LAST_UPDATED_COLUMN);
                                // Remove from the pending queue
                                notPendingJobAnymoreSet.add(submittedJob);
                                continue;
                            }
                        }
                    }
                }
            }
        }
    }
    return notPendingJobAnymoreSet;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) FilePrint(edu.pitt.dbmi.ccd.commons.file.FilePrint) AlgorithmParamRequest(edu.pitt.dbmi.tetrad.db.entity.AlgorithmParamRequest) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo) HpcJobLog(edu.pitt.dbmi.tetrad.db.entity.HpcJobLog) HashSet(java.util.HashSet)

Example 19 with HpcJobInfo

use of edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo in project tetrad by cmu-phil.

the class SubmittedHpcJobUpdaterTask method monitorSubmittedJobStatus.

private synchronized Set<HpcJobInfo> monitorSubmittedJobStatus(final Set<HpcJobInfo> submittedDisplayHpcJobInfoSet, final DefaultTableModel model) {
    Map<Long, Integer> rowMap = new HashMap<>();
    for (int row = 0; row < model.getRowCount(); row++) {
        rowMap.put(Long.valueOf(model.getValueAt(row, HpcJobActivityEditor.ID_COLUMN).toString()), row);
    }
    Set<HpcJobInfo> finishedJobSet = new HashSet<>();
    for (HpcJobInfo hpcJobInfo : submittedDisplayHpcJobInfoSet) {
        Long id = hpcJobInfo.getId();
        if (!rowMap.containsKey(id)) {
            // System.out.println("hpcJobInfo not found in rowMap");
            continue;
        }
        int modelRow = rowMap.get(id);
        Map<HpcAccount, Set<HpcJobInfo>> submittedHpcJobInfoMap = hpcJobManager.getSubmittedHpcJobInfoMap();
        Set<HpcJobInfo> submittedJobSet = submittedHpcJobInfoMap.get(hpcJobInfo.getHpcAccount());
        if (submittedJobSet != null) {
            for (HpcJobInfo submittedJob : submittedJobSet) {
                if (submittedJob.getId() == hpcJobInfo.getId()) {
                    hpcJobInfo = submittedJob;
                    // submittedHpcJobInfoMap id matched!");
                    continue;
                }
            }
        }
        int status = hpcJobInfo.getStatus();
        // Status
        switch(hpcJobInfo.getStatus()) {
            case -1:
                model.setValueAt("Pending", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                break;
            case 0:
                model.setValueAt("Submitted", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                break;
            case 1:
                model.setValueAt("Running", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                break;
            case 2:
                model.setValueAt("Kill Request", modelRow, HpcJobActivityEditor.STATUS_COLUMN);
                break;
        }
        // last update
        HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
        model.setValueAt(FilePrint.fileTimestamp(hpcJobLog.getLastUpdatedTime().getTime()), modelRow, HpcJobActivityEditor.ACTIVE_LAST_UPDATED_COLUMN);
        // was finished.
        if (status > 2) {
            finishedJobSet.add(hpcJobInfo);
        }
    }
    return finishedJobSet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo) FilePrint(edu.pitt.dbmi.ccd.commons.file.FilePrint) HpcJobLog(edu.pitt.dbmi.tetrad.db.entity.HpcJobLog) HashSet(java.util.HashSet)

Example 20 with HpcJobInfo

use of edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo in project tetrad by cmu-phil.

the class SubmittedHpcJobUpdaterTask method run.

@Override
public void run() {
    if (hpcJobActivityEditor.selectedTabbedPaneIndex() != 0)
        return;
    final DefaultTableModel model = (DefaultTableModel) hpcJobActivityEditor.getJobsTableModel();
    Set<HpcJobInfo> submittedDisplayHpcJobInfoSet = hpcJobActivityEditor.getSubmittedDisplayHpcJobInfoSet();
    Set<HpcJobInfo> finishedJobSet = monitorSubmittedJobStatus(submittedDisplayHpcJobInfoSet, model);
    hpcJobActivityEditor.removeSubmittedDisplayHpcJobInfo(finishedJobSet);
    hpcJobActivityEditor.removeSubmittedDisplayJobFromActiveTableModel(finishedJobSet);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo)

Aggregations

HpcJobInfo (edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo)20 HpcAccount (edu.pitt.dbmi.tetrad.db.entity.HpcAccount)14 HpcJobLog (edu.pitt.dbmi.tetrad.db.entity.HpcJobLog)8 HpcJobManager (edu.cmu.tetradapp.app.hpc.manager.HpcJobManager)7 HashSet (java.util.HashSet)7 Set (java.util.Set)6 TetradDesktop (edu.cmu.tetradapp.app.TetradDesktop)5 FilePrint (edu.pitt.dbmi.ccd.commons.file.FilePrint)5 HashMap (java.util.HashMap)5 DefaultTableModel (javax.swing.table.DefaultTableModel)5 AlgorithmParamRequest (edu.pitt.dbmi.tetrad.db.entity.AlgorithmParamRequest)4 Date (java.util.Date)4 HpcAccountManager (edu.cmu.tetradapp.app.hpc.manager.HpcAccountManager)3 JobInfo (edu.pitt.dbmi.ccd.rest.client.dto.algo.JobInfo)3 ArrayList (java.util.ArrayList)3 HpcJobPreProcessTask (edu.cmu.tetradapp.app.hpc.task.HpcJobPreProcessTask)2 JobQueueService (edu.pitt.dbmi.ccd.rest.client.service.jobqueue.JobQueueService)2 AlgorithmParameter (edu.pitt.dbmi.tetrad.db.entity.AlgorithmParameter)2 HpcParameter (edu.pitt.dbmi.tetrad.db.entity.HpcParameter)2 Path (java.nio.file.Path)2