Skip to content

Commit

Permalink
phoromatic: Support for updating the system status
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellarabel committed May 19, 2014
1 parent f09a3c4 commit 820ea78
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGE-LOG
Expand Up @@ -3,6 +3,7 @@ PHORONIX TEST SUITE CHANGE-LOG
Phoronix Test Suite (Git)

- Cleaning up more of the Phoromatic UI
- phoromatic: Support for updating the system status

Phoronix Test Suite 5.2 Milestone 2
18 May 2014
Expand Down
79 changes: 43 additions & 36 deletions pts-core/modules/phoromatic.php
Expand Up @@ -93,6 +93,14 @@ protected static function upload_to_remote_server($to_post, $server_address = nu
$to_post['n'] = phodevi::read_property('system', 'hostname');
return pts_network::http_upload_via_post('http://' . $server_address . ':' . $server_http_port . '/phoromatic.php', $to_post);
}
protected static function update_system_status($current_task, $estimated_time_remaining = 0)
{
return $server_response = phoromatic::upload_to_remote_server(array(
'r' => 'update_system_status',
'a' => $current_task,
'time' => $estimated_time_remaining
));
}
public static function run_connection($args)
{
self::$account_id = substr($args[0], strrpos($args[0], '/') + 1);
Expand Down Expand Up @@ -133,6 +141,7 @@ public static function run_connection($args)
$phoromatic_results_identifier = $phoromatic_schedule_id;
$phoromatic_save_identifier = $json['phoromatic']['save_identifier'];
$phoromatic_trigger = $phoromatic_schedule_id;
phoromatic::update_system_status('Running Benchmarks For Schedule: ' . $phoromatic_trigger . ' - ' . $phoromatic_schedule_id);

if($json['phoromatic']['settings']['RunInstallCommand'])
{
Expand Down Expand Up @@ -175,6 +184,7 @@ public static function run_connection($args)
// Run the actual tests
$test_run_manager->pre_execution_process();
$test_run_manager->call_test_runs();
phoromatic::update_system_status('Benchmarks Completed For Schedule: ' . $phoromatic_trigger . ' - ' . $phoromatic_schedule_id);
$test_run_manager->post_execution_process();

// Upload to Phoromatic
Expand All @@ -196,9 +206,14 @@ public static function run_connection($args)
phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], $phoromatic_trigger, $phoromatic_schedule_id, 'POST_RUN');
}
break;
case 'exit':
echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL;
phoromatic::update_system_status('Exiting Phoromatic');
break;
}
}
sleep(60);
phoromatic::update_system_status('Idling, Waiting For Task');
}
}
private static function set_user_context($context_script, $trigger, $schedule_id, $process)
Expand Down Expand Up @@ -238,6 +253,34 @@ private static function set_user_context($context_script, $trigger, $schedule_id

return false;
}
public static function __pre_test_install($test_identifier)
{
static $last_update_time = 0;

if(time() > ($last_update_time + 600))
{
phoromatic::update_system_status('Installing Tests');
$last_update_time = time();
}
}
public static function __pre_test_run($pts_test_result)
{
// TODO: need a way to get the estimated time remaining from the test_run_manager so we can pass that back to the update_system_status parameter so server can read it
// TODO: report name of test identifier/run i.e. . ' For ' . PHOROMATIC_TITLE
phoromatic::update_system_status('Running ' . $pts_test_result->test_profile->get_identifier());
}
public static function __event_user_error($user_error)
{
// Report PTS user error warnings to Phoromatic server
phoromatic::report_warning_to_phoromatic($user_error->get_error_string());
}
public static function __event_results_saved($test_run_manager)
{
/*if(pts_module::read_variable('AUTO_UPLOAD_RESULTS_TO_PHOROMATIC') && pts_module::is_module_setup())
{
phoromatic::upload_unscheduled_test_results($test_run_manager->get_file_name());
}*/
}


//
Expand Down Expand Up @@ -661,36 +704,6 @@ public static function user_system_process()
// Process Functions
//


public static function __pre_test_install($test_identifier)
{
static $last_update_time = 0;

if(time() > ($last_update_time + 600))
{
phoromatic::update_system_status('Installing Tests');
$last_update_time = time();
}
}
public static function __pre_test_run($pts_test_result)
{
// TODO: need a way to get the estimated time remaining from the test_run_manager so we can pass that back to the update_system_status parameter so server can read it
// TODO: report name of test identifier/run i.e. . ' For ' . PHOROMATIC_TITLE
phoromatic::update_system_status('Running ' . $pts_test_result->test_profile->get_identifier());
}
public static function __event_user_error($user_error)
{
// Report PTS user error warnings to Phoromatic server
phoromatic::report_warning_to_phoromatic($user_error->get_error_string());
}
public static function __event_results_saved($test_run_manager)
{
if(pts_module::read_variable('AUTO_UPLOAD_RESULTS_TO_PHOROMATIC') && pts_module::is_module_setup())
{
phoromatic::upload_unscheduled_test_results($test_run_manager->get_file_name());
}
}

//
// Other Functions
//
Expand All @@ -707,12 +720,6 @@ protected static function update_system_details()

return self::read_xml_value($server_response, 'PhoronixTestSuite/Phoromatic/General/Response') == 'TRUE';
}
protected static function update_system_status($current_task, $estimated_time_remaining = 0)
{
$server_response = phoromatic::upload_to_remote_server(array('r' => 'update_system_status', 'a' => $current_task, 'time' => $estimated_time_remaining));

return self::read_xml_value($server_response, 'PhoronixTestSuite/Phoromatic/General/Response') == 'TRUE';
}
protected static function report_warning_to_phoromatic($warning)
{
$server_response = phoromatic::upload_to_remote_server(array('r' => 'report_pts_warning', 'a' => $warning));
Expand Down
@@ -0,0 +1,46 @@
<?php

/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2009 - 2014, Phoronix Media
Copyright (C) 2009 - 2014, Michael Larabel
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

if($ACTIVITY == null)
{
$json['phoromatic']['response'] = 'Update Failed';
echo json_encode($json);
exit;
}

if(empty($ESTIMATED_TIME) || !is_numeric($ESTIMATED_TIME))
{
$ESTIMATED_TIME = -1;
}


$stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET CurrentTask = :current_task, EstimatedTimeForTask = :time_for_task WHERE AccountID = :account_id AND SystemID = :system_id');
$stmt->bindValue(':account_id', $ACCOUNT_ID);
$stmt->bindValue(':system_id', SYSTEM_ID);
$stmt->bindValue(':current_task', $ACTIVITY);
$stmt->bindValue(':current_task', $ESTIMATED_TIME);
$stmt->execute();

$json['phoromatic']['response'] = 'Status Updated';
echo json_encode($json);

?>
2 changes: 1 addition & 1 deletion pts-core/phoromatic/pages/phoromatic_results.php
Expand Up @@ -94,7 +94,7 @@ public static function render_page_process($PATH)
{
break;
}
$main .= '<a href="?results/' . $test_result_row['UploadID'] . '"><li>' . $test_result_row['Title'] . '<br /><em>' . phoromatic_system_id_to_name($test_result_row['SystemID']) . ' - ' . $test_result_row['UploadTime'] . '</em></li></a>';
$main .= '<a href="?results/' . $test_result_row['UploadID'] . '"><li>' . $test_result_row['Title'] . '<br /><em>' . phoromatic_system_id_to_name($test_result_row['SystemID']) . ' - ' . phoromatic_user_friendly_timedate($test_result_row['UploadTime']) . '</em></li></a>';
$results++;

}
Expand Down

0 comments on commit 820ea78

Please sign in to comment.