myexperiments.php 8.04 KB
Newer Older
Leigh B Stoller's avatar
Leigh B Stoller committed
1
2
<?php
#
3
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
Leigh B Stoller's avatar
Leigh B Stoller committed
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
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
include_once("geni_defs.php");
chdir("apt");
include("quickvm_sup.php");
29
30
include_once("profile_defs.php");
include_once("instance_defs.php");
Leigh B Stoller's avatar
Leigh B Stoller committed
31
32
33
34
35
36
37
38
$page_title = "My Experiments";
$dblink = GetDBLink("sa");

#
# Verify page arguments.
#
$optargs = OptionalPageArguments("target_user",   PAGEARG_USER,
				 "all",           PAGEARG_BOOLEAN);
39
40
41
if (!isset($all)) {
    $all = 0;
}
Leigh B Stoller's avatar
Leigh B Stoller committed
42
43
44
45
#
# Get current user.
#
RedirectSecure();
46
47
$this_user = CheckLoginOrRedirect();

Leigh B Stoller's avatar
Leigh B Stoller committed
48
49
50
51
52
53
54
if (!isset($target_user)) {
    $target_user = $this_user;
}
if (!$this_user->SameUser($target_user)) {
    if (!ISADMIN()) {
	SPITUSERERROR("You do not have permission to view ".
		      "target user's profiles");
55
	exit();
Leigh B Stoller's avatar
Leigh B Stoller committed
56
57
58
59
60
61
62
63
    }
}
$target_idx  = $target_user->uid_idx();
$target_uuid = $target_user->uuid();

SPITHEADER(1);

echo "<link rel='stylesheet'
64
            href='css/tablesorter.css'>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
65

66
67
68
69
70
71
72
$query_result1 = null;
$query_result2 = null;

if ($all && ISADMIN()) {
    $query_result1 = 
        DBQueryFatal("select a.*,s.expires,s.hrn,u.email, ".
                     " (UNIX_TIMESTAMP(now()) > ".
73
74
75
76
                     "  UNIX_TIMESTAMP(s.expires)) as expired, ".
                     "  truncate(a.physnode_count * ".
                     "   ((UNIX_TIMESTAMP(now()) - ".
                     "     UNIX_TIMESTAMP(a.created)) / 3600.0),2) as phours ".
77
78
79
80
81
82
83
84
85
86
                     "  from apt_instances as a ".
                     "left join geni.geni_slices as s on ".
                     "     s.uuid=a.slice_uuid ".
                     "left join geni.geni_users as u on u.uuid=a.creator_uuid ".
                     "order by a.creator");
}
else {
    $query_result1 =
        DBQueryFatal("select a.*,s.expires,s.hrn,u.email, ".
                     " (UNIX_TIMESTAMP(now()) > ".
87
88
89
90
                     "  UNIX_TIMESTAMP(s.expires)) as expired, ".
                     "  truncate(a.physnode_count * ".
                     "   ((UNIX_TIMESTAMP(now()) - ".
                     "     UNIX_TIMESTAMP(a.created)) / 3600.0),2) as phours ".
91
92
93
94
95
96
97
98
99
                     "  from apt_instances as a ".
                     "left join geni.geni_slices as s on ".
                     "     s.uuid=a.slice_uuid ".
                     "left join geni.geni_users as u on u.uuid=a.creator_uuid ".
                     "where a.creator_uuid='$target_uuid'");

    $query_result2 =
        DBQueryFatal("select distinct a.*,s.expires,s.hrn,u.email, ".
                     " (UNIX_TIMESTAMP(now()) > ".
100
101
102
103
                     "  UNIX_TIMESTAMP(s.expires)) as expired, ".
                     "  truncate(a.physnode_count * ".
                     "   ((UNIX_TIMESTAMP(now()) - ".
                     "     UNIX_TIMESTAMP(a.created)) / 3600.0),2) as phours ".
104
105
106
107
108
109
110
111
112
113
                     "  from apt_instances as a ".
                     "left join geni.geni_slices as s on ".
                     "     s.uuid=a.slice_uuid ".
                     "left join geni.geni_users as u on u.uuid=a.creator_uuid ".
                     "left join group_membership as g on ".
                     "     g.uid_idx='$target_idx' and  ".
                     "     g.pid_idx=a.pid_idx ".
                     "where a.creator_uuid='$target_uuid' or ".
                     "      g.uid_idx is not null ".
                     "order by a.creator");
Leigh B Stoller's avatar
Leigh B Stoller committed
114
115
}

