Skip to content

Commit

Permalink
Get the SBATCH config page to work better + various clena-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
samuell committed Aug 15, 2013
1 parent 852136d commit f819305
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 101 deletions.
Expand Up @@ -50,8 +50,13 @@ public class ConfigureCommandPage extends WizardPage implements Listener {
List<Widget> widgets;
private static Logger log;

/**
* Constructor
* @param workbench
* @param selection
*/
protected ConfigureCommandPage(IWorkbench workbench, IStructuredSelection selection) {
super("Page 3");
super("Configure Command Page");
setTitle("Select tool");
setDescription("Select a tool from the ones available in the tool group just selected ...");
this.workbench = workbench;
Expand All @@ -61,20 +66,15 @@ protected ConfigureCommandPage(IWorkbench workbench, IStructuredSelection select
this.log = LoggerFactory.getLogger(ConfigureCommandPage.class);
}

/**
* Set whether the "Next" button is active
*/
public boolean canFlipToNextPage() {
return true;
}

@Override
public void createControl(Composite parent) {
parentComposite = parent;
composite = new Composite(parent, SWT.NULL);
HPCUtils.createGridLayout(composite, 3);
setControl(composite);
}

void onEnterPage() {
Combo comboTool = ((SelectToolPage) this.getWizard().getPage("Page 2")).comboTool;
Combo comboTool = ((SelectToolPage) this.getWizard().getPage("Select Tool Page")).comboTool;
String selectedToolName = comboTool.getText();
if (currentTool != null) {
String currentToolName = currentTool.getName();
Expand All @@ -86,7 +86,7 @@ void onEnterPage() {
}
}

void drawPageForTool(String toolName) {
private void drawPageForTool(String toolName) {
createControl(parentComposite);
currentTool = ToolConfigDomain.getInstance().getToolByName(toolName);
parameters = currentTool.getParameters();
Expand All @@ -98,6 +98,14 @@ void drawPageForTool(String toolName) {
this.composite.pack();
}

@Override
public void createControl(Composite parent) {
parentComposite = parent;
composite = new Composite(parent, SWT.NULL);
HPCUtils.createGridLayout(composite, 3);
setControl(composite);
}

private void createResultingCommandTextbox(String commandString) {
createLabel("Resulting command");

Expand Down Expand Up @@ -366,7 +374,7 @@ public String getCommandText() {

@Override
public IWizardPage getNextPage() {
ConfigureSbatchScriptPage configSbatchScriptPage = ((ConfigureSbatchScriptPage) this.getWizard().getPage("Page 4"));
ConfigureSbatchScriptPage configSbatchScriptPage = ((ConfigureSbatchScriptPage) this.getWizard().getPage("Configure Sbatch Page"));
configSbatchScriptPage.onEnterPage();
return configSbatchScriptPage;
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class ConfigureSbatchScriptPage extends WizardPage implements Listener {


protected ConfigureSbatchScriptPage(IWorkbench workbench, IStructuredSelection selection) {
super("Page 4");
super("Configure Sbatch Page");
setTitle("Configure SBATCH parameters");
setDescription("Set the parameters for the SBATCH job batch script to be sent to the SLURM resource manager");
this.workbench = workbench;
Expand All @@ -61,8 +62,8 @@ protected ConfigureSbatchScriptPage(IWorkbench workbench, IStructuredSelection s
@Override
public void createControl(Composite parent) {
parentComposite = parent;
composite = new Composite(parent, SWT.NULL);
HPCUtils.createGridLayout(composite, 3);
composite = new Composite(parent, SWT.NULL );
HPCUtils.createGridLayout(composite, 2);
setControl(composite);
}

Expand All @@ -71,82 +72,12 @@ void onEnterPage() {
// Don't redraw wizard page on second visit
if (!this.initialized) {
this.initialized = true;
createControl(parentComposite);

// Get user info, to use for writing the SBATCH config
String currentBinary = ((ConfigureCommandPage) this.getWizard().getPage("Page 3")).currentTool.getBinary();
List<String> modulesForCommand = HPCUtils.getApplication().getModulesForBinary(currentBinary);

// Get user info, to use for writing the SBATCH config
Map<String,Object> userInfo = HPCUtils.getApplication().getUserInfo();
// String username = (String) userInfo.get("username");
List<String> projects = (List<String>) userInfo.get("projects");

// Get various info used for writing SBATCH config
Map<String,Object> clusterInfo = HPCUtils.getApplication().getClusterInfo();
String maxNodesStr = (String) clusterInfo.get("maxnodes");
String maxCpusStr = (String) clusterInfo.get("maxcpus");
List<String> partitions = (List<String>) clusterInfo.get("partitions");

// Populate wizard here
// Modules relevant to the binary chosen in the previous wizard page
createLabel("HPC Module to load");
createComboBox("module", modulesForCommand, 2);

// -A [project name] | Combo // TODO: Retrieve the user's project automatic
createLabel("Project to account");
createComboBox("project", projects, 2);

// -p [partition] | Combo // Simple list, or get info from cluster?
createLabel("Partition (type of job)");
createComboBox("partition", partitions, 2);

// -N [no of nodes] | Text-field / up-down number field?
createLabel("No of Nodes");
List<String> maxNodesStringList = new ArrayList<String>();
if (maxNodesStr != null) {
int maxNodes = Integer.parseInt(maxNodesStr);
if (maxNodes > 0) {
int[] nodeNos = HPCUtils.range(1, maxNodes, 1);
for (int i=0;i<maxNodes;i++) {
String nodeNoStr = Integer.toString(nodeNos[i]);
maxNodesStringList.add(nodeNoStr);
}
} else {
logger.error("MaxCPUs is zero!");
}
}
createComboBox("noofnodes", maxNodesStringList, 2);

// -n [no of cpus] | Text-field / up-down number field?
createLabel("No of CPUs");
List<String> maxCpusStringList = new ArrayList<String>();
if (maxCpusStr != null) {
int maxCpus = Integer.parseInt(maxCpusStr);
if (maxCpus > 0) {
int[] cpuNos = HPCUtils.range(1, maxCpus, 1);
for (int i=0;i<maxCpus;i++) {
String cpuNoStr = Integer.toString(cpuNos[i]);
maxCpusStringList.add(cpuNoStr);
}
} else {
logger.error("MaxCPUs is zero!");
}
}
createComboBox("noofcpus", maxCpusStringList, 2);

// -t d-hh:mm:ss | ?
createLabel("Running time (d-hh:mm:ss)"); // TODO: Find a good widget for setting the time?
createTextField("runtime", 2);

// --qos=short | Combo (yes/no)
createLabel("Activate --qos=short option?");
createComboBox("qosshort", Arrays.asList("no", "yes"), 2, "no");
// -J [JobName] | TextField
createLabel("Job name");
createTextField("jobname", 2, "Untitled");

createControl(parentComposite);
createSbatchConfigControls();
createResultingSBatchScriptTextbox();
updateCodeWindow();

this.composite.pack();

((ExecuteCommandWizard) this.getWizard()).setCanFinish(true);
Expand All @@ -155,12 +86,88 @@ void onEnterPage() {
}
}

private void createSbatchConfigControls() {
// Get user info, to use for writing the SBATCH config
String currentBinary = ((ConfigureCommandPage) this.getWizard().getPage("Configure Command Page")).currentTool.getBinary();
List<String> modulesForCommand = HPCUtils.getApplication().getModulesForBinary(currentBinary);

// Get user info, to use for writing the SBATCH config
Map<String,Object> userInfo = HPCUtils.getApplication().getUserInfo();
// String username = (String) userInfo.get("username");
List<String> projects = (List<String>) userInfo.get("projects");

// Get various info used for writing SBATCH config
Map<String,Object> clusterInfo = HPCUtils.getApplication().getClusterInfo();
String maxNodesStr = (String) clusterInfo.get("maxnodes");
String maxCpusStr = (String) clusterInfo.get("maxcpus");
List<String> partitions = (List<String>) clusterInfo.get("partitions");

// Populate wizard here
// Modules relevant to the binary chosen in the previous wizard page
createLabel("HPC Module to load");
createComboBox("module", modulesForCommand, 1);

// -A [project name] | Combo // TODO: Retrieve the user's project automatic
createLabel("Project to account");
createComboBox("project", projects, 1);

// -p [partition] | Combo // Simple list, or get info from cluster?
createLabel("Partition (type of job)");
createComboBox("partition", partitions, 1);

// -N [no of nodes] | Text-field / up-down number field?
createLabel("No of Nodes");
List<String> maxNodesStringList = new ArrayList<String>();
if (maxNodesStr != null) {
int maxNodes = Integer.parseInt(maxNodesStr);
if (maxNodes > 0) {
int[] nodeNos = HPCUtils.range(1, maxNodes, 1);
for (int i=0;i<maxNodes;i++) {
String nodeNoStr = Integer.toString(nodeNos[i]);
maxNodesStringList.add(nodeNoStr);
}
} else {
logger.error("MaxCPUs is zero!");
}
}
createComboBox("noofnodes", maxNodesStringList, 1);

// -n [no of cpus] | Text-field / up-down number field?
createLabel("No of CPUs");
List<String> maxCpusStringList = new ArrayList<String>();
if (maxCpusStr != null) {
int maxCpus = Integer.parseInt(maxCpusStr);
if (maxCpus > 0) {
int[] cpuNos = HPCUtils.range(1, maxCpus, 1);
for (int i=0;i<maxCpus;i++) {
String cpuNoStr = Integer.toString(cpuNos[i]);
maxCpusStringList.add(cpuNoStr);
}
} else {
logger.error("MaxCPUs is zero!");
}
}
createComboBox("noofcpus", maxCpusStringList, 1);

// -t d-hh:mm:ss | ?
createLabel("Running time (d-hh:mm:ss)"); // TODO: Find a good widget for setting the time?
createTextField("runtime", 1);

// --qos=short | Combo (yes/no)
createLabel("Activate --qos=short option?");
createComboBox("qosshort", Arrays.asList("no", "yes"), 1, "no");
// -J [JobName] | TextField
createLabel("Job name");
createTextField("jobname", 1, "Untitled");
}

private void createResultingSBatchScriptTextbox() {
createLabel("Resulting SBATCH Script");
sbatchStyledText = new StyledText(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL );
sbatchStyledText.setText(this.getDefaultSbatchTextWithCommand());
GridData gd = new GridData( SWT.NONE|GridData.FILL_BOTH );
gd.horizontalSpan = 2;
sbatchStyledText = new StyledText(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL ); // SWT.WRAP
GridData gd = new GridData( SWT.NONE | GridData.FILL_BOTH );
gd.grabExcessHorizontalSpace = true;
gd.minimumWidth = 320;
gd.heightHint = 180;
sbatchStyledText.setLayoutData(gd);
}

Expand Down Expand Up @@ -261,7 +268,7 @@ private void updateCodeWindow() {
}

private String getDefaultSbatchTextWithCommand() {
String command = ((ConfigureCommandPage) this.getWizard().getPage("Page 3")).getCommandText();
String command = ((ConfigureCommandPage) this.getWizard().getPage("Configure Command Page")).getCommandText();
String newSbatchText = sbatchTemplate + "\n" + command;
return newSbatchText;
}
Expand Down
Expand Up @@ -61,10 +61,10 @@ public void addPages() {
@Override
public boolean performFinish() {

// ConfigureCommandPage cmdPage = (ConfigureCommandPage) this.getPage("Page 3");
// ConfigureCommandPage cmdPage = (ConfigureCommandPage) this.getPage("Configure Command Page");
// String command = cmdPage.getCommandText();

ConfigureSbatchScriptPage sbatchPage = (ConfigureSbatchScriptPage) this.getPage("Page 4");
ConfigureSbatchScriptPage sbatchPage = (ConfigureSbatchScriptPage) this.getPage("Configure Sbatch Page");
String sbatchParam = sbatchPage.getResultingSbatchAndCommandText();

String dateTimeStamp = HPCUtils.dateTimeStamp();
Expand Down
Expand Up @@ -27,7 +27,8 @@ public class SelectToolGroupPage extends WizardPage {
String selectedToolGroup;

protected SelectToolGroupPage(IWorkbench workbench, IStructuredSelection selection) {
super("Page 1");
// Set the name for this page
super("Select ToolGroup Page");
setTitle("Configure command: Select tool group");
setDescription("Select the group of commands that you wish to execute");
this.workbench = workbench;
Expand Down Expand Up @@ -87,7 +88,7 @@ public Combo getComboToolGroup() {

@Override
public IWizardPage getNextPage() {
SelectToolPage selectToolPage = ((SelectToolPage) this.getWizard().getPage("Page 2"));
SelectToolPage selectToolPage = ((SelectToolPage) this.getWizard().getPage("Select Tool Page"));
selectToolPage.onEnterPage();
return selectToolPage;
}
Expand Down
Expand Up @@ -19,7 +19,8 @@ public class SelectToolPage extends WizardPage {
private IStructuredSelection selection;

protected SelectToolPage(IWorkbench workbench, IStructuredSelection selection) {
super("Page 2");
// Set the name for this page
super("Select Tool Page");
setTitle("Select tool");
setDescription("Select a tool from the ones available in the tool group just selected ...");
this.workbench = workbench;
Expand Down Expand Up @@ -65,7 +66,7 @@ private void createCombo(Composite composite) {
}

public void onEnterPage() {
SelectToolGroupPage selectToolGroupPage = ((SelectToolGroupPage) this.getWizard().getPage("Page 1"));
SelectToolGroupPage selectToolGroupPage = ((SelectToolGroupPage) this.getWizard().getPage("Select ToolGroup Page"));
String currentToolGroupName = selectToolGroupPage.comboToolGroup.getText();
String[] toolNames = ToolConfigDomain.getInstance().getToolNamesForGroupName(currentToolGroupName);
updateDroplist(toolNames);
Expand All @@ -79,7 +80,7 @@ public void updateDroplist(String[] tools) {

@Override
public IWizardPage getNextPage() {
ConfigureCommandPage configCommandPage = ((ConfigureCommandPage) this.getWizard().getPage("Page 3"));
ConfigureCommandPage configCommandPage = ((ConfigureCommandPage) this.getWizard().getPage("Configure Command Page"));
configCommandPage.onEnterPage();
return configCommandPage;
}
Expand Down

0 comments on commit f819305

Please sign in to comment.