Search in sources :

Example 1 with HpcAccount

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

the class HpcJobsScheduledTask method run.

// Pooling job status from HPC nodes
@Override
public void run() {
    TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
    if (desktop == null)
        return;
    final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
    // No Hpc Account in the first place, no need to proceed!
    List<HpcAccount> hpcAccounts = hpcAccountManager.getHpcAccounts();
    if (hpcAccounts == null || hpcAccounts.isEmpty())
        return;
    final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
    // LOGGER.debug("HpcJobsScheduledTask: " + new Date(System.currentTimeMillis()));
    // Load active jobs: Status (0 = Submitted; 1 = Running; 2 = Kill
    // Request)
    Map<HpcAccount, Set<HpcJobInfo>> submittedHpcJobInfos = hpcJobManager.getSubmittedHpcJobInfoMap();
    for (HpcAccount hpcAccount : submittedHpcJobInfos.keySet()) {
        LOGGER.debug("HpcJobsScheduledTask: " + hpcAccount.getConnectionName());
        Set<HpcJobInfo> hpcJobInfos = submittedHpcJobInfos.get(hpcAccount);
        // Pid-HpcJobInfo map
        Map<Long, HpcJobInfo> hpcJobInfoMap = new HashMap<>();
        for (HpcJobInfo hpcJobInfo : hpcJobInfos) {
            if (hpcJobInfo.getPid() != null) {
                long pid = hpcJobInfo.getPid().longValue();
                hpcJobInfoMap.put(pid, hpcJobInfo);
                LOGGER.debug("id: " + hpcJobInfo.getId() + " : " + hpcJobInfo.getAlgoId() + ": pid: " + pid + " : " + hpcJobInfo.getResultFileName());
            } else {
                LOGGER.debug("id: " + hpcJobInfo.getId() + " : " + hpcJobInfo.getAlgoId() + ": no pid! : " + hpcJobInfo.getResultFileName());
                hpcJobInfos.remove(hpcJobInfo);
            }
        }
        // Finished job map
        HashMap<Long, HpcJobInfo> finishedJobMap = new HashMap<>();
        for (HpcJobInfo job : hpcJobInfos) {
            finishedJobMap.put(job.getPid(), job);
        }
        try {
            List<JobInfo> jobInfos = hpcJobManager.getRemoteActiveJobs(hpcAccountManager, hpcAccount);
            for (JobInfo jobInfo : jobInfos) {
                LOGGER.debug("Remote pid: " + jobInfo.getId() + " : " + jobInfo.getAlgoId() + " : " + jobInfo.getResultFileName());
                long pid = jobInfo.getId();
                if (finishedJobMap.containsKey(pid)) {
                    finishedJobMap.remove(pid);
                }
                int remoteStatus = jobInfo.getStatus();
                String recentStatusText = (remoteStatus == 0 ? "Submitted" : (remoteStatus == 1 ? "Running" : "Kill Request"));
                // Local job
                HpcJobInfo hpcJobInfo = hpcJobInfoMap.get(pid);
                // map
                HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
                if (hpcJobInfo != null) {
                    int status = hpcJobInfo.getStatus();
                    if (status != remoteStatus) {
                        // Update status
                        hpcJobInfo.setStatus(remoteStatus);
                        hpcJobManager.updateHpcJobInfo(hpcJobInfo);
                        hpcJobLog.setLastUpdatedTime(new Date(System.currentTimeMillis()));
                        String log = "Job status changed to " + recentStatusText;
                        LOGGER.debug(hpcJobInfo.getAlgoId() + " : id : " + hpcJobInfo.getId() + " : pid : " + pid);
                        LOGGER.debug(log);
                        hpcJobManager.logHpcJobLogDetail(hpcJobLog, remoteStatus, log);
                    }
                }
            }
            // Download finished jobs' results
            if (finishedJobMap.size() > 0) {
                Set<ResultFile> resultFiles = hpcJobManager.listRemoteAlgorithmResultFiles(hpcAccountManager, hpcAccount);
                Set<String> resultFileNames = new HashSet<>();
                for (ResultFile resultFile : resultFiles) {
                    resultFileNames.add(resultFile.getName());
                // LOGGER.debug(hpcAccount.getConnectionName()
                // + " Result : " + resultFile.getName());
                }
                for (HpcJobInfo hpcJobInfo : finishedJobMap.values()) {
                    // Job
                    // is
                    // done
                    // or
                    // killed or
                    // time-out
                    HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
                    String recentStatusText = "Job finished";
                    // Finished
                    int recentStatus = 3;
                    if (hpcJobInfo.getStatus() == 2) {
                        recentStatusText = "Job killed";
                        // Killed
                        recentStatus = 4;
                    }
                    hpcJobInfo.setStatus(recentStatus);
                    hpcJobManager.updateHpcJobInfo(hpcJobInfo);
                    // LOGGER.debug("hpcJobInfo: id: "
                    // + hpcJobInfo.getId() + " : "
                    // + hpcJobInfo.getStatus());
                    hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, recentStatusText);
                    LOGGER.debug(hpcJobInfo.getAlgoId() + " : id : " + hpcJobInfo.getId() + " : " + recentStatusText);
                    GeneralAlgorithmEditor editor = hpcJobManager.getGeneralAlgorithmEditor(hpcJobInfo);
                    if (editor != null) {
                        LOGGER.debug("GeneralAlgorithmEditor is not null");
                        String resultJsonFileName = hpcJobInfo.getResultJsonFileName();
                        String errorResultFileName = hpcJobInfo.getErrorResultFileName();
                        if (resultFileNames.contains(resultJsonFileName)) {
                            // Result Downloaded
                            recentStatus = 5;
                            String json = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager, hpcAccount, resultJsonFileName, editor);
                            if (!json.toLowerCase().contains("not found")) {
                                editor.setAlgorithmResult(json);
                            }
                            String log = "Result downloaded";
                            hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
                            LOGGER.debug(hpcJobInfo.getAlgoId() + " : id : " + hpcJobInfo.getId() + " : " + log);
                        } else if (resultFileNames.contains(errorResultFileName)) {
                            // Error Result Downloaded
                            recentStatus = 6;
                            String error = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager, hpcAccount, errorResultFileName, editor);
                            if (!error.toLowerCase().contains("not found")) {
                                editor.setAlgorithmErrorResult(error);
                            }
                            String log = "Error Result downloaded";
                            hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
                            LOGGER.debug(hpcJobInfo.getAlgoId() + " : id : " + hpcJobInfo.getId() + " : " + log);
                        } else {
                            // Try again
                            Thread.sleep(5000);
                            String json = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager, hpcAccount, resultJsonFileName, editor);
                            if (!json.toLowerCase().contains("not found")) {
                                editor.setAlgorithmResult(json);
                                // Result Downloaded
                                recentStatus = 5;
                                String log = "Result downloaded";
                                hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
                                LOGGER.debug(hpcJobInfo.getAlgoId() + " : id : " + hpcJobInfo.getId() + " : " + log);
                            } else {
                                String error = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager, hpcAccount, errorResultFileName, editor);
                                if (!error.toLowerCase().contains("not found")) {
                                    editor.setAlgorithmErrorResult(error);
                                    // Error Result
                                    recentStatus = 6;
                                    // Downloaded
                                    String log = "Error Result downloaded";
                                    hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
                                    LOGGER.debug(hpcJobInfo.getAlgoId() + " : id : " + hpcJobInfo.getId() + " : " + log);
                                } else {
                                    // Result Not Found
                                    recentStatus = 7;
                                    String log = resultJsonFileName + " not found";
                                    hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
                                    LOGGER.debug(hpcJobInfo.getAlgoId() + " : id : " + hpcJobInfo.getId() + " : " + log);
                                }
                            }
                        }
                    }
                    hpcJobManager.removeFinishedHpcJob(hpcJobInfo);
                }
            } else {
                LOGGER.debug("No finished job yet.");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) GeneralAlgorithmEditor(edu.cmu.tetradapp.editor.GeneralAlgorithmEditor) HpcJobManager(edu.cmu.tetradapp.app.hpc.manager.HpcJobManager) JobInfo(edu.pitt.dbmi.ccd.rest.client.dto.algo.JobInfo) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo) HpcAccountManager(edu.cmu.tetradapp.app.hpc.manager.HpcAccountManager) TetradDesktop(edu.cmu.tetradapp.app.TetradDesktop) HashSet(java.util.HashSet) ResultFile(edu.pitt.dbmi.ccd.rest.client.dto.algo.ResultFile) Date(java.util.Date) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo) HpcJobLog(edu.pitt.dbmi.tetrad.db.entity.HpcJobLog)

