Skip to content

Commit

Permalink
Merge pull request #65 from nsimakov/xdmod8.5/ak_reports_fixes
Browse files Browse the repository at this point in the history
Different fixes for 8.5 release
  • Loading branch information
nsimakov authored Aug 19, 2019
2 parents 4b11aef + 9943a50 commit 49dcad9
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 73 deletions.
59 changes: 43 additions & 16 deletions bin/appkernel_reports_manager
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
* @author Nikolay Simakov
* @author Jeffrey T. Palmer <[email protected]>
*/
require_once __DIR__ . '/../configuration/linker.php';

require_once __DIR__ . '/../share/configuration/linker.php';

use CCR\DB;
use CCR\Log;
use AppKernel\AppKernelDb;
use AppKernel\Report;

/**
* Log level determined by "verbose" and "debug".
*
* @var int
*/
$logLevel = -1;


// ================================================================================
// Parse command line options
$options = array(
Expand Down Expand Up @@ -41,6 +49,16 @@ $options = array(
"r:",
"resource:",
"Generate report ony for specified resource"
),
array(
"v",
"verbose",
"verbose output"
),
array(
"d",
"debug",
"debug output"
)
);
$options1 = "";
Expand All @@ -50,7 +68,7 @@ foreach ($options as $opt) {
$options2[$opt[0]] = $opt[1];
}
$args = getopt($options1, $options2);

