Skip to content

Commit

Permalink
Update upgrade documentation and add required cmds.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpwhite4 authored and jtpalmer committed Apr 5, 2019
1 parent 70098c8 commit 7d3ce1f
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 18 deletions.
278 changes: 278 additions & 0 deletions background_scripts/xdmod-supremm-admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
#!/usr/bin/env php
<?php
/**
* Perform administrative tasks for the Open XDMoD
* Job Performance (SUPREMM) module.
*/
require_once __DIR__ . '/../configuration/linker.php';

use CCR\DB;
use CCR\DB\MySQLHelper;
use CCR\Log;

// Catch any unexpected exceptions.
try {
main();
} catch (Exception $e) {
do {
$logger->crit(array(
'message' => $e->getMessage(),
'stacktrace' => $e->getTraceAsString(),
));
} while ($e = $e->getPrevious());
exit(1);
}

/**
* Main function.
*/
function main()
{
global $argv, $logger;

$opts = array(
'h' => 'help',
'v' => 'verbose',
'd' => 'debug',
'q' => 'quiet',
'f' => 'force',
'r:' => 'resource:',
'a:' => 'action:'
);

$shortOptions = implode('', array_keys($opts));
$longOptions = array_values($opts);

$args = getopt($shortOptions, $longOptions);

if ($args === false) {
fwrite(STDERR, "Failed to parse arguments\n");
exit(1);
}

$help = false;

$config = array(
'logLevel' => -1,
'action' => null,
'resource' => null,
'force' => false
);

foreach ($args as $key => $value) {
if (is_array($value)) {
fwrite(STDERR, "Multiple values not allowed for '$key'\n");
exit(1);
}

switch ($key) {
case 'h':
case 'help':
$help = true;
break;
case 'q':
case 'quiet':
$config['logLevel'] = max($config['logLevel'], Log::WARNING);
break;
case 'v':
case 'verbose':
$config['logLevel'] = max($config['logLevel'], Log::INFO);
break;
case 'd':
case 'debug':
$config['logLevel'] = max($config['logLevel'], Log::DEBUG);
break;
case 'f':
case 'force':
$config['force'] = true;
break;
case 'r':
case 'resource':
$config['resource'] = $value;
break;
case 'a':
case 'action':
$config['action'] = $value;
break;
default:
fwrite(STDERR, "Unexpected option '$key'\n");
exit(1);
break;
}
}

if ($help) {
displayHelpText();
exit;
}

if ($config['logLevel'] === -1) { $config['logLevel'] = Log::NOTICE; }

$logConf = array(
'file' => false,
'mail' => false,
'consoleLogLevel' => $config['logLevel'],
);

$logger = Log::factory('xdmod-supremm-admin', $logConf);

$cmd = implode(' ', array_map('escapeshellarg', $argv));
$logger->info("Command: $cmd");

switch ($config['action']) {
case 'truncate':
truncateAction($config);
break;
default:
$logger->crit('No action specified');
displayHelpText();
exit(1);
}

exit;
}

/**
* Truncate all the job tables.
*/
function truncateAction($config)
{
global $logger;

if ($config['resource'] === null) {
$logger->crit('No resource specified');
exit(1);
}

if (!$config['force'] && !confirm('Truncate all job data for resource ' . $config['resource'] . '?')) {
return;
}

$db = DB::factory('datawarehouse');

$searchColumn = 'code';
if (is_numeric($config['resource'])) {
$searchColumn = 'id';
}
$resourceQuery = $db->prepare('SELECT id FROM `modw`.`resourcefact` WHERE ' . $searchColumn . ' = :resource');
$resourceQuery->execute(array('resource' => $config['resource']));
$result = $resourceQuery->fetchAll(PDO::FETCH_COLUMN, 0);

if (count($result) !== 1) {
$logger->crit('Unable to find resource ' . $config['resource'] . ' in the database');
return;
}

$resource_id = $result[0];

$logger->notice('Reset job ingest status for job summaries in mongo for resource_id ' . $resource_id);

$sdb = new \DataWarehouse\Query\SUPREMM\SupremmDbInterface();

$docs_updated = $sdb->updateEtlVersion($resource_id, 0);
if ($docs_updated === null) {
$logger->warning('No mongo data found for resource. No action taken');
} else {
if ($docs_updated['ok']) {
$logger->notice('Job summary documents status reset for ' . $docs_updated['nModified'] . ' jobs');
} else {
$logger->warning('Job summary document update failed ' . json_encode($docs_updated));
}
}

$logger->notice('Removing job data from sql database for resource_id ' . $resource_id);

$tables = array(
'executable',
'cwd',
'host',
'jobhost',
'job_errors'
);

foreach ($tables as $table) {
$rows = $db->execute('DELETE FROM `modw_supremm`.`' . $table . '` WHERE resource_id = :resource_id', array('resource_id' => $resource_id));
$logger->notice('Deleted ' . $rows . ' rows from ' . $table);
}

$multiDel = <<<EOF
DELETE FROM `modw_supremm` . `job` , `modw_supremm` . `job_name` , `modw_supremm` . `job_peers`
USING `modw_supremm`.`job`
LEFT JOIN `modw_supremm`.`job_name` ON `modw_supremm`.`job`.jobname_id = `modw_supremm`.`job_name`.id
LEFT JOIN `modw_supremm`.`job_peers` ON `modw_supremm`.`job`._id = `modw_supremm`.`job_peers`.job_id
WHERE
`modw_supremm`.`job`.resource_id = :resource_id
EOF;
$rows = $db->execute($multiDel, array('resource_id' => $resource_id));
$logger->notice('Deleted ' . $rows . ' rows from job, job_name and job_peers tables.');
}

