forked from SciGaP/PHP-Reference-Gateway
/
create_experiment.php
271 lines (200 loc) · 7.59 KB
/
create_experiment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
session_start();
include 'utilities.php';
use Airavata\API\Error\InvalidRequestException;
use Airavata\API\Error\AiravataClientException;
use Airavata\API\Error\AiravataSystemException;
create_http_header();
connect_to_id_store();
verify_login();
$airavataclient = get_airavata_client();
$echoResources = array('localhost', 'trestles.sdsc.edu', 'lonestar.tacc.utexas.edu');
$wrfResources = array('trestles.sdsc.edu');
$appResources = array('Echo' => $echoResources, 'WRF' => $wrfResources);
?>
<html>
<?php create_html_head(); ?>
<body>
<?php create_nav_bar(); ?>
<div class="container" style="max-width: 750px;">
<h1>Create a new experiment</h1>
<?php
if (isset($_POST['save']) || isset($_POST['launch']))
{
$expId = create_experiment();
if (isset($_POST['launch']) && $expId)
{
launch_experiment($expId);
}
else
{
print_success_message("<p>Experiment {$_POST['experiment-name']} created!</p>" .
'<p>You will be redirected to the summary page shortly, or you can
<a href="experiment_summary.php?expId=' . $expId . '">go directly</a> to experiment summary page.</p>');
redirect('experiment_summary.php?expId=' . $expId);
}
}
//$transport->close();
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" role="form" enctype="multipart/form-data">
<?php
if (isset($_POST['continue']))
{
$disabled = ' disabled';
$experimentName = $_POST['experiment-name'];
$experimentDescription = $_POST['experiment-description'] . ' ';
$project = $_POST['project'];
$application = $_POST['application'];
// ugly hack until app catalog is in place
$echo = ($application == 'Echo')? ' selected' : '';
$wrf = ($application == 'WRF')? ' selected' : '';
echo '<input type="hidden" name="experiment-name" value="' . $experimentName . '">';
echo '<input type="hidden" name="experiment-description" value="' . $experimentDescription . '">';
echo '<input type="hidden" name="project" value="' . $project . '">';
echo '<input type="hidden" name="application" value="' . $application . '">';
}
else
{
$disabled = '';
$experimentName = '';
$experimentDescription = '';
$project = '';
$application = '';
$echo = '';
$wrf = '';
}
echo '
<div class="form-group">
<label for="experiment-name">Experiment Name</label>
<input type="text" class="form-control" name="experiment-name" id="experiment-name" placeholder="Enter experiment name" autofocus required' . $disabled . ' value="' . $experimentName . '">
</div>
<div class="form-group">
<label for="experiment-description">Experiment Description</label>
<textarea class="form-control" name="experiment-description" id="experiment-description" placeholder="Optional: Enter a short description of the experiment"' . $disabled . '>' . $experimentDescription . '</textarea>
</div>
<div class="form-group">
<label for="project">Project</label>
';
create_project_select($project, !$disabled);
echo '
</div>
<div class="form-group">
<label for="application">Application</label>';
create_application_select($application, !$disabled);
echo '</div>';
if (!isset($_POST['continue']))
{
echo '<div class="btn-toolbar">
<input name="continue" type="submit" class="btn btn-primary" value="Continue">
<input name="clear" type="reset" class="btn btn-default" value="Reset values">
</div>
';
}
else
{
echo '<div class="panel panel-default">
<div class="panel-heading">Application configuration</div>
<div class="panel-body">
<label>Application input</label>
<div class="well">
';
create_inputs($application, true);
echo '</div>
<div class="form-group">
<label for="compute-resource">Compute Resource</label>';
create_compute_resources_select($application, null);
echo '
</div>
<div class="form-group">
<label for="node-count">Node Count</label>
<input type="number" class="form-control" name="node-count" id="node-count" value="1" min="1">
</div>
<div class="form-group">
<label for="cpu-count">Total Core Count</label>
<input type="number" class="form-control" name="cpu-count" id="cpu-count" value="4" min="1">
</div>
<!--
<div class="form-group">
<label for="threads">Number of Threads</label>
<input type="number" class="form-control" name="threads" id="threads" value="0" min="0">
</div>
-->
<div class="form-group">
<label for="wall-time">Wall Time Limit</label>
<div class="input-group">
<input type="number" class="form-control" name="wall-time" id="wall-time" value="30" min="0">
<span class="input-group-addon">minutes</span>
</div>
</div>
<!--
<div class="form-group">
<label for="memory">Total Physical Memory</label>
<div class="input-group">
<input type="number" class="form-control" name="memory" id="memory" value="0" min="0">
<span class="input-group-addon">kB</span>
</div>
</div>
-->
</div>
</div>
<!-- use <button> instead of <input> in order to match height of <a> in Firefox -->
<div class="btn-toolbar">
<div class="btn-group">
<button name="save" type="submit" class="btn btn-primary" value="Save">Save</button>
<button name="launch" type="submit" class="btn btn-success" value="Save and launch">Save and launch</button>
</div>
<div class="btn-group">
<button name="clear" type="reset" class="btn btn-default" value="Reset values">Reset application configuration</button>
<a href="' . $_SERVER['PHP_SELF'] . '" class="btn btn-default" role="button">Start over</a>
</div>
</div>';
}
?>
</form>
</div>
</body>
</html>
<?php
/**
* Create a new experiment from the values submitted in the form
* @return null
*/
function create_experiment()
{
global $airavataclient;
$experiment = assemble_experiment();
//var_dump($experiment);
$expId = null;
try
{
if($experiment)
{
$expId = $airavataclient->createExperiment($experiment);
}
if ($expId)
{
/*
print_success_message("Experiment {$_POST['experiment-name']} created!" .
' <a href="experiment_summary.php?expId=' . $expId . '">Go to experiment summary page</a>');
*/
}
else
{
print_error_message("Error creating experiment {$_POST['experiment-name']}!");
}
}
catch (InvalidRequestException $ire)
{
print_error_message('InvalidRequestException!<br><br>' . $ire->getMessage());
}
catch (AiravataClientException $ace)
{
print_error_message('AiravataClientException!<br><br>' . $ace->getMessage());
}
catch (AiravataSystemException $ase)
{
print_error_message('AiravataSystemException!<br><br>' . $ase->getMessage());
}
return $expId;
}
unset($_POST);