Merge pull request 'Corregida llamada a instalar/desinstalar oglives en servidores ogboot' (#101) from manage-ogboot-oglives into main
Reviewed-on: #101pull/102/head^2
commit
e7e095b8ef
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue