diff --git a/CHANGELOG.md b/CHANGELOG.md index ab94347..78f39ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## [1.3.0] - 2026-03-31 +### Added +Añadida acción Refresh para actualizar el estado de un cliente o clientes. Se actualiza su configuración de discos y se recarga el ogBrowser por si hubiese cambio del menu. ## [1.2.11] - 2026-03-25 ### Added diff --git a/config/api_platform/Client.yaml b/config/api_platform/Client.yaml index 3b0e448..229aa8c 100644 --- a/config/api_platform/Client.yaml +++ b/config/api_platform/Client.yaml @@ -100,6 +100,13 @@ resources: uriTemplate: /clients/server/power-off controller: App\Controller\OgAgent\PowerOffAction + refresh_client: + class: ApiPlatform\Metadata\Post + method: POST + input: App\Dto\Input\MultipleClientsInput + uriTemplate: /clients/server/refresh + controller: App\Controller\OgAgent\RefreshAction + check_partition_sizes: class: ApiPlatform\Metadata\Post method: POST diff --git a/src/Controller/OgAgent/RefreshAction.php b/src/Controller/OgAgent/RefreshAction.php new file mode 100644 index 0000000..2107a2d --- /dev/null +++ b/src/Controller/OgAgent/RefreshAction.php @@ -0,0 +1,93 @@ +clients as $clientEntity) { + /** @var Client $client */ + $client = $clientEntity->getEntity(); + + if (!$client->getIp()) { + throw new BadRequestHttpException('IP is required'); + } + + // ONLY execute if the client is in OG_LIVE state + if ($client->getStatus() !== ClientStatus::OG_LIVE) { + $this->logger->info('Skipping refresh for client not in OG_LIVE state', ['client' => $client->getId(), 'status' => $client->getStatus()]); + continue; + } + + $data = [ + 'nfn' => 'Actualizar', + 'ids' => '0' + ]; + + $response = $this->createRequest( + method: 'POST', + url: 'https://'.$client->getIp().':8000/ogAdmClient/Actualizar', + params: [ + 'json' => $data, + ], + token: $client->getToken(), + ); + + if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) { + $this->logger->error('Error refreshing client', ['client' => $client->getId(), 'error' => $response['error']]); + + if ($input->queue) { + $this->createService->__invoke($client, CommandTypes::REFRESH, TraceStatus::PENDING, null, []); + continue; + } + + continue; + } + + $this->logger->info('Refreshing client menu and disk configuration', ['client' => $client->getId()]); + + $jobId = $response['job_id'] ?? null; + + // We do not change the status here, it remains OG_LIVE + // $client->setStatus(ClientStatus::OG_LIVE); + + $this->createService->__invoke($client, CommandTypes::REFRESH, TraceStatus::SUCCESS, $jobId, []); + } + + return new JsonResponse(data: [], status: Response::HTTP_OK); + } +} diff --git a/src/Model/CommandTypes.php b/src/Model/CommandTypes.php index cff2407..a788231 100644 --- a/src/Model/CommandTypes.php +++ b/src/Model/CommandTypes.php @@ -29,6 +29,7 @@ final class CommandTypes public const string HARDWARE_INVENTORY = 'hardware-inventory'; public const string SOFTWARE_INVENTORY = 'software-inventory'; public const string KILL_JOB = 'kill-job'; + public const string REFRESH = 'refresh'; private const array COMMAND_TYPES = [ self::DEPLOY_IMAGE => 'Deploy Image', @@ -56,6 +57,7 @@ final class CommandTypes self::HARDWARE_INVENTORY => 'Hardware Inventory', self::SOFTWARE_INVENTORY => 'Software Inventory', self::KILL_JOB => 'Kill Job', + self::REFRESH => 'Refresh', ]; public static function getCommandTypes(): array