Beispiel #1
0
function ShowNodeHistory($node_id = null, $record = null, $count = 200, $showall = 0, $reverse = 0, $date = null, $IP = null, $mac = null, $node_opt = "")
{
    global $TBSUEXEC_PATH;
    global $PROTOGENI;
    $atime = 0;
    $ftime = 0;
    $rtime = 0;
    $dtime = 0;
    $nodestr = "";
    $arg = "";
    $opt = "-ls -n " . escapeshellarg($count);
    if (!$showall) {
        $opt .= " -a";
    }
    if ($reverse) {
        $opt .= " -r";
    }
    if ($date) {
        $date = date("Y-m-d H:i:s", strtotime($date));
        $opt .= " -d " . escapeshellarg($date);
    } elseif ($record) {
        $opt .= " -x " . escapeshellarg($record);
    }
    if ($node_id || $IP || $mac) {
        if ($IP) {
            $opt .= " -i " . escapeshellarg($IP);
            $nodestr = "<th>Node</th>";
        }
        if ($mac) {
            $opt .= " -m " . escapeshellarg($mac);
            $nodestr = "<th>Node</th>";
        } else {
            $arg = escapeshellarg($node_id);
        }
    } else {
        $opt .= " -A";
        $node_id = "";
        $nodestr = "<th>Node</th>";
        #
        # When supplying a date, we want a summary of all nodes at that
        # point in time, not a listing.
        #
        if ($date) {
            $opt .= " -c";
        }
    }
    if ($fp = popen("{$TBSUEXEC_PATH} nobody nobody " . "  webnode_history {$opt} {$arg}", "r")) {
        if (!$showall) {
            $str = "Allocation";
        } else {
            $str = "";
        }
        if ($node_id == "") {
            echo "<center><b>\n                  {$str} History for All Nodes.\n                  </b></center>\n";
        } else {
            $node_url = CreateURL("shownode", URLARG_NODEID, $node_id);
            echo "<center><b>\n                  {$str} History for Node <a href='{$node_url}'>{$node_id}</a>.\n                  </b></center>\n";
        }
        # Keep track of history record bounds, for paging through.
        $max_history_id = 0;
        # Build up table contents
        ob_start();
        $line = fgets($fp);
        while (!feof($fp)) {
            #
            # Formats:
            # nodeid REC tstamp duration uid pid eid
            # nodeid SUM alloctime freetime reloadtime downtime
            #
            $results = preg_split("/[\\s]+/", $line, 9, PREG_SPLIT_NO_EMPTY);
            $nodeid = $results[0];
            $type = $results[1];
            if ($type == "SUM") {
                # Save summary info for later
                $atime = $results[2];
                $ftime = $results[3];
                $rtime = $results[4];
                $dtime = $results[5];
            } elseif ($type == "REC") {
                $stamp = $results[2];
                $datestr = date("Y-m-d H:i:s", $stamp);
                $duration = $results[3];
                $durstr = "";
                if ($duration >= 24 * 60 * 60) {
                    $durstr = sprintf("%dd", $duration / (24 * 60 * 60));
                    $duration %= 24 * 60 * 60;
                }
                if ($duration >= 60 * 60) {
                    $durstr = sprintf("%s%dh", $durstr, $duration / (60 * 60));
                    $duration %= 60 * 60;
                }
                if ($duration >= 60) {
                    $durstr = sprintf("%s%dm", $durstr, $duration / 60);
                    $duration %= 60;
                }
                $durstr = sprintf("%s%ds", $durstr, $duration);
                $uid = $results[4];
                $pid = $results[5];
                $thisid = intval($results[8]);
                if ($thisid >= $max_history_id) {
                    $max_history_id = $thisid;
                }
                $slice = "--";
                $expurl = null;
                if ($pid == "FREE") {
                    $pid = "--";
                    $eid = "--";
                    $uid = "--";
                } else {
                    $eid = $results[6];
                    if ($results[7]) {
                        $experiment = Experiment::Lookup($results[7]);
                        $experiment_stats = ExperimentStats::Lookup($results[7]);
                        if ($experiment_stats && $experiment_stats->slice_uuid()) {
                            $url = CreateURL("genihistory", "slice_uuid", $experiment_stats->slice_uuid());
                            $slice = "<a href='{$url}'>" . "<img src=\"greenball.gif\" border=0></a>";
                        }
                        if ($experiment) {
                            $expurl = CreateURL("showexp", URLARG_EID, $experiment->idx());
                        } else {
                            $expurl = CreateURL("showexpstats", "record", $experiment_stats->exptidx());
                        }
                    }
                }
                if ($node_id == "") {
                    $nodeurl = CreateURL("shownodehistory", URLARG_NODEID, $nodeid);
                    echo "<tr>\n                          <td><a href='{$nodeurl}'>{$nodeid}</a></td>\n                          <td>{$pid}</td>";
                    if ($expurl) {
                        echo "<td><a href='{$expurl}'>{$eid}</a></td>";
                    } else {
                        echo "<td>{$eid}</td>";
                    }
                    if ($PROTOGENI) {
                        echo "<td>{$slice}</td>";
                    }
                    echo "<td>{$uid}</td>\n                          <td>{$datestr}</td>\n                          <td>{$durstr}</td>\n                          </tr>\n";
                } else {
                    echo "<tr>\n                          <td>{$pid}</td>";
                    if ($expurl) {
                        echo "<td><a href='{$expurl}'>{$eid}</a></td>";
                    } else {
                        echo "<td>{$eid}</td>";
                    }
                    if ($PROTOGENI) {
                        echo "<td>{$slice}</td>";
                    }
                    echo "<td>{$uid}</td>\n                          <td>{$datestr}</td>\n                          <td>{$durstr}</td>\n                          </tr>\n";
                }
            }
            $line = fgets($fp, 1024);
        }
        pclose($fp);
        $table_html = ob_get_contents();
        ob_end_clean();
        echo "<center><a href='shownodehistory.php3?record={$max_history_id}" . "&count={$count}&{$node_opt}'>Next {$count} records</a></center>\n";
        echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";
        echo "<tr>\n\t       {$nodestr}\n               <th>Pid</th>\n               <th>Eid</th>";
        if ($PROTOGENI) {
            echo "<th>Slice</th>";
        }
        echo " <th>Allocated By</th>\n               <th>Allocation Date</th>\n\t       <th>Duration</th>\n              </tr>\n";
        echo $table_html;
        echo "</table>\n";
        echo "<center><a href='shownodehistory.php3?record={$max_history_id}" . "&count={$count}&{$node_opt}'>Next {$count} records</a></center>\n";
        $ttime = $atime + $ftime + $rtime + $dtime;
        if ($ttime) {
            echo "<br>\n                  <center><b>\n                  Usage Summary for Node {$node_id}.\n                  </b></center><br>\n";
            echo "<table border=1 align=center>\n";
            $str = "Allocated";
            $pct = sprintf("%5.1f", $atime * 100.0 / $ttime);
            echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n";
            $str = "Free";
            $pct = sprintf("%5.1f", $ftime * 100.0 / $ttime);
            echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n";
            $str = "Reloading";
            $pct = sprintf("%5.1f", $rtime * 100.0 / $ttime);
            echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n";
            $str = "Down";
            $pct = sprintf("%5.1f", $dtime * 100.0 / $ttime);
            echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n";
            echo "</table>\n";
        }
    }
}
    # Need these below.
    $pid = $experiment->pid();
    $gid = $experiment->gid();
    $eid = $experiment->eid();
    $idx = $experiment->idx();
    $stats = $experiment->GetStats();
    if (!$stats) {
        TBERROR("Could not load stats object for experiment {$pid}/{$eid}", 1);
    }
    $archive_idx = $stats->archive_idx();
    # Permission
    if (!$isadmin && !$experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
        USERERROR("You do not have permission to view this archive!", 1);
    }
} elseif (isset($index)) {
    $stats = ExperimentStats::Lookup($index);
    if (!$stats) {
        PAGEARGERROR("Invalid experiment index: {$index}");
    }
    # Need these below.
    $pid = $stats->pid();
    $eid = $stats->eid();
    $gid = $stats->gid();
    $idx = $index;
    $archive_idx = $stats->archive_idx();
    # Permission
    if (!$isadmin && !$stats->AccessCheck($this_user, $TB_PROJECT_READINFO)) {
        USERERROR("You do not have permission to view tags for " . "archive in {$pid}/{$eid}!", 1);
    }
}
# This gets scrubbed ...
 function GetStats()
 {
     return ExperimentStats::Lookup($this->exptidx());
 }
 $exptidx = $row["exptidx"];
 $pid = $row["pid"];
 $eid = $row["eid"];
 $alloc = $row["allocated"];
 $id = 0;
 $slice = "--";
 if (isset($row["released"])) {
     $free = $row["released"];
 } else {
     $free = "&nbsp";
 }
 if (isset($row["history_id"])) {
     $id = $row["history_id"];
 }
 $experiment = Experiment::Lookup($exptidx);
 $experiment_stats = ExperimentStats::Lookup($exptidx);
 if ($experiment_stats && $experiment_stats->slice_uuid()) {
     $url = CreateURL("genihistory", "slice_uuid", $experiment_stats->slice_uuid());
     $slice = "<a href='{$url}'>" . "<img src=\"greenball.gif\" border=0></a>";
 }
 if ($experiment) {
     $expurl = CreateURL("showexp", URLARG_EID, $experiment->idx());
 } else {
     $expurl = CreateURL("showexpstats", "record", $experiment_stats->exptidx());
 }
 if ($id > $max_history_id) {
     $max_history_id = $id;
 }
 $html .= "<tr>";
 if (!$tag) {
     $html .= "<td>{$thistag}</td>";