use of edu.cmu.tetradapp.app.TetradDesktop 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();
}
}
}
use of edu.cmu.tetradapp.app.TetradDesktop in project tetrad by cmu-phil.
the class DeleteHpcJobInfoAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JTable table = (JTable) e.getSource();
int modelRow = Integer.valueOf(e.getActionCommand());
DefaultTableModel finishedJobTableModel = (DefaultTableModel) table.getModel();
long jobId = Long.valueOf(finishedJobTableModel.getValueAt(modelRow, HpcJobActivityEditor.ID_COLUMN).toString()).longValue();
int answer = JOptionPane.showConfirmDialog(parentComp, "Would you like to delete this HPC job id: " + jobId + "?", "Delete 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(finishedJobTableModel.getValueAt(modelRow, HpcJobActivityEditor.ID_COLUMN).toString()).longValue());
if (hpcJobInfo != null) {
// Update table
finishedJobTableModel.removeRow(modelRow);
table.updateUI();
hpcJobManager.removeHpcJobInfoTransaction(hpcJobInfo);
}
}
use of edu.cmu.tetradapp.app.TetradDesktop in project tetrad by cmu-phil.
the class HpcAccountSettingAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
HpcAccountManager manager = desktop.getHpcAccountManager();
JComponent comp = buildHpcAccountSettingComponent(manager);
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), comp, "High-Performance Computing Account Setting", JOptionPane.PLAIN_MESSAGE);
}
use of edu.cmu.tetradapp.app.TetradDesktop in project tetrad by cmu-phil.
the class HpcJobManager method requestHpcJobKilled.
public HpcJobInfo requestHpcJobKilled(final HpcJobInfo hpcJobInfo) throws Exception {
final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
HpcAccountService hpcAccountService = getHpcAccountService(hpcAccount);
JobQueueService jobQueueService = hpcAccountService.getJobQueueService();
TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
JsonWebTokenManager jsonWebTokenManager = hpcAccountManager.getJsonWebTokenManager();
jobQueueService.requestJobKilled(hpcJobInfo.getPid(), jsonWebTokenManager.getJsonWebToken(hpcAccount));
JobInfo jobInfo = jobQueueService.getJobStatus(hpcJobInfo.getPid(), jsonWebTokenManager.getJsonWebToken(hpcAccount));
if (jobInfo != null) {
hpcJobInfo.setStatus(jobInfo.getStatus());
return hpcJobInfo;
}
return null;
}
use of edu.cmu.tetradapp.app.TetradDesktop in project tetrad by cmu-phil.
the class Tetrad method launchFrame.
/**
* Launches the frame. (This is left as a separate method in case we ever
* want to launch it as an applet.)
*/
private void launchFrame() {
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT);
// Set up the desktop.
this.desktop = new TetradDesktop();
getDesktop().addPropertyChangeListener(this);
JOptionUtils.setCenteringComp(getDesktop());
DesktopController.setReference(getDesktop());
// Set up the frame. Note the order in which the next few steps
// happen. First, the frame is given a preferred size, so that if
// someone unmaximizes it it doesn't shrivel up to the top left
// corner. Next, the content pane is set. Next, it is packed. Finally,
// it is maximized. For some reason, most of the details of this
// order are important. jdramsey 12/14/02
this.frame = new JFrame(this.mainTitle) {
private static final long serialVersionUID = -9077349253115802418L;
@Override
public Dimension getPreferredSize() {
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
double minLength = Math.min(size.getWidth(), size.getHeight());
double height = minLength * 0.8;
double width = height * (4.0 / 3);
return new Dimension((int) width, (int) height);
// return Toolkit.getDefaultToolkit().getScreenSize();
// Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
// return new Dimension(size.width - 100, size.height - 100);
}
};
// Fixing a bug caused by switch to Oracle Java (at least for Mac), although I must say the following
// code is what should have worked to begin with. Bug was that sessions would appear only in the lower
// left hand corner of the screen.
this.frame.setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
// this.frame.setMinimumSize(Toolkit.getDefaultToolkit().getScreenSize());
// this.frame.setMaximumSize(Toolkit.getDefaultToolkit().getScreenSize());
getFrame().setContentPane(getDesktop());
getFrame().pack();
getFrame().setLocationRelativeTo(null);
// This doesn't let the user resize the main window.
// getFrame().setExtendedState(Frame.MAXIMIZED_BOTH);
Image image = ImageUtils.getImage(this, "tyler16.png");
getFrame().setIconImage(image);
// Add an initial session editor to the desktop. Must be done
// from here, not in the constructor of TetradDesktop.
getDesktop().newSessionEditor();
getFrame().setVisible(true);
getFrame().setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
getFrame().addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
exitApplication();
}
});
SplashScreen.hide();
// try {
// Preferences.userRoot().clear();
// } catch (BackingStoreException e) {
// e.printStackTrace();
// }
}
Aggregations