116
117
function SPITROWS($all, $name, $result)
{
Leigh B Stoller's avatar
Leigh B Stoller committed
118
119
    global $TBBASE, $urn_mapping;
    
120
121
    echo "<input class='form-control search' type='search' data-column='all'
             id='experiment_search_${name}' placeholder='Search'>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
122

123
    echo "  <table class='tablesorter' id='tablesorter_${name}'>
Leigh B Stoller's avatar
Leigh B Stoller committed
124
125
126
         <thead>
          <tr>
           <th>Profile</th>\n";
127
128
129
        
    if (ISADMIN()) {
        echo " <th>Slice</th>";
Leigh B Stoller's avatar
Leigh B Stoller committed
130
    }
131
132
    if ($all) {
        echo "     <th>Creator</th>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
133
    }
134
135
    echo "     <th>Project</th>
               <th>Status</th>
136
137
138
139
               <th>Cluster</th>
               <th>PCs</th>
               <th>PHours<b>[1]</b></th>
               <th>VMs</th>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
140
    echo "     <th>Created</th>
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
               <th>Expires</th>
               </tr>
             </thead>
         <tbody>\n";
    
    while ($row = mysql_fetch_array($result)) {
        $profile_id   = $row["profile_id"];
        $version      = $row["profile_version"];
        $uuid         = $row["uuid"];
        $status       = $row["status"];
        $created      = DateStringGMT($row["created"]);
        $expires      = DateStringGMT($row["expires"]);
        $creator_idx  = $row["creator_idx"];
        $profile_name = $profile_id;
        $creator_uid  = $row["creator"];
        $pid          = $row["pid"];
Leigh B Stoller's avatar
Leigh B Stoller committed
157
158
159
160
        $urn          = $row["aggregate_urn"];
        $cluster      = $urn_mapping[$urn];
        $pcount       = $row["physnode_count"];
        $vcount       = $row["virtnode_count"];
161
        $phours       = $row["phours"];
162
163
164
165
166
167
        list($foo,$hrn) = preg_split("/\./", $row["hrn"]);
        $email        = $row["email"];
        # If a guest user, use email instead.
        if (isset($email)) {
            $creator = $email;
        }
Leigh B Stoller's avatar
Leigh B Stoller committed
168
        elseif (ISADMIN()) {
169
170
171
            $creator = "<a href='$TBBASE/showuser.php3?user=$creator_idx'>".
                "$creator_uid</a>";
        }
Leigh B Stoller's avatar
Leigh B Stoller committed
172
173
174
        else {
            $creator = $creator_uid;
        }
175
176
177
178
179
180
181
182
183
184
        if ($row["expired"]) {
            $status = "expired";
        }

        $profile = Profile::Lookup($profile_id, $version);
        if ($profile) {
            $profile_name = $profile->name();
        }

        echo " <tr>
Leigh B Stoller's avatar
Leigh B Stoller committed
185
186
187
            <td>
             <a href='status.php?uuid=$uuid'>$profile_name</a>
            </td>";
188
189
190
191
192
193
        if (ISADMIN()) {
            echo "<td>$hrn</td>";
        }
        if ($all) {
            echo "<td>$creator</td>";
        }
Leigh B Stoller's avatar
Leigh B Stoller committed
194
195
196
197
198
199
200
201
202
        if (ISADMIN()) {
            echo "  <td><a href='$TBBASE/showproject.php3?pid=$pid'>".
                "$pid</a></td>";
        }
        else {
            echo "  <td>$pid</td>\n";
        }
        echo "  <td>$status</td>\n";
        echo "  <td>$cluster</td>\n";
203
204
205
        echo "  <td>$pcount</td>";
        echo "  <td>$phours</td>";
        echo "  <td>$vcount</td>";
Leigh B Stoller's avatar
Leigh B Stoller committed
206
        echo"   <td class='format-date'>$created</td>
207
            <td class='format-date'>$expires</td>
Leigh B Stoller's avatar
Leigh B Stoller committed
208
           </tr>\n";
209
210
    }
    echo "   </tbody>
211
        </table>\n";
212
    echo "[1] <b>PHours</b>: Number of nodes times number of hours in use.<br>";
213
214
215
}

echo "<div class='row'>
216
217
        <div class='col-lg-12 col-lg-offset-0
                    col-md-12 col-md-offset-0
218
219
                    col-sm-12 col-sm-offset-0
                    col-xs-12 col-xs-offset-0'>\n";
220

221
222
223
224
if (mysql_num_rows($query_result1) == 0) {
    $message = "<b>No experiments to show you. Maybe you want to ".
	"<a href='instantiate.php'>start one?</a></b><br>";
    echo $message;
225
}
226
227
228
229
230
else {
    SPITROWS($all, "table1", $query_result1);
}
if ($query_result2 && mysql_num_rows($query_result2)) {
    echo "<br>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
231
    echo "Other experiments in my projects";
232
233
234
235
    echo "<br>\n";
    SPITROWS(1, "table2", $query_result2);
}

236
echo " </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
237
238
      </div>\n";

239
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
240
241
echo "<script src='js/lib/jquery.tablesorter.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.widgets.min.js'></script>\n";
242
echo "<script src='js/lib/bootstrap.js'></script>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
243
244
245
246
echo "<script src='js/lib/require.js' data-main='js/myexperiments'></script>\n";

SPITFOOTER();
?>