/**
* Prompt the user for confirmation.
*
* @param string $msg Confirmation message.
*
* @return bool True if the message is confirmed.
*/
function confirm($msg)
{
$response = null;

while ($response === null) {
$response = readline("$msg (yes/no): [no] ");

if (!in_array($response, array('yes', 'no', ''))) {
echo "\n'$response' is not a valid option.\n\n";
$response = null;
}
}

return $response == 'yes';
}

/**
* Output help text to STDOUT.
*/
function displayHelpText()
{
echo <<<'EOF'
Perform administrative tasks.
This command currently supports truncating all job data for a given resource.
Usage: xdmod-supremm-admin -a ACTION [OPTS]
-h, --help
Display this message and exit.
-v, --verbose
Output info level logging.
--debug
Output debug level logging.
-q, --quiet
Output warning level logging.
-f, --force
Force the action. You will not be prompted to confirm the
action requested.
-a, --action=[ACTION]
Perform the requested ACTION.
Actions:
truncate --resource=RESOURCE
The truncate action removes the data for a given resource
Examples:
xdmod-admin --action=truncate --resource='hpc'
This will remove all job data from the supremm realm for the resource 'hpc'.

EOF;
}

23 changes: 23 additions & 0 deletions classes/DataWarehouse/Query/SUPREMM/SupremmDbInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ public function __construct() {

}

/**
* Update the etl ingest version number for all documents in mongo for a
* resource.
*/
public function updateEtlVersion($resource_id, $new_etl_version) {

$resconf =& $this->getResourceConfig($resource_id);

if( $resconf === null) {
return null;
}

$collection = $resconf['handle']->selectCollection($resconf['collection']);

$result = $collection->update(
array('processed.' . $this->getEtlUid() . '.version' => $this->etl_version),
array('$set' => array('processed.' . $this->getEtlUid() . '.version' => $new_etl_version)),
array('multiple' => true, 'socketTimeoutMS' => -1, 'wTimeoutMS' => -1)
);

return $result;
}

/** get the list of configured resources
* @return array list of resource ids of the configured resources
*/
Expand Down
8 changes: 6 additions & 2 deletions docs/supremm-install-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ identical to the version of the base XDMoD install. The versions of the
summarization software and PCP software for a given XDMoD version are listed
below.

### Open XDMoD 8.0.0
### Open XDMoD 8.1.0

<table>
<thead>
Expand All @@ -46,7 +46,7 @@ below.
</thead>
<tbody>
<tr>
<td> Job Summarization </td><td align="right"> 1.1.0 </td><td align="right"> 1.1.x </td>
<td> Job Summarization </td><td align="right"> 1.1.1 </td><td align="right"> 1.1.x </td>
</tr>
<tr>
<td> PCP </td><td align="right"> 3.12.2 </td><td align="right"> 3.11.x - 3.12.x </td>
Expand All @@ -58,6 +58,10 @@ below.
The SUPReMM software has been tested with MongoDB version 3.4.15. We expect
that the software is compatible with any supported release version of MongoDB.

The summarization software should be compatible with the 4.x releases of PCP.
However the XDMoD team have not tested this configuration and will not be able
to provide support for it.

System Requirements
---------------------

Expand Down
Loading

0 comments on commit 7d3ce1f

Please sign in to comment.