Example 2 with HpcAccount

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

the class WindowMenuListener method menuSelected.

/**
 * Reacts when the window menu is selected by constructing a menu on the fly
 * consisting of an alphabetized list of sessoin editors. The user can
 * navigate to any session editor by selecting its name from the list.
 *
 * @param e the menu event indicating that the window menu has been
 *          selected.
 */
public void menuSelected(MenuEvent e) {
    windowMenu.removeAll();
    itemsToFrames.clear();
    JInternalFrame[] layer0Frames = desktop.getDesktopPane().getAllFramesInLayer(0);
    List<String> titles = new ArrayList<>();
    Map<String, JInternalFrame> titlesToFrames = new HashMap<>();
    for (JInternalFrame layer0Frame : layer0Frames) {
        String title = layer0Frame.getTitle();
        title = ((title == null) || title.equals("")) ? "[untitled]" : title;
        titles.add(title);
        titlesToFrames.put(title, layer0Frame);
    }
    Collections.sort(titles);
    for (Object title1 : titles) {
        String title = (String) title1;
        JMenuItem item = new JMenuItem(title);
        this.windowMenu.add(item);
        item.addActionListener(this);
        this.itemsToFrames.put(item, titlesToFrames.get(title));
    }
    // If there are hpc account(s) setup, show the hpc activity
    HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
    List<HpcAccount> hpcAccounts = hpcAccountManager.getHpcAccounts();
    if (hpcAccounts != null && !hpcAccounts.isEmpty()) {
        this.windowMenu.addSeparator();
        String title = "HPC Job Activity";
        JMenuItem item = new JMenuItem(new HpcJobActivityAction(title));
        this.windowMenu.add(item);
    // item.addActionListener(hpcJobActivityMenuListener);
    }
}
Also used : HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) HpcJobActivityAction(edu.cmu.tetradapp.app.hpc.action.HpcJobActivityAction) HpcAccountManager(edu.cmu.tetradapp.app.hpc.manager.HpcAccountManager)

