From ec4dcbd000b229af6312e896b05bff2091c642d3 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Mon, 4 May 2026 14:15:18 +0200 Subject: [PATCH] Corregida llamada a instalar/desinstalar oglives en servidores ogboot --- CHANGELOG.md | 5 +++++ .../OgBoot/AbstractOgBootController.php | 6 ++++++ src/Controller/OgBoot/OgLive/InstallAction.php | 14 ++++++++------ src/Controller/OgBoot/OgLive/UninstallAction.php | 16 ++++++++++++---- src/Dto/Input/OgLiveInput.php | 9 +++++++++ src/State/Processor/OgLiveProcessor.php | 11 +++++++++++ 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6fd5ed..8e492cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [1.7.2] - 2026-05-04 +### Fixed +- Corregida llamada a instalar/desinstalar oglives en servidores ogboot + + ## [1.7.1] - 2026-05-04 ### Fixed - Corregido bug en la propagación de parametros de las OU, se propagaban parametros de hijos a padres. diff --git a/src/Controller/OgBoot/AbstractOgBootController.php b/src/Controller/OgBoot/AbstractOgBootController.php index e1b7b9b..50d6e7a 100644 --- a/src/Controller/OgBoot/AbstractOgBootController.php +++ b/src/Controller/OgBoot/AbstractOgBootController.php @@ -73,6 +73,9 @@ abstract class AbstractOgBootController extends AbstractController $statusCode = $response->getStatusCode(); $content = json_decode($response->getContent(false), true); $errorMessage = $content['error'] ?? $content['message'] ?? $e->getMessage(); + if (isset($content['details'])) { + $errorMessage .= ' - ' . (is_array($content['details']) ? json_encode($content['details']) : $content['details']); + } $this->logger->error(sprintf('Client/Server error in request to %s: %s', $url, $errorMessage)); throw new HttpException($statusCode, "External API Error ($statusCode): $errorMessage"); @@ -106,6 +109,9 @@ abstract class AbstractOgBootController extends AbstractController $statusCode = $response->getStatusCode(); $content = json_decode($response->getContent(false), true); $errorMessage = $content['error'] ?? $content['message'] ?? $e->getMessage(); + if (isset($content['details']) && $content['details'] !== '') { + $errorMessage .= ' - ' . (is_array($content['details']) ? json_encode($content['details']) : $content['details']); + } $this->logger->error(sprintf('Client/Server error in request to %s: %s', $url, $errorMessage)); throw new HttpException($statusCode, "External API Error ($statusCode): $errorMessage"); diff --git a/src/Controller/OgBoot/OgLive/InstallAction.php b/src/Controller/OgBoot/OgLive/InstallAction.php index 67ed159..449c21b 100644 --- a/src/Controller/OgBoot/OgLive/InstallAction.php +++ b/src/Controller/OgBoot/OgLive/InstallAction.php @@ -51,12 +51,6 @@ class InstallAction extends AbstractOgBootController throw new BadRequestHttpException('This OgLive is not attached to any BootServer.'); } - $content = $this->createRequestFromBootServer($bootServer, 'POST', '/ogboot/v1/oglives/install', $params); - - if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) { - throw new BadRequestHttpException('An error occurred while installing OgLive: ' . $content['error']. ' (' . $content['details'] . ')'); - } - $this->createService->__invoke(null, CommandTypes::INSTALL_OGLIVE, TraceStatus::IN_PROGRESS, 'InstallOgLive_'.$data->getUuid(), $inputData); $data->setName($this->simplifyOgLiveFilenameService->__invoke($data->getFilename()) ?? 'OgLive_'.$data->getUuid()); @@ -65,6 +59,14 @@ class InstallAction extends AbstractOgBootController $this->entityManager->persist($data); $this->entityManager->flush(); + $content = $this->createRequestFromBootServer($bootServer, 'POST', '/ogboot/v1/oglives/install', $params); + + if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) { + $data->setStatus(OgLiveStatus::FAILED); + $this->entityManager->flush(); + throw new BadRequestHttpException('An error occurred while installing OgLive: ' . $content['error']. ' (' . ($content['details'] ?? '') . ')'); + } + return new JsonResponse(data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/UninstallAction.php b/src/Controller/OgBoot/OgLive/UninstallAction.php index 9e5e34a..7b6fea1 100644 --- a/src/Controller/OgBoot/OgLive/UninstallAction.php +++ b/src/Controller/OgBoot/OgLive/UninstallAction.php @@ -37,10 +37,18 @@ class UninstallAction extends AbstractOgBootController throw new BadRequestHttpException('This OgLive is not attached to any BootServer.'); } - $content = $this->createRequestFromBootServer($bootServer, 'DELETE', '/ogboot/v1/oglives/'.$data->getChecksum()); - - if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) { - throw new BadRequestHttpException('An error occurred while uninstalling the OgLive: ' . $content['error'] . ' (' . $content['details'] . ')'); + try { + $content = $this->createRequestFromBootServer($bootServer, 'DELETE', '/ogboot/v1/oglives/'.$data->getChecksum()); + + if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) { + throw new BadRequestHttpException('An error occurred while uninstalling the OgLive: ' . $content['error'] . ' (' . ($content['details'] ?? '') . ')'); + } + } catch (\Symfony\Component\HttpKernel\Exception\HttpException $e) { + if ($e->getStatusCode() === Response::HTTP_NOT_FOUND) { + $this->logger->warning('OgLive not found on boot server, proceeding with DB removal to keep synchronization.'); + } else { + throw $e; + } } $this->entityManager->remove($data); diff --git a/src/Dto/Input/OgLiveInput.php b/src/Dto/Input/OgLiveInput.php index 2646088..2395eeb 100644 --- a/src/Dto/Input/OgLiveInput.php +++ b/src/Dto/Input/OgLiveInput.php @@ -3,6 +3,7 @@ namespace App\Dto\Input; use ApiPlatform\Metadata\ApiProperty; +use App\Entity\BootServer; use App\Entity\OgLive; use App\Model\OgLiveStatus; use Symfony\Component\Serializer\Annotation\Groups; @@ -16,6 +17,10 @@ final class OgLiveInput #[ApiProperty(description: 'The download url of the ogLive', example: "http://example.com/oglive1.iso")] public ?string $downloadUrl = null; + #[Groups(['og-live:write'])] + #[ApiProperty(description: 'The boot server this OgLive belongs to')] + public ?string $bootServer = null; + public function __construct(?OgLive $ogLive = null) { if (!$ogLive) { @@ -23,6 +28,9 @@ final class OgLiveInput } $this->downloadUrl = $ogLive->getDownloadUrl(); + if ($ogLive->getBootServer()) { + $this->bootServer = '/boot-servers/' . $ogLive->getBootServer()->getUuid(); + } } public function createOrUpdateEntity(?OgLive $ogLive = null): OgLive @@ -42,6 +50,7 @@ final class OgLiveInput $ogLive->setDownloadUrl($this->downloadUrl); $ogLive->setStatus(OgLiveStatus::INACTIVE); + return $ogLive; } } \ No newline at end of file diff --git a/src/State/Processor/OgLiveProcessor.php b/src/State/Processor/OgLiveProcessor.php index 46673e0..c239743 100644 --- a/src/State/Processor/OgLiveProcessor.php +++ b/src/State/Processor/OgLiveProcessor.php @@ -15,6 +15,7 @@ use App\Dto\Input\OgLiveInput; use App\Dto\Output\OgLiveOutput; use App\Model\OgLiveStatus; use App\Repository\OgLiveRepository; +use App\Repository\BootServerRepository; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; @@ -25,6 +26,7 @@ readonly class OgLiveProcessor implements ProcessorInterface { public function __construct( private OgLiveRepository $ogLiveRepository, + private BootServerRepository $bootServerRepository, private ValidatorInterface $validator, private InstallAction $installAction, private UninstallAction $uninstallAction, @@ -64,6 +66,15 @@ readonly class OgLiveProcessor implements ProcessorInterface } $ogLive = $data->createOrUpdateEntity($entity); + + if ($data->bootServer) { + $uuid = str_replace('/boot-servers/', '', $data->bootServer); + $bootServer = $this->bootServerRepository->findOneByUuid($uuid); + if ($bootServer) { + $ogLive->setBootServer($bootServer); + } + } + $this->validator->validate($ogLive); $this->ogLiveRepository->save($ogLive);