[532] | 1 | <?php |
---|
| 2 | |
---|
| 3 | $clustername = "GINA Cluster"; |
---|
| 4 | $cluster= "GINA Cluster"; |
---|
| 5 | $c= "GINA Cluster"; |
---|
| 6 | |
---|
| 7 | global $c, $clustername, $cluster; |
---|
| 8 | |
---|
| 9 | include_once "./libtoga.php"; |
---|
| 10 | |
---|
| 11 | $ds = new DataSource(); |
---|
| 12 | $myxml_data = &$ds->getData(); |
---|
| 13 | |
---|
| 14 | //printf( "d %s\n", strlen( $myxml_data ) ); |
---|
| 15 | //return 0; |
---|
| 16 | |
---|
| 17 | global $jobs; |
---|
| 18 | |
---|
| 19 | $data_gatherer = new DataGatherer( $clustername ); |
---|
| 20 | $data_gatherer->parseXML( &$myxml_data ); |
---|
| 21 | |
---|
| 22 | $heartbeat = &$data_gatherer->getHeartbeat(); |
---|
| 23 | $jobs = &$data_gatherer->getJobs(); |
---|
| 24 | //$gnodes = $data_gatherer->getNodes(); |
---|
| 25 | $cpus = &$data_gatherer->getCpus(); |
---|
| 26 | $use_fqdn = &$data_gatherer->getUsingFQDN(); |
---|
| 27 | |
---|
| 28 | // The ext grid script will send a task field which will specify what it wants to do |
---|
| 29 | //$task = ''; |
---|
| 30 | |
---|
| 31 | if( isset($_POST['task']) ) |
---|
| 32 | { |
---|
| 33 | $task = $_POST['task']; |
---|
| 34 | } |
---|
| 35 | if( isset( $HTTP_POST_VARS['task' ] ) ) |
---|
| 36 | { |
---|
| 37 | $task = $HTTP_POST_VARS['task']; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | //getList(); |
---|
| 41 | |
---|
| 42 | switch($task) |
---|
| 43 | { |
---|
| 44 | case "LISTING": |
---|
| 45 | getList(); |
---|
| 46 | break; |
---|
| 47 | default: |
---|
| 48 | echo "{failure:true}"; |
---|
| 49 | break; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | function getList() |
---|
| 53 | { |
---|
[535] | 54 | global $jobs, $hearbeat; |
---|
[532] | 55 | |
---|
| 56 | $job_count = count( $jobs ); |
---|
| 57 | |
---|
| 58 | if( $job_count == 0 ) |
---|
| 59 | { |
---|
| 60 | echo 'crap({"total":"0", "results":""})'; |
---|
| 61 | return 0; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | $jobresults = array(); |
---|
| 65 | |
---|
| 66 | foreach( $jobs as $jobid => $jobattrs ) |
---|
| 67 | { |
---|
[535] | 68 | //if( $jobattrs['reported'] != $heartbeat ) |
---|
| 69 | //{ |
---|
| 70 | // continue; |
---|
| 71 | //} |
---|
[532] | 72 | |
---|
[534] | 73 | $jr['jid'] = strval( $jobid ); |
---|
| 74 | $jr['status'] = $jobattrs['status']; |
---|
| 75 | $jr['owner'] = $jobattrs['owner']; |
---|
| 76 | $jr['queue'] = $jobattrs['queue']; |
---|
| 77 | $jr['name'] = $jobattrs['name']; |
---|
| 78 | $jr['requested_time'] = makeTime( timeToEpoch( $jobattrs['requested_time'] ) ); |
---|
| 79 | |
---|
[535] | 80 | if( $jr['status'] == 'R' ) |
---|
[532] | 81 | { |
---|
| 82 | $nodes = count( $jobattrs[nodes] ); |
---|
| 83 | } |
---|
| 84 | else |
---|
| 85 | { |
---|
| 86 | $nodes = (int) $jobattrs[nodes]; |
---|
| 87 | } |
---|
| 88 | |
---|
[534] | 89 | $jr['ppn'] = strval( $jobattrs[ppn] ? $jobattrs[ppn] : 1 ); |
---|
[535] | 90 | $jr['nodect'] = strval( $nodes ); |
---|
[532] | 91 | |
---|
[535] | 92 | if( $jr['status'] == 'R' ) |
---|
[532] | 93 | { |
---|
| 94 | $jr['nodes'] = implode( ",", $jobattrs['nodes'] ); |
---|
| 95 | } |
---|
[535] | 96 | else |
---|
| 97 | { |
---|
| 98 | $jr['nodes'] = ""; |
---|
| 99 | } |
---|
[532] | 100 | |
---|
[534] | 101 | $jr['queued_timestamp'] = makeDate( $jobattrs['queued_timestamp'] ); |
---|
| 102 | $jr['start_timestamp'] = ($jobattrs['start_timestamp'] ? makeDate( $jobattrs['start_timestamp'] ) : ""); |
---|
| 103 | |
---|
[535] | 104 | if( $jr['status'] == 'R' ) |
---|
| 105 | { |
---|
| 106 | $runningtime = (int) $jobattrs['reported'] - (int) $jobattrs['start_timestamp']; |
---|
| 107 | $jr['runningtime'] = makeTime( $runningtime ); |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | $jr['runningtime'] = ""; |
---|
| 112 | } |
---|
| 113 | |
---|
[534] | 114 | $jobresults[] = $jr; |
---|
[532] | 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | //$results = array(); |
---|
| 119 | |
---|
| 120 | //foreach( $jobresults as $resid => $jr ) |
---|
| 121 | //{ |
---|
| 122 | // $jr_count = 0; |
---|
| 123 | // $job_record = array(); |
---|
| 124 | |
---|
| 125 | // foreach( $jr as $atrname => $atrval ) |
---|
| 126 | // { |
---|
| 127 | // $job_record[$jr_count] = $atrval; |
---|
| 128 | // $job_record[$atrname] = $atrval; |
---|
| 129 | |
---|
| 130 | // $jr_count = $jr_count + 1; |
---|
| 131 | // } |
---|
| 132 | |
---|
| 133 | // $results[] = $job_record; |
---|
| 134 | //} |
---|
| 135 | |
---|
| 136 | $jsonresults = JEncode( $jobresults ); |
---|
| 137 | |
---|
| 138 | echo '{"total":"'. count( $jobresults) .'","results":'. $jsonresults .'}'; |
---|
| 139 | |
---|
| 140 | return 0; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | // Encodes a SQL array into a JSON formated string |
---|
| 144 | function JEncode( $arr ) |
---|
| 145 | { |
---|
| 146 | if (version_compare(PHP_VERSION,"5.2","<")) |
---|
| 147 | { |
---|
| 148 | require_once("./JSON.php"); //if php<5.2 need JSON class |
---|
| 149 | |
---|
| 150 | $json = new Services_JSON();//instantiate new json object |
---|
| 151 | $data = $json->encode($arr); //encode the data in json format |
---|
| 152 | } |
---|
| 153 | else |
---|
| 154 | { |
---|
| 155 | $data = json_encode($arr); //encode the data in json format |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | return $data; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | ?> |
---|