endexp.php3 4.75 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
2
3
4
5
6
7
8
9
<html>
<head>
<title>Terminate Experiment</title>
<link rel="stylesheet" href="tbstyle.css" type="text/css">
</head>
<body>
<?php
include("defs.php3");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
10
11
12
#
# Only known and logged in users can end experiments.
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
13
14
$uid = "";
if ( ereg("php3\?([[:alnum:]]+)",$REQUEST_URI,$Vals) ) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
15
16
    $uid=$Vals[1];
    addslashes($uid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
17
} else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
18
    unset($uid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
19
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
20
LOGGEDINORDIE($uid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
21

Leigh B. Stoller's avatar
Leigh B. Stoller committed
22
23
24
#
# Must provide the EID!
# 
25
26
if (!isset($exp_pideid) ||
    strcmp($exp_pideid, "") == 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
27
28
29
  USERERROR("The experiment ID was not provided!", 1);
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
30
#
31
32
# First get the project (PID) from the form parameter, which came in
# as <pid>$$<eid>.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
33
#
34
$exp_eid = strstr($exp_pideid, "\$\$");
35
$exp_eid = substr($exp_eid, 2);
36
$exp_pid = substr($exp_pideid, 0, strpos($exp_pideid, "\$\$", 0));
37

38
39
40
41
42
43
44
45
46
47
#
# Stop now if the Confirm box was not Depressed
#
if (!isset($confirm) ||
    strcmp($confirm, "yes")) {
  USERERROR("The \"Confirm\" button was not depressed! If you really ".
            "want to end experiment '$exp_eid' in project '$exp_pid', ".
            "please go back and try again.", 1);
}

48
49
#
# Check to make sure thats this is a valid PID/EID tuple.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
50
51
#
$query_result = mysql_db_query($TBDBNAME,
52
53
54
55
56
	"SELECT * FROM experiments WHERE ".
        "eid=\"$exp_eid\" and pid=\"$exp_pid\"");
if (mysql_num_rows($query_result) == 0) {
  USERERROR("The experiment $exp_eid is not a valid experiment ".
            "in project $exp_pid.", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
57
58
}

59
60
61
62
#
# Verify that this uid is a member of the project for the experiment
# being displayed.
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
63
$query_result = mysql_db_query($TBDBNAME,
64
	"SELECT pid FROM proj_memb WHERE uid=\"$uid\" and pid=\"$exp_pid\"");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
65
if (mysql_num_rows($query_result) == 0) {
66
67
  USERERROR("You are not a member of Project $exp_pid for ".
            "Experiment: $exp_eid.", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
68
69
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
70
71
72
73
74
75
76
77
78
#
# As per what happened when the experiment was created, we need to
# go back to that directory and use the .ir file to terminate the
# experiment, and then delete the files and the directory.
#
# XXX These paths/filenames are setup in beginexp_process.php3.
#
# No need to tell me how bogus this is.
#
79
80
$dirname = "$TBWWW_DIR"."$TBNSSUBDIR" . "/" . "$exp_pid" . "-" . "$exp_eid";
$nsname  = "$dirname" . "/" . "$exp_eid" . ".ns";
81
$irname  = "$dirname" . "/" . "$exp_eid" . ".ir";
82
$repname = "$dirname" . "/" . "$exp_eid" . ".report";
83
$logname = "$dirname" . "/" . "$exp_eid" . ".log";
84
$assname = "$dirname" . "/" . "assign"   . ".log";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
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
# Check to see if the experiment directory exists before continuing.
# We will allow experiments to be deleted even without the files
# describing it, since in some cases the user is handling that part on
# his/her own.
# 
if (! file_exists($dirname)) {
    $query_result = mysql_db_query($TBDBNAME,
	"DELETE FROM experiments WHERE eid='$exp_eid' and pid=\"$exp_pid\"");
    if (! $query_result) {
        $err = mysql_error();
        TBERROR("Database Error deleting experiment $exp_eid ".
                "in project $exp_pid: $err\n", 1);
    }

    echo "<center><br><h2>
          Experiment $exp_pid Terminated!<br>
          Since there was no IR file to work from, the EID has been removed,
          <br>but you will need to make sure the nodes are released yourself.
          </h2></center><br>";

    echo "</body>
          </html>\n";
    die("");
}

#
# By this point, the IR file must exist to go on.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
114
115
# 
if (! file_exists($irname)) {
116
    TBERROR("IR file $irname for experiment $exp_eid does not exist!\n", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
117
118
119
120
121
122
123
124
125
126
127
128
129
}

echo "<center><br>";
echo "<h3>Terminating the experiment. This may take a few minutes ...</h3>";
echo "</center>";

#
# Run the scripts. We use a script wrapper to deal with changing
# to the proper directory and to keep some of these details out
# of this. 
#
$output = array();
$retval = 0;
130
$result = exec("$TBBIN_DIR/tbstopit $dirname $exp_pid $exp_eid $exp_eid.ir",
131
               $output, $retval);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
132
133
134
135
136
137
138
139
140
141
if ($retval) {
    echo "<br><br><h2>
          Termination Failure($retval): Output as follows:
          </h2>
          <br>
          <XMP>\n";
          for ($i = 0; $i < count($output); $i++) {
	      echo "$output[$i]\n";
          }
    echo "</XMP>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
142

Leigh B. Stoller's avatar
Leigh B. Stoller committed
143
144
145
146
147
148
    die("");
}

#
# Remove all trace! 
#
149
150
151
152
153
154
155
156
157
158
159
160
if (file_exists($nsname))
    unlink("$nsname");
if (file_exists($irname))
    unlink("$irname");
if (file_exists($repname))
    unlink("$repname");
if (file_exists($logname))
    unlink("$logname");
if (file_exists($assname))
    unlink("$assname");
if (file_exists($dirname))
     rmdir("$dirname");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
161
162
163
164
165

#
# From the database too!
#
$query_result = mysql_db_query($TBDBNAME,
166
	"DELETE FROM experiments WHERE eid='$exp_eid' and pid=\"$exp_pid\"");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
167
168
if (! $query_result) {
    $err = mysql_error();
169
170
    TBERROR("Database Error deleting experiment $exp_eid ".
            "in project $exp_pid: $err\n", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
171
172
173
}

echo "<center><br>";
174
echo "<h2>Experiment $exp_pid Terminated!<br>";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
175
176
177
echo "</h2></center><br>";

?>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
178
179
180
</center>
</body>
</html>