-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable show raw data and Job Viewer for the Jobs realm #730
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
namespace DataWarehouse\Query\Jobs; | ||
|
||
use \DataWarehouse\Query\Model\Table; | ||
use \DataWarehouse\Query\Model\TableField; | ||
use \DataWarehouse\Query\Model\FormulaField; | ||
use \DataWarehouse\Query\Model\WhereCondition; | ||
use \DataWarehouse\Query\Model\Schema; | ||
|
||
/* | ||
* @author Joe White | ||
* @date 2015-03-25 | ||
* | ||
*/ | ||
class JobDataset extends \DataWarehouse\Query\RawQuery | ||
{ | ||
private $documentation = array(); | ||
|
||
public function __construct( | ||
array $parameters, | ||
$stat = "all" | ||
) { | ||
|
||
parent::__construct('Jobs', 'modw_aggregates', 'jobfact_by_day', array()); | ||
|
||
$config = \Xdmod\Config::factory(); | ||
|
||
$dataTable = $this->getDataTable(); | ||
$joblistTable = new Table($dataTable->getSchema(), $dataTable->getName() . "_joblist", "jl"); | ||
$factTable = new Table(new Schema('modw'), 'job_tasks', 'jt'); | ||
|
||
$this->addTable($joblistTable ); | ||
$this->addTable($factTable ); | ||
|
||
$this->addWhereCondition(new WhereCondition( | ||
new TableField($joblistTable, "agg_id"), | ||
"=", | ||
new TableField($dataTable, "id") | ||
)); | ||
$this->addWhereCondition(new WhereCondition( | ||
new TableField($joblistTable, "jobid"), | ||
"=", | ||
new TableField($factTable, "job_id") | ||
)); | ||
|
||
if (isset($parameters['primary_key'])) { | ||
$pdostr = $this->nextPdoIndex($parameters['primary_key']); | ||
$this->addWhereCondition(new WhereCondition(new TableField($factTable, 'job_id'), "=", $pdostr)); | ||
} else { | ||
$matches = array(); | ||
if (preg_match('/^(\d+)(?:[\[_](\d+)\]?)?$/', $parameters['job_identifier'], $matches)) { | ||
$pdostr = $this->nextPdoIndex($parameters['resource_id']); | ||
$this->addWhereCondition(new WhereCondition(new TableField($factTable, 'resource_id'), '=', $pdostr)); | ||
if (isset($matches[2])) { | ||
$pdostr = $this->nextPdoIndex($matches[1]); | ||
$this->addWhereCondition(new WhereCondition(new TableField($factTable, 'local_jobid'), '=', $pdostr)); | ||
|
||
$pdostr = $this->nextPdoIndex($matches[2]); | ||
$this->addWhereCondition(new WhereCondition(new TableField($factTable, 'local_job_array_index'), '=', $pdostr)); | ||
} else { | ||
$pdostr = $this->nextPdoIndex($matches[1]); | ||
$this->addWhereCondition(new WhereCondition(new TableField($factTable, 'local_job_id_raw'), '=', $pdostr)); | ||
} | ||
} else { | ||
throw new \Exception('invalid query parameters'); | ||
} | ||
} | ||
|
||
if ($stat == "accounting") { | ||
$i = 0; | ||
foreach ($config['rawstatistics']['modw.job_tasks'] as $sdata) { | ||
$sfield = $sdata['key']; | ||
if ($sdata['dtype'] == 'accounting') { | ||
$this->addField(new TableField($factTable, $sfield)); | ||
$this->documentation[$sfield] = $sdata; | ||
} elseif ($sdata['dtype'] == 'foreignkey') { | ||
if (isset($sdata['join'])) { | ||
$info = $sdata['join']; | ||
$i += 1; | ||
$tmptable = new Table(new Schema($info['schema']), $info['table'], "ft$i"); | ||
$this->addTable($tmptable); | ||
$this->addWhereCondition(new WhereCondition(new TableField($factTable, $sfield), '=', new TableField($tmptable, "id"))); | ||
$fcol = isset($info['column']) ? $info['column'] : 'name'; | ||
$this->addField(new TableField($tmptable, $fcol, $sdata['name'])); | ||
|
||
$this->documentation[ $sdata['name'] ] = $sdata; | ||
} | ||
} | ||
} | ||
$rf = new Table(new Schema('modw'), 'resourcefact', 'rf'); | ||
$this->addTable($rf); | ||
$this->addWhereCondition(new WhereCondition(new TableField($factTable, 'resource_id'), '=', new TableField($rf, 'id'))); | ||
$this->addField(new TableField($rf, 'timezone')); | ||
$this->documentation['timezone'] = array( | ||
"name" => "Timezone", | ||
"documentation" => "The timezone of the resource.", | ||
"group" => "Administration", | ||
'visibility' => 'public', | ||
"per" => "resource"); | ||
} | ||
else | ||
{ | ||
$this->addField(new TableField($factTable, "job_id", "jobid")); | ||
$this->addField(new TableField($factTable, "local_jobid", "local_job_id")); | ||
|
||
$rt = new Table(new Schema("modw"), "resourcefact", "rf"); | ||
$this->joinTo($rt, "task_resource_id", "code", "resource"); | ||
|
||
$pt = new Table(new Schema('modw'), 'person', 'p'); | ||
$this->joinTo($pt, "person_id", "long_name", "name"); | ||
|
||
$st = new Table(new Schema('modw'), 'systemaccount', 'sa'); | ||
$this->joinTo($st, "systemaccount_id", "username", "username"); | ||
} | ||
} | ||
|
||
private function joinTo($othertable, $joinkey, $otherkey, $colalias, $idcol = "id") | ||
{ | ||
$this->addTable($othertable); | ||
$this->addWhereCondition(new WhereCondition(new TableField($this->getDataTable(), $joinkey), '=', new TableField($othertable, $idcol))); | ||
$this->addField(new TableField($othertable, $otherkey, $colalias)); | ||
} | ||
|
||
public function getColumnDocumentation() | ||
{ | ||
return $this->documentation; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace DataWarehouse\Query\Jobs; | ||
|
||
class JobMetadata | ||
{ | ||
public function getJobMetadata($user, $jobid) | ||
{ | ||
$job = $this->lookupJob($user, $jobid); | ||
if ($job == null) { | ||
return array(); | ||
} | ||
|
||
return array( | ||
\DataWarehouse\Query\RawQueryTypes::ACCOUNTING => true | ||
); | ||
} | ||
|
||
public function getJobSummary($user, $jobid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do all of these methods return empty arrays? If there is a reason it should be documented in this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there is no job summary data for the Jobs realm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto for job timeseries data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, lets document that in the class. |
||
{ | ||
return array(); | ||
} | ||
|
||
public function getJobExecutableInfo($user, $jobid) | ||
{ | ||
return array(); | ||
} | ||
|
||
public function getJobTimeseriesMetaData($user, $jobid) | ||
{ | ||
return array(); | ||
} | ||
|
||
public function getJobTimeseriesMetricMeta($user, $jobid, $metric) | ||
{ | ||
return array(); | ||
} | ||
|
||
public function getJobTimeseriesMetricNodeMeta($user, $jobid, $metric, $nodeid) | ||
{ | ||
return array(); | ||
} | ||
|
||
public function getJobTimeseriesData($user, $jobid, $tsid, $nodeid, $cpuid) | ||
{ | ||
return array(); | ||
} | ||
|
||
/* | ||
* Get the local_job_id, end_time, etc for the given job entry in the | ||
* database. This information is used to lookup the job summary/timeseries | ||
* data in the document store. (But see the to-do note below). | ||
*/ | ||
private function lookupJob($user, $jobid) | ||
{ | ||
$query = new \DataWarehouse\Query\Jobs\JobDataset(array('primary_key' => $jobid)); | ||
$query->setMultipleRoleParameters($user->getAllRoles(), $user); | ||
$stmt = $query->getRawStatement(); | ||
|
||
$job = $stmt->fetchAll(\PDO::FETCH_ASSOC); | ||
if (count($job) != 1) { | ||
return null; | ||
} | ||
return $job[0]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
namespace DataWarehouse\Query\Jobs; | ||
|
||
use \DataWarehouse\Query\Model\Table; | ||
use \DataWarehouse\Query\Model\TableField; | ||
use \DataWarehouse\Query\Model\WhereCondition; | ||
use \DataWarehouse\Query\Model\Schema; | ||
|
||
class RawData extends \DataWarehouse\Query\Query | ||
{ | ||
|
||
public function __construct( | ||
$aggregation_unit_name, | ||
$start_date, | ||
$end_date, | ||
$group_by, | ||
$stat = 'jl.jobid', | ||
array $parameters = array(), | ||
$query_groupname = 'query_groupname', | ||
array $parameterDescriptions = array(), | ||
$single_stat = false | ||
) { | ||
|
||
parent::__construct( | ||
'Jobs', | ||
'modw_aggregates', | ||
'jobfact', | ||
array(), | ||
$aggregation_unit_name, | ||
$start_date, | ||
$end_date, | ||
null, | ||
null, | ||
$parameters, | ||
$query_groupname, | ||
$parameterDescriptions, | ||
$single_stat | ||
); | ||
|
||
|
||
$dataTable = $this->getDataTable(); | ||
$joblistTable = new Table($dataTable->getSchema(), $dataTable->getName() . "_joblist", "jl"); | ||
$factTable = new Table(new Schema('modw'), "job_tasks", "jt" ); | ||
|
||
$resourcefactTable = new Table(new Schema('modw'), 'resourcefact', 'rf'); | ||
$this->addTable($resourcefactTable); | ||
|
||
$this->addWhereCondition(new WhereCondition( | ||
new TableField($dataTable, "task_resource_id"), | ||
'=', | ||
new TableField($resourcefactTable, "id") | ||
)); | ||
|
||
$personTable = new Table(new Schema('modw'), 'person', 'p'); | ||
|
||
$this->addTable($personTable); | ||
$this->addWhereCondition(new WhereCondition( | ||
new TableField($dataTable, "person_id"), | ||
'=', | ||
new TableField($personTable, "id") | ||
)); | ||
|
||
$this->addField(new TableField($resourcefactTable, "code", 'resource')); | ||
$this->addField(new TableField($personTable, "long_name", "name")); | ||
|
||
$this->addField(new TableField($factTable, "job_id", "jobid") ); | ||
$this->addField(new TableField($factTable, "local_jobid", "local_job_id") ); | ||
|
||
$this->addTable($joblistTable ); | ||
$this->addTable($factTable ); | ||
|
||
$this->addWhereCondition(new WhereCondition( | ||
new TableField($joblistTable, "agg_id"), | ||
"=", | ||
new TableField($dataTable, "id") | ||
)); | ||
$this->addWhereCondition(new WhereCondition( | ||
new TableField($joblistTable, "jobid"), | ||
"=", | ||
new TableField($factTable, "job_id") | ||
)); | ||
|
||
switch($stat) { | ||
case "job_count": | ||
$this->addWhereCondition(new WhereCondition("jt.end_time_ts", "between", "d.day_start_ts and d.day_end_ts") ); | ||
break; | ||
case "started_job_count": | ||
$this->addWhereCondition(new WhereCondition("jt.start_time_ts", "between", "d.day_start_ts and d.day_end_ts") ); | ||
break; | ||
default: | ||
// All other metrics show running job count | ||
break; | ||
} | ||
} | ||
|
||
public function getQueryString($limit = null, $offset = null, $extraHavingClause = null) | ||
{ | ||
$wheres = $this->getWhereConditions(); | ||
$groups = $this->getGroups(); | ||
|
||
$select_tables = $this->getSelectTables(); | ||
$select_fields = $this->getSelectFields(); | ||
|
||
$select_order_by = $this->getSelectOrderBy(); | ||
|
||
$data_query = "SELECT DISTINCT ".implode(", ", $select_fields). | ||
" FROM ".implode(", ", $select_tables). | ||
" WHERE ".implode(" AND ", $wheres); | ||
|
||
if(count($groups) > 0) | ||
{ | ||
$data_query .= " GROUP BY \n".implode(",\n", $groups); | ||
} | ||
if($extraHavingClause != null) | ||
{ | ||
$data_query .= " HAVING " . $extraHavingClause . "\n"; | ||
} | ||
if(count($select_order_by) > 0) | ||
{ | ||
$data_query .= " ORDER BY \n".implode(",\n", $select_order_by); | ||
} | ||
|
||
if($limit !== null && $offset !== null) | ||
{ | ||
$data_query .= " LIMIT $limit OFFSET $offset"; | ||
} | ||
return $data_query; | ||
} | ||
|
||
public function getCountQueryString() | ||
{ | ||
$wheres = $this->getWhereConditions(); | ||
$groups = $this->getGroups(); | ||
|
||
$select_tables = $this->getSelectTables(); | ||
$select_fields = $this->getSelectFields(); | ||
|
||
$data_query = "SELECT COUNT(*) AS row_count FROM (SELECT DISTINCT ".implode(", ", $select_fields). | ||
" FROM ".implode(", ", $select_tables). | ||
" WHERE ".implode(" AND ", $wheres); | ||
|
||
if(count($groups) > 0) | ||
{ | ||
$data_query .= " GROUP BY \n".implode(",\n", $groups); | ||
} | ||
return $data_query . ') as a'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -725,6 +725,15 @@ public function getCountQueryString() | |
$data_query .= ") as a WHERE a.total IS NOT NULL"; | ||
return $data_query; | ||
} | ||
|
||
protected function nextPdoIndex($value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need documentation here as well. |
||
{ | ||
$pdosubst = ':subst' . $this->pdoindex; | ||
$this->pdoparams[$pdosubst] = $value; | ||
$this->pdoindex += 1; | ||
return $pdosubst; | ||
} | ||
|
||
public function setParameters(array $parameters = array()) | ||
{ | ||
$this->parameters = $parameters; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class needs a block at the top describing what it does and what data it encapsulates.