-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathExperimentController.php
More file actions
executable file
·374 lines (322 loc) · 16.3 KB
/
Copy pathExperimentController.php
File metadata and controls
executable file
·374 lines (322 loc) · 16.3 KB
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
use Airavata\Model\Status\JobState;
use Airavata\Model\Group\ResourceType;
class ExperimentController extends BaseController
{
/**
* Limit used in fetching paginated results
* @var int
*/
var $limit = 20;
/**
* Instantiate a new ExperimentController Instance
**/
public function __construct()
{
$this->beforeFilter('verifylogin');
$this->beforeFilter('verifyauthorizeduser');
Session::put("nav-active", "experiment");
}
public function createView()
{
Session::forget('exp_create_continue');
return View::make('experiment/create');
}
public function createSubmit()
{
if (isset($_POST['continue'])) {
Session::put('exp_create_continue', true);
$computeResources = CRUtilities::create_compute_resources_select($_POST['application'], null);
$queueDefaults = array("queueName" => Config::get('pga_config.airavata')["queue-name"],
"nodeCount" => Config::get('pga_config.airavata')["node-count"],
"cpuCount" => Config::get('pga_config.airavata')["total-cpu-count"],
"wallTimeLimit" => Config::get('pga_config.airavata')["wall-time-limit"]
);
$clonedExp = false; $savedExp = false;
if( Input::has("clonedExp"))
$clonedExp = true;
if( Input::has("savedExp"))
$savedExp = true;
// Condition added to deal with php ini default value set for post_max_size issue.
$allowedFileSize = Config::get('pga_config.airavata')["server-allowed-file-size"];
$serverLimit = intval( ini_get( 'post_max_size') );
if( $serverLimit < $allowedFileSize)
$allowedFileSize = $serverLimit;
$experimentInputs = array(
"clonedExp" => $clonedExp,
"savedExp" => $savedExp,
"disabled" => ' disabled',
"experimentName" => $_POST['experiment-name'],
"experimentDescription" => $_POST['experiment-description'] . ' ',
"project" => $_POST['project'],
"application" => $_POST['application'],
"echo" => ($_POST['application'] == 'Echo') ? ' selected' : '',
"wrf" => ($_POST['application'] == 'WRF') ? ' selected' : '',
"queueDefaults" => $queueDefaults,
"advancedOptions" => Config::get('pga_config.airavata')["advanced-experiment-options"],
"computeResources" => $computeResources,
"resourceHostId" => null,
"advancedOptions" => Config::get('pga_config.airavata')["advanced-experiment-options"],
"allowedFileSize" => $allowedFileSize
);
$users = SharingUtilities::getProfilesForSharedUsers($_POST['project'], ResourceType::PROJECT);
$owner = array();
return View::make("experiment/create-complete", array("expInputs" => $experimentInputs, "users" => json_encode($users), "owner" => json_encode($owner)));
} else if (isset($_POST['save']) || isset($_POST['launch'])) {
$expId = ExperimentUtilities::create_experiment();
if (isset($_POST['launch']) && $expId) {
ExperimentUtilities::launch_experiment($expId);
}
/* Not required.
else
{
CommonUtilities::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=' . URL::to('/') . '"/experiment/summary?expId=' . $expId . '">go directly</a> to experiment summary page.</p>');
}*/
$users = SharingUtilities::getProfilesForSharedUsers($expId, ResourceType::EXPERIMENT);
return Redirect::to('experiment/summary?expId=' . $expId);
} else
return Redirect::to("home")->with("message", "Something went wrong here. Please file a bug report using the link in the Help menu.");
}
public function summary()
{
$experiment = ExperimentUtilities::get_experiment($_GET['expId']);
if(isset($_GET['isAutoRefresh']) && $_GET['isAutoRefresh'] == 'true'){
$autoRefresh = true;
}else{
$autoRefresh = false;
}
if ($experiment != null) {
//viewing experiments of other gateways is not allowed if user is not super admin
if( $experiment->gatewayId != Session::get("gateway_id") && !Session::has("super-admin")){
Session::put("permissionDenied", true);
CommonUtilities::print_error_message('It seems that you do not have permissions to view this experiment or it belongs to another gateway.');
if (Input::has("dashboard"))
return View::make("partials/experiment-info", array("invalidExperimentId" => 1, "users" => json_encode(array())));
else
return View::make("experiment/summary", array("invalidExperimentId" => 1, "users" => json_encode(array())));
}
else
Session::forget("permissionDenied");
$project = ProjectUtilities::get_project($experiment->projectId);
$expVal = ExperimentUtilities::get_experiment_values($experiment);
$jobDetails = ExperimentUtilities::get_job_details($experiment->experimentId);
//var_dump( $jobDetails); exit;
foreach( $jobDetails as $index => $jobDetail){
if(isset($jobDetail->jobStatus)){
$jobDetails[ $index]->jobStatus->jobStateName = JobState::$__names[$jobDetail->jobStatus->jobState];
}
else{
$jobDetails[ $index]->jobStatus = new stdClass();
$jobDetails[ $index]->jobStatus->jobStateName = null;
}
}
$expVal["jobDetails"] = $jobDetails;
$users = SharingUtilities::getProfilesForSharedUsers(Input::get("expId"), ResourceType::EXPERIMENT);
$owner = array();
if (strcmp(Session::get("username"), $experiment->userName) !== 0) {
$owner[$experiment->userName] = $users[$experiment->userName];
$users = array_diff_key($users, $owner);
}
$data = array(
"expId" => Input::get("expId"),
"experiment" => $experiment,
"project" => $project,
"jobDetails" => $jobDetails,
"expVal" => $expVal,
"autoRefresh"=> $autoRefresh,
"users" => json_encode($users),
"owner" => json_encode($owner),
"can_write" => SharingUtilities::userCanWrite(Session::get("username"), $experiment->experimentId, ResourceType::EXPERIMENT)
);
if( Input::has("dashboard"))
{
$detailedExperiment = ExperimentUtilities::get_detailed_experiment( $_GET['expId']);
$data["detailedExperiment"] = $detailedExperiment;
}
if (Request::ajax()) {
//admin wants to see an experiment summary
if (Input::has("dashboard")) {
$data["dashboard"] = true;
return View::make("partials/experiment-info", $data);
} else
return json_encode($data);
} else {
return View::make("experiment/summary", $data);
}
} else {
if (Input::has("dashboard"))
return View::make("partials/experiment-info", array("invalidExperimentId" => 1, "users" => json_encode(array())));
else
return View::make("experiment/summary", array("invalidExperimentId" => 1, "users" => json_encode(array())));
}
}
public function expCancel()
{
ExperimentUtilities::cancel_experiment(Input::get("expId"));
return Redirect::to('experiment/summary?expId=' . Input::get("expId"));
}
public function expChange()
{
//var_dump( Input::all() ); exit;
$experiment = ExperimentUtilities::get_experiment(Input::get('expId'));
$expVal = ExperimentUtilities::get_experiment_values($experiment);
$expVal["jobState"] = ExperimentUtilities::get_job_status($experiment);
/*if (isset($_POST['save']))
{
$updatedExperiment = CommonUtilities::apply_changes_to_experiment($experiment);
CommonUtilities::update_experiment($experiment->experimentId, $updatedExperiment);
}*/
if (isset($_POST['launch'])) {
ExperimentUtilities::launch_experiment($experiment->experimentId);
return Redirect::to('experiment/summary?expId=' . $experiment->experimentId);
} elseif (isset($_POST['cancel'])) {
ExperimentUtilities::cancel_experiment($experiment->experimentId);
return Redirect::to('experiment/summary?expId=' . $experiment->experimentId);
}
}
public function editView()
{
if (SharingUtilities::userCanWrite(Session::get("username"), $_GET['expId'], ResourceType::EXPERIMENT) === true) {
$queueDefaults = array("queueName" => Config::get('pga_config.airavata')["queue-name"],
"nodeCount" => Config::get('pga_config.airavata')["node-count"],
"cpuCount" => Config::get('pga_config.airavata')["total-cpu-count"],
"wallTimeLimit" => Config::get('pga_config.airavata')["wall-time-limit"]
);
$experiment = ExperimentUtilities::get_experiment($_GET['expId']);
$expVal = ExperimentUtilities::get_experiment_values($experiment);
$expVal["jobState"] = ExperimentUtilities::get_job_status($experiment);
$computeResources = CRUtilities::create_compute_resources_select($experiment->executionId, $expVal['scheduling']->resourceHostId);
$clonedExp = false; $savedExp = false;
if( Input::has("clonedExp"))
$clonedExp = true;
if( Input::has("savedExp"))
$savedExp = true;
$experimentInputs = array(
"clonedExp" => $clonedExp,
"savedExp" => $savedExp,
"disabled" => ' ',
"experimentName" => $experiment->experimentName,
"experimentDescription" => $experiment->description,
"application" => $experiment->executionId,
"autoSchedule" => $experiment->userConfigurationData->airavataAutoSchedule,
"userDN" => $experiment->userConfigurationData->userDN,
"allowedFileSize" => Config::get('pga_config.airavata')["server-allowed-file-size"],
'experiment' => $experiment,
"queueDefaults" => $queueDefaults,
'computeResources' => $computeResources,
"resourceHostId" => $expVal['scheduling']->resourceHostId,
'project' => $experiment->projectId,
'expVal' => $expVal,
'cloning' => true,
'advancedOptions' => Config::get('pga_config.airavata')["advanced-experiment-options"]
);
$users = SharingUtilities::getProfilesForSharedUsers($_GET['expId'], ResourceType::EXPERIMENT);
$owner = array();
if (strcmp(Session::get("username"), $experiment->userName) !== 0) {
$owner[$experiment->userName] = $users[$experiment->userName];
$users = array_diff_key($users, $owner);
}
return View::make("experiment/edit", array("expInputs" => $experimentInputs, "users" => json_encode($users), "owner" => json_encode($owner)));
}
else {
Redirect::to("experiment/summary?expId=" . $experiment->experimentId)->with("error", "You do not have permission to edit this experiment");
}
}
public function cloneExperiment()
{
if (isset($_GET['expId'])) {
$cloneId = ExperimentUtilities::clone_experiment($_GET['expId']);
$experiment = ExperimentUtilities::get_experiment($cloneId);
$project = ProjectUtilities::get_project($experiment->projectId);
$expVal = ExperimentUtilities::get_experiment_values($experiment);
$expVal["jobState"] = ExperimentUtilities::get_job_status($experiment);
return Redirect::to('experiment/edit?expId=' . $cloneId . "&clonedExp=true");
}
}
public function editSubmit()
{
if (SharingUtilities::userCanWrite(Session::get("username"), Input::get('expId'), ResourceType::EXPERIMENT)) {
if (isset($_POST['save']) || isset($_POST['launch'])) {
$experiment = ExperimentUtilities::get_experiment(Input::get('expId')); // update local experiment variable
$updatedExperiment = ExperimentUtilities::apply_changes_to_experiment($experiment, Input::all());
ExperimentUtilities::update_experiment($experiment->experimentId, $updatedExperiment);
if (isset($_POST['save'])) {
$experiment = ExperimentUtilities::get_experiment(Input::get('expId')); // update local experiment variable
}
if (isset($_POST['launch'])) {
ExperimentUtilities::launch_experiment($experiment->experimentId);
}
return Redirect::to('experiment/summary?expId=' . $experiment->experimentId);
} else
return View::make("home");
}
}
public function getQueueView()
{
$queues = ExperimentUtilities::getQueueDatafromResourceId(Input::get("crId"));
$queueDefaults = array("queueName" => Config::get('pga_config.airavata')["queue-name"],
"nodeCount" => Config::get('pga_config.airavata')["node-count"],
"cpuCount" => Config::get('pga_config.airavata')["total-cpu-count"],
"wallTimeLimit" => Config::get('pga_config.airavata')["wall-time-limit"]
);
return View::make("partials/experiment-queue-block", array("queues" => $queues, "queueDefaults" => $queueDefaults));
}
public function browseView()
{
$pageNo = Input::get('pageNo');
$prev = Input::get('prev');
$isSearch = Input::get('search');
if (empty($pageNo) || isset($isSearch) ) {
$pageNo = 1;
} else {
if (isset($prev)) {
$pageNo -= 1;
} else {
$pageNo += 1;
}
}
$expContainer = ExperimentUtilities::get_expsearch_results_with_pagination(Input::all(), $this->limit,
($pageNo - 1) * $this->limit);
$experimentStates = ExperimentUtilities::getExpStates();
$can_write = array();
foreach ($expContainer as $experiment) {
$can_write[$experiment['experiment']->experimentId] = SharingUtilities::userCanWrite(Session::get("username"), $experiment['experiment']->experimentId, ResourceType::EXPERIMENT);
}
return View::make('experiment/browse', array(
'input' => Input::all(),
'pageNo' => $pageNo,
'limit' => $this->limit,
'expStates' => $experimentStates,
'expContainer' => $expContainer,
'can_write' => $can_write
));
}
/**
* Generate JSON containing permissions information for this project.
*
* This function retrieves the user profile and permissions for every user
* other than the client that has access to the project. In the event that
* the project does not exist, return an error message.
*/
public function sharedUsers()
{
if (Session::has("authz-token") && array_key_exists('resourceId', $_GET)) {
return Response::json(SharingUtilities::getProfilesForSharedUsers($_GET['resourceId'], ResourceType::EXPERIMENT));
}
else {
return Response::json(array("error" => "Error: No project specified"));
}
}
public function unsharedUsers()
{
if (Session::has("authz-token") && array_key_exists('resourceId', $_GET)) {
return Response::json(SharingUtilities::getProfilesForUnsharedUsers($_GET['resourceId'], ResourceType::EXPERIMENT));
}
else {
return Response::json(array("error" => "Error: No experiment specified"));
}
}
}
?>