1 | <?php |
---|
2 | |
---|
3 | global $clustername, $tpl; |
---|
4 | |
---|
5 | function validateFormInput() { |
---|
6 | global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; |
---|
7 | global $end_from_time, $end_to_time; |
---|
8 | |
---|
9 | $error = 0; |
---|
10 | |
---|
11 | $none_set = 0; |
---|
12 | |
---|
13 | //if( $id == '' or $user == '' or $name == '' or $start_from_time == '' or $start_to_time == '' or $queue == '' or $end_from_time == '' or $end_to_time == '') $none_set = 1; |
---|
14 | |
---|
15 | //if (!isset($id) and !isset($user) and !isset($start_from_time) and !isset($start_to_time) and !isset($end_from_time) and !isset($end_to_time) and !isset($queue) ) $none_set = 0; |
---|
16 | |
---|
17 | if( $none_set ) { |
---|
18 | $error = 1; |
---|
19 | $error_msg = "<FONT COLOR=\"red\"><B>No search criteria set!</B></FONT>"; |
---|
20 | } |
---|
21 | |
---|
22 | // doe checks en set error en error_msg in case shit |
---|
23 | |
---|
24 | if( $error) { |
---|
25 | $tpl->assign( "form_error_msg", $error_msg ); |
---|
26 | return 0; |
---|
27 | } else { |
---|
28 | return 1; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | function makeTime( $time ) { |
---|
33 | |
---|
34 | $days = intval( $time / 86400 ); |
---|
35 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
36 | |
---|
37 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
38 | |
---|
39 | $date_str = ''; |
---|
40 | $day_str = ''; |
---|
41 | |
---|
42 | if( $days > 0 ) { |
---|
43 | if( $days > 1 ) |
---|
44 | $day_str .= $days . ' days'; |
---|
45 | else |
---|
46 | $day_str .= $days . ' day'; |
---|
47 | } |
---|
48 | |
---|
49 | $hours = intval( $time / 3600 ); |
---|
50 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
51 | |
---|
52 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
53 | |
---|
54 | if( $hours > 0 ) { |
---|
55 | $date_str .= $hours . ':'; |
---|
56 | $date_unit = 'hours'; |
---|
57 | } |
---|
58 | |
---|
59 | $minutes = intval( $time / 60 ); |
---|
60 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
61 | |
---|
62 | if( $minutes > 0 ) { |
---|
63 | |
---|
64 | if( $minutes >= 10 ) |
---|
65 | $date_str .= $minutes . ':'; |
---|
66 | else |
---|
67 | $date_str .= '0' . $minutes . ':'; |
---|
68 | |
---|
69 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
70 | } else { |
---|
71 | if($hours > 0 ) { |
---|
72 | $date_str .= '00:'; |
---|
73 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
79 | |
---|
80 | if( $seconds > 0 ) { |
---|
81 | |
---|
82 | if( $seconds >= 10 ) |
---|
83 | $date_str .= $seconds . ' ' . $date_unit; |
---|
84 | else |
---|
85 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
86 | |
---|
87 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
88 | |
---|
89 | $date_str .= '00 ' . $date_unit; |
---|
90 | |
---|
91 | if( $days > 0) { |
---|
92 | |
---|
93 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
94 | $date_str = $day_str . ' - ' . $date_str; |
---|
95 | else |
---|
96 | $date_str = $day_str; |
---|
97 | } |
---|
98 | |
---|
99 | return $date_str; |
---|
100 | } |
---|
101 | |
---|
102 | function makeDate( $time ) { |
---|
103 | return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
104 | } |
---|
105 | |
---|
106 | function timeToEpoch( $time ) { |
---|
107 | |
---|
108 | $time_fields = explode( ':', $time ); |
---|
109 | |
---|
110 | if( count($time_fields) == 3 ) { |
---|
111 | |
---|
112 | $hours = $time_fields[0]; |
---|
113 | $minutes = $time_fields[1]; |
---|
114 | $seconds = $time_fields[2]; |
---|
115 | |
---|
116 | } else if( count($time_fields) == 2 ) { |
---|
117 | |
---|
118 | $hours = 0; |
---|
119 | $minutes = $time_fields[0]; |
---|
120 | $seconds = $time_fields[1]; |
---|
121 | |
---|
122 | } else if( count($time_fields) == 1 ) { |
---|
123 | |
---|
124 | $hours = 0; |
---|
125 | $minutes = 0; |
---|
126 | $seconds = $time_fields[0]; |
---|
127 | } |
---|
128 | |
---|
129 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
130 | |
---|
131 | return $myepoch; |
---|
132 | } |
---|
133 | |
---|
134 | function makeSearchPage() { |
---|
135 | global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; |
---|
136 | global $end_from_time, $end_to_time, $filter; |
---|
137 | |
---|
138 | $tpl->assign( "cluster", $clustername ); |
---|
139 | $tpl->assign( "id_value", $id ); |
---|
140 | $tpl->assign( "user_value", $user ); |
---|
141 | $tpl->assign( "queue_value", $queue ); |
---|
142 | $tpl->assign( "name_value", $name ); |
---|
143 | $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) ); |
---|
144 | $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) ); |
---|
145 | $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) ); |
---|
146 | $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) ); |
---|
147 | |
---|
148 | if( validateFormInput() ) { |
---|
149 | |
---|
150 | $tpl->newBlock( "search_results" ); |
---|
151 | $tdb = new TarchDbase(); |
---|
152 | $search_ids = $tdb->searchDbase( $id, $queue, $user, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); |
---|
153 | |
---|
154 | foreach( $search_ids as $foundid ) { |
---|
155 | |
---|
156 | $job = $tdb->getJobArray( $foundid ); |
---|
157 | $nodes = $tdb->getNodesForJob( $foundid ); |
---|
158 | |
---|
159 | $tpl->newBlock( "node" ); |
---|
160 | $tpl->assign( "id", $job[id] ); |
---|
161 | $tpl->assign( "state", $job[status] ); |
---|
162 | $tpl->assign( "user", $job[owner] ); |
---|
163 | $tpl->assign( "queue", $job[queue] ); |
---|
164 | $tpl->assign( "name", $job[name] ); |
---|
165 | $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job[requested_time] ) ) ); |
---|
166 | $tpl->assign( "req_memory", $job[requested_memory] ); |
---|
167 | |
---|
168 | $nodes_nr = count( $nodes ); |
---|
169 | $domain = $job[domain]; |
---|
170 | $ppn = (int) $job[ppn] ? $job[ppn] : 1; |
---|
171 | $cpus = $nodes_nr * $ppn; |
---|
172 | |
---|
173 | $tpl->assign( "nodes", $nodes_nr ); |
---|
174 | $tpl->assign( "cpus", $cpus ); |
---|
175 | |
---|
176 | $runningtime = intval( $job[stop_timestamp] - $job[start_timestamp] ); |
---|
177 | $tpl->assign( "started", makeDate( $job[start_timestamp] ) ); |
---|
178 | $tpl->assign( "finished", makeDate( $job[stop_timestamp] ) ); |
---|
179 | $tpl->assign( "runningtime", makeTime( $runningtime ) ); |
---|
180 | |
---|
181 | print_r( $job ); |
---|
182 | print_r( $nodes ); |
---|
183 | //output jobzooi |
---|
184 | |
---|
185 | } |
---|
186 | |
---|
187 | if( count( $search_ids ) == 1 ) { |
---|
188 | |
---|
189 | $tpl->newBlock( "showhosts" ); |
---|
190 | } |
---|
191 | |
---|
192 | // show search results |
---|
193 | |
---|
194 | } |
---|
195 | } |
---|
196 | ?> |
---|