diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d97ddf..8e492cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog -## [1.7.0] - 2026-84-28 + +## [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. +- Corregido también bug en la propagación de la interfaz de red a los clientes de una OU + +## [1.7.0] - 2026-04-28 ### Added - Añadido endpoint para consultar y mostrar versiones de los distintos paquetes de Opengnsys - Sondeo del estado de las aulas 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/Controller/PropagateNetworkSettingsAction.php b/src/Controller/PropagateNetworkSettingsAction.php index 6e79ba9..0a41156 100644 --- a/src/Controller/PropagateNetworkSettingsAction.php +++ b/src/Controller/PropagateNetworkSettingsAction.php @@ -48,7 +48,8 @@ class PropagateNetworkSettingsAction extends AbstractController $client->setBootServer($networkSettings->getBootServer()); $client->setOgLive($networkSettings->getOgLive()); $client->setTemplate($networkSettings->getPxeTemplate()); - $client->setEthernet($networkSettings->getEthernet()); + $client->setResolution($networkSettings->getResolution()); + $client->setNetiface($networkSettings->getNetiface()); } $this->entityManager->flush(); 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/Entity/AbstractEntity.php b/src/Entity/AbstractEntity.php index b4d7cba..385524e 100644 --- a/src/Entity/AbstractEntity.php +++ b/src/Entity/AbstractEntity.php @@ -34,6 +34,12 @@ abstract class AbstractEntity $this->uuid = Uuid::uuid7(); } + public function __clone() + { + $this->id = null; + $this->uuid = Uuid::uuid7(); + } + public function getId(): ?int { return $this->id; diff --git a/src/Entity/NetworkSettings.php b/src/Entity/NetworkSettings.php index 86a6747..66570ed 100644 --- a/src/Entity/NetworkSettings.php +++ b/src/Entity/NetworkSettings.php @@ -93,6 +93,38 @@ class NetworkSettings extends AbstractEntity $this->organizationalUnits = new ArrayCollection(); } + public function __clone() + { + parent::__clone(); + $this->organizationalUnits = new ArrayCollection(); + } + + public function copyFrom(NetworkSettings $source): void + { + $this->nextServer = $source->getNextServer(); + $this->bootFileName = $source->getBootFileName(); + $this->proxy = $source->getProxy(); + $this->dns = $source->getDns(); + $this->netmask = $source->getNetmask(); + $this->router = $source->getRouter(); + $this->ntp = $source->getNtp(); + $this->netiface = $source->getNetiface(); + $this->p2pTime = $source->getP2pTime(); + $this->p2pMode = $source->getP2pMode(); + $this->mcastIp = $source->getMcastIp(); + $this->mcastSpeed = $source->getMcastSpeed(); + $this->mcastMode = $source->getMcastMode(); + $this->mcastPort = $source->getMcastPort(); + $this->resolution = $source->getResolution(); + $this->menu = $source->getMenu(); + $this->hardwareProfile = $source->getHardwareProfile(); + $this->repository = $source->getRepository(); + $this->ogLive = $source->getOgLive(); + $this->ogShare = $source->getOgShare(); + $this->pxeTemplate = $source->getPxeTemplate(); + $this->bootServer = $source->getBootServer(); + } + public function getNextServer(): ?string { return $this->nextServer; diff --git a/src/Entity/OrganizationalUnit.php b/src/Entity/OrganizationalUnit.php index d776214..2178124 100644 --- a/src/Entity/OrganizationalUnit.php +++ b/src/Entity/OrganizationalUnit.php @@ -335,17 +335,29 @@ class OrganizationalUnit extends AbstractEntity public function updateNetworkSettingsRecursively(?NetworkSettings $networkSettings): void { - $this->setNetworkSettings($networkSettings); + if ($networkSettings === null) { + $this->setNetworkSettings(null); + } else { + $currentSettings = $this->getNetworkSettings(); + if ($currentSettings === null || $currentSettings === $networkSettings) { + $this->setNetworkSettings(clone $networkSettings); + } else { + $currentSettings->copyFrom($networkSettings); + } + } - /** @var Client $client */ - foreach ($this->getClients() as $client) { - $client->setMenu($networkSettings->getMenu()); - $client->setHardwareProfile($networkSettings->getHardwareProfile()); - $client->setRepository($networkSettings->getRepository()); - $client->setBootServer($networkSettings->getBootServer()); - $client->setOgLive($networkSettings->getOgLive()); - $client->setTemplate($networkSettings->getPxeTemplate()); - $client->setResolution($networkSettings->getResolution()); + if ($networkSettings !== null) { + /** @var Client $client */ + foreach ($this->getClients() as $client) { + $client->setMenu($networkSettings->getMenu()); + $client->setHardwareProfile($networkSettings->getHardwareProfile()); + $client->setRepository($networkSettings->getRepository()); + $client->setBootServer($networkSettings->getBootServer()); + $client->setOgLive($networkSettings->getOgLive()); + $client->setTemplate($networkSettings->getPxeTemplate()); + $client->setResolution($networkSettings->getResolution()); + $client->setNetiface($networkSettings->getNetiface()); + } } foreach ($this->getOrganizationalUnits() as $childUnit) { 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);