// default values
// With the '-m' argument passed into this script along with a username,
// reports only associated with the username will be built and sent.
Expand Down Expand Up @@ -97,22 +115,31 @@ foreach ($args as $arg => $value) {
case 'resource':
$resource = $value;
break;

case 'v':
case 'verbose':
$logLevel = max($logLevel, Log::INFO);
break;
case 'd':
case 'debug':
$logLevel = max($logLevel, Log::DEBUG);
break;
default:
fwrite(STDERR, 'Invalid arguments: '.$arg.' => '.$value."\n");
break;
}
}
print("Accepted arguments:\n");
foreach ($args as $arg => $value) {
print("\t" . $arg . ' => ' . $value . "\n");
if($logLevel >= Log::DEBUG) {
print("Accepted arguments:\n");
foreach ($args as $arg => $value) {
print("\t" . $arg . ' => ' . $value . "\n");
}
}
// ================================================================================

// ================================================================================
// Logger configuration.
$conf = array(
'file' => false,
'emailSubject' => 'App Kernel Report Scheduler'
'emailSubject' => 'App Kernel Report Scheduler',
'consoleLogLevel' => $logLevel
);
$conf['emailSubject'] .= (APPLICATION_ENV == 'dev') ? ' [Dev]' : '';
$logger = Log::factory('ak-reports', $conf);
Expand All @@ -128,14 +155,14 @@ $logger->notice(array(

$dailyDeliveries = $db->query(
'SELECT user_id, send_report_daily, send_report_weekly, send_report_monthly, settings
FROM mod_appkernel.report
FROM report
WHERE send_report_daily = 1'
);

$dayOfTheWeek = intval($end_date->format('w')) + 1;
$weeklyDeliveries = $db->query(
'SELECT user_id, send_report_daily, send_report_weekly, send_report_monthly, settings
FROM mod_appkernel.report
FROM report
WHERE send_report_weekly = :dayOfTheWeek',
array(':dayOfTheWeek' => $dayOfTheWeek)
);
Expand All @@ -147,7 +174,7 @@ if ($lastDayOfTheMonth == $dayOfTheMonth) {
'SELECT
user_id, send_report_daily, send_report_weekly,
send_report_monthly, settings
FROM mod_appkernel.report
FROM report
WHERE send_report_monthly >= :dayOfTheMonth',
array(':dayOfTheMonth' => $dayOfTheMonth)
);
Expand All @@ -156,7 +183,7 @@ if ($lastDayOfTheMonth == $dayOfTheMonth) {
'SELECT
user_id, send_report_daily, send_report_weekly,
send_report_monthly, settings
FROM mod_appkernel.report
FROM report
WHERE send_report_monthly = :dayOfTheMonth',
array(':dayOfTheMonth' => $dayOfTheMonth)
);
Expand Down Expand Up @@ -198,11 +225,11 @@ foreach ($allGroupDeliveries as $groupDeliveries) {
$logger->err( "can not find user with id: {$delivery['user_id']}");
continue;
}

$username = $user->getUsername();
$user_email = $user->getEmailAddress();
$internal_dashboard_user=$user->isDeveloper() || $user->isDeveloper();

if ($maint_mode && $username != $maint_user) {
continue;
}
Expand All @@ -211,7 +238,7 @@ foreach ($allGroupDeliveries as $groupDeliveries) {
$logger->info("Preparing report $report_type for $username ({$delivery['user_id']})");

$report_param = json_decode($delivery['settings'], true);

if ($appkernel !== null) {
$report_param['appKer'] = array(
$appkernel
Expand Down
3 changes: 2 additions & 1 deletion classes/AppKernel/CurrentQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ private function get_active_tasks()
);
foreach ($sqlres as $res) {
//$res['time_activated']
if($this->report_params['resource']===null || in_array($res['resource'], $this->report_params['resource']))
if($this->report_params['resource']===null || empty($this->report_params['resource']) ||
in_array($res['resource'], $this->report_params['resource']))
$active_tasks[]=$res;
}
return $active_tasks;
Expand Down
65 changes: 35 additions & 30 deletions classes/AppKernel/PerformanceMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,23 @@ public function __construct($options)
$params = array();

if(isset($this->resource)) {
$quotedResourceIds = array_reduce(
$this->resource['data'],
function ($carry, $item) use ($pdo) {
$carry[] = $pdo->quote($item['id']);
return $carry;
},
array()
);
$sql = "SELECT akr.resource_id, akr.resource, akr.nickname FROM mod_appkernel.resource akr " .
"WHERE akr.xdmod_resource_id IN (" . implode(', ', $quotedResourceIds) . ')';
if (array_key_exists('data', $this->resource)) {
// limit resources by xdmod_resource_id
$quotedResourceIds = array_reduce(
$this->resource['data'],
function ($carry, $item) use ($pdo) {
$carry[] = $pdo->quote($item['id']);
return $carry;
},
array()
);
$sql = "SELECT akr.resource_id, akr.resource, akr.nickname FROM mod_appkernel.resource akr " .
"WHERE akr.xdmod_resource_id IN (" . implode(', ', $quotedResourceIds) . ')';
} elseif (!empty($this->resource)) {
// limit resources by AKRR resource name
$sql = "SELECT akr.resource_id, akr.resource, akr.nickname FROM mod_appkernel.resource akr " .
"WHERE akr.resource IN ('" . implode("', '", $this->resource) . "')";
}
}

$sqlres_tasdb=$pdo->query($sql, $params);
Expand Down Expand Up @@ -174,35 +181,36 @@ public function make_report($internal_dashboard_user=false)
$tdStyle=array(
' '=>'style="background-color:white;"',
'F'=>'style="background-color:#FFB0C4;"',
'U'=>'style="background-color:#F7FE2E;"',
'O'=>'style="background-color:#FE9A2E;"',
'C'=>'style="background-color:#81BEF7;"',
'U'=>'style="background-color:#FFB336;"',
'O'=>'style="background-color:#81BEF7;"',
'C'=>'style="background-color:#FFF8DC;"',
'N'=>'style="background-color:#B0FFC5;"',
'R'=>'style="background-color:#F781F3;"'
'R'=>'style="background-color:#DCDCDC;"'
);

$message='';
$message.='<h3>Table 3. Performance Heat Map of All App Kernels on Each System</h3>';
$message.='<h3>Table 3. Performance Heat Map of All App Kernels on Each System</h3>' . "\n";

$message.='<b>KEY</b>: Each day is summarized in a table cell as pair of a symbol and a number. The symbol represents the status of last application kernel'
. ' execution on that day and the number shows the total number of runs. Each cell is colored according to the status of last application kernel run.'
. ' The description of the codes are: <br/><br/>'
. '<table border="1" cellspacing="0" style="">'
. ' The description of the codes are: <br/><br/>' . "\n"
. '<table border="1" cellspacing="0" style="">' . "\n"
. '<tr>'
. '<td>Code</td>'
. '<td>Description</td>'
. '</tr>';
. '</tr>' . "\n";


foreach(array('N','U','O','F','C','R', ' ') as $c){
$message.="<tr>";
$message.="<td {$tdStyle[$c]}>{$c}</td>";
$message.="<td {$tdStyle[$c]}>{$c}</td>\n";
$message.="<td>".TaskState::$summaryCodes[$c]."</td>";
$message.="</tr>";
$message.="</tr>\n";
}

$message.='</table>';
$message.="</table>\n";
$message.='The status code is linked to full report of the last run.<br/><br/>';
print($message);


$totalColumns=1+count($rec_dates)+1;
Expand Down Expand Up @@ -485,12 +493,12 @@ private function getMap()
$rec_dates = array();

$start_date = clone $this->start_date;
$end_date = clone $this->end_date;
$end_date_exclusive = clone $this->end_date_exclusive;

$run_date = clone $this->start_date;
$day_interval = new DateInterval('P1D');

while ($run_date <= $end_date) {
while ($run_date < $end_date_exclusive) {
$rec_dates[] = $run_date->format('Y/m/d');
$run_date->add($day_interval);
}
Expand Down Expand Up @@ -524,7 +532,7 @@ private function getMap()
SQL;
$params = array(
':start_date' => $start_date->format('Y/m/d'),
':end_date' => $end_date->format('Y/m/d')
':end_date' => $end_date_exclusive->format('Y/m/d')
);

// If a userOrganization has been provided then filter the results on them.
Expand All @@ -546,7 +554,7 @@ private function getMap()
SQL;
$params[':organization_id'] = $this->userOrganization;
} elseif (isset($this->resource_ids)) {
} elseif (isset($this->resource_ids) && (!(empty($this->resource_ids)))) {
$resourceIds = implode(', ', $this->resource_ids);
$sql = <<<SQL
SELECT aki.ak_id,
Expand All @@ -563,7 +571,6 @@ private function getMap()
SQL;

}

$rows = $pdo->query($sql, $params);

$controlState = array();
Expand All @@ -587,8 +594,7 @@ private function getMap()
SQL;
$params = array(
':start_date' => $start_date->format('Y/m/d'),
':end_date' => $end_date->format('Y/m/d')

':end_date' => $end_date_exclusive->format('Y/m/d')
);

// If we have resource id's then we should additionally filter on them.
Expand Down Expand Up @@ -644,7 +650,7 @@ function ($value) use ($arr_db) {
// Proceed with filtering the values...
if ((!isset($ak_id)) ||
(isset($this->resource_ids) && !array_key_exists($resource, $this->resource_ids)) ||
(isset($this->appKer) && !in_array($this->ak_shortnames[$appKer], $this->appKer)) ||
(isset($this->appKer) && (!(empty($this->appKer) || in_array($this->ak_shortnames[$appKer], $this->appKer)))) ||
(isset($this->problemSize) && !in_array($problemSize, $this->problemSize))
) {
continue;
Expand Down Expand Up @@ -683,7 +689,6 @@ function ($value) use ($arr_db) {
$runsStatus[$resource][$appKer][$problemSize][$rec_date]->add_task($task);
}
}

//sort
ksort($runsStatus);
foreach ($runsStatus as $resource => $val1) {
Expand Down
Loading

0 comments on commit 49dcad9

Please sign in to comment.