Example 3 with HpcAccount

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

the class HpcAccountSelectionAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final JCheckBox checkBox = (JCheckBox) e.getSource();
    for (HpcAccount hpcAccount : hpcAccounts) {
        if (checkBox.getText().equals(hpcAccount.getConnectionName())) {
            if (checkBox.isSelected() && !checkedHpcAccountList.contains(hpcAccount)) {
                checkedHpcAccountList.add(hpcAccount);
            } else if (!checkBox.isSelected() && checkedHpcAccountList.contains(hpcAccount)) {
                checkedHpcAccountList.remove(hpcAccount);
            }
        }
    }
    int index = tabbedPane.getSelectedIndex();
    tabbedPane.setSelectedIndex(-1);
    tabbedPane.setSelectedIndex(index);
}
Also used : JCheckBox(javax.swing.JCheckBox) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount)

Example 4 with HpcAccount

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

the class HpcAccountSettingAction method buildHpcAccountSettingComponent.

private static JComponent buildHpcAccountSettingComponent(final HpcAccountManager manager) {
    // Get ComputingAccount from DB
    final DefaultListModel<HpcAccount> listModel = new DefaultListModel<HpcAccount>();
    for (HpcAccount account : manager.getHpcAccounts()) {
        listModel.addElement(account);
    }
    // JSplitPane
    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    // Left pane -> JList (parent pane)
    JPanel leftPanel = new JPanel(new BorderLayout());
    // Right pane -> ComputingAccountEditor
    final JPanel accountDetailPanel = new JPanel(new BorderLayout());
    accountDetailPanel.add(new HpcAccountEditor(splitPane, listModel, manager, new HpcAccount()), BorderLayout.CENTER);
    splitPane.setLeftComponent(leftPanel);
    splitPane.setRightComponent(accountDetailPanel);
    // Center Panel
    final JList<HpcAccount> accountList = new JList<>(listModel);
    accountList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    accountList.setLayoutOrientation(JList.VERTICAL);
    accountList.setSelectedIndex(-1);
    accountList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            int selectedIndex = ((JList<?>) e.getSource()).getSelectedIndex();
            // Show or remove the detail
            accountDetailPanel.removeAll();
            if (selectedIndex > -1) {
                HpcAccount computingAccount = listModel.get(selectedIndex);
                System.out.println(computingAccount);
                accountDetailPanel.add(new HpcAccountEditor(splitPane, listModel, manager, computingAccount), BorderLayout.CENTER);
            }
            accountDetailPanel.updateUI();
        }
    });
    // Left Panel
    JPanel buttonPanel = new JPanel(new BorderLayout());
    JButton addButton = new JButton("Add");
    addButton.setSize(new Dimension(14, 8));
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Show the empty ComputingAccountEditor
            accountDetailPanel.removeAll();
            accountDetailPanel.add(new HpcAccountEditor(splitPane, listModel, manager, new HpcAccount()), BorderLayout.CENTER);
            accountDetailPanel.updateUI();
        }
    });
    buttonPanel.add(addButton, BorderLayout.WEST);
    JButton removeButton = new JButton("Remove");
    removeButton.setSize(new Dimension(14, 8));
    removeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (accountList.isSelectionEmpty())
                return;
            int selectedIndex = accountList.getSelectedIndex();
            if (selectedIndex > -1) {
                HpcAccount computingAccount = listModel.get(selectedIndex);
                // Pop up the confirm dialog
                int option = JOptionPane.showConfirmDialog(accountDetailPanel, "Are you sure that you want to delete " + computingAccount + " ?", "HPC Account Setting", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                // If yes, remove it from DB and listModel
                if (option == JOptionPane.YES_OPTION) {
                    manager.removeAccount(computingAccount);
                    listModel.remove(selectedIndex);
                }
            }
        }
    });
    buttonPanel.add(removeButton, BorderLayout.EAST);
    leftPanel.add(buttonPanel, BorderLayout.NORTH);
    JScrollPane accountListScroller = new JScrollPane(accountList);
    leftPanel.add(accountListScroller, BorderLayout.CENTER);
    int minWidth = 300;
    int minHeight = 200;
    int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
    int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    int frameWidth = screenWidth / 2;
    int frameHeight = screenHeight / 2;
    frameWidth = minWidth > frameWidth ? minWidth : frameWidth;
    frameHeight = minHeight > frameHeight ? minHeight : frameHeight;
    splitPane.setDividerLocation(frameWidth / 4);
    accountListScroller.setPreferredSize(new Dimension(frameWidth / 4, frameHeight));
    accountDetailPanel.setPreferredSize(new Dimension(frameWidth * 3 / 4, frameHeight));
    return splitPane;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) HpcAccountEditor(edu.cmu.tetradapp.app.hpc.editor.HpcAccountEditor) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) JList(javax.swing.JList)

