-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RemoteApi: allow to restart the daemon
fixes #406
- Loading branch information
1 parent
746dca3
commit 321de3e
Showing
7 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
library/Vspheredb/Daemon/RpcNamespace/RpcNamespaceProcess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Vspheredb\Daemon\RpcNamespace; | ||
|
||
use Evenement\EventEmitterInterface; | ||
use Evenement\EventEmitterTrait; | ||
use React\EventLoop\LoopInterface; | ||
|
||
class RpcNamespaceProcess implements EventEmitterInterface | ||
{ | ||
use EventEmitterTrait; | ||
|
||
const ON_RESTART = 'restart'; | ||
|
||
/** @var LoopInterface */ | ||
protected $loop; | ||
|
||
public function __construct(LoopInterface $loop) | ||
{ | ||
$this->loop = $loop; | ||
} | ||
|
||
/* | ||
public function infoRequest() | ||
{ | ||
return $this->prepareProcessInfo($this->daemon); | ||
} | ||
protected function prepareProcessInfo(Daemon $daemon) | ||
{ | ||
$details = $this->daemon->getProcessDetails()->getPropertiesToInsert(); | ||
$details['process_info'] = \json_decode($details['process_info']); | ||
return (object) [ | ||
'state' => $this->daemon->getProcessState()->getInfo(), | ||
'details' => (object) $details, | ||
]; | ||
} | ||
*/ | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function restartRequest() | ||
{ | ||
// Grant some time to ship the response | ||
$this->loop->addTimer(0.1, function () { | ||
$this->emit(self::ON_RESTART); | ||
}); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Vspheredb\Web\Form; | ||
|
||
use gipfl\IcingaWeb2\Icon; | ||
use gipfl\Translation\TranslationHelper; | ||
use gipfl\Web\Form\Feature\NextConfirmCancel; | ||
use gipfl\Web\InlineForm; | ||
use Icinga\Module\Vspheredb\Daemon\RemoteClient; | ||
use React\EventLoop\LoopInterface; | ||
use function Clue\React\Block\await; | ||
|
||
class RestartDaemonForm extends InlineForm | ||
{ | ||
use TranslationHelper; | ||
|
||
/** @var RemoteClient */ | ||
protected $client; | ||
|
||
/** @var LoopInterface */ | ||
protected $loop; | ||
|
||
public function __construct(RemoteClient $client, LoopInterface $loop) | ||
{ | ||
$this->client = $client; | ||
$this->loop = $loop; | ||
} | ||
|
||
protected function assemble() | ||
{ | ||
(new NextConfirmCancel( | ||
NextConfirmCancel::buttonNext($this->translate('Restart'), [ | ||
'title' => $this->translate('Click to restart the vSphereDB background daemon'), | ||
]), | ||
NextConfirmCancel::buttonConfirm($this->translate('Yes, please restart')), | ||
NextConfirmCancel::buttonCancel($this->translate('Cancel')) | ||
))->addToForm($this); | ||
} | ||
|
||
protected function onSuccess() | ||
{ | ||
await($this->client->request('process.restart'), $this->loop); | ||
} | ||
} |