From 0482a3e9e80335cea8919ee7d2e19d49fd638d13 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Tue, 31 Mar 2026 13:18:45 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20accion=20Refresh=20para=20actual?= =?UTF-8?q?izar=20el=20estado=20de=20un=20cliente=20o=20clientes.=20Se=20a?= =?UTF-8?q?ctualiza=20su=20configuracion=20de=20discos=20y=20se=20recarga?= =?UTF-8?q?=20el=20ogBrowser=20por=20si=20hubiese=20cambio=20del=20menu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 + config/api_platform/Client.yaml | 7 ++ src/Controller/OgAgent/RefreshAction.php | 93 ++++++++++++++++++++++++ src/Model/CommandTypes.php | 2 + 4 files changed, 105 insertions(+) create mode 100644 src/Controller/OgAgent/RefreshAction.php 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 -- 2.40.1