Example 5 with HpcAccount

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

the class HpcJobActivityEditor method buildController.

private void buildController(final JPanel controllerPane, final TetradDesktop desktop) {
    // Content
    Box contentBox = Box.createVerticalBox();
    JPanel hpcPanel = new JPanel(new BorderLayout());
    JLabel hpcAccountLabel = new JLabel("HPC Account: ", JLabel.TRAILING);
    hpcAccountLabel.setPreferredSize(new Dimension(100, 5));
    hpcPanel.add(hpcAccountLabel, BorderLayout.WEST);
    Box hpcAccountCheckBox = Box.createHorizontalBox();
    final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
    List<HpcAccount> hpcAccounts = hpcAccountManager.getHpcAccounts();
    HpcAccountSelectionAction hpcAccountSelectionAction = new HpcAccountSelectionAction(hpcAccounts);
    for (HpcAccount hpcAccount : hpcAccounts) {
        checkedHpcAccountList.add(hpcAccount);
        final JCheckBox hpcCheckBox = new JCheckBox(hpcAccount.getConnectionName(), true);
        hpcCheckBox.addActionListener(hpcAccountSelectionAction);
        hpcAccountCheckBox.add(hpcCheckBox);
    }
    hpcPanel.add(hpcAccountCheckBox, BorderLayout.CENTER);
    contentBox.add(hpcPanel);
    controllerPane.add(contentBox, BorderLayout.CENTER);
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) HpcAccountManager(edu.cmu.tetradapp.app.hpc.manager.HpcAccountManager) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) Dimension(java.awt.Dimension)

Aggregations

HpcAccount (edu.pitt.dbmi.tetrad.db.entity.HpcAccount)20 HpcJobInfo (edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo)14 HpcJobLog (edu.pitt.dbmi.tetrad.db.entity.HpcJobLog)7 Set (java.util.Set)7 HashSet (java.util.HashSet)6 HpcAccountManager (edu.cmu.tetradapp.app.hpc.manager.HpcAccountManager)5 HpcJobManager (edu.cmu.tetradapp.app.hpc.manager.HpcJobManager)5 FilePrint (edu.pitt.dbmi.ccd.commons.file.FilePrint)5 HashMap (java.util.HashMap)4 TetradDesktop (edu.cmu.tetradapp.app.TetradDesktop)3 JobInfo (edu.pitt.dbmi.ccd.rest.client.dto.algo.JobInfo)3 AlgorithmParamRequest (edu.pitt.dbmi.tetrad.db.entity.AlgorithmParamRequest)3 BorderLayout (java.awt.BorderLayout)3 Dimension (java.awt.Dimension)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Vector (java.util.Vector)3 JPanel (javax.swing.JPanel)3 HpcAccountService (edu.cmu.tetradapp.app.hpc.manager.HpcAccountService)2 HpcJobPreProcessTask (edu.cmu.tetradapp.app.hpc.task.HpcJobPreProcessTask)2