Skip to content

Commit

Permalink
cp upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
iWirk committed Sep 27, 2022
1 parent 2bc627c commit 4473dad
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 140 deletions.
24 changes: 24 additions & 0 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function __construct()
$this->middleware('can:settings-edit_voice')->only(['updateVoice']);

$this->middleware('can:settings-cp_update_check')->only(['checkForCpUpdate']);

$this->middleware('can:settings-cp_upgrade')->only(['checkForCpUpdate']);
}

/**
Expand Down Expand Up @@ -87,4 +89,26 @@ public function checkForCpUpdate(): JsonResponse
'target' => $target
]);
}

/**
* Initiates the upgrade process for the control panel by calling the cli using the gRpc Bridge
*
* @return JsonResponse
*/
public function upgradeCp(): JsonResponse
{
try {
$bridgeClient = new BridgeClientService();

$bridgeClient->upgradeControlPanel();
} catch (Exception $e) {
flash('BRIDGE ERROR', $e->getMessage(), 'error');
}

flash('Control Panel update started.', 'the application will be offline for a few minutes ', 'warning');

return response()->json([
'upgrade' => 'started'
]);
}
}
31 changes: 25 additions & 6 deletions app/Services/Bridge/BridgeClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Services\Bridge;

use Bridge\BridgeClient;
use Bridge\CheckForCpUpdateRequest;
use Bridge\GetCpVersionRequest;
use Bridge\EmptyMessage;
use Bridge\UpgradeCpRequest;
use Exception;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Storage;
Expand Down Expand Up @@ -36,10 +36,10 @@ public function __construct()
* @return string
*/
public function getControlPanelVersion(): string {
$request = new GetCpVersionRequest();
$request = new EmptyMessage();
list($response, $status) = $this->client->getCpVersion($request)->wait();
if ($status->code !== \Grpc\STATUS_OK) {
throw new Exception('Error while getting version: ' . $status->code . ", " . $status->details . PHP_EOL);
throw new Exception('Error while retrieving current version: ' . $status->code . ", " . $status->details . PHP_EOL);
}
return $response->getVersion();
}
Expand All @@ -49,11 +49,30 @@ public function getControlPanelVersion(): string {
* @return string
*/
public function checkForControlPanelUpdate(): string {
$request = new CheckForCpUpdateRequest();
$request = new EmptyMessage();
list($response, $status) = $this->client->CheckForCpUpdate($request)->wait();
if ($status->code !== \Grpc\STATUS_OK) {
throw new Exception('Error while checking for Control Panel update: ' . $status->code . ", " . $status->details . PHP_EOL);
throw new Exception('Error while checking for Control Panel updates: ' . $status->code . ", " . $status->details . PHP_EOL);
}
return $response->getTarget();
}

/**
* @throws Exception
* @return void
*/
public function upgradeControlPanel(): void {
$request = new UpgradeCpRequest();

$target = $this->checkForControlPanelUpdate();
if ($target === 'none') {
throw new Exception('Error while initiating Control Panel upgrade: No valid upgrade target found');
}

$request->setVersion($target);
list($response, $status) = $this->client->UpgradeCp($request)->wait();
if ($status->code !== \Grpc\STATUS_OK) {
throw new Exception('Error while initiating Control Panel upgrade: ' . $status->code . ", " . $status->details . PHP_EOL);
}
}
}
22 changes: 18 additions & 4 deletions bridge/Bridge/BridgeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public function SayHello(\Bridge\HelloRequest $argument,

/**
* Get the current version of the control panel
* @param \Bridge\GetCpVersionRequest $argument input argument
* @param \Bridge\EmptyMessage $argument input argument
* @param array $metadata metadata
* @param array $options call options
* @return \Grpc\UnaryCall
*/
public function GetCpVersion(\Bridge\GetCpVersionRequest $argument,
public function GetCpVersion(\Bridge\EmptyMessage $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/bridge.Bridge/GetCpVersion',
$argument,
Expand All @@ -48,17 +48,31 @@ public function GetCpVersion(\Bridge\GetCpVersionRequest $argument,
}

/**
* @param \Bridge\CheckForCpUpdateRequest $argument input argument
* @param \Bridge\EmptyMessage $argument input argument
* @param array $metadata metadata
* @param array $options call options
* @return \Grpc\UnaryCall
*/
public function CheckForCpUpdate(\Bridge\CheckForCpUpdateRequest $argument,
public function CheckForCpUpdate(\Bridge\EmptyMessage $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/bridge.Bridge/CheckForCpUpdate',
$argument,
['\Bridge\CheckForCpUpdateReply', 'decode'],
$metadata, $options);
}

/**
* @param \Bridge\UpgradeCpRequest $argument input argument
* @param array $metadata metadata
* @param array $options call options
* @return \Grpc\UnaryCall
*/
public function UpgradeCp(\Bridge\UpgradeCpRequest $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/bridge.Bridge/UpgradeCp',
$argument,
['\Bridge\EmptyMessage', 'decode'],
$metadata, $options);
}

}
32 changes: 26 additions & 6 deletions bridge/Bridge/BridgeStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,47 @@ public function SayHello(

/**
* Get the current version of the control panel
* @param \Bridge\GetCpVersionRequest $request client request
* @param \Bridge\EmptyMessage $request client request
* @param \Grpc\ServerContext $context server request context
* @return \Bridge\GetCpVersionReply for response data, null if if error occured
* initial metadata (if any) and status (if not ok) should be set to $context
*/
public function GetCpVersion(
\Bridge\GetCpVersionRequest $request,
\Bridge\EmptyMessage $request,
\Grpc\ServerContext $context
): ?\Bridge\GetCpVersionReply {
$context->setStatus(\Grpc\Status::unimplemented());
return null;
}

/**
* @param \Bridge\CheckForCpUpdateRequest $request client request
* @param \Bridge\EmptyMessage $request client request
* @param \Grpc\ServerContext $context server request context
* @return \Bridge\CheckForCpUpdateReply for response data, null if if error occured
* initial metadata (if any) and status (if not ok) should be set to $context
*/
public function CheckForCpUpdate(
\Bridge\CheckForCpUpdateRequest $request,
\Bridge\EmptyMessage $request,
\Grpc\ServerContext $context
): ?\Bridge\CheckForCpUpdateReply {
$context->setStatus(\Grpc\Status::unimplemented());
return null;
}

/**
* @param \Bridge\UpgradeCpRequest $request client request
* @param \Grpc\ServerContext $context server request context
* @return \Bridge\EmptyMessage for response data, null if if error occured
* initial metadata (if any) and status (if not ok) should be set to $context
*/
public function UpgradeCp(
\Bridge\UpgradeCpRequest $request,
\Grpc\ServerContext $context
): ?\Bridge\EmptyMessage {
$context->setStatus(\Grpc\Status::unimplemented());
return null;
}

/**
* Get the method descriptors of the service for server registration
*
Expand All @@ -69,13 +83,19 @@ public final function getMethodDescriptors(): array
'/bridge.Bridge/GetCpVersion' => new \Grpc\MethodDescriptor(
$this,
'GetCpVersion',
'\Bridge\GetCpVersionRequest',
'\Bridge\EmptyMessage',
\Grpc\MethodDescriptor::UNARY_CALL
),
'/bridge.Bridge/CheckForCpUpdate' => new \Grpc\MethodDescriptor(
$this,
'CheckForCpUpdate',
'\Bridge\CheckForCpUpdateRequest',
'\Bridge\EmptyMessage',
\Grpc\MethodDescriptor::UNARY_CALL
),
'/bridge.Bridge/UpgradeCp' => new \Grpc\MethodDescriptor(
$this,
'UpgradeCp',
'\Bridge\UpgradeCpRequest',
\Grpc\MethodDescriptor::UNARY_CALL
),
];
Expand Down
31 changes: 0 additions & 31 deletions bridge/Bridge/CheckForCpUpdateRequest.php

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified bridge/GPBMetadata/Bridge.php
Binary file not shown.
56 changes: 0 additions & 56 deletions bridge/GetVersionRequest.php

This file was deleted.

4 changes: 4 additions & 0 deletions config/cerberus.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,9 @@
'slug' => 'settings-cp_update_check',
'description' => 'a user can check if an update of the control panel is available'
],
[
'slug' => 'settings-cp_upgrade',
'description' => 'a user can initiate the upgrade process for the control panel.'
],
]
];
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@
},
"resolutions": {
"vue-loader": "^15.10.0"
},
"dependencies": {
"retry-axios": "^3.0.0"
}
}
Loading

0 comments on commit 4473dad

Please sign in to comment.