-
Notifications
You must be signed in to change notification settings - Fork 3
/
2DSA_2.php
287 lines (244 loc) · 8.22 KB
/
2DSA_2.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/*
* 2DSA_2.php
*
* Final database update and submission for the 2DSA analysis
*
*/
include_once 'checkinstance.php';
elogrs( __FILE__ );
if ( ($_SESSION['userlevel'] != 2) &&
($_SESSION['userlevel'] != 3) &&
($_SESSION['userlevel'] != 4) &&
($_SESSION['userlevel'] != 5) ) // only data analyst and up
{
header('Location: index.php');
if ( $is_cli ) {
$errstr = "ERROR: " . __FILE__ . " user level is insufficient";
echo "$errstr\n";
$cli_errors[] = $errstr;
return;
}
exit();
}
// Verify that job submission is ok now
include_once 'lib/motd.php';
if ( motd_isblocked() && ($_SESSION['userlevel'] < 4) )
{
header("Location: index.php");
if ( $is_cli ) {
$errstr = "ERROR: " . __FILE__ . " Job submission is blocked";
echo "$errstr\n";
$cli_errors[] = $errstr;
return;
}
exit();
}
// define( 'DEBUG', true );
include_once 'config.php';
include_once 'db.php';
include_once 'lib/utility.php';
include_once 'lib/payload_manager.php';
include_once 'lib/HPC_analysis.php';
include_once 'lib/file_writer.php';
include_once $class_dir . 'submit_local.php';
include_once $class_dir . 'submit_gfac.php';
include_once $class_dir . 'submit_airavata.php';
include_once $class_dir . 'progress.php';
include_once $class_dir . 'priority.php';
// Create the payload manager and restore the data
$payload = new Payload_2DSA( $_SESSION );
$payload->restore();
elogrs( __FILE__ . " after payload_restore" );
// Create the HPC analysis agent and file writer
$HPC = new HPC_2DSA();
$file = new File_2DSA();
$filenames = array();
$HPCAnalysisRequestID = 0;
$separate_datasets = $_SESSION['separate_datasets'];
$files_ok = true; // Let's also make sure there weren't any problems writing the files
if ( $separate_datasets > 0 )
{ // Multiple datasets and non-global: build composite jobs
$dataset_count = $payload->get( 'datasetCount' );
$job_params = $payload->get( 'job_parameters' );
$mgroup_count = max( 1, $job_params['req_mgroupcount'] );
$mc_iters = max( 1, $job_params['mc_iterations'] );
$reqds_count = 50; // Initial datasets per request
if ( $mc_iters > 50 )
$reqds_count = 25;
if ( $separate_datasets == 1 )
{
$reqds_count = 1;
$mgroup_count = 1;
}
$groups = (int)( $reqds_count / $mgroup_count );
$groups = max( 1, $groups );
$reqds_count = $mgroup_count * $groups; // Multiple of PMGC
$ds_remain = $dataset_count; // Remaining datasets
$index = 0; // Input datasets index
$kr = 0; // Output request index
$missit_msg = "<br/>ds_remain=" . $ds_remain;
echo "<script>us_submit_prog.show();</script>";
priority( "2DSA", $dataset_count, $job_params );
while ( $ds_remain > 0 )
{ // Loop to build HPC requests of composite jobs
echo "<script>us_submit_prog.msg.prep('$ds_remain');</script>";
if ( ( $ds_remain - $reqds_count ) < $mgroup_count )
$reqds_count = $ds_remain;
else
$reqds_count = min( $reqds_count, $ds_remain );
$composite = $payload->get_ds_range( $index, $reqds_count );
$HPCAnalysisRequestID = $HPC->writeDB( $composite );
$filenames[ $kr ] = $file->write( $composite, $HPCAnalysisRequestID );
if ( $filenames[ $kr ] === false )
{
$missit_msg .= "<br/>composite=" . $composite;
$missit_msg .= "<br/> kr=" . $kr;
$missit_msg .= "<br/> fnkr=" . $filenames[$kr];
$files_ok = false;
}
else
{ // Write the xml file content to the db
$xml_content = mysqli_real_escape_string( $link, file_get_contents( $filenames[ $kr ] ) );
$edit_filename = $composite['dataset'][0]['edit'];
$experimentID = $_SESSION['request'][$index]['experimentID'];
$query = "UPDATE HPCAnalysisRequest " .
"SET requestXMLfile = '$xml_content', " .
"experimentID = '$experimentID', " .
"editXMLFilename = '$edit_filename' " .
"WHERE HPCAnalysisRequestID = $HPCAnalysisRequestID ";
mysqli_query( $link, $query )
or die("Query failed : $query<br />\n" . mysqli_error($link));
}
$index += $reqds_count;
$ds_remain -= $reqds_count;
$kr++;
}
}
else
{ // Multiple datasets and global
$globalfit = $payload->get();
priority( "2DSA-GF", $payload->get( 'datasetCount' ), $payload->get( 'job_parameters' ) );
$HPCAnalysisRequestID = $HPC->writeDB( $globalfit );
$filenames[ 0 ] = $file->write( $globalfit, $HPCAnalysisRequestID );
$missit_msg = '';
if ( $filenames[ 0 ] === false )
{
$missit_msg = "<br/>filenames[0]=" . $filenames[0];
$files_ok = false;
}
else if ( $filenames[ 0 ] === '2DSA-IT-MISSING' )
{
$files_ok = false;
$missit_msg = "<br/><b>Global Fit without all needed 2DSA-IT models</b/>";
}
else
{
// Write the xml file content to the db
$xml_content = mysqli_real_escape_string( $link, file_get_contents( $filenames[ 0 ] ) );
$edit_filename = $globalfit['dataset'][0]['edit'];
$query = "UPDATE HPCAnalysisRequest " .
"SET requestXMLfile = '$xml_content', " .
"editXMLFilename = '$edit_filename' " .
"WHERE HPCAnalysisRequestID = $HPCAnalysisRequestID ";
mysqli_query( $link, $query )
or die("Query failed : $query<br />\n" . mysqli_error($link));
}
}
if ( $files_ok )
{
$output_msg = <<<HTML
<script>us_submit_prog.hide()</script>
<pre>
Thank you, your job was accepted and is currently processing. An
email will be sent to {$_SESSION['submitter_email']} when the job is
completed.
HTML;
// EXEC COMMAND FOR TIGRE
if ( isset($_SESSION['cluster']) )
{
$cluster = $_SESSION['cluster']['shortname'];
unset( $_SESSION['cluster'] );
if ( isset( $global_cluster_details )
&& is_array( $global_cluster_details )
&& array_key_exists( $cluster, $global_cluster_details )
&& array_key_exists( 'airavata', $global_cluster_details[$cluster] ) ) {
if ( $global_cluster_details[$cluster]['airavata' ] ) {
$job = new submit_airavata();
} else {
$job = new submit_local();
}
} else {
error_log( "$cluster not properly setup\n" );
$msg = "<br /><span class='message'>Configuration error: Unsupported cluster $cluster</span><br />\n";
echo $msg;
exit;
}
$save_cwd = getcwd(); // So we can come back to the current
// working directory later
foreach ( $filenames as $filename )
{
echo "<script>us_submit_prog.msg.submit('" . basename( $filename ) . "');</script>";
chdir( dirname( $filename ) );
$job-> clear();
$job-> parse_input( basename( $filename ) );
if ( ! DEBUG ) $job-> submit();
$retval = $job->get_messages();
if ( ! empty( $retval ) )
{
$output_msg .= "<br /><span class='message'>Message from the queue...</span><br />\n" .
print_r( $retval, true ) . " <br />\n";
}
else {
$output_msg .= "<br /><span class='message'>Message from the queue...filename=$filename</span><br/>\n";
$output_msg .= "</pre>\n";
echo <<<HTML
<!-- Begin page content -->
<div id='content'>
<h1 class="title">$page_title</h1>
<!-- Place page content here -->
$message
<p>$output_msg</p>
</div>
HTML;
if ( $is_cli ) {
echo __FILE__ . " exiting 3\n";
}
exit(0);
}
}
$job->close_transport(); // Will be dummy for newer classes
chdir( $save_cwd );
}
$output_msg .= "</pre>\n";
}
else
{
$output_msg = <<<HTML
Thank you, there have been one or more problems writing the various files necessary
for job submission. Please contact your system administrator.
$missit_msg
HTML;
}
// Start displaying page
$page_title = '2DSA Analysis Submitted';
include 'header.php';
$message = ( isset( $message ) ) ? "<p class='message'>$message</p>" : "";
$show = $payload->show( $HPCAnalysisRequestID, $filenames ); // debugging info, if enabled
echo <<<HTML
<!-- Begin page content -->
<div id='content'>
<h1 class="title">$page_title</h1>
<!-- Place page content here -->
$message
<p>$output_msg</p>
<p><a href="queue_setup_1.php">Submit another request</a></p>
$show
</div>
HTML;
include 'footer.php';
if ( $is_cli ) {
return;
}
exit();
?>