| @@ 77-101 (lines=25) @@ | ||
| 74 | * @param string $destFilename |
|
| 75 | * @return \DataSift\Storyplayer\CommandLib\CommandResult |
|
| 76 | */ |
|
| 77 | public function downloadFile($sourceFilename, $destFilename) |
|
| 78 | { |
|
| 79 | // what are we doing? |
|
| 80 | $log = Log::usingLog()->startAction("download file '{$this->args[0]}':'{$sourceFilename}' to '{$destFilename}'"); |
|
| 81 | ||
| 82 | // make sure we have valid host details |
|
| 83 | $hostDetails = $this->getHostDetails(); |
|
| 84 | ||
| 85 | // get an object to talk to this host |
|
| 86 | $host = OsLib::getHostAdapter($this->st, $hostDetails->osName); |
|
| 87 | ||
| 88 | // upload the file |
|
| 89 | $result = $host->downloadFile($hostDetails, $sourceFilename, $destFilename); |
|
| 90 | ||
| 91 | // did the command used to upload succeed? |
|
| 92 | if ($result->didCommandFail()) { |
|
| 93 | $msg = "download failed with return code '{$result->returnCode}' and output '{$result->output}'"; |
|
| 94 | $log->endAction($msg); |
|
| 95 | throw Exceptions::newActionFailedException(__METHOD__, $msg); |
|
| 96 | } |
|
| 97 | ||
| 98 | // all done |
|
| 99 | $log->endAction(); |
|
| 100 | return $result; |
|
| 101 | } |
|
| 102 | ||
| 103 | /** |
|
| 104 | * @param string $filename |
|
| @@ 65-89 (lines=25) @@ | ||
| 62 | */ |
|
| 63 | class UsingShell extends HostAwareModule |
|
| 64 | { |
|
| 65 | public function runCommand($command) |
|
| 66 | { |
|
| 67 | // what are we doing? |
|
| 68 | $log = Log::usingLog()->startAction("run command '{$command}' on host '{$this->args[0]}'"); |
|
| 69 | ||
| 70 | // make sure we have valid host details |
|
| 71 | $hostDetails = $this->getHostDetails(); |
|
| 72 | ||
| 73 | // get an object to talk to this host |
|
| 74 | $host = OsLib::getHostAdapter($this->st, $hostDetails->osName); |
|
| 75 | ||
| 76 | // run the command in the guest operating system |
|
| 77 | $result = $host->runCommand($hostDetails, $command); |
|
| 78 | ||
| 79 | // did the command succeed? |
|
| 80 | if ($result->didCommandFail()) { |
|
| 81 | $msg = "command failed with return code '{$result->returnCode}' and output '{$result->output}'"; |
|
| 82 | $log->endAction($msg); |
|
| 83 | throw Exceptions::newActionFailedException(__METHOD__, $msg); |
|
| 84 | } |
|
| 85 | ||
| 86 | // all done |
|
| 87 | $log->endAction(); |
|
| 88 | return $result; |
|
| 89 | } |
|
| 90 | ||
| 91 | public function runCommandAsUser($command, $user) |
|
| 92 | { |
|
| @@ 353-377 (lines=25) @@ | ||
| 350 | * @param string $appName |
|
| 351 | * @return mixed |
|
| 352 | */ |
|
| 353 | public function getAppSettings($appName) |
|
| 354 | { |
|
| 355 | // what are we doing? |
|
| 356 | $log = Log::usingLog()->startAction("get settings for '{$appName}' from host '{$this->args[0]}'"); |
|
| 357 | ||
| 358 | // make sure we have valid host details |
|
| 359 | $hostDetails = $this->getHostDetails(); |
|
| 360 | ||
| 361 | // do we have any app settings? |
|
| 362 | if (!isset($hostDetails->appSettings, $hostDetails->appSettings->$appName)) { |
|
| 363 | $log->endAction("setting does not exist :("); |
|
| 364 | throw Exceptions::newActionFailedException(__METHOD__); |
|
| 365 | } |
|
| 366 | ||
| 367 | // yes we do |
|
| 368 | $value = $hostDetails->appSettings->$appName; |
|
| 369 | ||
| 370 | // log the settings |
|
| 371 | $printer = new DataPrinter(); |
|
| 372 | $logValue = $printer->convertToString($value); |
|
| 373 | $log->endAction("settings for '{$appName}' are '{$logValue}'"); |
|
| 374 | ||
| 375 | // all done |
|
| 376 | return $value; |
|
| 377 | } |
|
| 378 | ||
| 379 | /** |
|
| 380 | * @param string $path |
|
| @@ 66-91 (lines=26) @@ | ||
| 63 | * |
|
| 64 | * @return void |
|
| 65 | */ |
|
| 66 | public function addItem($key, $value) |
|
| 67 | { |
|
| 68 | // get our table name from the constructor |
|
| 69 | $tableName = $this->args[0]; |
|
| 70 | ||
| 71 | $log = Log::usingLog()->startAction("add item '{$key}' to {$tableName} table"); |
|
| 72 | ||
| 73 | // get the table |
|
| 74 | $table = RuntimeTable::fromRuntimeTable($tableName)->getTable(); |
|
| 75 | ||
| 76 | // make sure we don't have a duplicate entry |
|
| 77 | if (isset($table->$key)){ |
|
| 78 | $msg = "table already contains item '{$key}'"; |
|
| 79 | $log->endAction($msg); |
|
| 80 | throw Exceptions::newActionFailedException(__METHOD__, $msg); |
|
| 81 | } |
|
| 82 | ||
| 83 | // add the entry |
|
| 84 | $table->$key = $value; |
|
| 85 | ||
| 86 | // save the updated runtime config |
|
| 87 | $this->saveRuntimeConfig($log); |
|
| 88 | ||
| 89 | // all done |
|
| 90 | $log->endAction(); |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * removeItem |
|