diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java
index 2381b03061..c28b289fc6 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java
@@ -70,6 +70,12 @@ public final class Tetrad implements PropertyChangeListener {
"Tetrad " + Version.currentViewableVersion()
.toString();
+
+ /**
+ * Skip latest version checking
+ */
+ private static boolean skipLatest;
+
//==============================CONSTRUCTORS===========================//
public Tetrad() {
@@ -98,7 +104,7 @@ public void propertyChange(final PropertyChangeEvent e) {
* contents and all of the images which Tetrad IV uses, all in their proper
* relative directories.
*
- * @param argv moves line arguments (none for now).
+ * @param argv --skip-latest argument will skip checking for latest version.
*/
public static void main(final String[] argv) {
setLookAndFeel();
@@ -106,6 +112,14 @@ public static void main(final String[] argv) {
// This is needed to get numbers to be parsed and rendered uniformly, especially in the interface.
Locale.setDefault(Locale.US);
+ // Check if we should skip checking for latest version
+ if (argv.length > 0 && argv[0] != null && argv[0].compareToIgnoreCase("--skip-latest") == 0) {
+ skipLatest = true;
+ } else {
+ skipLatest = false;
+ }
+
+
new Tetrad().launchFrame();
}
@@ -174,7 +188,7 @@ public Dimension getPreferredSize() {
// this.frame.setMinimumSize(Toolkit.getDefaultToolkit().getScreenSize());
// this.frame.setMaximumSize(Toolkit.getDefaultToolkit().getScreenSize());
- SplashScreen.show(getFrame(), "Loading Tetrad...", 1000);
+ SplashScreen.show(getFrame(), "Loading Tetrad...", 1000, skipLatest);
getFrame().setContentPane(getDesktop());
getFrame().pack();
@@ -231,6 +245,7 @@ private JFrame getFrame() {
private TetradDesktop getDesktop() {
return desktop;
}
+
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java
index 0a5979818b..6cdbd288f8 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java
@@ -424,7 +424,7 @@ private Node addNode(String nodeType, String nodeName, int centerX,
return node;
}
- private void addEdge(String nodeName1, String nodeName2) {
+ public void addEdge(String nodeName1, String nodeName2) {
// Retrieve the nodes from the session wrapper.
Node node1 = getSessionWrapper().getNode(nodeName1);
@@ -451,6 +451,8 @@ private void addEdge(String nodeName1, String nodeName2) {
// Add the edge.
getSessionWrapper().addEdge(edge);
+ getSessionWorkbench().revalidate();
+ getSessionWorkbench().repaint();
}
private static SessionNodeWrapper getNewModelNode(String nextButtonType,
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java
index 2b582cc2e3..9b840fc7f3 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java
@@ -21,8 +21,7 @@
package edu.cmu.tetradapp.app;
-import edu.cmu.tetrad.graph.Edge;
-import edu.cmu.tetrad.graph.Graph;
+import edu.cmu.tetrad.graph.*;
import edu.cmu.tetrad.session.*;
import edu.cmu.tetrad.util.*;
import edu.cmu.tetradapp.editor.EditorWindow;
@@ -38,6 +37,8 @@
import javax.swing.border.TitledBorder;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
+import javax.swing.event.MenuDragMouseEvent;
+import javax.swing.event.MenuDragMouseListener;
import java.awt.*;
import java.awt.Point;
import java.awt.event.*;
@@ -105,8 +106,6 @@ public SessionEditorNode(SessionNodeWrapper modelNode, SimulationStudy simulatio
this.simulationStudy = simulationStudy;
displayComp.setName(modelNode.getSessionName());
-
- System.out.println("modelNode.getSessionName(): " + modelNode.getButtonType());
if (displayComp instanceof NoteDisplayComp) {
createParamObjects(this);
@@ -127,7 +126,6 @@ public void mousePressed(MouseEvent e) {
}
});
} else {
- // Any node type except notes
setDisplayComp(displayComp);
setLayout(new BorderLayout());
add((JComponent) getSessionDisplayComp(), BorderLayout.CENTER);
@@ -266,8 +264,6 @@ public void internalFrameClosing(InternalFrameEvent e) {
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
- editorWindow.setResizable(true);
- editorWindow.setMaximum(true);
editorWindow.setVisible(true);
spawnedEditor = editorWindow;
@@ -391,6 +387,22 @@ public void mousePressed(MouseEvent e) {
}
});
+// sessionEditorNode.addMouseMotionListener(new MouseMotionAdapter() {
+// public void mouseMoved(MouseEvent e) {
+// Point p = e.getPoint();
+// if (p.getX() > 40 && p.getY() > 40) {
+// ToolTipManager toolTipManager =
+// ToolTipManager.sharedInstance();
+// toolTipManager.setInitialDelay(750);
+// JPopupMenu popup = sessionEditorNode.getPopup();
+//
+// if (!popup.isShowing()) {
+// popup.show(sessionEditorNode, e.getX(), e.getY());
+// }
+// }
+// }
+// });
+
sessionEditorNode.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
sessionEditorNode.getSimulationStudy().getSession().setSessionChanged(true);
@@ -564,11 +576,17 @@ public void actionPerformed(ActionEvent e) {
return popup;
}
+ JPopupMenu popup = null;
+
/**
* Creates the popup for the node.
*/
private JPopupMenu getPopup() {
- JPopupMenu popup = new JPopupMenu();
+ if (popup != null && popup.isShowing()) {
+ return popup;
+ }
+
+ popup = new JPopupMenu();
JMenuItem createModel = new JMenuItem("Create Model");
createModel.setToolTipText("Creates a new model for this node" +
@@ -739,52 +757,63 @@ public void actionPerformed(ActionEvent e) {
}
});
-// JMenuItem editSimulationParameters =
-// new JMenuItem("Edit Parameters...");
-// editSimulationParameters.setToolTipText("");
+ JMenuItem editSimulationParameters =
+ new JMenuItem("Edit Parameters...");
+ editSimulationParameters.setToolTipText("");
-// editSimulationParameters.addActionListener(new ActionListener() {
-// public void actionPerformed(ActionEvent e) {
-// SessionModel model = getSessionNode().getModel();
-// Class modelClass;
-//
-// if (model == null) {
-// modelClass = determineTheModelClass(getSessionNode());
-// } else {
-// modelClass = model.getClass();
-// }
+ editSimulationParameters.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ SessionModel model = getSessionNode().getModel();
+ Class modelClass;
+
+ if (model == null) {
+ modelClass = determineTheModelClass(getSessionNode());
+ } else {
+ modelClass = model.getClass();
+ }
+
+ if (!getSessionNode().existsParameterizedConstructor(
+ modelClass)) {
+ JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
+ "There is no parameterization for this model.");
+ return;
+ }
+
+ Parameters param = getSessionNode().getParam(modelClass);
+ Object[] arguments =
+ getSessionNode().getModelConstructorArguments(
+ modelClass);
+
+ if (param != null) {
+ try {
+ editParameters(modelClass, param, arguments);
+ int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(),
+ "Should I overwrite the contents of this box and all delete the contents\n" +
+ "of all boxes downstream?",
+ "Double check...", JOptionPane.YES_NO_OPTION);
+ if (ret == JOptionPane.YES_OPTION) {
+ getSessionNode().destroyModel();
+ getSessionNode().createModel(modelClass, true);
+ }
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+ }
+ });
+
+// final SessionNode thisNode = getSessionNode();
//
-// if (!getSessionNode().existsParameterizedConstructor(
-// modelClass)) {
-// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
-// "There is no parameterization for this model.");
-// return;
-// }
+// // popup.add(getConsistentParentMenuItems(getConsistentParentBoxTypes(thisNode)));
+//// popup.add(getConsistentChildBoxMenus(getConsistentChildBoxTypes(thisNode, null)));
//
-// Parameters param = getSessionNode().getParam(modelClass);
-// Object[] arguments =
-// getSessionNode().getModelConstructorArguments(
-// modelClass);
+// addConsistentParentMenuItems(popup, getConsistentParentBoxTypes(thisNode));
+// addConsistentChildBoxMenus(popup, getConsistentChildBoxTypes(thisNode, null));
//
-// if (param != null) {
-// try {
-// editParameters(modelClass, param, arguments);
-// int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(),
-// "Should I overwrite the contents of this box and all delete the contents\n" +
-// "of all boxes downstream?",
-// "Double check...", JOptionPane.YES_NO_OPTION);
-// if (ret == JOptionPane.YES_OPTION) {
-// getSessionNode().destroyModel();
-// getSessionNode().createModel(modelClass, true);
-// }
-// } catch (Exception e1) {
-// e1.printStackTrace();
-// }
-// }
-// }
-// });
+// popup.addSeparator();
popup.add(createModel);
+ popup.add(editSimulationParameters);
popup.add(editModel);
popup.add(destroyModel);
@@ -796,85 +825,111 @@ public void actionPerformed(ActionEvent e) {
popup.addSeparator();
-// final SessionNode thisNode = getSessionNode();
-//
-// popup.add(getConsistentParentMenuItems(getConsistentParentBoxTypes(thisNode)));
-// popup.add(getConsistentChildBoxMenus(getConsistentChildBoxTypes(thisNode, null)));
-
-// popup.addSeparator();
-
addEditLoggerSettings(popup);
popup.add(propagateDownstream);
return popup;
}
- private JMenu getConsistentChildBoxMenus(List consistentChildBoxes) {
- JMenu newChildren = new JMenu("New Child Box");
-
- for (String _type : consistentChildBoxes) {
- final JMenuItem menuItem = new JMenuItem(_type);
-
- menuItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, menuItem.getText());
- }
- });
-
- newChildren.add(menuItem);
- }
- return newChildren;
- }
-
- private JMenu getConsistentParentMenuItems(List consistentParentBoxes) {
- final JMenu newParents = new JMenu("New Parent Box");
-
- for (String _type : consistentParentBoxes) {
- final JMenuItem menuItem = new JMenuItem(_type);
-
- menuItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- new ConstructTemplateAction("Test").addParent(SessionEditorNode.this, menuItem.getText());
- }
- });
-
- newParents.add(menuItem);
- }
- return newParents;
- }
-
- private List getConsistentChildBoxTypes(SessionNode thisNode, SessionModel model) {
- List consistentChildBoxes = new ArrayList<>();
-
- for (String type : TetradApplicationConfig.getInstance().getConfigs().keySet()) {
- SessionNodeConfig config = TetradApplicationConfig.getInstance().getSessionNodeConfig(type);
- Class[] modelClasses = config.getModels();
-
- SessionNode newNode = new SessionNode(modelClasses);
+// private void addConsistentChildBoxMenus(JPopupMenu menu, List consistentChildBoxes) {
+// for (String _type : consistentChildBoxes) {
+// final JMenuItem menuItem = new JMenuItem(_type);
+//
+// menuItem.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent e) {
+// String text = menuItem.getText();
+// String[] tokens = text.split(" ");
+// String type = tokens[1];
+// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, type);
+// }
+// });
+//
+// menu.add(menuItem);
+// }
+// }
- if (thisNode.isConsistentParent(newNode)) {
- consistentChildBoxes.add(type);
- }
- }
- return consistentChildBoxes;
- }
+// private JMenu addConsistentChildBoxMenus(List consistentChildBoxes) {
+// JMenu newChildren = new JMenu("New Child Box");
+//
+// for (String _type : consistentChildBoxes) {
+// final JMenuItem menuItem = new JMenuItem(_type);
+//
+// menuItem.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent e) {
+// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, menuItem.getText());
+// }
+// });
+//
+//
+//
+// newChildren.add(menuItem);
+// }
+// return newChildren;
+// }
- private List getConsistentParentBoxTypes(SessionNode thisNode) {
- List consistentParentBoxes = new ArrayList<>();
+// private JMenu addConsistentParentMenuItems(JPopupMenu menu, List consistentParentNodes) {
+// final JMenu newParents = new JMenu("New Parent Box");
+//
+// for (final SessionNode node : consistentParentNodes) {
+// final JMenuItem menuItem = new JMenuItem("Add Links: " + node.getDisplayName());
+//
+// menuItem.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent e) {
+// String displayName1 = node.getDisplayName();
+// String displayName2 = SessionEditorNode.this.getSessionNode().getDisplayName();
+// new ConstructTemplateAction("Test").addEdge(displayName1, displayName2);
+// }
+// });
+//
+// menu.add(menuItem);
+// }
+//
+// return newParents;
+// }
- for (String type : TetradApplicationConfig.getInstance().getConfigs().keySet()) {
- SessionNodeConfig config = TetradApplicationConfig.getInstance().getSessionNodeConfig(type);
- Class[] modelClasses = config.getModels();
- SessionNode newNode = new SessionNode(modelClasses);
+// private List getConsistentChildBoxTypes(SessionNode thisNode, SessionModel model) {
+// List consistentChildBoxes = new ArrayList<>();
+//
+// List nodes = sessionWorkbench.getSessionWrapper().getNodes();
+// List sessionNodes = new ArrayList<>();
+// for (Node node : nodes) sessionNodes.add(((SessionNodeWrapper) node).getSessionNode());
+//
+// Set strings = TetradApplicationConfig.getInstance().getConfigs().keySet();
+//
+// for (String type : strings) {
+// SessionNodeConfig config = TetradApplicationConfig.getInstance().getSessionNodeConfig(type);
+// Class[] modelClasses = config.getModels();
+//
+// SessionNode newNode = new SessionNode(modelClasses);
+//
+// if (newNode.isConsistentParent(thisNode, sessionNodes)) {
+// consistentChildBoxes.add("Add " + type);
+// }
+// }
+//
+// return consistentChildBoxes;
+// }
- if (thisNode.isConsistentParent(newNode)) {
- consistentParentBoxes.add(type);
- }
- }
- return consistentParentBoxes;
- }
+// private List getConsistentParentBoxTypes(SessionNode thisNode) {
+// List consistentParentBoxes = new ArrayList<>();
+//
+// for (Node _node : getSessionWorkbench().getSessionWrapper().getNodes()) {
+// SessionNode node = ((SessionNodeWrapper) _node).getSessionNode();
+//
+// if (sessionWorkbench.getSessionWrapper().isAncestorOf(thisNode, node)) {
+// continue;
+// }
+//
+// if (!thisNode.getParents().contains(node) && thisNode.isConsistentParent(node)) {
+// consistentParentBoxes.add(node);
+// }
+// }
+//
+// return consistentParentBoxes;
+// }
/**
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java
index 6279fcb76b..9855901435 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java
@@ -108,19 +108,19 @@ public SessionEditorToolbar(final SessionEditorWorkbench workbench) {
"
to construct the object in the second node." +
"
As a shortcut, hold down the Control key." +
""),
- new ButtonInfo("Data", "Data & Simulation", "data",
- "Add a node for a data object."),
- new ButtonInfo("Search", "Search", "search",
- "Add a node for a search algorithm."),
- new ButtonInfo("Comparison", "Comparison", "compare",
- "Add a node to compare graphs or SEM IM's."),
new ButtonInfo("Graph", "Graph", "graph", "Add a graph node."),
+ new ButtonInfo("Compare", "Compare", "compare",
+ "Add a node to compare graphs or SEM IM's."),
new ButtonInfo("PM", "Parametric Model", "pm",
"Add a node for a parametric model."),
new ButtonInfo("IM", "Instantiated Model", "im",
"Add a node for an instantiated model."),
new ButtonInfo("Estimator", "Estimator", "estimator",
"Add a node for an estimator."),
+ new ButtonInfo("Data", "Data & Simulation", "data",
+ "Add a node for a data object."),
+ new ButtonInfo("Search", "Search", "search",
+ "Add a node for a search algorithm."),
new ButtonInfo("Updater", "Updater", "updater",
"Add a node for an updater."),
new ButtonInfo("Classify", "Classify", "search",
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbarHarry.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbarHarry.java
new file mode 100644
index 0000000000..4738cd44de
--- /dev/null
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbarHarry.java
@@ -0,0 +1,476 @@
+///////////////////////////////////////////////////////////////////////////////
+// For information as to what this class does, see the Javadoc, below. //
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, //
+// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph //
+// Ramsey, and Clark Glymour. //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation; either version 2 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program; if not, write to the Free Software //
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
+///////////////////////////////////////////////////////////////////////////////
+
+package edu.cmu.tetradapp.app;
+
+import edu.cmu.tetradapp.util.ImageUtils;
+import edu.cmu.tetradapp.workbench.AbstractWorkbench;
+
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.*;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Displays a vertical list of buttons that determine the next action the user
+ * can take in the session editor workbench, whether it's selecting and moving a
+ * node, adding a node of a particular type, or adding an edge.
+ *
+ * @author Joseph Ramsey jdramsey@andrew.cmu.edu
+ * @see SessionEditor
+ * @see SessionEditorToolbarHarry
+ */
+final class SessionEditorToolbarHarry extends JPanel {
+
+ //=========================MEMBER FIELDS============================//
+
+ /**
+ * True iff the toolbar is responding to events.
+ */
+ private boolean respondingToEvents = true;
+ /**
+ * The node type of the button that is used for the Select/Move tool.
+ */
+ private final String selectType = "Select";
+
+
+ /**\
+ * The map from JToggleButtons to String node types.
+ */
+ private final Map nodeTypes = new HashMap<>();
+
+ /**
+ * True iff the shift key was down on last click.
+ */
+ private boolean shiftDown = false;
+
+ /**
+ * The workbench this toolbar controls.
+ */
+ private SessionEditorWorkbench workbench;
+
+ //=============================CONSTRUCTORS==========================//
+
+ /**
+ * Constructs a new session toolbar.
+ *
+ * @param workbench the workbench this toolbar controls.
+ */
+ public SessionEditorToolbarHarry(final SessionEditorWorkbench workbench) {
+ if (workbench == null) {
+ throw new NullPointerException("Workbench must not be null.");
+ }
+
+ this.workbench = workbench;
+
+ // Set up panel.
+ Box buttonsPanel = Box.createVerticalBox();
+// buttonsPanel.setBackground(new Color(198, 232, 252));
+ buttonsPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+
+ // Create buttons.
+ /*
+ Node infos for all of the nodes.
+ */
+ ButtonInfo[] buttonInfos = new ButtonInfo[]{
+ new ButtonInfo("Select", "Select and Move", "move",
+ "Select and move nodes or groups of nodes " +
+ "
on the workbench."),
+// new ButtonInfo("Edge", "Draw Edge", "flow",
+// "Add an edge from one node to another to declare" +
+// "
that the object in the first node should be used " +
+// "
to construct the object in the second node." +
+// "
As a shortcut, hold down the Control key." +
+// ""),
+ new ButtonInfo("Graph", "Graph", "graph", "Add a graph node."),
+ new ButtonInfo("Data", "Data", "data",
+ "Add a node for a data object."),
+// new ButtonInfo("Data", "Data & Simulation", "data",
+// "Add a node for a data object."),
+// new ButtonInfo("Search", "Search", "search",
+// "Add a node for a search algorithm."),
+ new ButtonInfo("Simulation", "Simulation", "data",
+ "Add a node for a data object."),
+// new ButtonInfo("Comparison", "Comparison", "compare",
+// "Add a node to compare graphs or SEM IM's."),
+// new ButtonInfo("PM", "Parametric Model", "pm",
+// "Add a node for a parametric model."),
+// new ButtonInfo("IM", "Instantiated Model", "im",
+// "Add a node for an instantiated model."),
+// new ButtonInfo("Estimator", "Estimator", "estimator",
+// "Add a node for an estimator."),
+// new ButtonInfo("Updater", "Updater", "updater",
+// "Add a node for an updater."),
+// new ButtonInfo("Classify", "Classify", "search",
+// "Add a node for a classifier."),
+// new ButtonInfo("Regression", "Regression", "regression",
+// "Add a node for a regression."),
+// new ButtonInfo("Knowledge", "Knowledge", "knowledge", "Add a knowledge box node."),
+ new ButtonInfo("Note", "Note", "note",
+ "Add a note to the session.")
+ };
+ JToggleButton[] buttons = new JToggleButton[buttonInfos.length];
+
+ for (int i = 0; i < buttonInfos.length; i++) {
+ buttons[i] = constructButton(buttonInfos[i]);
+ }
+
+ // Add all buttons to a button group.
+ ButtonGroup buttonGroup = new ButtonGroup();
+
+ for (int i = 0; i < buttonInfos.length; i++) {
+ buttonGroup.add(buttons[i]);
+ }
+
+ // This seems to be fixed. Now creating weirdness. jdramsey 3/4/2014
+// // Add a focus listener to help buttons not deselect when the
+// // mouse slides away from the button.
+// FocusListener focusListener = new FocusAdapter() {
+// public void focusGained(FocusEvent e) {
+// JToggleButton component = (JToggleButton) e.getComponent();
+// component.getModel().setSelected(true);
+// }
+// };
+//
+// for (int i = 0; i < buttonInfos.length; i++) {
+// buttons[i].addFocusListener(focusListener);
+// }
+
+ // Add an action listener to help send messages to the
+ // workbench.
+ ChangeListener changeListener = new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ JToggleButton _button = (JToggleButton) e.getSource();
+
+ if (_button.getModel().isSelected()) {
+ setWorkbenchMode(_button);
+// setCursor(workbench.getCursor());
+ }
+ }
+ };
+
+ for (int i = 0; i < buttonInfos.length; i++) {
+ buttons[i].addChangeListener(changeListener);
+ }
+
+ // Select the Select button.
+ JToggleButton button = getButtonForType(this.selectType);
+
+ button.getModel().setSelected(true);
+
+ // Add the buttons to the workbench.
+ for (int i = 0; i < buttonInfos.length; i++) {
+ if (!buttonInfos[i].getNodeTypeName().equals("Select")) {
+ buttonsPanel.add(buttons[i]);
+ buttonsPanel.add(Box.createVerticalStrut(5));
+ }
+ }
+
+ // Put the panel in a scrollpane.
+ this.setLayout(new BorderLayout());
+ JScrollPane scroll = new JScrollPane(buttonsPanel);
+ scroll.setPreferredSize(new Dimension(130, 1000));
+ add(scroll, BorderLayout.CENTER);
+
+ // Add property change listener so that selection can be moved
+ // back to "SELECT_MOVE" after an action.
+ workbench.addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent e) {
+ if (!isRespondingToEvents()) {
+ return;
+ }
+
+ String propertyName = e.getPropertyName();
+
+ if ("nodeAdded".equals(propertyName)) {
+ if (!isShiftDown()) {
+ resetSelectMove();
+ }
+ }
+ }
+ });
+
+ KeyboardFocusManager.getCurrentKeyboardFocusManager()
+ .addKeyEventDispatcher(new KeyEventDispatcher() {
+ public boolean dispatchKeyEvent(KeyEvent e) {
+ int keyCode = e.getKeyCode();
+ int id = e.getID();
+
+ if (keyCode == KeyEvent.VK_SHIFT) {
+ if (id == KeyEvent.KEY_PRESSED) {
+ setShiftDown(true);
+ } else if (id == KeyEvent.KEY_RELEASED) {
+ setShiftDown(false);
+ resetSelectMove();
+ }
+ }
+
+ return false;
+ }
+ });
+
+ resetSelectMove();
+ }
+
+ /**
+ * Sets the selection back to move/select.
+ */
+ private void resetSelectMove() {
+ JToggleButton selectButton = getButtonForType(selectType);
+ if (!(selectButton.isSelected())) {
+ selectButton.doClick();
+ selectButton.requestFocus();
+ }
+ }
+
+// /**
+// * Sets the selection back to Flowchart.
+// */
+// public void resetFlowchart() {
+// JToggleButton edgeButton = getButtonForType(edgeType);
+// edgeButton.doClick();
+// edgeButton.requestFocus();
+// }
+
+ /**
+ * True iff the toolbar is responding to events. This may need to be turned
+ * off temporarily.
+ */
+ private boolean isRespondingToEvents() {
+ return respondingToEvents;
+ }
+
+ /**
+ * Sets whether the toolbar should react to events. This may need to be
+ * turned off temporarily.
+ */
+ public void setRespondingToEvents(boolean respondingToEvents) {
+ this.respondingToEvents = respondingToEvents;
+ }
+
+ protected void processKeyEvent(KeyEvent e) {
+ System.out.println("process key event " + e);
+ super.processKeyEvent(e);
+ }
+
+ //===========================PRIVATE METHODS=========================//
+
+ /**
+ * Constructs the button with the given node type and image prefix. If the
+ * node type is "Select", constructs a button that allows nodes to be
+ * selected and moved. If the node type is "Edge", constructs a button that
+ * allows edges to be drawn. For other node types, constructs buttons that
+ * allow those type of nodes to be added to the workbench. If a non-null
+ * image prefix is provided, images for Up.gif, Down.gif,
+ * Off.gif and Roll.gif are loaded from the /images
+ * directory relative to this compiled class and used to provide up, down,
+ * off, and rollover images for the constructed button. On construction,
+ * nodes are mapped to their node types in the Map, nodeTypes
.
+ * Listeners are added to the node.
+ *
+ * @param buttonInfo contains the info needed to construct the button.
+ */
+ private JToggleButton constructButton(ButtonInfo buttonInfo) {
+ String imagePrefix = buttonInfo.getImagePrefix();
+
+ if (imagePrefix == null) {
+ throw new NullPointerException("Image prefix must not be null.");
+ }
+
+ JToggleButton button = new JToggleButton();
+
+ button.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ setShiftDown(e.isShiftDown());
+// setControlDown(e.isControlDown());
+ }
+ });
+
+ if ("Select".equals(buttonInfo.getNodeTypeName())) {
+ button.setIcon(new ImageIcon(ImageUtils.getImage(this, "move.gif")));
+ } else if ("Edge".equals(buttonInfo.getNodeTypeName())) {
+ button.setIcon(
+ new ImageIcon(ImageUtils.getImage(this, "flow.gif")));
+ } else {
+ button.setName(buttonInfo.getNodeTypeName());
+ button.setText("" + buttonInfo.getDisplayName() +
+ "");
+ }
+
+ button.setMaximumSize(new Dimension(110, 40)); // For a vertical box.
+ button.setToolTipText(buttonInfo.getToolTipText());
+ this.nodeTypes.put(button, buttonInfo.getNodeTypeName());
+
+ return button;
+ }
+
+ /**
+ * Sets the state of the workbench in response to a button press.
+ *
+ * @param button the JToggleButton whose workbench state is to be set.
+ */
+ private void setWorkbenchMode(JToggleButton button) {
+ String nodeType = this.nodeTypes.get(button);
+
+ /*
+ The node type of the button that is used for the edge-drawing tool.
+ */
+ String edgeType = "Edge";
+ if (selectType.equals(nodeType)) {
+ workbench.setWorkbenchMode(AbstractWorkbench.SELECT_MOVE);
+ workbench.setNextButtonType(null);
+ setCursor(new Cursor(Cursor.HAND_CURSOR));
+ workbench.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ } else if (edgeType.equals(nodeType)) {
+ workbench.setWorkbenchMode(AbstractWorkbench.ADD_EDGE);
+ workbench.setNextButtonType(null);
+// setCursor(workbench.getCursor());
+
+// Toolkit toolkit = Toolkit.getDefaultToolkit();
+// Image image = ImageUtils.getImage(this, "arrowCursorImage.png");
+// Cursor c = toolkit.createCustomCursor(image, new Point(10, 10), "img");
+// setCursor(c);
+// workbench.setCursor(c);
+
+ setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+ workbench.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+ } else {
+ workbench.setWorkbenchMode(AbstractWorkbench.ADD_NODE);
+ workbench.setNextButtonType(nodeType);
+
+// Toolkit toolkit = Toolkit.getDefaultToolkit();
+// Image image = ImageUtils.getImage(this, "cursorImage.png");
+// Cursor c = toolkit.createCustomCursor(image, new Point(10, 10), "img");
+// setCursor(c);
+// workbench.setCursor(c);
+
+// setCursor(workbench.getCursor());
+
+ setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
+ workbench.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
+
+ }
+ }
+
+ /**
+ * @return the JToggleButton for the given node type, or null if no such
+ * button exists.
+ */
+ private JToggleButton getButtonForType(String nodeType) {
+ for (Object o : nodeTypes.keySet()) {
+ JToggleButton button = (JToggleButton) o;
+
+ if (nodeType.equals(nodeTypes.get(button))) {
+ return button;
+ }
+ }
+
+ return null;
+ }
+
+ private boolean isShiftDown() {
+ return shiftDown;
+ }
+
+ private void setShiftDown(boolean shiftDown) {
+ this.shiftDown = shiftDown;
+ }
+
+// public boolean isControlDown() {
+// return shiftDown;
+// }
+//
+// private void setControlDown(boolean shiftDown) {
+// this.shiftDown = shiftDown;
+// }
+
+ /**
+ * Holds info for constructing a single button.
+ */
+ private static final class ButtonInfo {
+
+ /**
+ * This is the name used to construct nodes on the graph of this type.
+ * Need to coordinate with session.
+ */
+ private String nodeTypeName;
+
+ /**
+ * The name displayed on the button.
+ */
+ private final String displayName;
+
+ /**
+ * The prefixes for images for this button. It is assumed that files
+ * Up.gif, Down.gif, Off.gif and
+ * Roll.gif are located in the /images directory relative to
+ * this compiled class.
+ */
+ private final String imagePrefix;
+
+ /**
+ * Tool tip text displayed for the button.
+ */
+ private final String toolTipText;
+
+ public ButtonInfo(String nodeTypeName, String displayName,
+ String imagePrefix, String toolTipText) {
+ this.nodeTypeName = nodeTypeName;
+ this.displayName = displayName;
+ this.imagePrefix = imagePrefix;
+ this.toolTipText = toolTipText;
+ }
+
+ public String getNodeTypeName() {
+ return nodeTypeName;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setNodeTypeName(String nodeTypeName) {
+ this.nodeTypeName = nodeTypeName;
+ }
+
+ public String getImagePrefix() {
+ return imagePrefix;
+ }
+
+ public String getToolTipText() {
+ return toolTipText;
+ }
+ }
+}
+
+
+
+
+
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradApplicationConfig.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradApplicationConfig.java
index e854513022..bac87a9c72 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradApplicationConfig.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradApplicationConfig.java
@@ -133,7 +133,7 @@ public SessionNodeConfig getSessionNodeConfig(Class model) {
private static Map buildConfiguration(Element root) {
Elements elements = root.getChildElements();
ClassLoader loader = getClassLoader();
- Map configs = new HashMap<>();
+ Map configs = new LinkedHashMap<>();
for (int i = 0; i < elements.size(); i++) {
Element node = elements.get(i);
String id = node.getAttributeValue("id");
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java
index 9131cdb1ce..3d8a8d6ee7 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java
@@ -136,11 +136,6 @@ public TetradDesktop() {
// ===========================PUBLIC METHODS============================//
- public void buildHpcJobActivityPane() {
-
- }
-
-
public void newSessionEditor() {
String newName = getNewSessionName();
SessionEditor editor = new SessionEditor(newName);
@@ -369,8 +364,7 @@ public SessionEditor getFrontmostSessionEditor() {
* Reacts to property change events 'editorClosing', 'closeFrame', and
* 'name'.
*
- * @param e
- * the property change event.
+ * @param e the property change event.
*/
public void propertyChange(PropertyChangeEvent e) {
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java
index 533f54d79b..b86b672ebe 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java
@@ -59,7 +59,7 @@ final class TetradMenuBar extends JMenuBar {
/**
* Creates the main menubar for Tetrad.
*/
- public TetradMenuBar(final TetradDesktop desktop) {
+ public TetradMenuBar(TetradDesktop desktop) {
this.desktop = desktop;
setBorder(new EtchedBorder());
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java
index 0d5e6c903d..94e403ad07 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java
@@ -66,7 +66,7 @@ final class WindowMenuListener implements MenuListener, ActionListener {
* Constructs the window menu listener. Requires to be told which object
* the window menu is and which object the desktop pane is.
*/
- public WindowMenuListener(JMenu windowMenu, final TetradDesktop desktop) {
+ public WindowMenuListener(JMenu windowMenu, TetradDesktop desktop) {
if (windowMenu == null) {
throw new NullPointerException("Window menu must not be null.");
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/DeleteHpcJobInfoAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/DeleteHpcJobInfoAction.java
index 959f75d226..67fb6029f8 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/DeleteHpcJobInfoAction.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/DeleteHpcJobInfoAction.java
@@ -23,49 +23,45 @@
*/
public class DeleteHpcJobInfoAction extends AbstractAction {
- private static final long serialVersionUID = 7915068087861233608L;
+ private static final long serialVersionUID = 7915068087861233608L;
- private final Component parentComp;
+ private final Component parentComp;
- public DeleteHpcJobInfoAction(final Component parentComp) {
- this.parentComp = parentComp;
- }
+ public DeleteHpcJobInfoAction(final Component parentComp) {
+ this.parentComp = parentComp;
+ }
- @Override
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
- JTable table = (JTable) e.getSource();
- int modelRow = Integer.valueOf(e.getActionCommand());
- DefaultTableModel finishedJobTableModel = (DefaultTableModel) table
- .getModel();
+ 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();
+ 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);
+ 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;
+ if (answer == JOptionPane.NO_OPTION)
+ return;
- TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
- final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
+ TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
+ final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
- HpcJobInfo hpcJobInfo = hpcJobManager
- .findHpcJobInfoById(Long.valueOf(
- finishedJobTableModel.getValueAt(modelRow,
- HpcJobActivityEditor.ID_COLUMN).toString())
- .longValue());
+ 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);
- }
+ if (hpcJobInfo != null) {
+ // Update table
+ finishedJobTableModel.removeRow(modelRow);
+ table.updateUI();
+ hpcJobManager.removeHpcJobInfoTransaction(hpcJobInfo);
+ }
- }
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSelectionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSelectionAction.java
index f890e32611..66b6992a42 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSelectionAction.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSelectionAction.java
@@ -18,39 +18,36 @@
*/
public class HpcAccountSelectionAction extends AbstractAction {
- private static final long serialVersionUID = -5506074283478552872L;
-
- private final List hpcAccounts;
-
- private final List checkedHpcAccountList;
-
- private final JTabbedPane tabbedPane;
-
- public HpcAccountSelectionAction(final List hpcAccounts,
- final List checkedHpcAccountList,
- final JTabbedPane tabbedPane) {
- this.hpcAccounts = hpcAccounts;
- this.checkedHpcAccountList = checkedHpcAccountList;
- this.tabbedPane = tabbedPane;
- }
-
- @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);
+ private static final long serialVersionUID = -5506074283478552872L;
+
+ private final List hpcAccounts;
+
+ private final List checkedHpcAccountList;
+
+ private final JTabbedPane tabbedPane;
+
+ public HpcAccountSelectionAction(final List hpcAccounts, final List checkedHpcAccountList,
+ final JTabbedPane tabbedPane) {
+ this.hpcAccounts = hpcAccounts;
+ this.checkedHpcAccountList = checkedHpcAccountList;
+ this.tabbedPane = tabbedPane;
+ }
+
+ @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);
}
- int index = tabbedPane.getSelectedIndex();
- tabbedPane.setSelectedIndex(-1);
- tabbedPane.setSelectedIndex(index);
- }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSettingAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSettingAction.java
index 59b0ab6444..3f67429268 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSettingAction.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcAccountSettingAction.java
@@ -35,139 +35,130 @@
*/
public class HpcAccountSettingAction extends AbstractAction {
- private static final long serialVersionUID = -4084211497363128243L;
-
- public HpcAccountSettingAction() {
- super("HPC Account");
- }
-
- @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);
- }
-
- private static JComponent buildHpcAccountSettingComponent(
- final HpcAccountManager manager) {
- // Get ComputingAccount from DB
- final DefaultListModel listModel = new DefaultListModel();
-
- for (HpcAccount account : manager.getHpcAccounts()) {
- listModel.addElement(account);
+ private static final long serialVersionUID = -4084211497363128243L;
+
+ public HpcAccountSettingAction() {
+ super("HPC 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 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);
- }
+ @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);
+ }
+
+ private static JComponent buildHpcAccountSettingComponent(final HpcAccountManager manager) {
+ // Get ComputingAccount from DB
+ final DefaultListModel listModel = new DefaultListModel();
+
+ for (HpcAccount account : manager.getHpcAccounts()) {
+ listModel.addElement(account);
}
- }
- });
- 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;
- }
+
+ // 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 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;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcJobActivityAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcJobActivityAction.java
index 2975d77a23..3cdbe0edbb 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcJobActivityAction.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/HpcJobActivityAction.java
@@ -1,5 +1,6 @@
package edu.cmu.tetradapp.app.hpc.action;
+import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
@@ -19,25 +20,25 @@
*/
public class HpcJobActivityAction extends AbstractAction {
- private static final long serialVersionUID = -8500391011385619809L;
+ private static final long serialVersionUID = -8500391011385619809L;
- private static final String TITLE = "High-Performance Computing Job Activity";
+ private static final String TITLE = "High-Performance Computing Job Activity";
- public HpcJobActivityAction(String actionTitle) {
- super(actionTitle);
- }
+ public HpcJobActivityAction(String actionTitle) {
+ super(actionTitle);
+ }
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- JComponent comp = new HpcJobActivityEditor();
- JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), comp,
- TITLE, JOptionPane.PLAIN_MESSAGE);
- } catch (HeadlessException e1) {
- //e1.printStackTrace();
- } catch (Exception e1) {
- //e1.printStackTrace();
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ try {
+ Frame ancestor = (Frame) JOptionUtils.centeringComp().getTopLevelAncestor();
+ JComponent comp = new HpcJobActivityEditor();
+ JOptionPane.showMessageDialog(ancestor, comp, TITLE, JOptionPane.PLAIN_MESSAGE);
+ } catch (HeadlessException e1) {
+ // e1.printStackTrace();
+ } catch (Exception e1) {
+ // e1.printStackTrace();
+ }
}
- }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/KillHpcJobAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/KillHpcJobAction.java
index 19b600a56a..a8ed351854 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/KillHpcJobAction.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/KillHpcJobAction.java
@@ -25,101 +25,93 @@
*/
public class KillHpcJobAction extends AbstractAction {
- private static final long serialVersionUID = 8275717978736439467L;
-
- private final Component parentComp;
-
- public KillHpcJobAction(Component parentComp) {
- this.parentComp = parentComp;
- }
-
- @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);
-
- hpcJobInfo.setStatus(4); // Killed
-
- // 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);
- }
- }
+ private static final long serialVersionUID = 8275717978736439467L;
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
+ private final Component parentComp;
+ public KillHpcJobAction(Component parentComp) {
+ this.parentComp = parentComp;
}
- }
+ @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);
+
+ hpcJobInfo.setStatus(4); // Killed
+
+ // 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();
+ }
+
+ }
+
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/LoadHpcGraphJsonAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/LoadHpcGraphJsonAction.java
index 54025e3d31..8017986506 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/LoadHpcGraphJsonAction.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/action/LoadHpcGraphJsonAction.java
@@ -29,6 +29,7 @@
import edu.cmu.tetrad.util.JOptionUtils;
import edu.cmu.tetrad.util.JsonUtils;
import edu.cmu.tetradapp.app.TetradDesktop;
+import edu.cmu.tetradapp.app.hpc.editor.LoadHpcGraphJsonTableModel;
import edu.cmu.tetradapp.app.hpc.manager.HpcAccountManager;
import edu.cmu.tetradapp.app.hpc.manager.HpcAccountService;
import edu.cmu.tetradapp.app.hpc.manager.HpcJobManager;
@@ -49,231 +50,204 @@
*/
public class LoadHpcGraphJsonAction extends AbstractAction {
- private static final long serialVersionUID = 3640705055173728331L;
+ private static final long serialVersionUID = 3640705055173728331L;
- /**
- * The component whose image is to be saved.
- */
- private GraphEditable graphEditable;
+ /**
+ * The component whose image is to be saved.
+ */
+ private GraphEditable graphEditable;
- private String jsonFileName = null;
+ private String jsonFileName = null;
- private HpcAccount hpcAccount = null;
+ private HpcAccount hpcAccount = null;
- public LoadHpcGraphJsonAction(GraphEditable graphEditable, String title) {
- super(title);
+ public LoadHpcGraphJsonAction(GraphEditable graphEditable, String title) {
+ super(title);
- if (graphEditable == null) {
- throw new NullPointerException("Component must not be null.");
- }
+ if (graphEditable == null) {
+ throw new NullPointerException("Component must not be null.");
+ }
- this.graphEditable = graphEditable;
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
- final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
- final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
-
- JComponent comp = buildHpcJsonChooserComponent(desktop);
- int option = JOptionPane.showConfirmDialog(
- JOptionUtils.centeringComp(), comp,
- "High-Performance Computing Account Json Results Chooser",
- JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
-
- if (option == JOptionPane.OK_OPTION && jsonFileName != null
- && hpcAccount != null) {
-
- try {
- HpcAccountService hpcAccountService = hpcJobManager
- .getHpcAccountService(hpcAccount);
-
- ResultService resultService = hpcAccountService.getResultService();
-
- String json = resultService.downloadAlgorithmResultFile(
- jsonFileName, HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
-
- Graph graph = JsonUtils.parseJSONObjectToTetradGraph(json);
- GraphUtils.circleLayout(graph, 300, 300, 150);
- graphEditable.setGraph(graph);
- graphEditable.setName(jsonFileName);
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- } else {
- System.out.println("Option: OK "
- + (option == JOptionPane.OK_OPTION));
- System.out
- .println("Option: jsonFileName " + (jsonFileName != null));
- System.out.println("Option: computingAccount "
- + (hpcAccount != null));
+ this.graphEditable = graphEditable;
}
- }
- private JComponent buildHpcJsonChooserComponent(final TetradDesktop desktop) {
- final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
- final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
- // Get ComputingAccount from DB
- final DefaultListModel listModel = new DefaultListModel();
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
+ final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
+ final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
+
+ JComponent comp = buildHpcJsonChooserComponent(desktop);
+ int option = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(), comp,
+ "High-Performance Computing Account Json Results Chooser", JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.PLAIN_MESSAGE);
+
+ if (option == JOptionPane.OK_OPTION && jsonFileName != null && hpcAccount != null) {
+
+ try {
+ HpcAccountService hpcAccountService = hpcJobManager.getHpcAccountService(hpcAccount);
+
+ ResultService resultService = hpcAccountService.getResultService();
+
+ String json = resultService.downloadAlgorithmResultFile(jsonFileName,
+ HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
- for (HpcAccount account : hpcAccountManager.getHpcAccounts()) {
- listModel.addElement(account);
+ Graph graph = JsonUtils.parseJSONObjectToTetradGraph(json);
+ GraphUtils.circleLayout(graph, 300, 300, 150);
+ graphEditable.setGraph(graph);
+ graphEditable.setName(jsonFileName);
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ } else {
+ System.out.println("Option: OK " + (option == JOptionPane.OK_OPTION));
+ System.out.println("Option: jsonFileName " + (jsonFileName != null));
+ System.out.println("Option: computingAccount " + (hpcAccount != null));
+ }
}
- // JSplitPane
- final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
-
- // Left pane -> JList (parent pane)
- JPanel leftPanel = new JPanel(new BorderLayout());
-
- // Right pane -> ComputingAccountResultList
- final JPanel jsonResultListPanel = new JPanel(new BorderLayout());
-
- int minWidth = 800;
- int minHeight = 600;
- int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
- int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
- int frameWidth = screenWidth * 3 / 4;
- int frameHeight = screenHeight * 3 / 4;
- final int paneWidth = minWidth > frameWidth ? minWidth : frameWidth;
- final int paneHeight = minHeight > frameHeight ? minHeight
- : frameHeight;
-
- // JTable
- final Vector columnNames = new Vector<>();
- columnNames.addElement("Name");
- columnNames.addElement("Created");
- columnNames.addElement("Last Modified");
- columnNames.addElement("Size");
-
- Vector> rowData = new Vector<>();
-
- final DefaultTableModel tableModel = new DefaultTableModel(rowData,
- columnNames);
- final JTable jsonResultTable = new JTable(tableModel);
- jsonResultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-
- // Resize table's column width
- jsonResultTable.getColumnModel().getColumn(0)
- .setPreferredWidth(paneWidth * 2 / 5);
- jsonResultTable.getColumnModel().getColumn(1)
- .setPreferredWidth(paneWidth * 2 / 15);
- jsonResultTable.getColumnModel().getColumn(2)
- .setPreferredWidth(paneWidth * 2 / 15);
- jsonResultTable.getColumnModel().getColumn(3)
- .setPreferredWidth(paneWidth * 2 / 15);
-
- ListSelectionModel selectionModel = jsonResultTable.getSelectionModel();
- selectionModel.addListSelectionListener(new ListSelectionListener() {
-
- @Override
- public void valueChanged(ListSelectionEvent e) {
- int row = jsonResultTable.getSelectedRow();
- if (row >= 0) {
- DefaultTableModel model = (DefaultTableModel) jsonResultTable
- .getModel();
- jsonFileName = (String) model.getValueAt(row, 0);
+ private JComponent buildHpcJsonChooserComponent(final TetradDesktop desktop) {
+ final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
+ final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
+ // Get ComputingAccount from DB
+ final DefaultListModel listModel = new DefaultListModel();
+
+ for (HpcAccount account : hpcAccountManager.getHpcAccounts()) {
+ listModel.addElement(account);
}
- }
- });
-
- final JScrollPane scrollTablePane = new JScrollPane(jsonResultTable);
-
- jsonResultListPanel.add(scrollTablePane, BorderLayout.CENTER);
-
- splitPane.setLeftComponent(leftPanel);
- splitPane.setRightComponent(jsonResultListPanel);
-
- // Center Panel
- final JList 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 json list
- if (selectedIndex > -1) {
- jsonFileName = null;
- hpcAccount = listModel.get(selectedIndex);
-
- TableColumnModel columnModel = jsonResultTable
- .getColumnModel();
- List columnWidthList = new ArrayList<>();
- for (int i = 0; i < columnModel.getColumnCount(); i++) {
- int width = columnModel.getColumn(i).getPreferredWidth();
- columnWidthList.add(width);
- }
-
- jsonResultTable.clearSelection();
-
- try {
- HpcAccountService hpcAccountService = hpcJobManager
- .getHpcAccountService(hpcAccount);
-
- ResultService resultService = hpcAccountService.getResultService();
-
- Set results = resultService
- .listAlgorithmResultFiles(HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
-
- Vector> jsonFiles = new Vector<>();
-
- for (ResultFile resultFile : results) {
- if (resultFile.getName().endsWith(".json")) {
- Vector rowData = new Vector<>();
- rowData.addElement(resultFile.getName());
- rowData.addElement(FilePrint
- .fileTimestamp(resultFile
- .getCreationTime().getTime()));
- rowData.addElement(FilePrint
- .fileTimestamp(resultFile
- .getLastModifiedTime()
- .getTime()));
- rowData.addElement(FilePrint.humanReadableSize(
- resultFile.getFileSize(), false));
-
- jsonFiles.add(rowData);
- }
+
+ // JSplitPane
+ final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+
+ // Left pane -> JList (parent pane)
+ JPanel leftPanel = new JPanel(new BorderLayout());
+
+ // Right pane -> ComputingAccountResultList
+ final JPanel jsonResultListPanel = new JPanel(new BorderLayout());
+
+ int minWidth = 800;
+ int minHeight = 600;
+ int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
+ int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
+ int frameWidth = screenWidth * 3 / 4;
+ int frameHeight = screenHeight * 3 / 4;
+ final int paneWidth = minWidth > frameWidth ? minWidth : frameWidth;
+ final int paneHeight = minHeight > frameHeight ? minHeight : frameHeight;
+
+ // JTable
+ final Vector columnNames = new Vector<>();
+ columnNames.addElement("Name");
+ columnNames.addElement("Created");
+ columnNames.addElement("Last Modified");
+ columnNames.addElement("Size");
+
+ Vector> rowData = new Vector<>();
+
+ final DefaultTableModel tableModel = new LoadHpcGraphJsonTableModel(rowData, columnNames);
+ final JTable jsonResultTable = new JTable(tableModel);
+ jsonResultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ // Resize table's column width
+ jsonResultTable.getColumnModel().getColumn(0).setPreferredWidth(paneWidth * 2 / 5);
+ jsonResultTable.getColumnModel().getColumn(1).setPreferredWidth(paneWidth * 2 / 15);
+ jsonResultTable.getColumnModel().getColumn(2).setPreferredWidth(paneWidth * 2 / 15);
+ jsonResultTable.getColumnModel().getColumn(3).setPreferredWidth(paneWidth * 2 / 15);
+
+ ListSelectionModel selectionModel = jsonResultTable.getSelectionModel();
+ selectionModel.addListSelectionListener(new ListSelectionListener() {
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ int row = jsonResultTable.getSelectedRow();
+ if (row >= 0) {
+ DefaultTableModel model = (DefaultTableModel) jsonResultTable.getModel();
+ jsonFileName = (String) model.getValueAt(row, 0);
+ }
}
+ });
- tableModel.setDataVector(jsonFiles, columnNames);
+ final JScrollPane scrollTablePane = new JScrollPane(jsonResultTable);
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
+ jsonResultListPanel.add(scrollTablePane, BorderLayout.CENTER);
- // Resize table's column width
- for (int i = 0; i < columnModel.getColumnCount(); i++) {
- jsonResultTable
- .getColumnModel()
- .getColumn(i)
- .setPreferredWidth(
- columnWidthList.get(i).intValue());
- }
+ splitPane.setLeftComponent(leftPanel);
+ splitPane.setRightComponent(jsonResultListPanel);
- }
- }
- });
+ // Center Panel
+ final JList 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 json list
+ if (selectedIndex > -1) {
+ jsonFileName = null;
+ hpcAccount = listModel.get(selectedIndex);
+
+ TableColumnModel columnModel = jsonResultTable.getColumnModel();
+ List columnWidthList = new ArrayList<>();
+ for (int i = 0; i < columnModel.getColumnCount(); i++) {
+ int width = columnModel.getColumn(i).getPreferredWidth();
+ columnWidthList.add(width);
+ }
- // Left Panel
- JScrollPane accountListScroller = new JScrollPane(accountList);
- leftPanel.add(accountListScroller, BorderLayout.CENTER);
+ jsonResultTable.clearSelection();
- splitPane.setDividerLocation(paneWidth / 5);
- accountListScroller.setPreferredSize(new Dimension(paneWidth / 5,
- paneHeight));
- jsonResultListPanel.setPreferredSize(new Dimension(paneWidth * 4 / 5,
- paneHeight));
+ try {
+ HpcAccountService hpcAccountService = hpcJobManager.getHpcAccountService(hpcAccount);
- return splitPane;
- }
+ ResultService resultService = hpcAccountService.getResultService();
+
+ Set results = resultService.listAlgorithmResultFiles(
+ HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
+
+ Vector> jsonFiles = new Vector<>();
+
+ for (ResultFile resultFile : results) {
+ if (resultFile.getName().endsWith(".json")) {
+ Vector rowData = new Vector<>();
+ rowData.addElement(resultFile.getName());
+ rowData.addElement(FilePrint.fileTimestamp(resultFile.getCreationTime().getTime()));
+ rowData.addElement(FilePrint.fileTimestamp(resultFile.getLastModifiedTime().getTime()));
+ rowData.addElement(FilePrint.humanReadableSize(resultFile.getFileSize(), false));
+
+ jsonFiles.add(rowData);
+ }
+ }
+
+ tableModel.setDataVector(jsonFiles, columnNames);
+
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ // Resize table's column width
+ for (int i = 0; i < columnModel.getColumnCount(); i++) {
+ jsonResultTable.getColumnModel().getColumn(i)
+ .setPreferredWidth(columnWidthList.get(i).intValue());
+ }
+
+ }
+ }
+ });
+
+ // Left Panel
+ JScrollPane accountListScroller = new JScrollPane(accountList);
+ leftPanel.add(accountListScroller, BorderLayout.CENTER);
+
+ splitPane.setDividerLocation(paneWidth / 5);
+ accountListScroller.setPreferredSize(new Dimension(paneWidth / 5, paneHeight));
+ jsonResultListPanel.setPreferredSize(new Dimension(paneWidth * 4 / 5, paneHeight));
+
+ return splitPane;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcAccountEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcAccountEditor.java
index 7ea02958b4..a6e0d12db3 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcAccountEditor.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcAccountEditor.java
@@ -34,280 +34,273 @@
*/
public class HpcAccountEditor extends JPanel {
- private static final long serialVersionUID = -3028667139958773226L;
-
- private final JComponent parentComponent;
-
- private final DefaultListModel listModel;
-
- private final HpcAccountManager hpcAccountManager;
-
- private final HpcAccount hpcAccount;
-
- public HpcAccountEditor(
- final JComponent parentComponent,
- final DefaultListModel listModel,
- final HpcAccountManager hpcAccountManager,
- final HpcAccount hpcAccount) {
- this.parentComponent = parentComponent;
- this.listModel = listModel;
- this.hpcAccountManager = hpcAccountManager;
- this.hpcAccount = hpcAccount;
- initiateUI();
- }
-
- private void initiateUI() {
- setLayout(new BorderLayout());
-
- // Header
- JPanel headerPanel = new JPanel(new BorderLayout());
- JLabel headerLabel = new JLabel("High-Performance Computing Account");
- headerLabel.setFont(new Font(headerLabel.getFont().getName(),
- Font.BOLD, 20));
- headerPanel.add(headerLabel, BorderLayout.CENTER);
- JPanel spacePanel = new JPanel();
- spacePanel.setSize(300, 100);
- headerPanel.add(spacePanel, BorderLayout.SOUTH);
- add(headerPanel, BorderLayout.NORTH);
-
- // Content
- Box contentBox = Box.createVerticalBox();
-
- // Connection Name
- Box connBox = Box.createHorizontalBox();
- JLabel connLabel = new JLabel("Connection", JLabel.TRAILING);
- connLabel.setPreferredSize(new Dimension(100, 5));
- connBox.add(connLabel);
-
- final JTextField connField = new JTextField(20);
- connField.setText(hpcAccount.getConnectionName());
- connField.addKeyListener(new KeyListener() {
-
- @Override
- public void keyTyped(KeyEvent e) {
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- hpcAccount.setConnectionName(connField.getText());
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- }
- });
- connLabel.setLabelFor(connField);
- connBox.add(connField);
-
- contentBox.add(connBox);
-
- // Username
- Box userBox = Box.createHorizontalBox();
- JLabel userLabel = new JLabel("Username", JLabel.TRAILING);
- userLabel.setPreferredSize(new Dimension(100, 5));
- userBox.add(userLabel);
-
- final JTextField userField = new JTextField(20);
- userField.setText(hpcAccount.getUsername());
- userField.addKeyListener(new KeyListener() {
-
- @Override
- public void keyTyped(KeyEvent e) {
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- hpcAccount.setUsername(userField.getText());
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- }
- });
- userLabel.setLabelFor(userField);
- userBox.add(userField);
-
- contentBox.add(userBox);
-
- // Password
- Box passBox = Box.createHorizontalBox();
- JLabel passLabel = new JLabel("Password", JLabel.TRAILING);
- passLabel.setPreferredSize(new Dimension(100, 5));
- passBox.add(passLabel);
-
- final JPasswordField passField = new JPasswordField(20);
- passField.setText(hpcAccount.getPassword());
- passField.addKeyListener(new KeyListener() {
-
- @Override
- public void keyTyped(KeyEvent e) {
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- hpcAccount.setPassword(new String(passField.getPassword()));
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- }
- });
- passLabel.setLabelFor(passField);
- passBox.add(passField);
-
- contentBox.add(passBox);
-
- // Scheme
- JPanel schemePanel = new JPanel(new BorderLayout());
- JLabel schemeLabel = new JLabel("Scheme", JLabel.TRAILING);
- schemeLabel.setPreferredSize(new Dimension(100, 5));
- schemePanel.add(schemeLabel, BorderLayout.WEST);
-
- final JRadioButton httpRadioButton = new JRadioButton("http");
- final JRadioButton httpsRadioButton = new JRadioButton("https");
- if (hpcAccount.getScheme().equalsIgnoreCase("https")) {
- httpsRadioButton.setSelected(true);
- } else {
- httpRadioButton.setSelected(true);
+ private static final long serialVersionUID = -3028667139958773226L;
+
+ private final JComponent parentComponent;
+
+ private final DefaultListModel listModel;
+
+ private final HpcAccountManager hpcAccountManager;
+
+ private final HpcAccount hpcAccount;
+
+ public HpcAccountEditor(final JComponent parentComponent, final DefaultListModel listModel,
+ final HpcAccountManager hpcAccountManager, final HpcAccount hpcAccount) {
+ this.parentComponent = parentComponent;
+ this.listModel = listModel;
+ this.hpcAccountManager = hpcAccountManager;
+ this.hpcAccount = hpcAccount;
+ initiateUI();
}
- ButtonGroup schemeGroup = new ButtonGroup();
- schemeGroup.add(httpRadioButton);
- schemeGroup.add(httpsRadioButton);
- Box schemeRadioBox = Box.createHorizontalBox();
- schemeRadioBox.add(httpRadioButton);
- schemeRadioBox.add(httpsRadioButton);
- schemeLabel.setLabelFor(schemeRadioBox);
- ActionListener schemeActionListener = new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if (httpRadioButton.isSelected()) {
- hpcAccount.setScheme("http");
+
+ private void initiateUI() {
+ setLayout(new BorderLayout());
+
+ // Header
+ JPanel headerPanel = new JPanel(new BorderLayout());
+ JLabel headerLabel = new JLabel("High-Performance Computing Account");
+ headerLabel.setFont(new Font(headerLabel.getFont().getName(), Font.BOLD, 20));
+ headerPanel.add(headerLabel, BorderLayout.CENTER);
+ JPanel spacePanel = new JPanel();
+ spacePanel.setSize(300, 100);
+ headerPanel.add(spacePanel, BorderLayout.SOUTH);
+ add(headerPanel, BorderLayout.NORTH);
+
+ // Content
+ Box contentBox = Box.createVerticalBox();
+
+ // Connection Name
+ Box connBox = Box.createHorizontalBox();
+ JLabel connLabel = new JLabel("Connection", JLabel.TRAILING);
+ connLabel.setPreferredSize(new Dimension(100, 5));
+ connBox.add(connLabel);
+
+ final JTextField connField = new JTextField(20);
+ connField.setText(hpcAccount.getConnectionName());
+ connField.addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ hpcAccount.setConnectionName(connField.getText());
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+ });
+ connLabel.setLabelFor(connField);
+ connBox.add(connField);
+
+ contentBox.add(connBox);
+
+ // Username
+ Box userBox = Box.createHorizontalBox();
+ JLabel userLabel = new JLabel("Username", JLabel.TRAILING);
+ userLabel.setPreferredSize(new Dimension(100, 5));
+ userBox.add(userLabel);
+
+ final JTextField userField = new JTextField(20);
+ userField.setText(hpcAccount.getUsername());
+ userField.addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ hpcAccount.setUsername(userField.getText());
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+ });
+ userLabel.setLabelFor(userField);
+ userBox.add(userField);
+
+ contentBox.add(userBox);
+
+ // Password
+ Box passBox = Box.createHorizontalBox();
+ JLabel passLabel = new JLabel("Password", JLabel.TRAILING);
+ passLabel.setPreferredSize(new Dimension(100, 5));
+ passBox.add(passLabel);
+
+ final JPasswordField passField = new JPasswordField(20);
+ passField.setText(hpcAccount.getPassword());
+ passField.addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ hpcAccount.setPassword(new String(passField.getPassword()));
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+ });
+ passLabel.setLabelFor(passField);
+ passBox.add(passField);
+
+ contentBox.add(passBox);
+
+ // Scheme
+ JPanel schemePanel = new JPanel(new BorderLayout());
+ JLabel schemeLabel = new JLabel("Scheme", JLabel.TRAILING);
+ schemeLabel.setPreferredSize(new Dimension(100, 5));
+ schemePanel.add(schemeLabel, BorderLayout.WEST);
+
+ final JRadioButton httpRadioButton = new JRadioButton("http");
+ final JRadioButton httpsRadioButton = new JRadioButton("https");
+ if (hpcAccount.getScheme().equalsIgnoreCase("https")) {
+ httpsRadioButton.setSelected(true);
} else {
- hpcAccount.setScheme("https");
- }
- }
- };
- httpRadioButton.addActionListener(schemeActionListener);
- httpsRadioButton.addActionListener(schemeActionListener);
- schemePanel.add(schemeRadioBox, BorderLayout.CENTER);
-
- contentBox.add(schemePanel);
-
- // Host
- Box hostBox = Box.createHorizontalBox();
- JLabel hostLabel = new JLabel("Host Name", JLabel.TRAILING);
- hostLabel.setPreferredSize(new Dimension(100, 5));
- hostBox.add(hostLabel);
-
- final JTextField hostField = new JTextField(20);
- hostField.setText(hpcAccount.getHostname());
- hostField.addKeyListener(new KeyListener() {
-
- @Override
- public void keyTyped(KeyEvent e) {
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- hpcAccount.setHostname(hostField.getText());
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- }
- });
- hostLabel.setLabelFor(hostField);
- hostBox.add(hostField);
-
- contentBox.add(hostBox);
-
- // Port number
- Box portBox = Box.createHorizontalBox();
- JLabel portLabel = new JLabel("Port Number", JLabel.TRAILING);
- portLabel.setPreferredSize(new Dimension(100, 5));
- portBox.add(portLabel);
-
- final JTextField portField = new JTextField(20);
- portField.setText(String.valueOf(hpcAccount.getPort()));
- portField.addKeyListener(new KeyListener() {
-
- @Override
- public void keyTyped(KeyEvent e) {
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- try {
- int port = Integer.parseInt(portField.getText());
- hpcAccount.setPort(port);
- } catch (NumberFormatException e1) {
- // TODO Auto-generated catch block
- if (portField.getText().trim().length() > 0) {
- JOptionPane.showMessageDialog(portField,
- "Port number is decimal number only!");
- }
+ httpRadioButton.setSelected(true);
}
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- }
- });
- portLabel.setLabelFor(portField);
- portBox.add(portField);
-
- contentBox.add(portBox);
-
- JPanel contentPanel = new JPanel(new BorderLayout());
- contentPanel.add(contentBox, BorderLayout.NORTH);
- add(contentPanel, BorderLayout.CENTER);
-
- // Footer -> Test and Save buttons
- JPanel footerPanel = new JPanel(new BorderLayout());
- final JButton testConnButton = new JButton("Test Connection");
- testConnButton.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- JButton button = (JButton) e.getSource();
- button.setText("Testing...");
- parentComponent.updateUI();
- button.setEnabled(false);
- boolean success = HpcAccountUtils
- .testConnection(hpcAccountManager, hpcAccount);
- // Pop-up the test result
- JOptionPane.showMessageDialog(null, ""
- + hpcAccount + " Connection "
- + (success ? "Successful" : "Failed"),
- "HPC Account Setting", JOptionPane.INFORMATION_MESSAGE);
- button.setEnabled(true);
- button.setText("Test Connection");
- hpcAccount.setLastLoginDate(new Date());
- hpcAccountManager.saveAccount(hpcAccount);
- }
- });
- JButton saveButton = new JButton("Save");
- saveButton.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- JButton button = (JButton) e.getSource();
- button.setText("Saving...");
- parentComponent.updateUI();
- button.setEnabled(false);
- hpcAccountManager.saveAccount(hpcAccount);
- if (listModel.indexOf(hpcAccount) == -1) {
- listModel.addElement(hpcAccount);
- }
- button.setEnabled(true);
- button.setText("Save");
- parentComponent.updateUI();
- }
- });
- footerPanel.add(testConnButton, BorderLayout.WEST);
- footerPanel.add(saveButton, BorderLayout.EAST);
- add(footerPanel, BorderLayout.SOUTH);
- }
+ ButtonGroup schemeGroup = new ButtonGroup();
+ schemeGroup.add(httpRadioButton);
+ schemeGroup.add(httpsRadioButton);
+ Box schemeRadioBox = Box.createHorizontalBox();
+ schemeRadioBox.add(httpRadioButton);
+ schemeRadioBox.add(httpsRadioButton);
+ schemeLabel.setLabelFor(schemeRadioBox);
+ ActionListener schemeActionListener = new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (httpRadioButton.isSelected()) {
+ hpcAccount.setScheme("http");
+ } else {
+ hpcAccount.setScheme("https");
+ }
+ }
+ };
+ httpRadioButton.addActionListener(schemeActionListener);
+ httpsRadioButton.addActionListener(schemeActionListener);
+ schemePanel.add(schemeRadioBox, BorderLayout.CENTER);
+
+ contentBox.add(schemePanel);
+
+ // Host
+ Box hostBox = Box.createHorizontalBox();
+ JLabel hostLabel = new JLabel("Host Name", JLabel.TRAILING);
+ hostLabel.setPreferredSize(new Dimension(100, 5));
+ hostBox.add(hostLabel);
+
+ final JTextField hostField = new JTextField(20);
+ hostField.setText(hpcAccount.getHostname());
+ hostField.addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ hpcAccount.setHostname(hostField.getText());
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+ });
+ hostLabel.setLabelFor(hostField);
+ hostBox.add(hostField);
+
+ contentBox.add(hostBox);
+
+ // Port number
+ Box portBox = Box.createHorizontalBox();
+ JLabel portLabel = new JLabel("Port Number", JLabel.TRAILING);
+ portLabel.setPreferredSize(new Dimension(100, 5));
+ portBox.add(portLabel);
+
+ final JTextField portField = new JTextField(20);
+ portField.setText(String.valueOf(hpcAccount.getPort()));
+ portField.addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ try {
+ int port = Integer.parseInt(portField.getText());
+ hpcAccount.setPort(port);
+ } catch (NumberFormatException e1) {
+ // TODO Auto-generated catch block
+ if (portField.getText().trim().length() > 0) {
+ JOptionPane.showMessageDialog(portField, "Port number is decimal number only!");
+ }
+ }
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+ });
+ portLabel.setLabelFor(portField);
+ portBox.add(portField);
+
+ contentBox.add(portBox);
+
+ JPanel contentPanel = new JPanel(new BorderLayout());
+ contentPanel.add(contentBox, BorderLayout.NORTH);
+ add(contentPanel, BorderLayout.CENTER);
+
+ // Footer -> Test and Save buttons
+ JPanel footerPanel = new JPanel(new BorderLayout());
+ final JButton testConnButton = new JButton("Test Connection");
+ testConnButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JButton button = (JButton) e.getSource();
+ button.setText("Testing...");
+ parentComponent.updateUI();
+ button.setEnabled(false);
+ boolean success = HpcAccountUtils.testConnection(hpcAccountManager, hpcAccount);
+ // Pop-up the test result
+ JOptionPane.showMessageDialog(null,
+ "" + hpcAccount + " Connection " + (success ? "Successful" : "Failed"), "HPC Account Setting",
+ JOptionPane.INFORMATION_MESSAGE);
+ button.setEnabled(true);
+ button.setText("Test Connection");
+ hpcAccount.setLastLoginDate(new Date());
+ hpcAccountManager.saveAccount(hpcAccount);
+ }
+ });
+ JButton saveButton = new JButton("Save");
+ saveButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JButton button = (JButton) e.getSource();
+ button.setText("Saving...");
+ parentComponent.updateUI();
+ button.setEnabled(false);
+ hpcAccountManager.saveAccount(hpcAccount);
+ if (listModel.indexOf(hpcAccount) == -1) {
+ listModel.addElement(hpcAccount);
+ }
+ button.setEnabled(true);
+ button.setText("Save");
+ parentComponent.updateUI();
+ }
+ });
+ footerPanel.add(testConnButton, BorderLayout.WEST);
+ footerPanel.add(saveButton, BorderLayout.EAST);
+ add(footerPanel, BorderLayout.SOUTH);
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobActivityEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobActivityEditor.java
index 26d5c2de31..00fdc1a6ec 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobActivityEditor.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobActivityEditor.java
@@ -53,671 +53,621 @@
*/
public class HpcJobActivityEditor extends JPanel implements FinalizingEditor {
- private static final long serialVersionUID = -6178713484456753741L;
-
- private final List checkedHpcAccountList;
-
- private final Set pendingDisplayHpcJobInfoSet;
-
- private final Set submittedDisplayHpcJobInfoSet;
-
- private final Timer pendingTimer;
-
- private final Timer submittedTimer;
-
- private int PENDING_TIME_INTERVAL = 100;
-
- private int SUBMITTED_TIME_INTERVAL = 1000;
-
- private JTable jobsTable;
-
- private JTabbedPane tabbedPane;
-
- private PendingHpcJobUpdaterTask pendingJobUpdater;
-
- private SubmittedHpcJobUpdaterTask submittedJobUpdater;
-
- public final static int ID_COLUMN = 0;
- public final static int STATUS_COLUMN = 1;
- public final static int DATA_UPLOAD_COLUMN = 5;
- public final static int KNOWLEDGE_UPLOAD_COLUMN = 6;
- public final static int ACTIVE_SUBMITTED_COLUMN = 7;
- public final static int ACTIVE_HPC_JOB_ID_COLUMN = 8;
- public final static int ACTIVE_LAST_UPDATED_COLUMN = 9;
- public final static int KILL_BUTTON_COLUMN = 10;
-
- public final static int DELETE_BUTTON_COLUMN = 11;
-
- public HpcJobActivityEditor() throws Exception{
- checkedHpcAccountList = new ArrayList<>();
- pendingDisplayHpcJobInfoSet = new HashSet<>();
- submittedDisplayHpcJobInfoSet = new HashSet<>();
- this.pendingTimer = new Timer();
- this.submittedTimer = new Timer();
- TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
- buildHpcJobActivityComponent(desktop);
- }
-
- private void buildHpcJobActivityComponent(final TetradDesktop desktop)
- throws Exception {
- setLayout(new BorderLayout());
-
- final JPanel controllerPane = new JPanel(new BorderLayout());
- add(controllerPane, BorderLayout.NORTH);
- Dimension preferredSize = new Dimension(100, 100);
- controllerPane.setPreferredSize(preferredSize);
- buildController(controllerPane, desktop);
-
- final JPanel contentPanel = new JPanel(new BorderLayout());
- add(contentPanel, BorderLayout.CENTER);
- buildActivityContent(contentPanel, desktop);
-
- int minWidth = 800;
- int minHeight = 600;
- int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
- int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
- int frameWidth = screenWidth * 5 / 6;
- int frameHeight = screenHeight * 3 / 4;
- final int paneWidth = minWidth > frameWidth ? minWidth : frameWidth;
- final int paneHeight = minHeight > frameHeight ? minHeight
- : frameHeight;
-
- setPreferredSize(new Dimension(paneWidth, paneHeight));
- }
-
- private class HpcAccountSelectionAction implements ActionListener {
-
- private final List hpcAccounts;
-
- public HpcAccountSelectionAction(final List hpcAccounts) {
- this.hpcAccounts = hpcAccounts;
+ private static final long serialVersionUID = -6178713484456753741L;
+
+ private final List checkedHpcAccountList;
+
+ private final Set pendingDisplayHpcJobInfoSet;
+
+ private final Set submittedDisplayHpcJobInfoSet;
+
+ private final Timer pendingTimer;
+
+ private final Timer submittedTimer;
+
+ private int PENDING_TIME_INTERVAL = 100;
+
+ private int SUBMITTED_TIME_INTERVAL = 1000;
+
+ private JTable jobsTable;
+
+ private JTabbedPane tabbedPane;
+
+ private PendingHpcJobUpdaterTask pendingJobUpdater;
+
+ private SubmittedHpcJobUpdaterTask submittedJobUpdater;
+
+ public final static int ID_COLUMN = 0;
+ public final static int STATUS_COLUMN = 1;
+ public final static int DATA_UPLOAD_COLUMN = 5;
+ public final static int KNOWLEDGE_UPLOAD_COLUMN = 6;
+ public final static int ACTIVE_SUBMITTED_COLUMN = 7;
+ public final static int ACTIVE_HPC_JOB_ID_COLUMN = 8;
+ public final static int ACTIVE_LAST_UPDATED_COLUMN = 9;
+ public final static int KILL_BUTTON_COLUMN = 10;
+
+ public final static int DELETE_BUTTON_COLUMN = 11;
+
+ public HpcJobActivityEditor() throws Exception {
+ checkedHpcAccountList = new ArrayList<>();
+ pendingDisplayHpcJobInfoSet = new HashSet<>();
+ submittedDisplayHpcJobInfoSet = new HashSet<>();
+ this.pendingTimer = new Timer();
+ this.submittedTimer = new Timer();
+ TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
+ buildHpcJobActivityComponent(desktop);
}
- @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);
- }
+ private void buildHpcJobActivityComponent(final TetradDesktop desktop) throws Exception {
+ setLayout(new BorderLayout());
+
+ final JPanel controllerPane = new JPanel(new BorderLayout());
+ add(controllerPane, BorderLayout.NORTH);
+ Dimension preferredSize = new Dimension(100, 100);
+ controllerPane.setPreferredSize(preferredSize);
+ buildController(controllerPane, desktop);
+
+ final JPanel contentPanel = new JPanel(new BorderLayout());
+ add(contentPanel, BorderLayout.CENTER);
+ buildActivityContent(contentPanel, desktop);
+
+ int minWidth = 800;
+ int minHeight = 600;
+ int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
+ int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
+ int frameWidth = screenWidth * 5 / 6;
+ int frameHeight = screenHeight * 3 / 4;
+ final int paneWidth = minWidth > frameWidth ? minWidth : frameWidth;
+ final int paneHeight = minHeight > frameHeight ? minHeight : frameHeight;
+
+ setPreferredSize(new Dimension(paneWidth, paneHeight));
+ }
+
+ private class HpcAccountSelectionAction implements ActionListener {
+
+ private final List hpcAccounts;
+
+ public HpcAccountSelectionAction(final List hpcAccounts) {
+ this.hpcAccounts = hpcAccounts;
+ }
+
+ @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);
}
- }
- int index = tabbedPane.getSelectedIndex();
- tabbedPane.setSelectedIndex(-1);
- tabbedPane.setSelectedIndex(index);
+
}
- }
+ private void buildController(final JPanel controllerPane, final TetradDesktop desktop) {
+ // Content
+ Box contentBox = Box.createVerticalBox();
+
+ JPanel hpcPanel = new JPanel(new BorderLayout());
- private void buildController(final JPanel controllerPane,
- final TetradDesktop desktop) {
- // Content
- Box contentBox = Box.createVerticalBox();
+ JLabel hpcAccountLabel = new JLabel("HPC Account: ", JLabel.TRAILING);
+ hpcAccountLabel.setPreferredSize(new Dimension(100, 5));
+ hpcPanel.add(hpcAccountLabel, BorderLayout.WEST);
- JPanel hpcPanel = new JPanel(new BorderLayout());
+ Box hpcAccountCheckBox = Box.createHorizontalBox();
+ final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
+ List hpcAccounts = hpcAccountManager.getHpcAccounts();
- JLabel hpcAccountLabel = new JLabel("HPC Account: ", JLabel.TRAILING);
- hpcAccountLabel.setPreferredSize(new Dimension(100, 5));
- hpcPanel.add(hpcAccountLabel, BorderLayout.WEST);
+ HpcAccountSelectionAction hpcAccountSelectionAction = new HpcAccountSelectionAction(hpcAccounts);
- Box hpcAccountCheckBox = Box.createHorizontalBox();
- final HpcAccountManager hpcAccountManager = desktop
- .getHpcAccountManager();
- List hpcAccounts = hpcAccountManager.getHpcAccounts();
+ for (HpcAccount hpcAccount : hpcAccounts) {
+ checkedHpcAccountList.add(hpcAccount);
+ final JCheckBox hpcCheckBox = new JCheckBox(hpcAccount.getConnectionName(), true);
+ hpcCheckBox.addActionListener(hpcAccountSelectionAction);
+ hpcAccountCheckBox.add(hpcCheckBox);
- HpcAccountSelectionAction hpcAccountSelectionAction = new HpcAccountSelectionAction(
- hpcAccounts);
+ }
+ hpcPanel.add(hpcAccountCheckBox, BorderLayout.CENTER);
- for (HpcAccount hpcAccount : hpcAccounts) {
- checkedHpcAccountList.add(hpcAccount);
- final JCheckBox hpcCheckBox = new JCheckBox(
- hpcAccount.getConnectionName(), true);
- hpcCheckBox.addActionListener(hpcAccountSelectionAction);
- hpcAccountCheckBox.add(hpcCheckBox);
+ contentBox.add(hpcPanel);
+ controllerPane.add(contentBox, BorderLayout.CENTER);
}
- hpcPanel.add(hpcAccountCheckBox, BorderLayout.CENTER);
- contentBox.add(hpcPanel);
+ private void buildActivityContent(final JPanel activityPanel, final TetradDesktop desktop) throws Exception {
- controllerPane.add(contentBox, BorderLayout.CENTER);
- }
+ jobsTable = new JTable();
+ jobsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- private void buildActivityContent(final JPanel activityPanel,
- final TetradDesktop desktop) throws Exception {
+ final JScrollPane scrollTablePane = new JScrollPane(jobsTable);
- jobsTable = new JTable();
- jobsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ tabbedPane = new JTabbedPane();
- final JScrollPane scrollTablePane = new JScrollPane(jobsTable);
+ JPanel activeJobsPanel = new JPanel(new BorderLayout());
+ activeJobsPanel.add(scrollTablePane, BorderLayout.CENTER);
+ tabbedPane.add("Active Jobs", activeJobsPanel);
- tabbedPane = new JTabbedPane();
+ final KillHpcJobAction killJobAction = new KillHpcJobAction(this);
- JPanel activeJobsPanel = new JPanel(new BorderLayout());
- activeJobsPanel.add(scrollTablePane, BorderLayout.CENTER);
- tabbedPane.add("Active Jobs", activeJobsPanel);
+ JPanel finishedJobsPanel = new JPanel(new BorderLayout());
- final KillHpcJobAction killJobAction = new KillHpcJobAction(
- this);
+ tabbedPane.add("Finished Jobs", finishedJobsPanel);
- JPanel finishedJobsPanel = new JPanel(new BorderLayout());
+ final DeleteHpcJobInfoAction deleteJobAction = new DeleteHpcJobInfoAction(this);
- tabbedPane.add("Finished Jobs", finishedJobsPanel);
+ ChangeListener changeListener = new ChangeListener() {
- final DeleteHpcJobInfoAction deleteJobAction = new DeleteHpcJobInfoAction(
- this);
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource();
+ int index = sourceTabbedPane.getSelectedIndex();
+ if (index == 0) {
+ finishedJobsPanel.remove(scrollTablePane);
+ activeJobsPanel.add(scrollTablePane, BorderLayout.CENTER);
+ try {
+ final Vector activeColumnNames = genActiveJobColumnNames();
+ final Vector> activeRowData = getActiveRowData(desktop, checkedHpcAccountList);
- ChangeListener changeListener = new ChangeListener() {
+ final DefaultTableModel activeJobTableModel = new HpcJobInfoTableModel(activeRowData,
+ activeColumnNames, KILL_BUTTON_COLUMN);
- @Override
- public void stateChanged(ChangeEvent e) {
- JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource();
- int index = sourceTabbedPane.getSelectedIndex();
- if (index == 0) {
- finishedJobsPanel.remove(scrollTablePane);
- activeJobsPanel.add(scrollTablePane, BorderLayout.CENTER);
- try {
- final Vector activeColumnNames = genActiveJobColumnNames();
- final Vector> activeRowData = getActiveRowData(
- desktop, checkedHpcAccountList);
+ jobsTable.setModel(activeJobTableModel);
- final DefaultTableModel activeJobTableModel = new HpcJobInfoTableModel(
- activeRowData, activeColumnNames,
- KILL_BUTTON_COLUMN);
+ if (activeRowData.size() > 0) {
+ new ButtonColumn(jobsTable, killJobAction, KILL_BUTTON_COLUMN);
+ }
- jobsTable.setModel(activeJobTableModel);
+ adjustActiveJobsWidthColumns(jobsTable);
+ jobsTable.updateUI();
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ } else if (index == 1) {
+ activeJobsPanel.remove(scrollTablePane);
+ finishedJobsPanel.add(scrollTablePane, BorderLayout.CENTER);
+ try {
+ final Vector finishedColumnNames = genFinishedJobColumnNames();
+ final Vector> finishedRowData = getFinishedRowData(desktop,
+ checkedHpcAccountList);
- if (activeRowData.size() > 0) {
- new ButtonColumn(jobsTable, killJobAction,
- KILL_BUTTON_COLUMN);
- }
+ final DefaultTableModel finishedJobTableModel = new HpcJobInfoTableModel(finishedRowData,
+ finishedColumnNames, DELETE_BUTTON_COLUMN);
- adjustActiveJobsWidthColumns(jobsTable);
- jobsTable.updateUI();
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- } else if (index == 1) {
- activeJobsPanel.remove(scrollTablePane);
- finishedJobsPanel.add(scrollTablePane, BorderLayout.CENTER);
- try {
- final Vector finishedColumnNames = genFinishedJobColumnNames();
- final Vector> finishedRowData = getFinishedRowData(
- desktop, checkedHpcAccountList);
-
- final DefaultTableModel finishedJobTableModel = new HpcJobInfoTableModel(
- finishedRowData, finishedColumnNames,
- DELETE_BUTTON_COLUMN);
-
- jobsTable.setModel(finishedJobTableModel);
-
- if (finishedRowData.size() > 0) {
- new ButtonColumn(jobsTable, deleteJobAction,
- DELETE_BUTTON_COLUMN);
+ jobsTable.setModel(finishedJobTableModel);
+
+ if (finishedRowData.size() > 0) {
+ new ButtonColumn(jobsTable, deleteJobAction, DELETE_BUTTON_COLUMN);
+ }
+ adjustFinishedJobsWidthColumns(jobsTable);
+ jobsTable.updateUI();
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
}
- adjustFinishedJobsWidthColumns(jobsTable);
- jobsTable.updateUI();
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
-
- };
- tabbedPane.addChangeListener(changeListener);
-
- activityPanel.add(tabbedPane, BorderLayout.CENTER);
-
-
- final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
-
- // Start active job updater
- pendingJobUpdater = new PendingHpcJobUpdaterTask(
- hpcJobManager, this);
-
- submittedJobUpdater = new SubmittedHpcJobUpdaterTask(
- hpcJobManager, this);
-
- tabbedPane.setSelectedIndex(-1);
- tabbedPane.setSelectedIndex(0);
-
- startUpdaters();
- }
-
- private void startUpdaters(){
- pendingTimer.schedule(pendingJobUpdater, 0, PENDING_TIME_INTERVAL);
- submittedTimer.schedule(submittedJobUpdater, 0, SUBMITTED_TIME_INTERVAL);
- }
-
- private void stopUpdaters(){
- pendingTimer.cancel();
- submittedTimer.cancel();
- }
-
- private void adjustActiveJobsWidthColumns(final JTable jobsTable) {
- jobsTable.getColumnModel().getColumn(0).setPreferredWidth(20);
- jobsTable.getColumnModel().getColumn(1).setPreferredWidth(30);
- jobsTable.getColumnModel().getColumn(3).setPreferredWidth(20);
- jobsTable.getColumnModel().getColumn(4).setPreferredWidth(40);
- jobsTable.getColumnModel().getColumn(8).setPreferredWidth(35);
- }
-
- private void adjustFinishedJobsWidthColumns(final JTable jobsTable) {
- jobsTable.getColumnModel().getColumn(0).setPreferredWidth(20);
- jobsTable.getColumnModel().getColumn(1).setPreferredWidth(30);
- jobsTable.getColumnModel().getColumn(3).setPreferredWidth(20);
- jobsTable.getColumnModel().getColumn(4).setPreferredWidth(40);
- jobsTable.getColumnModel().getColumn(6).setPreferredWidth(35);
- }
-
- private Vector genActiveJobColumnNames() {
- final Vector columnNames = new Vector<>();
-
- columnNames.addElement("Job ID");
- columnNames.addElement("Status");
- columnNames.addElement("Added");
- columnNames.addElement("HPC");
- columnNames.addElement("Algorithm");
- columnNames.addElement("Data Upload");
- columnNames.addElement("Knowledge Upload");
- columnNames.addElement("Submitted");
- columnNames.addElement("HPC Job ID");
- columnNames.addElement("lastUpdated");
- columnNames.addElement("");
-
- return columnNames;
- }
-
- private Vector genFinishedJobColumnNames() {
- final Vector columnNames = new Vector<>();
-
- columnNames.addElement("Job ID");
- columnNames.addElement("Status");
- columnNames.addElement("Added");
- columnNames.addElement("HPC");
- columnNames.addElement("Algorithm");
- columnNames.addElement("Submitted");
- columnNames.addElement("HPC Job ID");
- columnNames.addElement("Result Name");
- columnNames.addElement("Finished");
- columnNames.addElement("Canceled");
- columnNames.addElement("lastUpdated");
- columnNames.addElement("");
-
- return columnNames;
- }
-
- private Vector> getActiveRowData(
- final TetradDesktop desktop,
- final List exclusiveHpcAccounts) throws Exception {
- final Vector> activeRowData = new Vector<>();
- final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
- Map activeHpcJobInfoMap = null;
-
- // Pending
- Map> pendingHpcJobInfoMap = hpcJobManager
- .getPendingHpcJobInfoMap();
-
- pendingDisplayHpcJobInfoSet.clear();
-
- for (HpcAccount hpcAccount : pendingHpcJobInfoMap.keySet()) {
-
- if (exclusiveHpcAccounts != null
- && !exclusiveHpcAccounts.contains(hpcAccount)) {
- continue;
- }
-
- Set pendingHpcJobSet = pendingHpcJobInfoMap
- .get(hpcAccount);
- for (HpcJobInfo hpcJobInfo : pendingHpcJobSet) {
- // For monitoring purpose
- pendingDisplayHpcJobInfoSet.add(hpcJobInfo);
-
- if (activeHpcJobInfoMap == null) {
- activeHpcJobInfoMap = new HashMap<>();
- }
- activeHpcJobInfoMap.put(hpcJobInfo.getId(), hpcJobInfo);
- }
+ };
+ tabbedPane.addChangeListener(changeListener);
+
+ activityPanel.add(tabbedPane, BorderLayout.CENTER);
+
+ final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
+
+ // Start active job updater
+ pendingJobUpdater = new PendingHpcJobUpdaterTask(hpcJobManager, this);
+
+ submittedJobUpdater = new SubmittedHpcJobUpdaterTask(hpcJobManager, this);
+
+ tabbedPane.setSelectedIndex(-1);
+ tabbedPane.setSelectedIndex(0);
+
+ startUpdaters();
}
- // Submitted
- Map> submittedHpcJobInfoMap = hpcJobManager
- .getSubmittedHpcJobInfoMap();
-
- submittedDisplayHpcJobInfoSet.clear();
-
- for (HpcAccount hpcAccount : submittedHpcJobInfoMap.keySet()) {
-
- if (exclusiveHpcAccounts != null
- && !exclusiveHpcAccounts.contains(hpcAccount)) {
- continue;
- }
-
- Set submittedHpcJobSet = submittedHpcJobInfoMap
- .get(hpcAccount);
- for (HpcJobInfo hpcJobInfo : submittedHpcJobSet) {
- // For monitoring purpose
- submittedDisplayHpcJobInfoSet.add(hpcJobInfo);
-
- if (activeHpcJobInfoMap == null) {
- activeHpcJobInfoMap = new HashMap<>();
- }
- activeHpcJobInfoMap.put(hpcJobInfo.getId(), hpcJobInfo);
- }
+ private void startUpdaters() {
+ pendingTimer.schedule(pendingJobUpdater, 0, PENDING_TIME_INTERVAL);
+ submittedTimer.schedule(submittedJobUpdater, 0, SUBMITTED_TIME_INTERVAL);
}
- if (activeHpcJobInfoMap != null) {
+ private void stopUpdaters() {
+ pendingTimer.cancel();
+ submittedTimer.cancel();
+ }
- List activeJobIds = new ArrayList<>(
- activeHpcJobInfoMap.keySet());
+ private void adjustActiveJobsWidthColumns(final JTable jobsTable) {
+ jobsTable.getColumnModel().getColumn(0).setPreferredWidth(20);
+ jobsTable.getColumnModel().getColumn(1).setPreferredWidth(30);
+ jobsTable.getColumnModel().getColumn(3).setPreferredWidth(20);
+ jobsTable.getColumnModel().getColumn(4).setPreferredWidth(40);
+ jobsTable.getColumnModel().getColumn(8).setPreferredWidth(35);
+ }
- Collections.sort(activeJobIds);
- Collections.reverse(activeJobIds);
+ private void adjustFinishedJobsWidthColumns(final JTable jobsTable) {
+ jobsTable.getColumnModel().getColumn(0).setPreferredWidth(20);
+ jobsTable.getColumnModel().getColumn(1).setPreferredWidth(30);
+ jobsTable.getColumnModel().getColumn(3).setPreferredWidth(20);
+ jobsTable.getColumnModel().getColumn(4).setPreferredWidth(40);
+ jobsTable.getColumnModel().getColumn(6).setPreferredWidth(35);
+ }
- for (Long jobId : activeJobIds) {
+ private Vector genActiveJobColumnNames() {
+ final Vector columnNames = new Vector<>();
+
+ columnNames.addElement("Job ID");
+ columnNames.addElement("Status");
+ columnNames.addElement("Added");
+ columnNames.addElement("HPC");
+ columnNames.addElement("Algorithm");
+ columnNames.addElement("Data Upload");
+ columnNames.addElement("Knowledge Upload");
+ columnNames.addElement("Submitted");
+ columnNames.addElement("HPC Job ID");
+ columnNames.addElement("lastUpdated");
+ columnNames.addElement("");
+
+ return columnNames;
+ }
- final HpcJobInfo hpcJobInfo = activeHpcJobInfoMap.get(jobId);
+ private Vector genFinishedJobColumnNames() {
+ final Vector columnNames = new Vector<>();
+
+ columnNames.addElement("Job ID");
+ columnNames.addElement("Status");
+ columnNames.addElement("Added");
+ columnNames.addElement("HPC");
+ columnNames.addElement("Algorithm");
+ columnNames.addElement("Submitted");
+ columnNames.addElement("HPC Job ID");
+ columnNames.addElement("Result Name");
+ columnNames.addElement("Finished");
+ columnNames.addElement("Canceled");
+ columnNames.addElement("lastUpdated");
+ columnNames.addElement("");
+
+ return columnNames;
+ }
- Vector rowData = new Vector<>();
+ private Vector> getActiveRowData(final TetradDesktop desktop,
+ final List exclusiveHpcAccounts) throws Exception {
+ final Vector> activeRowData = new Vector<>();
+ final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
+ Map activeHpcJobInfoMap = null;
- HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
+ // Pending
+ Map> pendingHpcJobInfoMap = hpcJobManager.getPendingHpcJobInfoMap();
- // Local job id
- rowData.add(hpcJobInfo.getId().toString());
+ pendingDisplayHpcJobInfoSet.clear();
- int status = hpcJobInfo.getStatus();
+ for (HpcAccount hpcAccount : pendingHpcJobInfoMap.keySet()) {
- switch (status) {
- case -1:
- rowData.add("Pending");
- break;
- case 0:
- rowData.add("Submitted");
- break;
- case 1:
- rowData.add("Running");
- break;
- case 2:
- rowData.add("Kill Request");
- break;
+ if (exclusiveHpcAccounts != null && !exclusiveHpcAccounts.contains(hpcAccount)) {
+ continue;
+ }
+
+ Set pendingHpcJobSet = pendingHpcJobInfoMap.get(hpcAccount);
+ for (HpcJobInfo hpcJobInfo : pendingHpcJobSet) {
+ // For monitoring purpose
+ pendingDisplayHpcJobInfoSet.add(hpcJobInfo);
+
+ if (activeHpcJobInfoMap == null) {
+ activeHpcJobInfoMap = new HashMap<>();
+ }
+ activeHpcJobInfoMap.put(hpcJobInfo.getId(), hpcJobInfo);
+ }
}
- // Locally added time
- rowData.add(FilePrint.fileTimestamp(hpcJobLog.getAddedTime()
- .getTime()));
+ // Submitted
+ Map> submittedHpcJobInfoMap = hpcJobManager.getSubmittedHpcJobInfoMap();
- // HPC node name
- HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- rowData.add(hpcAccount.getConnectionName());
+ submittedDisplayHpcJobInfoSet.clear();
- // Algorithm
- rowData.add(hpcJobInfo.getAlgorithmName());
+ for (HpcAccount hpcAccount : submittedHpcJobInfoMap.keySet()) {
- // Dataset uploading progress
- AlgorithmParamRequest algorParamReq = hpcJobInfo
- .getAlgorithmParamRequest();
- String datasetPath = algorParamReq.getDatasetPath();
+ if (exclusiveHpcAccounts != null && !exclusiveHpcAccounts.contains(hpcAccount)) {
+ continue;
+ }
- int progress = hpcJobManager.getUploadFileProgress(datasetPath);
- if (progress > -1 && progress < 100) {
- rowData.add("" + progress + "%");
- } else {
- rowData.add("Done");
- }
+ Set submittedHpcJobSet = submittedHpcJobInfoMap.get(hpcAccount);
+ for (HpcJobInfo hpcJobInfo : submittedHpcJobSet) {
+ // For monitoring purpose
+ submittedDisplayHpcJobInfoSet.add(hpcJobInfo);
- // Prior Knowledge uploading progress
- String priorKnowledgePath = algorParamReq
- .getPriorKnowledgePath();
- if (priorKnowledgePath != null) {
- progress = hpcJobManager
- .getUploadFileProgress(priorKnowledgePath);
- if (progress > -1 && progress < 100) {
- rowData.add("" + progress + "%");
- } else {
- rowData.add("Done");
- }
- } else {
- rowData.add("Skipped");
+ if (activeHpcJobInfoMap == null) {
+ activeHpcJobInfoMap = new HashMap<>();
+ }
+ activeHpcJobInfoMap.put(hpcJobInfo.getId(), hpcJobInfo);
+ }
}
- if (status > -1) {
- // Submitted time
- rowData.add(FilePrint.fileTimestamp(hpcJobInfo
- .getSubmittedTime().getTime()));
+ if (activeHpcJobInfoMap != null) {
- // HPC job id
- rowData.add(hpcJobInfo.getPid() != null?"" + hpcJobInfo.getPid():"");
+ List activeJobIds = new ArrayList<>(activeHpcJobInfoMap.keySet());
- } else {
- rowData.add("");
- rowData.add("");
- }
+ Collections.sort(activeJobIds);
+ Collections.reverse(activeJobIds);
- // Last update time
- rowData.add(FilePrint.fileTimestamp(hpcJobLog
- .getLastUpdatedTime().getTime()));
+ for (Long jobId : activeJobIds) {
- // Cancel job
- rowData.add("Cancel");
+ final HpcJobInfo hpcJobInfo = activeHpcJobInfoMap.get(jobId);
- activeRowData.add(rowData);
- }
- }
+ Vector rowData = new Vector<>();
- return activeRowData;
- }
-
- private Vector> getFinishedRowData(
- final TetradDesktop desktop,
- final List exclusiveHpcAccounts) throws Exception {
- final Vector> finishedRowData = new Vector<>();
- HpcJobManager hpcJobManager = desktop.getHpcJobManager();
- Map finishedHpcJobIdMap = null;
-
- // Finished jobs
- Map> finishedHpcJobInfoMap = hpcJobManager
- .getFinishedHpcJobInfoMap();
- for (HpcAccount hpcAccount : finishedHpcJobInfoMap.keySet()) {
-
- if (exclusiveHpcAccounts != null
- && !exclusiveHpcAccounts.contains(hpcAccount)) {
- continue;
- }
-
- Set finishedHpcJobSet = finishedHpcJobInfoMap
- .get(hpcAccount);
- for (HpcJobInfo hpcJobInfo : finishedHpcJobSet) {
- if (finishedHpcJobIdMap == null) {
- finishedHpcJobIdMap = new HashMap<>();
- }
- finishedHpcJobIdMap.put(hpcJobInfo.getId(), hpcJobInfo);
- }
- }
+ HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
- if (finishedHpcJobIdMap != null) {
+ // Local job id
+ rowData.add(hpcJobInfo.getId().toString());
- List finishedJobIds = new ArrayList<>(
- finishedHpcJobIdMap.keySet());
+ int status = hpcJobInfo.getStatus();
- Collections.sort(finishedJobIds);
- Collections.reverse(finishedJobIds);
+ switch (status) {
+ case -1:
+ rowData.add("Pending");
+ break;
+ case 0:
+ rowData.add("Submitted");
+ break;
+ case 1:
+ rowData.add("Running");
+ break;
+ case 2:
+ rowData.add("Kill Request");
+ break;
+ }
- for (Long jobId : finishedJobIds) {
- final HpcJobInfo hpcJobInfo = finishedHpcJobIdMap.get(jobId);
+ // Locally added time
+ rowData.add(FilePrint.fileTimestamp(hpcJobLog.getAddedTime().getTime()));
- Vector rowData = new Vector<>();
+ // HPC node name
+ HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+ rowData.add(hpcAccount.getConnectionName());
- HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
+ // Algorithm
+ rowData.add(hpcJobInfo.getAlgorithmName());
- // Local job id
- rowData.add(hpcJobInfo.getId().toString());
+ // Dataset uploading progress
+ AlgorithmParamRequest algorParamReq = hpcJobInfo.getAlgorithmParamRequest();
+ String datasetPath = algorParamReq.getDatasetPath();
- int status = hpcJobInfo.getStatus();
+ int progress = hpcJobManager.getUploadFileProgress(datasetPath);
+ if (progress > -1 && progress < 100) {
+ rowData.add("" + progress + "%");
+ } else {
+ rowData.add("Done");
+ }
- switch (status) {
- case 3:
- rowData.add("Finished");
- break;
- case 4:
- rowData.add("Canceled");
- break;
- case 5:
- rowData.add("Finished");
- break;
- case 6:
- rowData.add("Error");
- break;
- }
+ // Prior Knowledge uploading progress
+ String priorKnowledgePath = algorParamReq.getPriorKnowledgePath();
+ if (priorKnowledgePath != null) {
+ progress = hpcJobManager.getUploadFileProgress(priorKnowledgePath);
+ if (progress > -1 && progress < 100) {
+ rowData.add("" + progress + "%");
+ } else {
+ rowData.add("Done");
+ }
+ } else {
+ rowData.add("Skipped");
+ }
- // Locally added time
- rowData.add(FilePrint.fileTimestamp(hpcJobLog.getAddedTime()
- .getTime()));
-
- // HPC node name
- HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- rowData.add(hpcAccount.getConnectionName());
-
- // Algorithm
- rowData.add(hpcJobInfo.getAlgorithmName());
-
- // Submitted time
- rowData.add(hpcJobInfo.getSubmittedTime() != null ? FilePrint
- .fileTimestamp(hpcJobInfo.getSubmittedTime().getTime())
- : "");
-
- // HPC job id
- rowData.add("" + hpcJobInfo.getPid());
-
- // Result Name
- switch (status) {
- case 3:
- rowData.add(hpcJobInfo.getResultFileName());
- break;
- case 4:
- rowData.add("");
- break;
- case 5:
- rowData.add(hpcJobInfo.getResultFileName());
- break;
- case 6:
- rowData.add(hpcJobInfo.getErrorResultFileName());
- break;
- }
+ if (status > -1) {
+ // Submitted time
+ rowData.add(FilePrint.fileTimestamp(hpcJobInfo.getSubmittedTime().getTime()));
+
+ // HPC job id
+ rowData.add(hpcJobInfo.getPid() != null ? "" + hpcJobInfo.getPid() : "");
+
+ } else {
+ rowData.add("");
+ rowData.add("");
+ }
+
+ // Last update time
+ rowData.add(FilePrint.fileTimestamp(hpcJobLog.getLastUpdatedTime().getTime()));
+
+ // Cancel job
+ rowData.add("Cancel");
- // Finished time
- if (status != 4) {
- rowData.add(FilePrint.fileTimestamp(hpcJobLog
- .getEndedTime().getTime()));
- } else {
- rowData.add("");
+ activeRowData.add(rowData);
+ }
}
- // Canceled time
- if (status == 4) {
- rowData.add(hpcJobLog.getCanceledTime() != null ? FilePrint
- .fileTimestamp(hpcJobLog.getCanceledTime()
- .getTime()) : "");
- } else {
- rowData.add("");
+ return activeRowData;
+ }
+
+ private Vector> getFinishedRowData(final TetradDesktop desktop,
+ final List exclusiveHpcAccounts) throws Exception {
+ final Vector> finishedRowData = new Vector<>();
+ HpcJobManager hpcJobManager = desktop.getHpcJobManager();
+ Map finishedHpcJobIdMap = null;
+
+ // Finished jobs
+ Map> finishedHpcJobInfoMap = hpcJobManager.getFinishedHpcJobInfoMap();
+ for (HpcAccount hpcAccount : finishedHpcJobInfoMap.keySet()) {
+
+ if (exclusiveHpcAccounts != null && !exclusiveHpcAccounts.contains(hpcAccount)) {
+ continue;
+ }
+
+ Set finishedHpcJobSet = finishedHpcJobInfoMap.get(hpcAccount);
+ for (HpcJobInfo hpcJobInfo : finishedHpcJobSet) {
+ if (finishedHpcJobIdMap == null) {
+ finishedHpcJobIdMap = new HashMap<>();
+ }
+ finishedHpcJobIdMap.put(hpcJobInfo.getId(), hpcJobInfo);
+ }
}
- // Last update time
- rowData.add(FilePrint.fileTimestamp(hpcJobLog
- .getLastUpdatedTime().getTime()));
+ if (finishedHpcJobIdMap != null) {
+
+ List finishedJobIds = new ArrayList<>(finishedHpcJobIdMap.keySet());
+
+ Collections.sort(finishedJobIds);
+ Collections.reverse(finishedJobIds);
+
+ for (Long jobId : finishedJobIds) {
+ final HpcJobInfo hpcJobInfo = finishedHpcJobIdMap.get(jobId);
+
+ Vector rowData = new Vector<>();
+
+ HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
+
+ // Local job id
+ rowData.add(hpcJobInfo.getId().toString());
+
+ int status = hpcJobInfo.getStatus();
+
+ switch (status) {
+ case 3:
+ rowData.add("Finished");
+ break;
+ case 4:
+ rowData.add("Canceled");
+ break;
+ case 5:
+ rowData.add("Finished");
+ break;
+ case 6:
+ rowData.add("Error");
+ break;
+ }
+
+ // Locally added time
+ rowData.add(FilePrint.fileTimestamp(hpcJobLog.getAddedTime().getTime()));
+
+ // HPC node name
+ HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+ rowData.add(hpcAccount.getConnectionName());
+
+ // Algorithm
+ rowData.add(hpcJobInfo.getAlgorithmName());
+
+ // Submitted time
+ rowData.add(hpcJobInfo.getSubmittedTime() != null
+ ? FilePrint.fileTimestamp(hpcJobInfo.getSubmittedTime().getTime()) : "");
+
+ // HPC job id
+ rowData.add("" + hpcJobInfo.getPid());
+
+ // Result Name
+ switch (status) {
+ case 3:
+ rowData.add(hpcJobInfo.getResultFileName());
+ break;
+ case 4:
+ rowData.add("");
+ break;
+ case 5:
+ rowData.add(hpcJobInfo.getResultFileName());
+ break;
+ case 6:
+ rowData.add(hpcJobInfo.getErrorResultFileName());
+ break;
+ }
+
+ // Finished time
+ if (status != 4) {
+ rowData.add(FilePrint.fileTimestamp(hpcJobLog.getEndedTime().getTime()));
+ } else {
+ rowData.add("");
+ }
+
+ // Canceled time
+ if (status == 4) {
+ rowData.add(hpcJobLog.getCanceledTime() != null
+ ? FilePrint.fileTimestamp(hpcJobLog.getCanceledTime().getTime()) : "");
+ } else {
+ rowData.add("");
+ }
+
+ // Last update time
+ rowData.add(FilePrint.fileTimestamp(hpcJobLog.getLastUpdatedTime().getTime()));
+
+ // Delete job from db
+ rowData.add("Delete");
+
+ finishedRowData.add(rowData);
+ }
- // Delete job from db
- rowData.add("Delete");
+ }
- finishedRowData.add(rowData);
- }
+ return finishedRowData;
+ }
+ public synchronized Set getPendingDisplayHpcJobInfoSet() {
+
+ return pendingDisplayHpcJobInfoSet;
}
- return finishedRowData;
- }
-
- public synchronized Set getPendingDisplayHpcJobInfoSet() {
-
- return pendingDisplayHpcJobInfoSet;
- }
-
- public synchronized void removePendingDisplayHpcJobInfo(
- final Set removingJobSet) {
- for (final HpcJobInfo hpcJobInfo : removingJobSet) {
- for (HpcJobInfo pendingJob: pendingDisplayHpcJobInfoSet) {
- if (hpcJobInfo.getId() == pendingJob.getId()) {
- pendingDisplayHpcJobInfoSet.remove(pendingJob);
- continue;
+ public synchronized void removePendingDisplayHpcJobInfo(final Set removingJobSet) {
+ for (final HpcJobInfo hpcJobInfo : removingJobSet) {
+ for (HpcJobInfo pendingJob : pendingDisplayHpcJobInfoSet) {
+ if (hpcJobInfo.getId() == pendingJob.getId()) {
+ pendingDisplayHpcJobInfoSet.remove(pendingJob);
+ continue;
+ }
+ }
}
- }
}
- }
- public Set getSubmittedDisplayHpcJobInfoSet() {
- return submittedDisplayHpcJobInfoSet;
- }
+ public Set getSubmittedDisplayHpcJobInfoSet() {
+ return submittedDisplayHpcJobInfoSet;
+ }
- public synchronized void addSubmittedDisplayHpcJobInfo(
- final Set submittedJobSet) {
- for(HpcJobInfo job : submittedJobSet){
- System.out.println("addSubmittedDisplayHpcJobInfo: job: " + job.getId());
+ public synchronized void addSubmittedDisplayHpcJobInfo(final Set submittedJobSet) {
+ for (HpcJobInfo job : submittedJobSet) {
+ System.out.println("addSubmittedDisplayHpcJobInfo: job: " + job.getId());
+ }
+ submittedDisplayHpcJobInfoSet.addAll(submittedJobSet);
}
- submittedDisplayHpcJobInfoSet.addAll(submittedJobSet);
- }
-
- public synchronized void removeSubmittedDisplayHpcJobInfo(
- final Set removingJobSet) {
- for (final HpcJobInfo hpcJobInfo : removingJobSet) {
- for (Iterator it = submittedDisplayHpcJobInfoSet
- .iterator(); it.hasNext();) {
- final HpcJobInfo submittedJob = it.next();
- if (hpcJobInfo.getId() == submittedJob.getId()) {
- submittedDisplayHpcJobInfoSet.remove(hpcJobInfo);
- continue;
+
+ public synchronized void removeSubmittedDisplayHpcJobInfo(final Set removingJobSet) {
+ for (final HpcJobInfo hpcJobInfo : removingJobSet) {
+ for (Iterator it = submittedDisplayHpcJobInfoSet.iterator(); it.hasNext();) {
+ final HpcJobInfo submittedJob = it.next();
+ if (hpcJobInfo.getId() == submittedJob.getId()) {
+ submittedDisplayHpcJobInfoSet.remove(hpcJobInfo);
+ continue;
+ }
+ }
}
- }
+
}
- }
+ public synchronized void removeSubmittedDisplayJobFromActiveTableModel(final Set finishedJobSet) {
+ DefaultTableModel model = (DefaultTableModel) jobsTable.getModel();
+ Map rowMap = new HashMap<>();
+ for (int row = 0; row < model.getRowCount(); row++) {
+ rowMap.put(Long.valueOf(model.getValueAt(row, ID_COLUMN).toString()), row);
+ }
+
+ for (final HpcJobInfo hpcJobInfo : finishedJobSet) {
+ if (rowMap.containsKey(hpcJobInfo.getId())) {
+ model.removeRow(rowMap.get(hpcJobInfo.getId()));
+ }
+ }
+
+ }
- public synchronized void removeSubmittedDisplayJobFromActiveTableModel(
- final Set finishedJobSet) {
- DefaultTableModel model = (DefaultTableModel) jobsTable.getModel();
- Map rowMap = new HashMap<>();
- for (int row = 0; row < model.getRowCount(); row++) {
- rowMap.put(
- Long.valueOf(model.getValueAt(row,
- ID_COLUMN).toString()), row);
+ public TableModel getJobsTableModel() {
+ return jobsTable.getModel();
}
- for (final HpcJobInfo hpcJobInfo : finishedJobSet) {
- if (rowMap.containsKey(hpcJobInfo.getId())) {
- model.removeRow(rowMap.get(hpcJobInfo.getId()));
- }
+ public int selectedTabbedPaneIndex() {
+ return tabbedPane.getSelectedIndex();
}
- }
-
- public TableModel getJobsTableModel() {
- return jobsTable.getModel();
- }
-
- public int selectedTabbedPaneIndex(){
- return tabbedPane.getSelectedIndex();
- }
-
- @Override
- public boolean finalizeEditor() {
- stopUpdaters();
- return true;
- }
+ @Override
+ public boolean finalizeEditor() {
+ stopUpdaters();
+ return true;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobInfoTableModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobInfoTableModel.java
index 07c5a71692..3ba8116ab2 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobInfoTableModel.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/HpcJobInfoTableModel.java
@@ -17,16 +17,16 @@ public class HpcJobInfoTableModel extends DefaultTableModel {
private final int buttonColumn;
- public HpcJobInfoTableModel(final Vector> activeRowData,
- final Vector activeColumnNames, final int buttonColumn) {
- super(activeRowData, activeColumnNames);
- this.buttonColumn = buttonColumn;
+ public HpcJobInfoTableModel(final Vector> activeRowData, final Vector activeColumnNames,
+ final int buttonColumn) {
+ super(activeRowData, activeColumnNames);
+ this.buttonColumn = buttonColumn;
}
public boolean isCellEditable(int row, int column) {
- if (column == buttonColumn)
- return true;
- return false;
+ if (column == buttonColumn)
+ return true;
+ return false;
}
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/LoadHpcGraphJsonTableModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/LoadHpcGraphJsonTableModel.java
new file mode 100644
index 0000000000..aa9a553661
--- /dev/null
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/editor/LoadHpcGraphJsonTableModel.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 University of Pittsburgh.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package edu.cmu.tetradapp.app.hpc.editor;
+
+import java.util.Vector;
+
+import javax.swing.table.DefaultTableModel;
+
+/**
+ *
+ * Feb 14, 2017 7:22:42 PM
+ *
+ * @author Chirayu (Kong) Wongchokprasitti
+ *
+ */
+public class LoadHpcGraphJsonTableModel extends DefaultTableModel {
+
+ private static final long serialVersionUID = 2896909588298923241L;
+
+ public LoadHpcGraphJsonTableModel(final Vector> rowData, final Vector columnNames) {
+ super(rowData, columnNames);
+ }
+
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ }
+
+}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountManager.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountManager.java
index 8dccceaafe..2464731812 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountManager.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountManager.java
@@ -14,30 +14,30 @@
*/
public class HpcAccountManager {
- private final HpcAccountService hpcAccountService;
-
- private final JsonWebTokenManager jsonWebTokenManager;
-
- public HpcAccountManager(final org.hibernate.Session session) {
- this.hpcAccountService = new HpcAccountService(session);
- this.jsonWebTokenManager = new JsonWebTokenManager();
- }
-
- public List getHpcAccounts() {
- List hpcAccounts = hpcAccountService.get();
- return hpcAccounts;
- }
-
- public void saveAccount(final HpcAccount hpcAccount) {
- hpcAccountService.update(hpcAccount);
- }
-
- public void removeAccount(final HpcAccount hpcAccount) {
- hpcAccountService.remove(hpcAccount);
- }
-
- public JsonWebTokenManager getJsonWebTokenManager() {
- return jsonWebTokenManager;
- }
+ private final HpcAccountService hpcAccountService;
+
+ private final JsonWebTokenManager jsonWebTokenManager;
+
+ public HpcAccountManager(final org.hibernate.Session session) {
+ this.hpcAccountService = new HpcAccountService(session);
+ this.jsonWebTokenManager = new JsonWebTokenManager();
+ }
+
+ public List getHpcAccounts() {
+ List hpcAccounts = hpcAccountService.get();
+ return hpcAccounts;
+ }
+
+ public void saveAccount(final HpcAccount hpcAccount) {
+ hpcAccountService.update(hpcAccount);
+ }
+
+ public void removeAccount(final HpcAccount hpcAccount) {
+ hpcAccountService.remove(hpcAccount);
+ }
+
+ public JsonWebTokenManager getJsonWebTokenManager() {
+ return jsonWebTokenManager;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountService.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountService.java
index a4ef9e3b25..556e3fe368 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountService.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcAccountService.java
@@ -16,54 +16,48 @@
*/
public class HpcAccountService {
- private final RemoteDataFileService remoteDataService;
+ private final RemoteDataFileService remoteDataService;
- private final DataUploadService dataUploadService;
+ private final DataUploadService dataUploadService;
- private final JobQueueService jobQueueService;
+ private final JobQueueService jobQueueService;
- private final ResultService resultService;
-
- public HpcAccountService(final HpcAccount hpcAccount,
- final int simultaneousUpload) throws Exception {
+ private final ResultService resultService;
- final String username = hpcAccount.getUsername();
- final String password = hpcAccount.getPassword();
- final String scheme = hpcAccount.getScheme();
- final String hostname = hpcAccount.getHostname();
- final int port = hpcAccount.getPort();
+ public HpcAccountService(final HpcAccount hpcAccount, final int simultaneousUpload) throws Exception {
- RestHttpsClient restHttpsClient = new RestHttpsClient(username, password, scheme,
- hostname, port);
+ final String username = hpcAccount.getUsername();
+ final String password = hpcAccount.getPassword();
+ final String scheme = hpcAccount.getScheme();
+ final String hostname = hpcAccount.getHostname();
+ final int port = hpcAccount.getPort();
- this.remoteDataService = new RemoteDataFileService(restHttpsClient,
- scheme, hostname, port);
+ RestHttpsClient restHttpsClient = new RestHttpsClient(username, password, scheme, hostname, port);
- this.dataUploadService = new DataUploadService(restHttpsClient,
- simultaneousUpload, scheme, hostname, port);
+ this.remoteDataService = new RemoteDataFileService(restHttpsClient, scheme, hostname, port);
- this.jobQueueService = new JobQueueService(restHttpsClient, scheme,
- hostname, port);
+ this.dataUploadService = new DataUploadService(restHttpsClient, simultaneousUpload, scheme, hostname, port);
- this.resultService = new ResultService(restHttpsClient,
- scheme, hostname, port);
-
- }
+ this.jobQueueService = new JobQueueService(restHttpsClient, scheme, hostname, port);
- public RemoteDataFileService getRemoteDataService() {
- return remoteDataService;
- }
+ this.resultService = new ResultService(restHttpsClient, scheme, hostname, port);
- public DataUploadService getDataUploadService() {
- return dataUploadService;
- }
+ }
- public JobQueueService getJobQueueService() {
- return jobQueueService;
- }
+ public RemoteDataFileService getRemoteDataService() {
+ return remoteDataService;
+ }
- public ResultService getResultService() {
- return resultService;
- }
+ public DataUploadService getDataUploadService() {
+ return dataUploadService;
+ }
+
+ public JobQueueService getJobQueueService() {
+ return jobQueueService;
+ }
+
+ public ResultService getResultService() {
+ return resultService;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcJobManager.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcJobManager.java
index 8ebdc5d468..d1625471ab 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcJobManager.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/HpcJobManager.java
@@ -41,442 +41,399 @@
*/
public class HpcJobManager {
- private final HpcJobLogService hpcJobLogService;
+ private final HpcJobLogService hpcJobLogService;
- private final HpcJobLogDetailService hpcJobLogDetailService;
+ private final HpcJobLogDetailService hpcJobLogDetailService;
- private final HpcJobInfoService hpcJobInfoService;
+ private final HpcJobInfoService hpcJobInfoService;
- private final int simultaneousUpload;
+ private final int simultaneousUpload;
- private final ExecutorService executorService;
+ private final ExecutorService executorService;
- private final Timer timer;
+ private final Timer timer;
- private int TIME_INTERVAL = 10000;
+ private int TIME_INTERVAL = 10000;
- private final Map uploadFileProgressMap;
+ private final Map uploadFileProgressMap;
- private final Map hpcGraphResultMap;
+ private final Map hpcGraphResultMap;
- private final Map> pendingHpcJobInfoMap;
+ private final Map> pendingHpcJobInfoMap;
- private final Map> submittedHpcJobInfoMap;
+ private final Map> submittedHpcJobInfoMap;
- private final Map hpcAccountServiceMap;
+ private final Map hpcAccountServiceMap;
- public HpcJobManager(final org.hibernate.Session session,
- final int simultaneousUpload) {
- this.hpcJobLogService = new HpcJobLogService(session);
- this.hpcJobLogDetailService = new HpcJobLogDetailService(session);
- this.hpcJobInfoService = new HpcJobInfoService(session);
- this.simultaneousUpload = simultaneousUpload;
+ public HpcJobManager(final org.hibernate.Session session, final int simultaneousUpload) {
+ this.hpcJobLogService = new HpcJobLogService(session);
+ this.hpcJobLogDetailService = new HpcJobLogDetailService(session);
+ this.hpcJobInfoService = new HpcJobInfoService(session);
+ this.simultaneousUpload = simultaneousUpload;
- executorService = Executors.newFixedThreadPool(simultaneousUpload);
+ executorService = Executors.newFixedThreadPool(simultaneousUpload);
- uploadFileProgressMap = new HashMap<>();
- pendingHpcJobInfoMap = new HashMap<>();
- submittedHpcJobInfoMap = new HashMap<>();
- hpcGraphResultMap = new HashMap<>();
- hpcAccountServiceMap = new HashMap<>();
+ uploadFileProgressMap = new HashMap<>();
+ pendingHpcJobInfoMap = new HashMap<>();
+ submittedHpcJobInfoMap = new HashMap<>();
+ hpcGraphResultMap = new HashMap<>();
+ hpcAccountServiceMap = new HashMap<>();
- resumePreProcessJobs();
- resumeSubmittedHpcJobInfos();
+ resumePreProcessJobs();
+ resumeSubmittedHpcJobInfos();
- this.timer = new Timer();
+ this.timer = new Timer();
- startHpcJobScheduler();
- }
+ startHpcJobScheduler();
+ }
+
+ public Map> getPendingHpcJobInfoMap() {
+ return pendingHpcJobInfoMap;
+ }
+
+ private synchronized void resumePreProcessJobs() {
+ // Lookup on DB for HpcJobInfo with status -1 (Pending)
+
+ List pendingHpcJobInfo = hpcJobInfoService.findByStatus(-1);
+ if (pendingHpcJobInfo != null) {
+ for (HpcJobInfo hpcJobInfo : pendingHpcJobInfo) {
+ System.out.println("resumePreProcessJobs: " + hpcJobInfo.getAlgorithmName() + " : "
+ + hpcJobInfo.getHpcAccount().getConnectionName() + " : "
+ + hpcJobInfo.getAlgorithmParamRequest().getDatasetPath());
+
+ final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+
+ Set hpcJobInfos = pendingHpcJobInfoMap.get(hpcAccount);
+ if (hpcJobInfos == null) {
+ hpcJobInfos = new LinkedHashSet<>();
+ }
+ hpcJobInfos.add(hpcJobInfo);
+ pendingHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
+
+ HpcJobPreProcessTask preProcessTask = new HpcJobPreProcessTask(hpcJobInfo);
+ executorService.submit(preProcessTask);
+ }
+ } else {
+ System.out.println("resumePreProcessJobs: no pending jobs to be resumed");
+ }
+ }
+
+ public void startHpcJobScheduler() {
+ System.out.println("startHpcJobScheduler");
+ HpcJobsScheduledTask hpcScheduledTask = new HpcJobsScheduledTask();
+ timer.schedule(hpcScheduledTask, 1000, TIME_INTERVAL);
+ }
+
+ public synchronized void submitNewHpcJobToQueue(final HpcJobInfo hpcJobInfo,
+ final GeneralAlgorithmEditor generalAlgorithmEditor) {
+
+ hpcJobInfoService.add(hpcJobInfo);
+ System.out.println("hpcJobInfo: id: " + hpcJobInfo.getId());
+
+ HpcJobLog hpcJobLog = new HpcJobLog();
+ hpcJobLog.setAddedTime(new Date(System.currentTimeMillis()));
+ hpcJobLog.setHpcJobInfo(hpcJobInfo);
+ hpcJobLogService.update(hpcJobLog);
+ System.out.println("HpcJobLog: id: " + hpcJobLog.getId());
- public Map> getPendingHpcJobInfoMap() {
- return pendingHpcJobInfoMap;
- }
+ HpcJobLogDetail hpcJobLogDetail = new HpcJobLogDetail();
+ hpcJobLogDetail.setAddedTime(new Date());
+ hpcJobLogDetail.setHpcJobLog(hpcJobLog);
+ hpcJobLogDetail.setJobState(-1);// Pending
+ hpcJobLogDetail.setProgress("Pending");
+ hpcJobLogDetailService.add(hpcJobLogDetail);
+ System.out.println("HpcJobLogDetail: id: " + hpcJobLogDetail.getId());
- private synchronized void resumePreProcessJobs() {
- // Lookup on DB for HpcJobInfo with status -1 (Pending)
+ hpcGraphResultMap.put(hpcJobInfo, generalAlgorithmEditor);
- List pendingHpcJobInfo = hpcJobInfoService.findByStatus(-1);
- if (pendingHpcJobInfo != null) {
- for (HpcJobInfo hpcJobInfo : pendingHpcJobInfo) {
- System.out.println("resumePreProcessJobs: "
- + hpcJobInfo.getAlgorithmName()
- + " : "
- + hpcJobInfo.getHpcAccount().getConnectionName()
- + " : "
- + hpcJobInfo.getAlgorithmParamRequest()
- .getDatasetPath());
+ // Put a new pre-process task into hpc job queue
+ HpcJobPreProcessTask preProcessTask = new HpcJobPreProcessTask(hpcJobInfo);
+ // Added a job to the pending list
final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- Set hpcJobInfos = pendingHpcJobInfoMap
- .get(hpcAccount);
+ Set hpcJobInfos = pendingHpcJobInfoMap.get(hpcAccount);
if (hpcJobInfos == null) {
- hpcJobInfos = new LinkedHashSet<>();
+ hpcJobInfos = new LinkedHashSet<>();
}
hpcJobInfos.add(hpcJobInfo);
pendingHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
- HpcJobPreProcessTask preProcessTask = new HpcJobPreProcessTask(
- hpcJobInfo);
- executorService.submit(preProcessTask);
- }
- } else {
- System.out
- .println("resumePreProcessJobs: no pending jobs to be resumed");
+ executorService.execute(preProcessTask);
+ }
+
+ public void stopHpcJobScheduler() {
+ timer.cancel();
+ }
+
+ public void restartHpcJobScheduler() {
+ stopHpcJobScheduler();
+ startHpcJobScheduler();
}
- }
-
- public void startHpcJobScheduler() {
- System.out.println("startHpcJobScheduler");
- HpcJobsScheduledTask hpcScheduledTask = new HpcJobsScheduledTask();
- timer.schedule(hpcScheduledTask, 1000, TIME_INTERVAL);
- }
-
- public synchronized void submitNewHpcJobToQueue(
- final HpcJobInfo hpcJobInfo,
- final GeneralAlgorithmEditor generalAlgorithmEditor) {
-
- hpcJobInfoService.add(hpcJobInfo);
- System.out.println("hpcJobInfo: id: " + hpcJobInfo.getId());
-
- HpcJobLog hpcJobLog = new HpcJobLog();
- hpcJobLog.setAddedTime(new Date(System.currentTimeMillis()));
- hpcJobLog.setHpcJobInfo(hpcJobInfo);
- hpcJobLogService.update(hpcJobLog);
- System.out.println("HpcJobLog: id: " + hpcJobLog.getId());
-
- HpcJobLogDetail hpcJobLogDetail = new HpcJobLogDetail();
- hpcJobLogDetail.setAddedTime(new Date());
- hpcJobLogDetail.setHpcJobLog(hpcJobLog);
- hpcJobLogDetail.setJobState(-1);// Pending
- hpcJobLogDetail.setProgress("Pending");
- hpcJobLogDetailService.add(hpcJobLogDetail);
- System.out.println("HpcJobLogDetail: id: " + hpcJobLogDetail.getId());
-
- hpcGraphResultMap.put(hpcJobInfo, generalAlgorithmEditor);
-
- // Put a new pre-process task into hpc job queue
- HpcJobPreProcessTask preProcessTask = new HpcJobPreProcessTask(
- hpcJobInfo);
-
- // Added a job to the pending list
- final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
-
- Set hpcJobInfos = pendingHpcJobInfoMap.get(hpcAccount);
- if (hpcJobInfos == null) {
- hpcJobInfos = new LinkedHashSet<>();
+
+ public HpcJobLog getHpcJobLog(final HpcJobInfo hpcJobInfo) {
+ return hpcJobLogService.findByHpcJobInfo(hpcJobInfo);
}
- hpcJobInfos.add(hpcJobInfo);
- pendingHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
-
- executorService.execute(preProcessTask);
- }
-
- public void stopHpcJobScheduler() {
- timer.cancel();
- }
-
- public void restartHpcJobScheduler() {
- stopHpcJobScheduler();
- startHpcJobScheduler();
- }
-
- public HpcJobLog getHpcJobLog(final HpcJobInfo hpcJobInfo) {
- return hpcJobLogService.findByHpcJobInfo(hpcJobInfo);
- }
-
- public void appendHpcJobLogDetail(final HpcJobLogDetail hpcJobLogDetail) {
- hpcJobLogDetailService.add(hpcJobLogDetail);
- }
-
- public HpcJobInfo findHpcJobInfoById(final long id) {
- return hpcJobInfoService.findById(id);
- }
-
- public void updateHpcJobInfo(final HpcJobInfo hpcJobInfo) {
- hpcJobInfoService.update(hpcJobInfo);
- updateSubmittedHpcJobInfo(hpcJobInfo);
- }
-
- public void updateHpcJobLog(final HpcJobLog hpcJobLog) {
- hpcJobLogService.update(hpcJobLog);
- }
-
- public void logHpcJobLogDetail(final HpcJobLog hpcJobLog, int jobStatus,
- String jobProgress) {
- Date now = new Date(System.currentTimeMillis());
- hpcJobLog.setLastUpdatedTime(now);
- if (jobStatus == 3) {// Finished
- hpcJobLog.setEndedTime(now);
+
+ public void appendHpcJobLogDetail(final HpcJobLogDetail hpcJobLogDetail) {
+ hpcJobLogDetailService.add(hpcJobLogDetail);
}
- if (jobStatus == 4) {// Killed
- hpcJobLog.setCanceledTime(now);
+
+ public HpcJobInfo findHpcJobInfoById(final long id) {
+ return hpcJobInfoService.findById(id);
+ }
+
+ public void updateHpcJobInfo(final HpcJobInfo hpcJobInfo) {
+ hpcJobInfoService.update(hpcJobInfo);
+ updateSubmittedHpcJobInfo(hpcJobInfo);
}
- updateHpcJobLog(hpcJobLog);
-
- HpcJobLogDetail hpcJobLogDetail = new HpcJobLogDetail();
- hpcJobLogDetail.setAddedTime(new Date(System.currentTimeMillis()));
- hpcJobLogDetail.setHpcJobLog(hpcJobLog);
- hpcJobLogDetail.setJobState(jobStatus);
- hpcJobLogDetail.setProgress(jobProgress);
- appendHpcJobLogDetail(hpcJobLogDetail);
- }
-
- public synchronized void updateUploadFileProgress(final String datasetPath,
- int percentageProgress) {
- uploadFileProgressMap.put(datasetPath, percentageProgress);
- }
-
- public int getUploadFileProgress(final String dataPath) {
- int progress = -1;
- if (uploadFileProgressMap.containsKey(dataPath)) {
- progress = uploadFileProgressMap.get(dataPath).intValue();
+
+ public void updateHpcJobLog(final HpcJobLog hpcJobLog) {
+ hpcJobLogService.update(hpcJobLog);
}
- return progress;
- }
-
- public void resumeSubmittedHpcJobInfos() {
- // Lookup on DB for HpcJobInfo with status 0 (Submitted); 1 (Running); 2
- // (Kill Request)
- for (int status = 0; status <= 2; status++) {
- //System.out.println("resumeSubmittedHpcJobInfos: "
- // + "looping status: " + status);
- List submittedHpcJobInfo = hpcJobInfoService
- .findByStatus(status);
- if (submittedHpcJobInfo != null) {
- for (HpcJobInfo hpcJobInfo : submittedHpcJobInfo) {
- addNewSubmittedHpcJob(hpcJobInfo);
+
+ public void logHpcJobLogDetail(final HpcJobLog hpcJobLog, int jobStatus, String jobProgress) {
+ Date now = new Date(System.currentTimeMillis());
+ hpcJobLog.setLastUpdatedTime(now);
+ if (jobStatus == 3) {// Finished
+ hpcJobLog.setEndedTime(now);
+ }
+ if (jobStatus == 4) {// Killed
+ hpcJobLog.setCanceledTime(now);
}
- }
+ updateHpcJobLog(hpcJobLog);
+
+ HpcJobLogDetail hpcJobLogDetail = new HpcJobLogDetail();
+ hpcJobLogDetail.setAddedTime(new Date(System.currentTimeMillis()));
+ hpcJobLogDetail.setHpcJobLog(hpcJobLog);
+ hpcJobLogDetail.setJobState(jobStatus);
+ hpcJobLogDetail.setProgress(jobProgress);
+ appendHpcJobLogDetail(hpcJobLogDetail);
}
- }
-
- public GeneralAlgorithmEditor getGeneralAlgorithmEditor(
- final HpcJobInfo hpcJobInfo) {
- return hpcGraphResultMap.get(hpcJobInfo);
- }
-
- public synchronized void addNewSubmittedHpcJob(final HpcJobInfo hpcJobInfo) {
- HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- System.out.println("addNewSubmittedHpcJob: connection: "
- + hpcAccount.getConnectionName());
- System.out.println("addNewSubmittedHpcJob: algorithm: "
- + hpcJobInfo.getAlgorithmName());
- System.out.println("addNewSubmittedHpcJob: status: "
- + hpcJobInfo.getStatus());
- System.out.println("addNewSubmittedHpcJob: " + "pid: "
- + hpcJobInfo.getPid());
-
- Set hpcJobInfos = submittedHpcJobInfoMap.get(hpcAccount);
- if (hpcJobInfos == null) {
- hpcJobInfos = new LinkedHashSet<>();
+
+ public synchronized void updateUploadFileProgress(final String datasetPath, int percentageProgress) {
+ uploadFileProgressMap.put(datasetPath, percentageProgress);
}
- hpcJobInfos.add(hpcJobInfo);
- submittedHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
-
- removePendingHpcJob(hpcJobInfo);
- }
-
- public synchronized void removeFinishedHpcJob(final HpcJobInfo hpcJobInfo) {
- HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- System.out.println("removedFinishedHpcJob: connection: "
- + hpcAccount.getConnectionName());
- System.out.println("removedFinishedHpcJob: algorithm: "
- + hpcJobInfo.getAlgorithmName());
- System.out.println("removedFinishedHpcJob: status: "
- + hpcJobInfo.getStatus());
- System.out
- .println("removedFinishedHpcJob: pid: " + hpcJobInfo.getPid());
- Set hpcJobInfos = submittedHpcJobInfoMap.get(hpcAccount);
- if (hpcJobInfos != null) {
-
- //System.out.println("removeFinishedHpcJob: hpcJobInfos not null");
-
- for (HpcJobInfo jobInfo : hpcJobInfos) {
- if (jobInfo.getId() == hpcJobInfo.getId()) {
-
- //System.out.println("removeFinishedHpcJob: Found hpcJobInfo in the submittedHpcJobInfoMap & removed it!");
-
- hpcJobInfos.remove(jobInfo);
+
+ public int getUploadFileProgress(final String dataPath) {
+ int progress = -1;
+ if (uploadFileProgressMap.containsKey(dataPath)) {
+ progress = uploadFileProgressMap.get(dataPath).intValue();
}
- }
+ return progress;
+ }
+
+ public void resumeSubmittedHpcJobInfos() {
+ // Lookup on DB for HpcJobInfo with status 0 (Submitted); 1 (Running); 2
+ // (Kill Request)
+ for (int status = 0; status <= 2; status++) {
+ // System.out.println("resumeSubmittedHpcJobInfos: "
+ // + "looping status: " + status);
+ List submittedHpcJobInfo = hpcJobInfoService.findByStatus(status);
+ if (submittedHpcJobInfo != null) {
+ for (HpcJobInfo hpcJobInfo : submittedHpcJobInfo) {
+ addNewSubmittedHpcJob(hpcJobInfo);
+ }
+ }
+ }
+ }
+
+ public GeneralAlgorithmEditor getGeneralAlgorithmEditor(final HpcJobInfo hpcJobInfo) {
+ return hpcGraphResultMap.get(hpcJobInfo);
+ }
- if (hpcJobInfos.isEmpty()) {
- submittedHpcJobInfoMap.remove(hpcAccount);
- } else {
+ public synchronized void addNewSubmittedHpcJob(final HpcJobInfo hpcJobInfo) {
+ HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+ System.out.println("addNewSubmittedHpcJob: connection: " + hpcAccount.getConnectionName());
+ System.out.println("addNewSubmittedHpcJob: algorithm: " + hpcJobInfo.getAlgorithmName());
+ System.out.println("addNewSubmittedHpcJob: status: " + hpcJobInfo.getStatus());
+ System.out.println("addNewSubmittedHpcJob: " + "pid: " + hpcJobInfo.getPid());
+
+ Set hpcJobInfos = submittedHpcJobInfoMap.get(hpcAccount);
+ if (hpcJobInfos == null) {
+ hpcJobInfos = new LinkedHashSet<>();
+ }
+ hpcJobInfos.add(hpcJobInfo);
submittedHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
- }
+
+ removePendingHpcJob(hpcJobInfo);
}
- hpcGraphResultMap.remove(hpcJobInfo);
- }
-
- public synchronized void removePendingHpcJob(final HpcJobInfo hpcJobInfo) {
- HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- System.out.println("removedPendingHpcJob: connection: "
- + hpcAccount.getConnectionName());
- System.out.println("removedPendingHpcJob: algorithm: "
- + hpcJobInfo.getAlgorithmName());
- System.out.println("removedPendingHpcJob: status: "
- + hpcJobInfo.getStatus());
- System.out.println("removedPendingHpcJob: pid: " + hpcJobInfo.getPid());
-
- Set hpcJobInfos = pendingHpcJobInfoMap.get(hpcAccount);
- if (hpcJobInfos != null) {
-
- //System.out.println("removedPendingHpcJob: hpcJobInfos not null");
-
- for (HpcJobInfo jobInfo : hpcJobInfos) {
- if (jobInfo.getId() == hpcJobInfo.getId()) {
-
- //System.out.println("removedPendingHpcJob: Found hpcJobInfo in the pendingHpcJobInfoMap & removed it!");
-
- hpcJobInfos.remove(jobInfo);
+
+ public synchronized void removeFinishedHpcJob(final HpcJobInfo hpcJobInfo) {
+ HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+ System.out.println("removedFinishedHpcJob: connection: " + hpcAccount.getConnectionName());
+ System.out.println("removedFinishedHpcJob: algorithm: " + hpcJobInfo.getAlgorithmName());
+ System.out.println("removedFinishedHpcJob: status: " + hpcJobInfo.getStatus());
+ System.out.println("removedFinishedHpcJob: pid: " + hpcJobInfo.getPid());
+ Set hpcJobInfos = submittedHpcJobInfoMap.get(hpcAccount);
+ if (hpcJobInfos != null) {
+
+ // System.out.println("removeFinishedHpcJob: hpcJobInfos not null");
+
+ for (HpcJobInfo jobInfo : hpcJobInfos) {
+ if (jobInfo.getId() == hpcJobInfo.getId()) {
+
+ // System.out.println("removeFinishedHpcJob: Found
+ // hpcJobInfo in the submittedHpcJobInfoMap & removed it!");
+
+ hpcJobInfos.remove(jobInfo);
+ }
+ }
+
+ if (hpcJobInfos.isEmpty()) {
+ submittedHpcJobInfoMap.remove(hpcAccount);
+ } else {
+ submittedHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
+ }
}
- }
+ hpcGraphResultMap.remove(hpcJobInfo);
+ }
- if (hpcJobInfos.isEmpty()) {
- pendingHpcJobInfoMap.remove(hpcAccount);
- } else {
- pendingHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
- }
+ public synchronized void removePendingHpcJob(final HpcJobInfo hpcJobInfo) {
+ HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+ System.out.println("removedPendingHpcJob: connection: " + hpcAccount.getConnectionName());
+ System.out.println("removedPendingHpcJob: algorithm: " + hpcJobInfo.getAlgorithmName());
+ System.out.println("removedPendingHpcJob: status: " + hpcJobInfo.getStatus());
+ System.out.println("removedPendingHpcJob: pid: " + hpcJobInfo.getPid());
+
+ Set hpcJobInfos = pendingHpcJobInfoMap.get(hpcAccount);
+ if (hpcJobInfos != null) {
+
+ // System.out.println("removedPendingHpcJob: hpcJobInfos not null");
+
+ for (HpcJobInfo jobInfo : hpcJobInfos) {
+ if (jobInfo.getId() == hpcJobInfo.getId()) {
+
+ // System.out.println("removedPendingHpcJob: Found
+ // hpcJobInfo in the pendingHpcJobInfoMap & removed it!");
+
+ hpcJobInfos.remove(jobInfo);
+ }
+ }
+
+ if (hpcJobInfos.isEmpty()) {
+ pendingHpcJobInfoMap.remove(hpcAccount);
+ } else {
+ pendingHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
+ }
+ }
}
- }
-
- public Map> getSubmittedHpcJobInfoMap() {
- return submittedHpcJobInfoMap;
- }
-
- public synchronized void updateSubmittedHpcJobInfo(
- final HpcJobInfo hpcJobInfo) {
- final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- Set hpcJobInfos = submittedHpcJobInfoMap.get(hpcAccount);
- if (hpcJobInfos != null) {
-
- //System.out.println("updateSubmittedHpcJobInfo: hpcJobInfos not null");
-
- for (HpcJobInfo jobInfo : hpcJobInfos) {
- if (jobInfo.getId() == hpcJobInfo.getId()) {
-
- //System.out.println("updateSubmittedHpcJobInfo: Found hpcJobInfo in the submittedHpcJobInfoMap & removed it!");
-
- hpcJobInfos.remove(jobInfo);
+
+ public Map> getSubmittedHpcJobInfoMap() {
+ return submittedHpcJobInfoMap;
+ }
+
+ public synchronized void updateSubmittedHpcJobInfo(final HpcJobInfo hpcJobInfo) {
+ final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+ Set hpcJobInfos = submittedHpcJobInfoMap.get(hpcAccount);
+ if (hpcJobInfos != null) {
+
+ // System.out.println("updateSubmittedHpcJobInfo: hpcJobInfos not
+ // null");
+
+ for (HpcJobInfo jobInfo : hpcJobInfos) {
+ if (jobInfo.getId() == hpcJobInfo.getId()) {
+
+ // System.out.println("updateSubmittedHpcJobInfo: Found
+ // hpcJobInfo in the submittedHpcJobInfoMap & removed it!");
+
+ hpcJobInfos.remove(jobInfo);
+ }
+ }
+
+ hpcJobInfos.add(hpcJobInfo);
+ submittedHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
}
- }
-
- hpcJobInfos.add(hpcJobInfo);
- submittedHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
}
- }
-
- public synchronized HpcAccountService getHpcAccountService(
- final HpcAccount hpcAccount) throws Exception {
- HpcAccountService hpcAccountService = hpcAccountServiceMap
- .get(hpcAccount);
- if (hpcAccountService == null) {
- hpcAccountService = new HpcAccountService(hpcAccount,
- simultaneousUpload);
- hpcAccountServiceMap.put(hpcAccount, hpcAccountService);
+
+ public synchronized HpcAccountService getHpcAccountService(final HpcAccount hpcAccount) throws Exception {
+ HpcAccountService hpcAccountService = hpcAccountServiceMap.get(hpcAccount);
+ if (hpcAccountService == null) {
+ hpcAccountService = new HpcAccountService(hpcAccount, simultaneousUpload);
+ hpcAccountServiceMap.put(hpcAccount, hpcAccountService);
+ }
+ return hpcAccountService;
}
- return hpcAccountService;
- }
-
- public synchronized void removeHpcAccountService(final HpcAccount hpcAccount) {
- hpcAccountServiceMap.remove(hpcAccount);
- }
-
- public synchronized Map> getFinishedHpcJobInfoMap() {
- final Map> finishedHpcJobInfoMap = new HashMap<>();
- // Lookup on DB for HpcJobInfo with status 3 (Finished); 4 (Killed);
- // 5 (Result Downloaded); 6 (Error Result Downloaded);
- for (int status = 3; status <= 6; status++) {
- //System.out.println("getFinishedHpcJobInfoMap: "
- // + "looping status: " + status);
- List finishedHpcJobInfo = hpcJobInfoService
- .findByStatus(status);
- if (finishedHpcJobInfo != null) {
- for (HpcJobInfo hpcJobInfo : finishedHpcJobInfo) {
- final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
- Set hpcJobInfos = finishedHpcJobInfoMap
- .get(hpcAccount);
- if (hpcJobInfos == null) {
- hpcJobInfos = new LinkedHashSet<>();
- }
- hpcJobInfos.add(hpcJobInfo);
- finishedHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
+
+ public synchronized void removeHpcAccountService(final HpcAccount hpcAccount) {
+ hpcAccountServiceMap.remove(hpcAccount);
+ }
+
+ public synchronized Map> getFinishedHpcJobInfoMap() {
+ final Map> finishedHpcJobInfoMap = new HashMap<>();
+ // Lookup on DB for HpcJobInfo with status 3 (Finished); 4 (Killed);
+ // 5 (Result Downloaded); 6 (Error Result Downloaded);
+ for (int status = 3; status <= 6; status++) {
+ // System.out.println("getFinishedHpcJobInfoMap: "
+ // + "looping status: " + status);
+ List finishedHpcJobInfo = hpcJobInfoService.findByStatus(status);
+ if (finishedHpcJobInfo != null) {
+ for (HpcJobInfo hpcJobInfo : finishedHpcJobInfo) {
+ final HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+ Set hpcJobInfos = finishedHpcJobInfoMap.get(hpcAccount);
+ if (hpcJobInfos == null) {
+ hpcJobInfos = new LinkedHashSet<>();
+ }
+ hpcJobInfos.add(hpcJobInfo);
+ finishedHpcJobInfoMap.put(hpcAccount, hpcJobInfos);
+ }
+ }
+ }
+ return finishedHpcJobInfoMap;
+ }
+
+ 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;
+
+ }
+
+ public List getRemoteActiveJobs(final HpcAccountManager hpcAccountManager, final HpcAccount hpcAccount)
+ throws ClientProtocolException, URISyntaxException, IOException, Exception {
+ HpcAccountService hpcAccountService = getHpcAccountService(hpcAccount);
+ JobQueueService jobQueueService = hpcAccountService.getJobQueueService();
+ return jobQueueService.getActiveJobs(HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
}
- return finishedHpcJobInfoMap;
- }
-
- 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;
+
+ public Set listRemoteAlgorithmResultFiles(final HpcAccountManager hpcAccountManager,
+ final HpcAccount hpcAccount) throws ClientProtocolException, URISyntaxException, IOException, Exception {
+ HpcAccountService hpcAccountService = getHpcAccountService(hpcAccount);
+ ResultService resultService = hpcAccountService.getResultService();
+ return resultService.listAlgorithmResultFiles(HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
}
- return null;
-
- }
-
- public List getRemoteActiveJobs(
- final HpcAccountManager hpcAccountManager,
- final HpcAccount hpcAccount) throws ClientProtocolException,
- URISyntaxException, IOException, Exception {
- HpcAccountService hpcAccountService = getHpcAccountService(hpcAccount);
- JobQueueService jobQueueService = hpcAccountService
- .getJobQueueService();
- return jobQueueService.getActiveJobs(HpcAccountUtils.getJsonWebToken(
- hpcAccountManager, hpcAccount));
- }
-
- public Set listRemoteAlgorithmResultFiles(
- final HpcAccountManager hpcAccountManager,
- final HpcAccount hpcAccount) throws ClientProtocolException,
- URISyntaxException, IOException, Exception {
- HpcAccountService hpcAccountService = getHpcAccountService(hpcAccount);
- ResultService resultService = hpcAccountService.getResultService();
- return resultService.listAlgorithmResultFiles(HpcAccountUtils
- .getJsonWebToken(hpcAccountManager, hpcAccount));
- }
-
- public String downloadAlgorithmResultFile(
- final HpcAccountManager hpcAccountManager,
- final HpcAccount hpcAccount, final String errorResultFileName)
- throws ClientProtocolException, URISyntaxException, IOException,
- Exception {
- HpcAccountService hpcAccountService = getHpcAccountService(hpcAccount);
- ResultService resultService = hpcAccountService.getResultService();
- return resultService.downloadAlgorithmResultFile(errorResultFileName,
- HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
- }
-
- public synchronized void removeHpcJobInfoTransaction(
- final HpcJobInfo hpcJobInfo) {
- HpcJobLog hpcJobLog = hpcJobLogService.findByHpcJobInfo(hpcJobInfo);
- List logDetailList = hpcJobLogDetailService
- .findByHpcJobLog(hpcJobLog);
- for (HpcJobLogDetail logDetail : logDetailList) {
- hpcJobLogDetailService.remove(logDetail);
+ public String downloadAlgorithmResultFile(final HpcAccountManager hpcAccountManager, final HpcAccount hpcAccount,
+ final String errorResultFileName)
+ throws ClientProtocolException, URISyntaxException, IOException, Exception {
+ HpcAccountService hpcAccountService = getHpcAccountService(hpcAccount);
+ ResultService resultService = hpcAccountService.getResultService();
+ return resultService.downloadAlgorithmResultFile(errorResultFileName,
+ HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
+ }
+
+ public synchronized void removeHpcJobInfoTransaction(final HpcJobInfo hpcJobInfo) {
+ HpcJobLog hpcJobLog = hpcJobLogService.findByHpcJobInfo(hpcJobInfo);
+ List logDetailList = hpcJobLogDetailService.findByHpcJobLog(hpcJobLog);
+ for (HpcJobLogDetail logDetail : logDetailList) {
+ hpcJobLogDetailService.remove(logDetail);
+ }
+ hpcJobLogService.remove(hpcJobLog);
}
- hpcJobLogService.remove(hpcJobLog);
- }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/JsonWebTokenManager.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/JsonWebTokenManager.java
index a92acd0e78..db3ea1c36f 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/JsonWebTokenManager.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/manager/JsonWebTokenManager.java
@@ -18,53 +18,48 @@
*/
public class JsonWebTokenManager {
- private final Map jsonWebTokenMap;
+ private final Map jsonWebTokenMap;
- private final Map jsonWebTokenRequestTimeMap;
+ private final Map jsonWebTokenRequestTimeMap;
- private final static long TOKEN_VALID_TIME = 60 * 60 * 1000;// 1-hour
- // expired time
- // in
- // millisecond
- private boolean locked = false;
+ private final static long TOKEN_VALID_TIME = 60 * 60 * 1000;// 1-hour
+ // expired time
+ // in
+ // millisecond
+ private boolean locked = false;
- public JsonWebTokenManager() {
- jsonWebTokenMap = new HashMap<>();
- jsonWebTokenRequestTimeMap = new HashMap<>();
- }
-
- public synchronized JsonWebToken getJsonWebToken(final HpcAccount hpcAccount)
- throws Exception {
- if (locked) {
- Thread.sleep(100);
- getJsonWebToken(hpcAccount);
+ public JsonWebTokenManager() {
+ jsonWebTokenMap = new HashMap<>();
+ jsonWebTokenRequestTimeMap = new HashMap<>();
}
- locked = true;
- long now = System.currentTimeMillis();
- JsonWebToken jsonWebToken = jsonWebTokenMap.get(hpcAccount);
- if (jsonWebToken == null
- || (now - jsonWebTokenRequestTimeMap.get(hpcAccount).getTime()) > TOKEN_VALID_TIME) {
- final String username = hpcAccount.getUsername();
- final String password = hpcAccount.getPassword();
- final String scheme = hpcAccount.getScheme();
- final String hostname = hpcAccount.getHostname();
- final int port = hpcAccount.getPort();
+ public synchronized JsonWebToken getJsonWebToken(final HpcAccount hpcAccount) throws Exception {
+ if (locked) {
+ Thread.sleep(100);
+ getJsonWebToken(hpcAccount);
+ }
+ locked = true;
+ long now = System.currentTimeMillis();
+ JsonWebToken jsonWebToken = jsonWebTokenMap.get(hpcAccount);
+ if (jsonWebToken == null || (now - jsonWebTokenRequestTimeMap.get(hpcAccount).getTime()) > TOKEN_VALID_TIME) {
+
+ final String username = hpcAccount.getUsername();
+ final String password = hpcAccount.getPassword();
+ final String scheme = hpcAccount.getScheme();
+ final String hostname = hpcAccount.getHostname();
+ final int port = hpcAccount.getPort();
- RestHttpsClient restClient = new RestHttpsClient(username,
- password, scheme, hostname, port);
+ RestHttpsClient restClient = new RestHttpsClient(username, password, scheme, hostname, port);
- // Authentication
- UserService userService = new UserService(restClient, scheme,
- hostname, port);
- // JWT token is valid for 1 hour
- jsonWebToken = userService.requestJWT();
- jsonWebTokenMap.put(hpcAccount, jsonWebToken);
- jsonWebTokenRequestTimeMap.put(hpcAccount,
- new Date(System.currentTimeMillis()));
+ // Authentication
+ UserService userService = new UserService(restClient, scheme, hostname, port);
+ // JWT token is valid for 1 hour
+ jsonWebToken = userService.requestJWT();
+ jsonWebTokenMap.put(hpcAccount, jsonWebToken);
+ jsonWebTokenRequestTimeMap.put(hpcAccount, new Date(System.currentTimeMillis()));
+ }
+ locked = false;
+ return jsonWebToken;
}
- locked = false;
- return jsonWebToken;
- }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobPreProcessTask.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobPreProcessTask.java
index b19746d605..eb0b0a414e 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobPreProcessTask.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobPreProcessTask.java
@@ -33,253 +33,222 @@
*/
public class HpcJobPreProcessTask implements Runnable {
- private final HpcJobInfo hpcJobInfo;
-
- public HpcJobPreProcessTask(final HpcJobInfo hpcJobInfo) {
- this.hpcJobInfo = hpcJobInfo;
- }
-
- @Override
- public void run() {
- TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
- while (desktop == null) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ private final HpcJobInfo hpcJobInfo;
+
+ public HpcJobPreProcessTask(final HpcJobInfo hpcJobInfo) {
+ this.hpcJobInfo = hpcJobInfo;
}
- final HpcAccountManager hpcAccountManager = desktop
- .getHpcAccountManager();
- final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
-
- HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
-
- AlgorithmParamRequest algorParamReq = hpcJobInfo
- .getAlgorithmParamRequest();
- String datasetPath = algorParamReq.getDatasetPath();
- String priorKnowledgePath = algorParamReq.getPriorKnowledgePath();
-
- try {
- HpcAccountService hpcAccountService = hpcJobManager
- .getHpcAccountService(hpcAccount);
-
- HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
-
- String log = "Initiated connection to "
- + hpcAccount.getConnectionName();
- System.out.println(log);
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
-
- log = "datasetPath: " + datasetPath;
- System.out.println(log);
- Path file = Paths.get(datasetPath);
- // Get file's MD5 hash and use it as its identifier
- String md5 = algorParamReq.getDatasetMd5();
-
- // Initiate data uploading progress
- hpcJobManager.updateUploadFileProgress(datasetPath, 0);
-
- Path prior = null;
- if (priorKnowledgePath != null) {
- log = "priorKnowledgePath: " + priorKnowledgePath;
- System.out.println(log);
- prior = Paths.get(priorKnowledgePath);
-
- // Initiate prior knowledge uploading progress
- hpcJobManager.updateUploadFileProgress(priorKnowledgePath, 0);
- }
-
- // Check if this dataset already exists with this md5 hash
- RemoteDataFileService remoteDataService = hpcAccountService
- .getRemoteDataService();
-
- DataFile dataFile = HpcAccountUtils.getRemoteDataFile(
- hpcAccountManager, remoteDataService, hpcAccount, md5);
- DataUploadService dataUploadService = hpcAccountService
- .getDataUploadService();
-
- // If not, upload the file
- if (dataFile == null) {
- log = "Started uploading " + file.getFileName().toString();
- System.out.println(log);
- dataUploadService.startUpload(file, HpcAccountUtils
- .getJsonWebToken(hpcAccountManager, hpcAccount));
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
-
- int progress;
- while ((progress = dataUploadService.getUploadJobStatus(file
- .toAbsolutePath().toString())) < 100) {
- // System.out.println("Uploading "
- // + file.toAbsolutePath().toString() + " Progress: "
- // + progress + "%");
- hpcJobManager.updateUploadFileProgress(datasetPath,
- progress);
- Thread.sleep(10);
- }
- hpcJobManager.updateUploadFileProgress(datasetPath, progress);
-
- log = "Finished uploading " + file.getFileName().toString();
- System.out.println(log);
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
-
- // Get remote datafile
- dataFile = HpcAccountUtils.getRemoteDataFile(hpcAccountManager,
- remoteDataService, hpcAccount, md5);
-
- HpcAccountUtils
- .summarizeDataset(remoteDataService, algorParamReq,
- dataFile.getId(), HpcAccountUtils
- .getJsonWebToken(hpcAccountManager,
- hpcAccount));
- log = "Summarized " + file.getFileName().toString();
- System.out.println(log);
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
- } else {
- log = "Skipped uploading " + file.getFileName().toString();
- System.out.println(log);
-
- hpcJobManager.updateUploadFileProgress(datasetPath, -1);
-
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
-
- if (dataFile.getFileSummary().getVariableType() == null) {
- HpcAccountUtils.summarizeDataset(remoteDataService,
- algorParamReq, dataFile.getId(), HpcAccountUtils
- .getJsonWebToken(hpcAccountManager,
- hpcAccount));
- log = "Summarized " + file.getFileName().toString();
- System.out.println(log);
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1,
- "Summarized " + file.getFileName().toString());
+ @Override
+ public void run() {
+ TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
+ while (desktop == null) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
+ final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
+ final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
- }
-
- DataFile priorKnowledgeFile = null;
-
- // Prior Knowledge File
- if (prior != null) {
- // Get prior knowledge file Id
- md5 = algorParamReq.getPriorKnowledgeMd5();
-
- priorKnowledgeFile = HpcAccountUtils
- .getRemotePriorKnowledgeFile(hpcAccountManager,
- remoteDataService, hpcAccount, md5);
-
- if (priorKnowledgeFile == null) {
- // Upload prior knowledge file
- dataUploadService.startUpload(prior, HpcAccountUtils
- .getJsonWebToken(hpcAccountManager, hpcAccount));
+ HpcAccount hpcAccount = hpcJobInfo.getHpcAccount();
+
+ AlgorithmParamRequest algorParamReq = hpcJobInfo.getAlgorithmParamRequest();
+ String datasetPath = algorParamReq.getDatasetPath();
+ String priorKnowledgePath = algorParamReq.getPriorKnowledgePath();
+
+ try {
+ HpcAccountService hpcAccountService = hpcJobManager.getHpcAccountService(hpcAccount);
+
+ HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
+
+ String log = "Initiated connection to " + hpcAccount.getConnectionName();
+ System.out.println(log);
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+
+ log = "datasetPath: " + datasetPath;
+ System.out.println(log);
+ Path file = Paths.get(datasetPath);
+ // Get file's MD5 hash and use it as its identifier
+ String md5 = algorParamReq.getDatasetMd5();
+
+ // Initiate data uploading progress
+ hpcJobManager.updateUploadFileProgress(datasetPath, 0);
- log = "Started uploading Prior Knowledge File";
- System.out.println(log);
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+ Path prior = null;
+ if (priorKnowledgePath != null) {
+ log = "priorKnowledgePath: " + priorKnowledgePath;
+ System.out.println(log);
+ prior = Paths.get(priorKnowledgePath);
- int progress;
- while ((progress = dataUploadService
- .getUploadJobStatus(prior.toAbsolutePath()
- .toString())) < 100) {
- hpcJobManager.updateUploadFileProgress(
- priorKnowledgePath, progress);
- Thread.sleep(10);
- }
-
- hpcJobManager.updateUploadFileProgress(priorKnowledgePath,
- progress);
-
- priorKnowledgeFile = HpcAccountUtils
- .getRemotePriorKnowledgeFile(hpcAccountManager,
- remoteDataService, hpcAccount, md5);
-
- log = "Finished uploading Prior Knowledge File";
- System.out.println(log);
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+ // Initiate prior knowledge uploading progress
+ hpcJobManager.updateUploadFileProgress(priorKnowledgePath, 0);
+ }
+ // Check if this dataset already exists with this md5 hash
+ RemoteDataFileService remoteDataService = hpcAccountService.getRemoteDataService();
+
+ DataFile dataFile = HpcAccountUtils.getRemoteDataFile(hpcAccountManager, remoteDataService, hpcAccount,
+ md5);
+ DataUploadService dataUploadService = hpcAccountService.getDataUploadService();
+
+ // If not, upload the file
+ if (dataFile == null) {
+ log = "Started uploading " + file.getFileName().toString();
+ System.out.println(log);
+ dataUploadService.startUpload(file, HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+
+ int progress;
+ while ((progress = dataUploadService.getUploadJobStatus(file.toAbsolutePath().toString())) < 100) {
+ // System.out.println("Uploading "
+ // + file.toAbsolutePath().toString() + " Progress: "
+ // + progress + "%");
+ hpcJobManager.updateUploadFileProgress(datasetPath, progress);
+ Thread.sleep(10);
+ }
+
+ hpcJobManager.updateUploadFileProgress(datasetPath, progress);
+
+ log = "Finished uploading " + file.getFileName().toString();
+ System.out.println(log);
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+
+ // Get remote datafile
+ dataFile = HpcAccountUtils.getRemoteDataFile(hpcAccountManager, remoteDataService, hpcAccount, md5);
+
+ HpcAccountUtils.summarizeDataset(remoteDataService, algorParamReq, dataFile.getId(),
+ HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
+ log = "Summarized " + file.getFileName().toString();
+ System.out.println(log);
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+ } else {
+ log = "Skipped uploading " + file.getFileName().toString();
+ System.out.println(log);
+
+ hpcJobManager.updateUploadFileProgress(datasetPath, -1);
+
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+
+ if (dataFile.getFileSummary().getVariableType() == null) {
+ HpcAccountUtils.summarizeDataset(remoteDataService, algorParamReq, dataFile.getId(),
+ HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
+ log = "Summarized " + file.getFileName().toString();
+ System.out.println(log);
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, "Summarized " + file.getFileName().toString());
+ }
+
+ }
+
+ DataFile priorKnowledgeFile = null;
+
+ // Prior Knowledge File
+ if (prior != null) {
+ // Get prior knowledge file Id
+ md5 = algorParamReq.getPriorKnowledgeMd5();
+
+ priorKnowledgeFile = HpcAccountUtils.getRemotePriorKnowledgeFile(hpcAccountManager, remoteDataService,
+ hpcAccount, md5);
+
+ if (priorKnowledgeFile == null) {
+ // Upload prior knowledge file
+ dataUploadService.startUpload(prior,
+ HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
+
+ log = "Started uploading Prior Knowledge File";
+ System.out.println(log);
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+
+ int progress;
+ while ((progress = dataUploadService.getUploadJobStatus(prior.toAbsolutePath().toString())) < 100) {
+ hpcJobManager.updateUploadFileProgress(priorKnowledgePath, progress);
+ Thread.sleep(10);
+ }
+
+ hpcJobManager.updateUploadFileProgress(priorKnowledgePath, progress);
+
+ priorKnowledgeFile = HpcAccountUtils.getRemotePriorKnowledgeFile(hpcAccountManager,
+ remoteDataService, hpcAccount, md5);
+
+ log = "Finished uploading Prior Knowledge File";
+ System.out.println(log);
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, -1, log);
+
+ }
+
+ }
+
+ // Algorithm Job Preparation
+ edu.pitt.dbmi.ccd.rest.client.dto.algo.AlgorithmParamRequest paramRequest = new edu.pitt.dbmi.ccd.rest.client.dto.algo.AlgorithmParamRequest();
+ paramRequest.setDatasetFileId(dataFile.getId());
+
+ Map dataValidation = new HashMap<>();
+ dataValidation.put("skipUniqueVarName", false);
+ System.out.println("dataValidation: skipUniqueVarName: false");
+ if (algorParamReq.getVariableType().equalsIgnoreCase("discrete")) {
+ dataValidation.put("skipNonzeroVariance", false);
+ System.out.println("dataValidation: skipNonzeroVariance: false");
+ } else {
+ dataValidation.put("skipCategoryLimit", false);
+ System.out.println("dataValidation: skipCategoryLimit: false");
+ }
+ paramRequest.setDataValidation(dataValidation);
+
+ Map algorithmParameters = new HashMap<>();
+ for (AlgorithmParameter param : algorParamReq.getAlgorithmParameters()) {
+ algorithmParameters.put(param.getParameter(), param.getValue());
+ System.out.println("AlgorithmParameter: " + param.getParameter() + " : " + param.getValue());
+ }
+
+ if (priorKnowledgeFile != null) {
+ algorithmParameters.put("priorKnowledgeFileId", priorKnowledgeFile.getId());
+ System.out.println("priorKnowledgeFileId: " + priorKnowledgeFile.getId());
+ }
+ paramRequest.setAlgorithmParameters(algorithmParameters);
+
+ Map jvmOptions = new HashMap<>();
+ for (JvmOption jvmOption : algorParamReq.getJvmOptions()) {
+ jvmOptions.put(jvmOption.getParameter(), jvmOption.getValue());
+ System.out.println("JvmOption: " + jvmOption.getParameter() + " : " + jvmOption.getValue());
+ }
+ paramRequest.setJvmOptions(jvmOptions);
+
+ // Submit a job
+ String algorithmName = hpcJobInfo.getAlgorithmName();
+ JobQueueService jobQueueService = hpcAccountService.getJobQueueService();
+ JobInfo jobInfo = jobQueueService.addToRemoteQueue(algorithmName, paramRequest,
+ HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
+
+ // Log the job submission
+ hpcJobInfo.setSubmittedTime(new Date(System.currentTimeMillis()));
+ hpcJobInfo.setStatus(0); // Submitted
+ hpcJobInfo.setPid(jobInfo.getId());
+ hpcJobInfo.setResultFileName(jobInfo.getResultFileName());
+ hpcJobInfo.setResultJsonFileName(jobInfo.getResultJsonFileName());
+ hpcJobInfo.setErrorResultFileName(jobInfo.getErrorResultFileName());
+
+ hpcJobManager.updateHpcJobInfo(hpcJobInfo);
+
+ log = "Submitted job to " + hpcAccount.getConnectionName();
+ System.out.println(log);
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, 0, log);
+
+ System.out.println(
+ "HpcJobPreProcessTask: HpcJobInfo: id : " + hpcJobInfo.getId() + " : pid : " + hpcJobInfo.getPid()
+ + " : " + hpcJobInfo.getAlgorithmName() + " : " + hpcJobInfo.getResultFileName());
+
+ hpcJobManager.addNewSubmittedHpcJob(hpcJobInfo);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- }
-
- // Algorithm Job Preparation
- edu.pitt.dbmi.ccd.rest.client.dto.algo.AlgorithmParamRequest paramRequest = new edu.pitt.dbmi.ccd.rest.client.dto.algo.AlgorithmParamRequest();
- paramRequest.setDatasetFileId(dataFile.getId());
-
- Map dataValidation = new HashMap<>();
- dataValidation.put("skipUniqueVarName", false);
- System.out.println("dataValidation: skipUniqueVarName: false");
- if (algorParamReq.getVariableType().equalsIgnoreCase("discrete")) {
- dataValidation.put("skipNonzeroVariance", false);
- System.out
- .println("dataValidation: skipNonzeroVariance: false");
- } else {
- dataValidation.put("skipCategoryLimit", false);
- System.out.println("dataValidation: skipCategoryLimit: false");
- }
- paramRequest.setDataValidation(dataValidation);
-
- Map algorithmParameters = new HashMap<>();
- for (AlgorithmParameter param : algorParamReq
- .getAlgorithmParameters()) {
- algorithmParameters.put(param.getParameter(), param.getValue());
- System.out.println("AlgorithmParameter: "
- + param.getParameter() + " : " + param.getValue());
- }
-
- if (priorKnowledgeFile != null) {
- algorithmParameters.put("priorKnowledgeFileId",
- priorKnowledgeFile.getId());
- System.out.println("priorKnowledgeFileId: "
- + priorKnowledgeFile.getId());
- }
- paramRequest.setAlgorithmParameters(algorithmParameters);
-
- Map jvmOptions = new HashMap<>();
- for (JvmOption jvmOption : algorParamReq.getJvmOptions()) {
- jvmOptions.put(jvmOption.getParameter(), jvmOption.getValue());
- System.out.println("JvmOption: " + jvmOption.getParameter()
- + " : " + jvmOption.getValue());
- }
- paramRequest.setJvmOptions(jvmOptions);
-
- // Submit a job
- String algorithmName = hpcJobInfo.getAlgorithmName();
- JobQueueService jobQueueService = hpcAccountService
- .getJobQueueService();
- JobInfo jobInfo = jobQueueService.addToRemoteQueue(algorithmName,
- paramRequest, HpcAccountUtils.getJsonWebToken(
- hpcAccountManager, hpcAccount));
-
- // Log the job submission
- hpcJobInfo.setSubmittedTime(new Date(System.currentTimeMillis()));
- hpcJobInfo.setStatus(0); // Submitted
- hpcJobInfo.setPid(jobInfo.getId());
- hpcJobInfo.setResultFileName(jobInfo.getResultFileName());
- hpcJobInfo.setResultJsonFileName(jobInfo.getResultJsonFileName());
- hpcJobInfo.setErrorResultFileName(jobInfo.getErrorResultFileName());
-
- hpcJobManager.updateHpcJobInfo(hpcJobInfo);
-
- log = "Submitted job to " + hpcAccount.getConnectionName();
- System.out.println(log);
- hpcJobManager.logHpcJobLogDetail(hpcJobLog, 0, log);
-
- System.out.println("HpcJobPreProcessTask: HpcJobInfo: id : "
- + hpcJobInfo.getId() + " : pid : " + hpcJobInfo.getPid()
- + " : " + hpcJobInfo.getAlgorithmName() + " : "
- + hpcJobInfo.getResultFileName());
-
- hpcJobManager.addNewSubmittedHpcJob(hpcJobInfo);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
- }
-
- public HpcJobInfo getHpcJobInfo() {
- return hpcJobInfo;
- }
+ public HpcJobInfo getHpcJobInfo() {
+ return hpcJobInfo;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobsScheduledTask.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobsScheduledTask.java
index 78a38f2b80..3440128912 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobsScheduledTask.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/HpcJobsScheduledTask.java
@@ -32,304 +32,251 @@
*/
public class HpcJobsScheduledTask extends TimerTask {
- public HpcJobsScheduledTask() {
- }
-
- // Pooling job status from HPC nodes
- @Override
- public void run() {
- TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
- if (desktop == null)
- return;
-
- final HpcAccountManager hpcAccountManager = desktop
- .getHpcAccountManager();
- final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
-
- System.out.println("HpcJobsScheduledTask: "
- + new Date(System.currentTimeMillis()));
-
- // Load active jobs: Status (0 = Submitted; 1 = Running; 2 = Kill
- // Request)
- Map> submittedHpcJobInfos = hpcJobManager
- .getSubmittedHpcJobInfoMap();
- if (submittedHpcJobInfos.size() == 0) {
- System.out.println("Submitted job pool is empty!");
- } else {
- System.out.println("Submitted job pool has "
- + submittedHpcJobInfos.keySet().size() + " hpcAccount"
- + (submittedHpcJobInfos.keySet().size() > 1 ? "s" : ""));
+ public HpcJobsScheduledTask() {
}
- for (HpcAccount hpcAccount : submittedHpcJobInfos.keySet()) {
+ // Pooling job status from HPC nodes
+ @Override
+ public void run() {
+ TetradDesktop desktop = (TetradDesktop) DesktopController.getInstance();
+ if (desktop == null)
+ return;
- System.out.println("HpcJobsScheduledTask: "
- + hpcAccount.getConnectionName());
+ final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
+ final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
- Set hpcJobInfos = submittedHpcJobInfos.get(hpcAccount);
- // Pid-HpcJobInfo map
- Map hpcJobInfoMap = new HashMap<>();
- for (HpcJobInfo hpcJobInfo : hpcJobInfos) {
- if (hpcJobInfo.getPid() != null) {
- long pid = hpcJobInfo.getPid().longValue();
- hpcJobInfoMap.put(pid, hpcJobInfo);
-
- System.out.println("id: " + hpcJobInfo.getId() + " : "
- + hpcJobInfo.getAlgorithmName() + ": pid: " + pid
- + " : " + hpcJobInfo.getResultFileName());
+ System.out.println("HpcJobsScheduledTask: " + new Date(System.currentTimeMillis()));
+ // Load active jobs: Status (0 = Submitted; 1 = Running; 2 = Kill
+ // Request)
+ Map> submittedHpcJobInfos = hpcJobManager.getSubmittedHpcJobInfoMap();
+ if (submittedHpcJobInfos.size() == 0) {
+ System.out.println("Submitted job pool is empty!");
} else {
+ System.out.println("Submitted job pool has " + submittedHpcJobInfos.keySet().size() + " hpcAccount"
+ + (submittedHpcJobInfos.keySet().size() > 1 ? "s" : ""));
+ }
- System.out.println("id: " + hpcJobInfo.getId() + " : "
- + hpcJobInfo.getAlgorithmName() + ": no pid! : "
- + hpcJobInfo.getResultFileName());
+ for (HpcAccount hpcAccount : submittedHpcJobInfos.keySet()) {
- hpcJobInfos.remove(hpcJobInfo);
- }
- }
-
- // Finished job map
- HashMap finishedJobMap = new HashMap<>();
- for (HpcJobInfo job : hpcJobInfos) {
- finishedJobMap.put(job.getPid(), job);
- }
-
- try {
- List jobInfos = hpcJobManager.getRemoteActiveJobs(
- hpcAccountManager, hpcAccount);
-
- for (JobInfo jobInfo : jobInfos) {
- System.out.println("Remote pid: " + jobInfo.getId() + " : "
- + jobInfo.getAlgorithmName() + " : "
- + 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"));
- HpcJobInfo hpcJobInfo = hpcJobInfoMap.get(pid);// Local job
- // 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;
- System.out.println(hpcJobInfo.getAlgorithmName()
- + " : id : " + hpcJobInfo.getId()
- + " : pid : " + pid);
- System.out.println(log);
-
- hpcJobManager.logHpcJobLogDetail(hpcJobLog,
- remoteStatus, log);
+ System.out.println("HpcJobsScheduledTask: " + hpcAccount.getConnectionName());
+
+ Set hpcJobInfos = submittedHpcJobInfos.get(hpcAccount);
+ // Pid-HpcJobInfo map
+ Map hpcJobInfoMap = new HashMap<>();
+ for (HpcJobInfo hpcJobInfo : hpcJobInfos) {
+ if (hpcJobInfo.getPid() != null) {
+ long pid = hpcJobInfo.getPid().longValue();
+ hpcJobInfoMap.put(pid, hpcJobInfo);
+
+ System.out.println("id: " + hpcJobInfo.getId() + " : " + hpcJobInfo.getAlgorithmName() + ": pid: "
+ + pid + " : " + hpcJobInfo.getResultFileName());
+
+ } else {
+
+ System.out.println("id: " + hpcJobInfo.getId() + " : " + hpcJobInfo.getAlgorithmName()
+ + ": no pid! : " + hpcJobInfo.getResultFileName());
+
+ hpcJobInfos.remove(hpcJobInfo);
+ }
}
- }
- }
- // Download finished jobs' results
- if (finishedJobMap.size() > 0) {
- Set resultFiles = hpcJobManager
- .listRemoteAlgorithmResultFiles(hpcAccountManager,
- hpcAccount);
-
- Set resultFileNames = new HashSet<>();
- for (ResultFile resultFile : resultFiles) {
- resultFileNames.add(resultFile.getName());
- // System.out.println(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";
- int recentStatus = 3; // Finished
- if (hpcJobInfo.getStatus() == 2) {
- recentStatusText = "Job killed";
- recentStatus = 4; // Killed
+ // Finished job map
+ HashMap finishedJobMap = new HashMap<>();
+ for (HpcJobInfo job : hpcJobInfos) {
+ finishedJobMap.put(job.getPid(), job);
}
- hpcJobInfo.setStatus(recentStatus);
- hpcJobManager.updateHpcJobInfo(hpcJobInfo);
- // System.out.println("hpcJobInfo: id: "
- // + hpcJobInfo.getId() + " : "
- // + hpcJobInfo.getStatus());
+ try {
+ List jobInfos = hpcJobManager.getRemoteActiveJobs(hpcAccountManager, hpcAccount);
+
+ for (JobInfo jobInfo : jobInfos) {
+ System.out.println("Remote pid: " + jobInfo.getId() + " : " + jobInfo.getAlgorithmName() + " : "
+ + 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"));
+ HpcJobInfo hpcJobInfo = hpcJobInfoMap.get(pid);// Local job
+ // 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;
+ System.out.println(hpcJobInfo.getAlgorithmName() + " : id : " + hpcJobInfo.getId()
+ + " : pid : " + pid);
+ System.out.println(log);
+
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, remoteStatus, log);
+ }
+ }
+ }
- hpcJobManager.logHpcJobLogDetail(hpcJobLog,
- recentStatus, recentStatusText);
+ // Download finished jobs' results
+ if (finishedJobMap.size() > 0) {
+ Set resultFiles = hpcJobManager.listRemoteAlgorithmResultFiles(hpcAccountManager,
+ hpcAccount);
- System.out.println(hpcJobInfo.getAlgorithmName()
- + " : id : " + hpcJobInfo.getId() + " : "
- + recentStatusText);
+ Set resultFileNames = new HashSet<>();
+ for (ResultFile resultFile : resultFiles) {
+ resultFileNames.add(resultFile.getName());
+ // System.out.println(hpcAccount.getConnectionName()
+ // + " Result : " + resultFile.getName());
+ }
- GeneralAlgorithmEditor editor = hpcJobManager
- .getGeneralAlgorithmEditor(hpcJobInfo);
- if (editor != null) {
- System.out
- .println("GeneralAlgorithmEditor is not null");
+ for (HpcJobInfo hpcJobInfo : finishedJobMap.values()) {// Job
+ // is
+ // done
+ // or
+ // killed or
+ // time-out
+ HpcJobLog hpcJobLog = hpcJobManager.getHpcJobLog(hpcJobInfo);
+ String recentStatusText = "Job finished";
+ int recentStatus = 3; // Finished
+ if (hpcJobInfo.getStatus() == 2) {
+ recentStatusText = "Job killed";
+ recentStatus = 4; // Killed
+ }
+ hpcJobInfo.setStatus(recentStatus);
+ hpcJobManager.updateHpcJobInfo(hpcJobInfo);
- String resultJsonFileName = hpcJobInfo
- .getResultJsonFileName();
- String errorResultFileName = hpcJobInfo
- .getErrorResultFileName();
+ // System.out.println("hpcJobInfo: id: "
+ // + hpcJobInfo.getId() + " : "
+ // + hpcJobInfo.getStatus());
- if (resultFileNames.contains(resultJsonFileName)) {
- recentStatus = 5; // Result Downloaded
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, recentStatusText);
- String json = downloadAlgorithmResultFile(
- hpcAccountManager, hpcJobManager,
- hpcAccount, resultJsonFileName, editor);
+ System.out.println(hpcJobInfo.getAlgorithmName() + " : id : " + hpcJobInfo.getId() + " : "
+ + recentStatusText);
- if (!json.toLowerCase().contains("not found")) {
- editor.setAlgorithmResult(json);
- }
+ GeneralAlgorithmEditor editor = hpcJobManager.getGeneralAlgorithmEditor(hpcJobInfo);
+ if (editor != null) {
+ System.out.println("GeneralAlgorithmEditor is not null");
- String log = "Result downloaded";
- hpcJobManager.logHpcJobLogDetail(hpcJobLog,
- recentStatus, log);
+ String resultJsonFileName = hpcJobInfo.getResultJsonFileName();
+ String errorResultFileName = hpcJobInfo.getErrorResultFileName();
- System.out.println(hpcJobInfo
- .getAlgorithmName()
- + " : id : "
- + hpcJobInfo.getId() + " : " + log);
+ if (resultFileNames.contains(resultJsonFileName)) {
+ recentStatus = 5; // Result Downloaded
- } else if (resultFileNames
- .contains(errorResultFileName)) {
- recentStatus = 6; // Error Result Downloaded
+ String json = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager, hpcAccount,
+ resultJsonFileName, editor);
- String error = downloadAlgorithmResultFile(
- hpcAccountManager, hpcJobManager,
- hpcAccount, errorResultFileName, editor);
+ if (!json.toLowerCase().contains("not found")) {
+ editor.setAlgorithmResult(json);
+ }
- if (!error.toLowerCase().contains("not found")) {
- editor.setAlgorithmErrorResult(error);
- }
+ String log = "Result downloaded";
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
- String log = "Error Result downloaded";
- hpcJobManager.logHpcJobLogDetail(hpcJobLog,
- recentStatus, log);
+ System.out.println(
+ hpcJobInfo.getAlgorithmName() + " : id : " + hpcJobInfo.getId() + " : " + log);
- System.out.println(hpcJobInfo
- .getAlgorithmName()
- + " : id : "
- + hpcJobInfo.getId() + " : " + log);
+ } else if (resultFileNames.contains(errorResultFileName)) {
+ recentStatus = 6; // Error Result Downloaded
- } else {
+ String error = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager, hpcAccount,
+ errorResultFileName, editor);
- // Try again
- Thread.sleep(5000);
+ if (!error.toLowerCase().contains("not found")) {
+ editor.setAlgorithmErrorResult(error);
+ }
- String json = downloadAlgorithmResultFile(
- hpcAccountManager, hpcJobManager,
- hpcAccount, resultJsonFileName, editor);
+ String log = "Error Result downloaded";
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
- if (!json.toLowerCase().contains("not found")) {
- editor.setAlgorithmResult(json);
+ System.out.println(
+ hpcJobInfo.getAlgorithmName() + " : id : " + hpcJobInfo.getId() + " : " + log);
- recentStatus = 5; // Result Downloaded
+ } else {
- String log = "Result downloaded";
- hpcJobManager.logHpcJobLogDetail(hpcJobLog,
- recentStatus, log);
+ // Try again
+ Thread.sleep(5000);
- System.out.println(hpcJobInfo
- .getAlgorithmName()
- + " : id : "
- + hpcJobInfo.getId() + " : " + log);
- } else {
- String error = downloadAlgorithmResultFile(
- hpcAccountManager, hpcJobManager,
- hpcAccount, errorResultFileName,
- editor);
-
- if (!error.toLowerCase().contains(
- "not found")) {
- editor.setAlgorithmErrorResult(error);
-
- recentStatus = 6; // Error Result
- // Downloaded
-
- String log = "Error Result downloaded";
- hpcJobManager.logHpcJobLogDetail(
- hpcJobLog, recentStatus, log);
-
- System.out.println(hpcJobInfo
- .getAlgorithmName()
- + " : id : "
- + hpcJobInfo.getId()
- + " : "
- + log);
- } else {
- recentStatus = 7; // Result Not Found
-
- String log = resultJsonFileName
- + " not found";
- hpcJobManager.logHpcJobLogDetail(
- hpcJobLog, recentStatus, log);
-
- System.out.println(hpcJobInfo
- .getAlgorithmName()
- + " : id : "
- + hpcJobInfo.getId()
- + " : "
- + log);
- }
+ String json = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager, hpcAccount,
+ resultJsonFileName, editor);
- }
+ if (!json.toLowerCase().contains("not found")) {
+ editor.setAlgorithmResult(json);
+
+ recentStatus = 5; // Result Downloaded
+
+ String log = "Result downloaded";
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
- }
+ System.out.println(hpcJobInfo.getAlgorithmName() + " : id : " + hpcJobInfo.getId()
+ + " : " + log);
+ } else {
+ String error = downloadAlgorithmResultFile(hpcAccountManager, hpcJobManager,
+ hpcAccount, errorResultFileName, editor);
+ if (!error.toLowerCase().contains("not found")) {
+ editor.setAlgorithmErrorResult(error);
+
+ recentStatus = 6; // Error Result
+ // Downloaded
+
+ String log = "Error Result downloaded";
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
+
+ System.out.println(hpcJobInfo.getAlgorithmName() + " : id : "
+ + hpcJobInfo.getId() + " : " + log);
+ } else {
+ recentStatus = 7; // Result Not Found
+
+ String log = resultJsonFileName + " not found";
+ hpcJobManager.logHpcJobLogDetail(hpcJobLog, recentStatus, log);
+
+ System.out.println(hpcJobInfo.getAlgorithmName() + " : id : "
+ + hpcJobInfo.getId() + " : " + log);
+ }
+
+ }
+
+ }
+
+ }
+ hpcJobManager.removeFinishedHpcJob(hpcJobInfo);
+ }
+ } else {
+ System.out.println("No finished job yet.");
+ }
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- hpcJobManager.removeFinishedHpcJob(hpcJobInfo);
- }
- } else {
- System.out.println("No finished job yet.");
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ }
}
- }
-
- private String downloadAlgorithmResultFile(
- final HpcAccountManager hpcAccountManager,
- final HpcJobManager hpcJobManager, final HpcAccount hpcAccount,
- final String resultFileName, final GeneralAlgorithmEditor editor)
- throws ClientProtocolException, URISyntaxException, IOException,
- Exception {
- int trial = 10;
- String txt = hpcJobManager.downloadAlgorithmResultFile(
- hpcAccountManager, hpcAccount, resultFileName);
- while (trial != 0 && txt.toLowerCase().contains("not found")) {
- Thread.sleep(5000);
- txt = hpcJobManager.downloadAlgorithmResultFile(hpcAccountManager,
- hpcAccount, resultFileName);
- trial--;
- }
+ private String downloadAlgorithmResultFile(final HpcAccountManager hpcAccountManager,
+ final HpcJobManager hpcJobManager, final HpcAccount hpcAccount, final String resultFileName,
+ final GeneralAlgorithmEditor editor)
+ throws ClientProtocolException, URISyntaxException, IOException, Exception {
+ int trial = 10;
+ String txt = hpcJobManager.downloadAlgorithmResultFile(hpcAccountManager, hpcAccount, resultFileName);
+ while (trial != 0 && txt.toLowerCase().contains("not found")) {
+ Thread.sleep(5000);
+ txt = hpcJobManager.downloadAlgorithmResultFile(hpcAccountManager, hpcAccount, resultFileName);
+ trial--;
+ }
- return txt;
- }
+ return txt;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/PendingHpcJobUpdaterTask.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/PendingHpcJobUpdaterTask.java
index 451d9707ef..ab821157d7 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/PendingHpcJobUpdaterTask.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/PendingHpcJobUpdaterTask.java
@@ -25,216 +25,168 @@
*/
public class PendingHpcJobUpdaterTask extends TimerTask {
- private final HpcJobManager hpcJobManager;
+ private final HpcJobManager hpcJobManager;
- private final HpcJobActivityEditor hpcJobActivityEditor;
+ private final HpcJobActivityEditor hpcJobActivityEditor;
- public PendingHpcJobUpdaterTask(final HpcJobManager hpcJobManager,
- final HpcJobActivityEditor hpcJobActivityEditor) {
- this.hpcJobManager = hpcJobManager;
- this.hpcJobActivityEditor = hpcJobActivityEditor;
- }
-
- @Override
- public void run() {
-
- if (hpcJobActivityEditor.selectedTabbedPaneIndex() != 0)
- return;
+ public PendingHpcJobUpdaterTask(final HpcJobManager hpcJobManager,
+ final HpcJobActivityEditor hpcJobActivityEditor) {
+ this.hpcJobManager = hpcJobManager;
+ this.hpcJobActivityEditor = hpcJobActivityEditor;
+ }
- final DefaultTableModel model = (DefaultTableModel) hpcJobActivityEditor
- .getJobsTableModel();
+ @Override
+ public void run() {
- Set pendingDisplayHpcJobInfoSet = hpcJobActivityEditor
- .getPendingDisplayHpcJobInfoSet();
+ if (hpcJobActivityEditor.selectedTabbedPaneIndex() != 0)
+ return;
- Set notPendingJobAnymoreSet = monitorDataUploadProgress(
- pendingDisplayHpcJobInfoSet, model);
+ final DefaultTableModel model = (DefaultTableModel) hpcJobActivityEditor.getJobsTableModel();
- hpcJobActivityEditor
- .addSubmittedDisplayHpcJobInfo(notPendingJobAnymoreSet);
+ Set pendingDisplayHpcJobInfoSet = hpcJobActivityEditor.getPendingDisplayHpcJobInfoSet();
- hpcJobActivityEditor
- .removePendingDisplayHpcJobInfo(notPendingJobAnymoreSet);
- }
+ Set notPendingJobAnymoreSet = monitorDataUploadProgress(pendingDisplayHpcJobInfoSet, model);
- private synchronized Set monitorDataUploadProgress(
- final Set pendingDisplayHpcJobInfoSet,
- final DefaultTableModel model) {
+ hpcJobActivityEditor.addSubmittedDisplayHpcJobInfo(notPendingJobAnymoreSet);
- Map rowMap = new HashMap<>();
- for (int row = 0; row < model.getRowCount(); row++) {
- rowMap.put(
- Long.valueOf(model.getValueAt(row,
- HpcJobActivityEditor.ID_COLUMN).toString()), row);
+ hpcJobActivityEditor.removePendingDisplayHpcJobInfo(notPendingJobAnymoreSet);
}
- Set notPendingJobAnymoreSet = new HashSet<>();
+ private synchronized Set monitorDataUploadProgress(final Set pendingDisplayHpcJobInfoSet,
+ final DefaultTableModel model) {
- for (HpcJobInfo hpcJobInfo : pendingDisplayHpcJobInfoSet) {
+ Map rowMap = new HashMap<>();
+ for (int row = 0; row < model.getRowCount(); row++) {
+ rowMap.put(Long.valueOf(model.getValueAt(row, HpcJobActivityEditor.ID_COLUMN).toString()), row);
+ }
- int status = hpcJobInfo.getStatus();
+ Set notPendingJobAnymoreSet = new HashSet<>();
- if (!rowMap.containsKey(hpcJobInfo.getId())) {
- continue;
- }
+ for (HpcJobInfo hpcJobInfo : pendingDisplayHpcJobInfoSet) {
- int modelRow = rowMap.get(hpcJobInfo.getId());
+ int status = hpcJobInfo.getStatus();
- // In case the job was accidentally added to the map OR the kill
- // request was issued
- if (status != -1) {
- notPendingJobAnymoreSet.add(hpcJobInfo);
- } else {
+ if (!rowMap.containsKey(hpcJobInfo.getId())) {
+ continue;
+ }
- // Dataset uploading progress
- AlgorithmParamRequest algorParamReq = hpcJobInfo
- .getAlgorithmParamRequest();
- String datasetPath = algorParamReq.getDatasetPath();
+ int modelRow = rowMap.get(hpcJobInfo.getId());
- int dataUploadProgress = hpcJobManager
- .getUploadFileProgress(datasetPath);
+ // In case the job was accidentally added to the map OR the kill
+ // request was issued
+ if (status != -1) {
+ notPendingJobAnymoreSet.add(hpcJobInfo);
+ } else {
- 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);
- }
+ // Dataset uploading progress
+ AlgorithmParamRequest algorParamReq = hpcJobInfo.getAlgorithmParamRequest();
+ String datasetPath = algorParamReq.getDatasetPath();
- // Prior Knowledge uploading progress
- String priorKnowledgePath = algorParamReq
- .getPriorKnowledgePath();
-
- int priorKnowledgeUploadProgress = -1;
- if (priorKnowledgePath != null) {
-
- System.out.println("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);
- }
+ int dataUploadProgress = hpcJobManager.getUploadFileProgress(datasetPath);
- if (dataUploadProgress == 100
- && (priorKnowledgeUploadProgress == -1 || priorKnowledgeUploadProgress == 100)) {
+ 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);
+ }
- System.out.println("HpcJobInfo Id: " + hpcJobInfo.getId()
- + " done with both uploading");
+ // Prior Knowledge uploading progress
+ String priorKnowledgePath = algorParamReq.getPriorKnowledgePath();
- Map> pendingHpcJobInfoMap = hpcJobManager
- .getPendingHpcJobInfoMap();
+ int priorKnowledgeUploadProgress = -1;
+ if (priorKnowledgePath != null) {
- Map> submittedHpcJobInfoMap = hpcJobManager
- .getSubmittedHpcJobInfoMap();
+ System.out.println("priorKnowledgePath: " + priorKnowledgePath);
- if (pendingHpcJobInfoMap != null) {
- Set pendingJobSet = pendingHpcJobInfoMap
- .get(hpcJobInfo.getHpcAccount());
+ priorKnowledgeUploadProgress = hpcJobManager.getUploadFileProgress(priorKnowledgePath);
- // 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;
- }
- }
+ 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);
+ }
- // The job is not in the pre-processed schedule task
- if (id == -1 && submittedHpcJobInfoMap != null) {
- Set 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;
+ if (dataUploadProgress == 100
+ && (priorKnowledgeUploadProgress == -1 || priorKnowledgeUploadProgress == 100)) {
+
+ System.out.println("HpcJobInfo Id: " + hpcJobInfo.getId() + " done with both uploading");
+
+ Map> pendingHpcJobInfoMap = hpcJobManager.getPendingHpcJobInfoMap();
+
+ Map> submittedHpcJobInfoMap = hpcJobManager.getSubmittedHpcJobInfoMap();
+
+ if (pendingHpcJobInfoMap != null) {
+ Set 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 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;
- }
+ return notPendingJobAnymoreSet;
+ }
}
diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/SubmittedHpcJobUpdaterTask.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/SubmittedHpcJobUpdaterTask.java
index 81ca9abc7a..098827003d 100644
--- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/SubmittedHpcJobUpdaterTask.java
+++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/hpc/task/SubmittedHpcJobUpdaterTask.java
@@ -24,113 +24,100 @@
*/
public class SubmittedHpcJobUpdaterTask extends TimerTask {
- private final HpcJobManager hpcJobManager;
+ private final HpcJobManager hpcJobManager;
- private final HpcJobActivityEditor hpcJobActivityEditor;
+ private final HpcJobActivityEditor hpcJobActivityEditor;
- public SubmittedHpcJobUpdaterTask(final HpcJobManager hpcJobManager,
- final HpcJobActivityEditor hpcJobActivityEditor) {
- this.hpcJobManager = hpcJobManager;
- this.hpcJobActivityEditor = hpcJobActivityEditor;
- }
-
- @Override
- public void run() {
- if (hpcJobActivityEditor.selectedTabbedPaneIndex() != 0)
- return;
-
- final DefaultTableModel model = (DefaultTableModel) hpcJobActivityEditor
- .getJobsTableModel();
+ public SubmittedHpcJobUpdaterTask(final HpcJobManager hpcJobManager,
+ final HpcJobActivityEditor hpcJobActivityEditor) {
+ this.hpcJobManager = hpcJobManager;
+ this.hpcJobActivityEditor = hpcJobActivityEditor;
+ }
- Set submittedDisplayHpcJobInfoSet = hpcJobActivityEditor
- .getSubmittedDisplayHpcJobInfoSet();
+ @Override
+ public void run() {
+ if (hpcJobActivityEditor.selectedTabbedPaneIndex() != 0)
+ return;
- Set finishedJobSet = monitorSubmittedJobStatus(
- submittedDisplayHpcJobInfoSet, model);
+ final DefaultTableModel model = (DefaultTableModel) hpcJobActivityEditor.getJobsTableModel();
- hpcJobActivityEditor.removeSubmittedDisplayHpcJobInfo(finishedJobSet);
+ Set submittedDisplayHpcJobInfoSet = hpcJobActivityEditor.getSubmittedDisplayHpcJobInfoSet();
- hpcJobActivityEditor
- .removeSubmittedDisplayJobFromActiveTableModel(finishedJobSet);
+ Set finishedJobSet = monitorSubmittedJobStatus(submittedDisplayHpcJobInfoSet, model);
- }
+ hpcJobActivityEditor.removeSubmittedDisplayHpcJobInfo(finishedJobSet);
- private synchronized Set monitorSubmittedJobStatus(
- final Set submittedDisplayHpcJobInfoSet,
- final DefaultTableModel model) {
+ hpcJobActivityEditor.removeSubmittedDisplayJobFromActiveTableModel(finishedJobSet);
- Map rowMap = new HashMap<>();
- for (int row = 0; row < model.getRowCount(); row++) {
- rowMap.put(
- Long.valueOf(model.getValueAt(row,
- HpcJobActivityEditor.ID_COLUMN).toString()), row);
}
- Set finishedJobSet = new HashSet<>();
-
- for (HpcJobInfo hpcJobInfo : submittedDisplayHpcJobInfoSet) {
+ private synchronized Set monitorSubmittedJobStatus(final Set submittedDisplayHpcJobInfoSet,
+ final DefaultTableModel model) {
- Long id = hpcJobInfo.getId();
-
- if (!rowMap.containsKey(id)) {
- //System.out.println("hpcJobInfo not found in rowMap");
- continue;
- }
+ Map rowMap = new HashMap<>();
+ for (int row = 0; row < model.getRowCount(); row++) {
+ rowMap.put(Long.valueOf(model.getValueAt(row, HpcJobActivityEditor.ID_COLUMN).toString()), row);
+ }
- int modelRow = rowMap.get(id);
+ Set