Merge pull request 'develop' (#35) from develop into main
ogcore-debian-package/pipeline/head This commit looks good Details
ogcore-debian-package/pipeline/tag This commit looks good Details

Reviewed-on: #35
develop 0.14.1
Manuel Aranda Rosales 2025-06-09 11:53:37 +02:00
commit fbdf569cf3
69 changed files with 602 additions and 127 deletions

View File

@ -1,4 +1,9 @@
# Changelog
## [0.14.1] - 2025-06-09
### Fixed
- Se han corregido los mensajes de error que se envian cuando las APIs de los modulos no estan disponibles.
- Se ha corregido un bug en la herencia de datos entre aulas y grupos, que hacia que no se almacenaran los datos de manera correcta.
## [0.14.0] - 2025-06-02
### Added
- Se ha añadido la funcionalidad de mover equipos entre aulas y grupos.

View File

@ -64,6 +64,20 @@ resources:
uriTemplate: /clients/server/remove-cache-image
controller: App\Controller\OgAgent\RemoveCacheImageAction
hardware_inventory:
class: ApiPlatform\Metadata\Post
method: POST
input: false
uriTemplate: /clients/server/{uuid}/hardware-inventory
controller: App\Controller\OgAgent\HardwareInventoryAction
software_inventory:
class: ApiPlatform\Metadata\Post
method: POST
input: App\Dto\Input\SoftwareInventoryPartitionInput
uriTemplate: /clients/server/{uuid}/software-inventory
controller: App\Controller\OgAgent\SoftwareInventoryAction
reboot_client:
class: ApiPlatform\Metadata\Post
method: POST

View File

@ -13,6 +13,7 @@ resources:
filters:
- 'api_platform.filter.software.order'
- 'api_platform.filter.software.search'
- 'software.software_profile_filter'
ApiPlatform\Metadata\Get:
provider: App\State\Provider\SoftwareProvider

View File

@ -119,6 +119,10 @@ services:
parent: 'App\Filter\ImageSearchRepositoryFilter'
tags: [ 'api_platform.filter' ]
software.software_profile_filter:
parent: 'App\Filter\SoftwareProfileSearchSoftwareFilter'
tags: [ 'api_platform.filter' ]
api_platform.filter.og_live.order:
parent: 'api_platform.doctrine.orm.order_filter'
arguments:
@ -277,7 +281,7 @@ services:
api_platform.filter.software_profile.search:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'id': 'exact', 'description': 'partial' } ]
arguments: [ { 'id': 'exact', 'description': 'partial'} ]
tags: [ 'api_platform.filter' ]
api_platform.filter.subnet.order:

View File

@ -10,6 +10,6 @@
"SSL_ENABLED": "false",
"OG_BOOT_IP": "127.0.0.1",
"OG_BOOT_API_PORT": "8082",
"OG_BOOT_PXE_PORT": "8085"
"OG_BOOT_PXE_PORT": "8082"
}
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250604084222 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E43DA5256D');
$this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E43DA5256D FOREIGN KEY (image_id) REFERENCES image_image_repository (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E43DA5256D');
$this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E43DA5256D FOREIGN KEY (image_id) REFERENCES image_image_repository (id)');
}
}

View File

@ -79,7 +79,7 @@ abstract class AbstractOgAgentController extends AbstractController
return [
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
'error' => 'Client/Server error',
'error' => 'Transport error',
'details' => $e->getMessage(),
];
}

View File

@ -26,6 +26,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -45,7 +46,7 @@ class CreateImageAction extends AbstractOgAgentController
public function __invoke(Image $image, ?Partition $partition = null, ?Client $client = null): JsonResponse
{
if (!$image->getClient()->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
$partitionInfo = [];
@ -151,7 +152,7 @@ class CreateImageAction extends AbstractOgAgentController
$this->logger->info('Creating image', ['image' => $imageImageRepository->getName(), 'repository' => $repository->getIp()]);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error creating image');
throw new BadRequestHttpException('Error creating image');
}
$jobId = $response['job_id'];

View File

@ -21,6 +21,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -42,7 +43,7 @@ class DeployImageAction extends AbstractOgAgentController
$image = $imageImageRepository->getImage();
if (!$client->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
$method = match ($input->method) {
@ -51,7 +52,7 @@ class DeployImageAction extends AbstractOgAgentController
DeployMethodTypes::UNICAST_DIRECT => 'unicast-direct',
DeployMethodTypes::UNICAST => 'unicast',
DeployMethodTypes::TORRENT => 'torrent',
default => throw new ValidatorException('Invalid method'),
default => throw new BadRequestHttpException('Invalid method'),
};
$mcastMode = $input->mcastMode.'-duplex';
@ -65,7 +66,7 @@ class DeployImageAction extends AbstractOgAgentController
DeployMethodTypes::MULTICAST, DeployMethodTypes::MULTICAST_UFTP, DeployMethodTypes::MULTICAST_UFTP_DIRECT, DeployMethodTypes::MULTICAST_UDPCAST, DeployMethodTypes::MULTICAST_UDPCAST_DIRECT => $ptcMulticastValue,
DeployMethodTypes::UNICAST, DeployMethodTypes::UNICAST_DIRECT => $ptcUnicastValue,
DeployMethodTypes::TORRENT => $ptcTorrentValue,
default => throw new ValidatorException('Invalid method'),
default => throw new BadRequestHttpException('Invalid method'),
};
$repository = $imageImageRepository->getRepository();
@ -94,7 +95,7 @@ class DeployImageAction extends AbstractOgAgentController
$this->logger->info('Deploying image', [ 'image' => $imageImageRepository->getName(), 'repository' => $repository->getIp()]);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error deploying image');
throw new BadRequestHttpException('Error deploying image');
}
$jobId = $response['job_id'];

View File

@ -0,0 +1,57 @@
<?php
namespace App\Controller\OgAgent;
use App\Entity\Client;
use App\Model\CommandTypes;
use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class HardwareInventoryAction extends AbstractOgAgentController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(Client $client): JsonResponse
{
$data = [
'nfn' => 'InventarioHardware',
'ids' => '0'
];
$response = $this->createRequest(
method: 'POST',
url: 'https://'.$client->getIp().':8000/opengnsys/InventarioHardware',
params: [
'json' => $data,
],
token: $client->getToken(),
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('Error performing hardware inventory: '.$response['error']);
}
$this->logger->info('Login client', ['client' => $client->getId()]);
$jobId = $response['job_id'];
$inputData = [
'client' => $client->getIp(),
];
$this->createService->__invoke($client, CommandTypes::HARDWARE_INVENTORY, TraceStatus::IN_PROGRESS, $jobId, $inputData);
return new JsonResponse(data: [], status: Response::HTTP_OK);
}
}

View File

@ -21,6 +21,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -48,11 +49,11 @@ class LoginAction extends AbstractOgAgentController
if (!$client->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
if ($client->getStatus() !== ClientStatus::OG_LIVE) {
throw new ValidatorException('Client is not in OG_LIVE status');
throw new BadRequestHttpException('Client is not in OG_LIVE status');
}
$data = [
@ -72,7 +73,7 @@ class LoginAction extends AbstractOgAgentController
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error logging in: '.$response['error']);
throw new BadRequestHttpException('Error logging in: '.$response['error']);
}
$this->logger->info('Login client', ['client' => $client->getId()]);

View File

@ -20,6 +20,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -41,7 +42,7 @@ class PartitionAssistantAction extends AbstractOgAgentController
$partitions = $input->partitions;
if (empty($partitions)) {
throw new ValidatorException('Partitions is required');
throw new BadRequestHttpException('Partitions is required');
}
foreach ($input->clients as $clientInput) {
@ -110,7 +111,7 @@ class PartitionAssistantAction extends AbstractOgAgentController
$this->logger->info('Partition assistant', ['client' => $client->getId()]);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error occurred while partitioning');
throw new BadRequestHttpException('Error occurred while partitioning');
}
$jobId = $response['job_id'];

View File

@ -20,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -43,7 +44,7 @@ class PowerOffAction extends AbstractOgAgentController
$client = $clientEntity->getEntity();
if (!$client->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
if ($client->getStatus() === ClientStatus::OFF) {
@ -67,7 +68,7 @@ class PowerOffAction extends AbstractOgAgentController
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error deploying image');
throw new BadRequestHttpException('Error deploying image');
}
$this->logger->info('Powering off client', ['client' => $client->getId()]);

View File

@ -19,6 +19,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -43,7 +44,7 @@ class RebootAction extends AbstractOgAgentController
if (!$client->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
$endpoint = $client->getStatus() === ClientStatus::OG_LIVE ? 'opengnsys/Reiniciar' : '/opengnsys/reboot';
@ -63,7 +64,7 @@ class RebootAction extends AbstractOgAgentController
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error deploying image');
throw new BadRequestHttpException('Error deploying image');
}
$this->logger->info('Rebooting client', ['client' => $client->getId()]);

View File

@ -10,6 +10,7 @@ use App\Model\CommandTypes;
use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -34,15 +35,15 @@ class RemoveCacheImageAction extends AbstractOgAgentController
$client = $clientEntity->getEntity();
if (!$partition->getImage()) {
throw new ValidatorException('Image is required');
throw new BadRequestHttpException('Image is required');
}
if (!$client->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
if ($client->getStatus() !== ClientStatus::OG_LIVE) {
throw new ValidatorException('Client is not in OG_LIVE status');
throw new BadRequestHttpException('Client is not in OG_LIVE status');
}
$script = `rm%20-r%20/opt/opengnsys/cache/opt/opengnsys/images/{$partition->getImage()->getName()}.*@'`;
@ -63,7 +64,7 @@ class RemoveCacheImageAction extends AbstractOgAgentController
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error logging in: '.$response['error']);
throw new BadRequestHttpException('Error logging in: '.$response['error']);
}
$this->logger->info('Login client', ['client' => $client->getId()]);

View File

@ -14,6 +14,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -37,7 +38,7 @@ class RunScriptAction extends AbstractOgAgentController
$client = $clientEntity->getEntity();
if (!$client->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
$data = [
@ -56,7 +57,7 @@ class RunScriptAction extends AbstractOgAgentController
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new ValidatorException('Error deploying image');
throw new BadRequestHttpException('Error deploying image');
}
$this->logger->info('Powering off client', ['client' => $client->getId()]);
@ -70,7 +71,7 @@ class RunScriptAction extends AbstractOgAgentController
'script' => $input->script,
];
$this->createService->__invoke($client, CommandTypes::RUN_SCRIPT, TraceStatus::SUCCESS, $jobId, $inputData);
$this->createService->__invoke($client, CommandTypes::RUN_SCRIPT, TraceStatus::IN_PROGRESS, $jobId, $inputData);
}
return new JsonResponse(data: [], status: Response::HTTP_OK);

View File

@ -0,0 +1,62 @@
<?php
namespace App\Controller\OgAgent;
use App\Dto\Input\SoftwareInventoryPartitionInput;
use App\Entity\Client;
use App\Model\CommandTypes;
use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class SoftwareInventoryAction extends AbstractOgAgentController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(Client $client, SoftwareInventoryPartitionInput $input): JsonResponse
{
$data = [
'nfn' => 'InventarioSoftware',
'ids' => '0',
'dsk' => (string) $input->partition->getEntity()->getDiskNumber(),
'par' => (string) $input->partition->getEntity()->getPartitionNumber(),
];
$response = $this->createRequest(
method: 'POST',
url: 'https://'.$client->getIp().':8000/opengnsys/InventarioSoftware',
params: [
'json' => $data,
],
token: $client->getToken(),
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('Error performing software inventory: '.$response['error']);
}
$this->logger->info('Login client', ['client' => $client->getId()]);
$jobId = $response['job_id'];
$inputData = [
'partition' => $input->partition->getEntity()->getUuid(),
'image' => $input->partition->getEntity()->getImage()?->getUuid(),
'client' => $client->getIp(),
];
$this->createService->__invoke($client, CommandTypes::SOFTWARE_INVENTORY, TraceStatus::IN_PROGRESS, $jobId, $inputData);
return new JsonResponse(data: [], status: Response::HTTP_OK);
}
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\HttpClient\Internal\ClientState;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -37,7 +38,7 @@ class StatusAction extends AbstractOgAgentController
$response = null;
if (!$client->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
if ($client->getStatus() === ClientStatus::OG_LIVE
@ -87,7 +88,8 @@ class StatusAction extends AbstractOgAgentController
$client->setStatus(ClientStatus::OFF);
$this->entityManager->persist($client);
$this->entityManager->flush();
throw new ValidatorException('Error checking client status: ' . $data['error']);
throw new BadRequestHttpException('Error checking client status: ' . $data['error'] . ' (' . $data['details'] . ')');
}
if (isset($data['cfg'])) {

View File

@ -38,7 +38,9 @@ class StatusController extends AbstractController
const string CREATE_IMAGE = 'RESPUESTA_CrearImagen';
const string RESTORE_IMAGE = 'RESPUESTA_RestaurarImagen';
const string CONFIGURE_IMAGE = 'RESPUESTA_Configurar';
const string HARDWARE_INVENTORY = 'RESPUESTA_InventarioHardware';
const string SOFTWARE_INVENTORY = 'RESPUESTA_InventarioSoftware';
const string RUN_SCRIPT = 'RESPUESTA_EjecutarScript';
public function __construct(
protected readonly EntityManagerInterface $entityManager,
@ -180,10 +182,54 @@ class StatusController extends AbstractController
$this->entityManager->flush();
}
if (isset($data['nfn']) && $data['nfn'] === self::RUN_SCRIPT) {
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
if ($trace) {
$trace->setStatus(TraceStatus::SUCCESS);
$trace->setFinishedAt(new \DateTime());
$this->entityManager->persist($trace);
$this->entityManager->flush();
}
}
if (isset($data['nfn']) && $data['nfn'] === self::HARDWARE_INVENTORY) {
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
if ($trace) {
$client = $trace->getClient();
$trace->setStatus(TraceStatus::SUCCESS);
$trace->setFinishedAt(new \DateTime());
$this->entityManager->persist($trace);
//$client->setHardwareProfile();
$this->entityManager->flush();
}
}
if (isset($data['nfn']) && $data['nfn'] === self::SOFTWARE_INVENTORY) {
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
if ($trace) {
$client = $trace->getClient();
$dataInput = json_decode(json_encode($trace->getInput()), true);
$imageUuid = $dataInput['image'] ?? null;
$trace->setStatus(TraceStatus::SUCCESS);
$trace->setFinishedAt(new \DateTime());
$this->entityManager->persist($trace);
$image = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['uuid' => $imageUuid]);
$this->createSoftwareProfile($data['contents'], $image);
$this->entityManager->flush();
}
}
return new JsonResponse(data: 'Webhook finished', status: Response::HTTP_OK);
}
public function createSoftwareProfile(string $base64Data, ImageImageRepository $imageImageRepository): void
public function createSoftwareProfile(string $base64Data, ?ImageImageRepository $imageImageRepository = null): void
{
$decodedData = base64_decode($base64Data);
$this->logger->info('Software profile decoded', ['data' => '']);
@ -200,10 +246,10 @@ class StatusController extends AbstractController
$this->entityManager->persist($softwareEntity);
}
$image = $imageImageRepository->getImage();
$image = $imageImageRepository?->getImage();
$softwareProfile = new SoftwareProfile();
$softwareProfile->setDescription('Perfil software: ' . $image->getClient()->getName());
$softwareProfile->setDescription('SW Profile - ' . $image->getClient()->getName());
$softwareProfile->setOrganizationalUnit($image->getClient()->getOrganizationalUnit());
foreach ($existingSoftware as $softwareEntity) {

View File

@ -9,6 +9,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -37,6 +38,10 @@ class OgBootController extends AbstractController
{
$data = $this->ogbootStatusService->__invoke();
if (isset($data['error']) && $data['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while fetching the status: ' . $data['details']);
}
return new JsonResponse( data: $data, status: Response::HTTP_OK);
}
}

View File

@ -7,6 +7,7 @@ use App\Entity\OgLive;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -26,13 +27,13 @@ class GetAction extends AbstractOgBootController
public function __invoke(OgLive $data): JsonResponse
{
if (!$data->getChecksum()) {
throw new ValidatorException('Checksum is required');
throw new BadRequestHttpException('Checksum is required');
}
$content = $this->createRequest('GET', '/ogboot/v1/oglives/'.$data->getChecksum());
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('An error occurred while fetching the OgLive: ' . $content['error']. ' (' . $content['details'] . ')');
}
return new JsonResponse(data: $content, status: Response::HTTP_OK);

View File

@ -6,6 +6,7 @@ use App\Controller\OgBoot\AbstractOgBootController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -25,8 +26,8 @@ class GetCollectionAction extends AbstractOgBootController
{
$content = $this->createRequest('GET', '/ogboot/v1/oglives');
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('An error occurred while fetching the collection: ' . $content['error']. ' (' . $content['details'] . ')');
}
return new JsonResponse(data: $content, status: Response::HTTP_OK);

View File

@ -6,6 +6,7 @@ use App\Controller\OgBoot\AbstractOgBootController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -25,8 +26,8 @@ class GetDefaultAction extends AbstractOgBootController
{
$content = $this->createRequest('GET', '/ogboot/v1/oglives/default');
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('An error occurred: ' . $content['error']. ' (' . $content['details'] . ')');
}
return new JsonResponse(status: Response::HTTP_OK);

View File

@ -7,6 +7,7 @@ use App\Entity\OgLive;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -25,8 +26,8 @@ class GetIsosAction extends AbstractOgBootController
{
$content = $this->createRequest('GET', '/ogboot/v1/oglives/isos');
if (!isset($content['message']) || !is_array($content['message'])) {
return new JsonResponse(data: ['error' => 'Invalid response'], status: Response::HTTP_BAD_REQUEST);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('An error occurred while fetching ISOs: ' . $content['error']. ' (' . $content['details'] . ')');
}
$isos = array_map(function ($iso) {

View File

@ -11,6 +11,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -30,7 +31,7 @@ class InstallAction extends AbstractOgBootController
public function __invoke(OgLive $data): JsonResponse
{
if (!$data->getDownloadUrl()) {
throw new ValidatorException('Download URL is required');
throw new BadRequestHttpException('Download URL is required');
}
$params = [
@ -47,13 +48,13 @@ class InstallAction extends AbstractOgBootController
$content = $this->createRequest('POST', '/ogboot/v1/oglives/install', $params);
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
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()));
$data->setName($this->simplifyOgLiveFilenameService->__invoke($data->getFilename()) ?? 'OgLive_'.$data->getUuid());
$data->setDate(new \DateTime());
$data->setStatus(OgLiveStatus::PENDING);
$this->entityManager->persist($data);

View File

@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -27,7 +28,7 @@ class SetDefaultAction extends AbstractOgBootController
public function __invoke(OgLive $data): JsonResponse
{
if (!$data->getChecksum()) {
throw new ValidatorException('Checksum URL is required');
throw new BadRequestHttpException('Checksum URL is required');
}
$params = [
@ -38,8 +39,8 @@ class SetDefaultAction extends AbstractOgBootController
$content = $this->createRequest('PUT', '/ogboot/v1/oglives/default', $params);
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('An error occurred: ' . $content['error'] . ' (' . $content['details'] . ')');
}
$oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]);

View File

@ -9,7 +9,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -32,8 +32,8 @@ class SyncAction extends AbstractOgBootController
{
$content = $this->createRequest('GET', '/ogboot/v1/oglives');
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('An error occurred while fetching ogLives: ' . $content['message'] . ' (' . $content['details'] . ')');
}
$allOgLives = $this->entityManager->getRepository(OgLive::class)->findAll();

View File

@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -28,13 +29,13 @@ class UninstallAction extends AbstractOgBootController
public function __invoke(OgLive $data): JsonResponse
{
if (!$data->getChecksum()) {
throw new ValidatorException('Checksum is required');
throw new BadRequestHttpException('Checksum is required');
}
$content = $this->createRequest( 'DELETE', '/ogboot/v1/oglives/'.$data->getChecksum());
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
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'] . ')');
}
$this->entityManager->remove($data);

View File

@ -45,10 +45,10 @@ class PostAction extends AbstractOgBootController
'server_ip' => $this->ogBootIp,
'server_api_port' => $this->ogBootApiPort,
'server_pxe_port' => $this->ogBootPxePort,
'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(),
'router' => $client->getOrganizationalUnit()->getNetworkSettings()?->getRouter(),
'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0',
'computer_name' => $client->getName(),
'netiface' => $client->getNetiface() ? $client->getNetiface() : $client->getOrganizationalUnit()->getNetworkSettings()->getNetiface(),
'netiface' => $client->getNetiface() ? $client->getNetiface() : $client->getOrganizationalUnit()->getNetworkSettings()?->getNetiface(),
'group' => $client->getOrganizationalUnit()->getName(),
'ogrepo' => $ogRepoIp,
'ogcore' => $this->ogCoreIP,

View File

@ -10,6 +10,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -34,7 +35,7 @@ class DeleteAction extends AbstractOgBootController
$content = $this->createRequest('DELETE', '/ogboot/v1/pxe-templates/'.$data->getName());
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
throw new BadRequestHttpException('An error occurred: ' . $content['error']);
}
$defaultTemplateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['isDefault' => true]);

View File

@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -28,7 +29,7 @@ class GetCollectionAction extends AbstractOgBootController
$content = $this->createRequest('GET', '/ogboot/v1/pxe-templates');
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
throw new BadRequestHttpException('An error occurred: ' . $content['error']);
}
return new JsonResponse( data: $content, status: Response::HTTP_OK);

View File

@ -9,6 +9,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -37,7 +38,7 @@ class PostAction extends AbstractOgBootController
$content = $this->createRequest('POST', '/ogboot/v1/pxe-templates' , $params);
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $content['error']);
throw new BadRequestHttpException('An error occurred: ' . $content['error']);
}
$data->setSynchronized(true);

View File

@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -52,7 +53,7 @@ class SyncAction extends AbstractOgBootController
$templateContent = $this->createRequest('GET', '/ogboot/v1/pxe-templates/' . $templateEntity->getName());
if (isset($templateContent['error']) && $templateContent['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('An error occurred: ' . $templateContent['error']);
throw new BadRequestHttpException('An error occurred: ' . $templateContent['error']);
}
$templateEntity->setTemplateContent($templateContent['template_content']);

View File

@ -7,6 +7,7 @@ use App\Entity\Subnet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -27,7 +28,7 @@ class DeleteAction extends AbstractOgDhcpController
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
{
if (!$data->getId()) {
throw new ValidatorException('Data Id is required');
throw new BadRequestHttpException('Data Id is required');
}
try {

View File

@ -8,6 +8,7 @@ use App\Entity\Subnet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -29,11 +30,11 @@ class DeleteHostAction extends AbstractOgDhcpController
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['uuid' => $clientUuid]);
if (!$client || $client->getSubnet() !== $data) {
throw new ValidatorException('Client not found');
throw new BadRequestHttpException('Client not found');
}
if (!$data->getId()) {
throw new ValidatorException('Data URL is required');
throw new BadRequestHttpException('Data URL is required');
}
$params = [

View File

@ -7,6 +7,7 @@ use App\Entity\Subnet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -26,7 +27,7 @@ class GetAction extends AbstractOgDhcpController
public function __invoke(Subnet $data): JsonResponse
{
if (!$data->getId()) {
throw new ValidatorException('Checksum is required');
throw new BadRequestHttpException('Checksum is required');
}
$content = $this->createRequest('GET', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId());

View File

@ -7,6 +7,7 @@ use App\Entity\Subnet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -26,7 +27,7 @@ class GetHostsAction extends AbstractOgDhcpController
public function __invoke(Subnet $data): JsonResponse
{
if (!$data->getId()) {
throw new ValidatorException('Checksum is required');
throw new BadRequestHttpException('Checksum is required');
}
$content = $this->createRequest('GET', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts');

View File

@ -7,6 +7,7 @@ use App\Entity\Subnet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -26,7 +27,7 @@ class PutAction extends AbstractOgDhcpController
public function __invoke(Subnet $data): JsonResponse
{
if (!$data->getId()) {
throw new ValidatorException('Id is required');
throw new BadRequestHttpException('Id is required');
}
$params = [

View File

@ -8,6 +8,7 @@ use App\Entity\ImageRepository;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -34,7 +35,7 @@ class CreateRepositoryAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/git/repositories', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error creating repository');
throw new BadRequestHttpException('Error creating repository');
}
return new JsonResponse(data: [], status: Response::HTTP_OK);

View File

@ -9,6 +9,7 @@ use App\Entity\ImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -38,7 +39,7 @@ class CreateTagAction extends AbstractOgRepositoryController
$image->getName().'/tags', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error creating repository');
throw new BadRequestHttpException('Error creating repository');
}
return new JsonResponse(data: [], status: Response::HTTP_OK);

View File

@ -7,6 +7,7 @@ use App\Entity\GitImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -30,7 +31,7 @@ class GetTagsAction extends AbstractOgRepositoryController
$content = $this->createRequest('GET', 'http://'.$repository->getIp().':8006/ogrepository/v1/git/repositories/'.$image->getName().'/tags');
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error getting tags');
throw new BadRequestHttpException('Error getting tags');
}
return new JsonResponse(data: $content, status: Response::HTTP_OK);

View File

@ -14,7 +14,7 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -35,7 +35,7 @@ class BackupImageAction extends AbstractOgRepositoryController
$repository = $imageImageRepository->getRepository();
if (!$image->getName()) {
throw new ValidatorException('Name is required');
throw new BadRequestHttpException('Name is required');
}
$params = [
@ -54,6 +54,10 @@ class BackupImageAction extends AbstractOgRepositoryController
$content = $this->createRequest('PUT', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('Error backing up image: ' . $content['error'] . ' - ' . $content['details']);
}
$inputData = [
'imageName' => $image->getName(),
'repositoryUuid' => $repository->getUuid(),

View File

@ -13,7 +13,7 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -32,25 +32,25 @@ class CancelTransmissionAction extends AbstractOgRepositoryController
public function __invoke(Trace $data): JsonResponse
{
if ($data->getCommand() !== CommandTypes::DEPLOY_IMAGE) {
throw new ValidatorException('Command is not DEPLOY_IMAGE');
throw new BadRequestHttpException('Command is not DEPLOY_IMAGE');
}
$input = $data->getInput();
if (!isset($input['client']) || !isset($input['image']) || !isset($input['method'])) {
throw new ValidatorException('Client, image and method are required');
throw new BadRequestHttpException('Client, image and method are required');
}
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['uuid' => $input['client']]);
$image = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['uuid' => $input['image']]);
if (!$client || !$image) {
throw new ValidatorException('Client or image not found');
throw new BadRequestHttpException('Client or image not found');
}
$method = $input['method'];
if (!$image->getImageFullsum()) {
throw new ValidatorException('Fullsum is required');
throw new BadRequestHttpException('Fullsum is required');
}
if ($method === DeployMethodTypes::TORRENT) {
@ -60,7 +60,7 @@ class CancelTransmissionAction extends AbstractOgRepositoryController
}
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error cancelling transmission');
throw new BadRequestHttpException('Error cancelling transmission: ' . $content['details']);
}
$data->setStatus(TraceStatus::CANCELLED);

View File

@ -14,8 +14,8 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -40,6 +40,7 @@ class ConvertAction extends AbstractOgRepositoryController
if (!$imageEntity){
$imageEntity = new Image();
$imageEntity->setName($image);
$imageEntity->setType('monolithic');
$imageEntity->setRemotePc(false);
$imageEntity->setIsGlobal(false);
@ -49,7 +50,7 @@ class ConvertAction extends AbstractOgRepositoryController
$imageImageRepositoryEntity = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['image' => $imageEntity, 'repository' => $repository]);
if ($imageImageRepositoryEntity){
throw new ValidatorException('This image already exists in this repository');
throw new BadRequestHttpException('This image already exists in this repository');
}
$imageImageRepositoryEntity = new ImageImageRepository();
@ -73,7 +74,7 @@ class ConvertAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/virtual', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error converting image');
throw new BadRequestHttpException('An error occurred while converting the image: ' . $content['error'] . ' - ' . $content['details']);
}
$this->entityManager->flush();

View File

@ -12,7 +12,7 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -32,7 +32,7 @@ class ConvertImageToVirtualAction extends AbstractOgRepositoryController
$image = $imageImageRepository->getImage();
if (!$image->getName()) {
throw new ValidatorException('Name is required');
throw new BadRequestHttpException('Name is required');
}
$params = [
@ -48,8 +48,8 @@ class ConvertImageToVirtualAction extends AbstractOgRepositoryController
$content = $this->createRequest('PUT', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/virtual', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error converting image');
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while converting the image to virtual: ' . $content['error']);
}
$inputData = [

View File

@ -13,7 +13,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -34,7 +34,7 @@ class CreateAuxFilesAction extends AbstractOgRepositoryController
$image = $data->getImage();
if (!$image->getName()) {
throw new ValidatorException('Name is required');
throw new BadRequestHttpException('Name is required');
}
$params = [
@ -49,6 +49,10 @@ class CreateAuxFilesAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while creating aux files: ' . $content['error'] . ' - ' . $content['details']);
}
$inputData = [
'imageName' => $data->getName(),
'imageImageRepositoryUuid' => $data->getUuid(),

View File

@ -9,7 +9,7 @@ use App\Entity\ImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -28,7 +28,7 @@ class DeletePermanentAction extends AbstractOgRepositoryController
public function __invoke(ImageImageRepository $data, HttpClientInterface $httpClient): JsonResponse
{
if (!$data->getImageFullsum()) {
throw new ValidatorException('Fullsum is required');
throw new BadRequestHttpException('Fullsum is required');
}
/** @var ImageRepository $image */

View File

@ -11,7 +11,7 @@ use App\Model\ImageStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -32,7 +32,7 @@ class DeleteTrashAction extends AbstractOgRepositoryController
$image = $imageImageRepository->getImage();
if (!$imageImageRepository->getImageFullsum()) {
throw new ValidatorException('Fullsum is required');
throw new BadRequestHttpException('Fullsum is required');
}
$this->logger->info('Deleting image', ['image' => $image->getName()]);

View File

@ -8,7 +8,7 @@ use App\Entity\ImageImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -27,11 +27,15 @@ class GetAction extends AbstractOgRepositoryController
public function __invoke(ImageImageRepository $data): JsonResponse
{
if (!$data->getImageFullsum()) {
throw new ValidatorException('Fullsum is required');
throw new BadRequestHttpException('Fullsum is required');
}
$content = $this->createRequest('GET', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum());
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while fetching the image: ' . $content['details']);
}
return new JsonResponse(data: $content, status: Response::HTTP_OK);
}
}

View File

@ -7,6 +7,7 @@ use App\Entity\ImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -25,6 +26,10 @@ class GetCollectionAction extends AbstractOgRepositoryController
{
$content = $this->createRequest('GET', 'http://'.$data->getIp(). ':8006/ogrepository/v1/images');
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while fetching the image collection: ' . $content['details']);
}
return new JsonResponse( data: $content, status: Response::HTTP_OK);
}
}

View File

@ -8,7 +8,7 @@ use App\Entity\ImageImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -27,13 +27,13 @@ class GetStatusAction extends AbstractOgRepositoryController
public function __invoke(ImageImageRepository $data): JsonResponse
{
if (!$data->getImageFullsum()) {
throw new ValidatorException('Fullsum is required');
throw new BadRequestHttpException('Fullsum is required');
}
$content = $this->createRequest('GET', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/status/images/'.$data->getImageFullsum());
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error getting status');
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while fetching the image status: ' . $content['details']);
}
return new JsonResponse(data: $content, status: Response::HTTP_OK);

View File

@ -13,8 +13,8 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -31,6 +31,12 @@ class ImportAction extends AbstractOgRepositoryController
*/
public function __invoke(ImportImageRepositoryInput $input, ImageRepository $repository): JsonResponse
{
$content = $this->createRequest('GET', 'http://'.$repository->getIp(). ':8006/ogrepository/v1/status');
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while fetching the status: ' . $content['details']);
}
$image = $input->name;
$imageEntity = $this->entityManager->getRepository(Image::class)->findOneBy(['name' => $image]);
@ -38,6 +44,7 @@ class ImportAction extends AbstractOgRepositoryController
if (!$imageEntity){
$imageEntity = new Image();
$imageEntity->setName($image);
$imageEntity->setType('monolithic');
$imageEntity->setRemotePc(false);
$imageEntity->setIsGlobal(false);
@ -47,7 +54,7 @@ class ImportAction extends AbstractOgRepositoryController
$imageImageRepositoryEntity = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['image' => $imageEntity, 'repository' => $repository]);
if ($imageImageRepositoryEntity){
throw new ValidatorException('This image already exists in this repository');
throw new BadRequestHttpException('This image already exists in this repository');
}
$imageImageRepositoryEntity = new ImageImageRepository();
@ -71,7 +78,7 @@ class ImportAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new ValidatorException('Error importing image');
throw new BadRequestHttpException('Error importing image' . ' - ' . $content['error'] . ' - ' . $content['details']);
}
$inputData = [

View File

@ -12,7 +12,7 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -31,7 +31,7 @@ class RecoverAction extends AbstractOgRepositoryController
public function __invoke(ImageImageRepository $data, HttpClientInterface $httpClient): JsonResponse
{
if (!$data->getImageFullsum()) {
throw new ValidatorException('Fullsum is required');
throw new BadRequestHttpException('Fullsum is required');
}
$image = $data->getImage();
@ -48,6 +48,10 @@ class RecoverAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/trash/images', $params);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while recovering the image: ' . $content['error'] . ' - ' . $content['details']);
}
$this->logger->info('Image recovered successfully', ['image' => $image->getName()]);
$data->setStatus(ImageStatus::SUCCESS);

View File

@ -14,7 +14,7 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -69,7 +69,7 @@ class RenameAction extends AbstractOgRepositoryController
$this->entityManager->flush();
if ($hasError) {
return new JsonResponse(['error' => 'Error renaming image'], Response::HTTP_INTERNAL_SERVER_ERROR);
throw new BadRequestHttpException('An error occurred while renaming the image: ' . $content['error'] . ' - ' . $content['details']);
}
return new JsonResponse([], Response::HTTP_OK);
@ -112,6 +112,7 @@ class RenameAction extends AbstractOgRepositoryController
'http://' . $repository->getRepository()->getIp() . ':8006/ogrepository/v1/images/rename',
$params
);
}
private function jsonError(string $message): JsonResponse

View File

@ -14,7 +14,7 @@ use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -40,7 +40,7 @@ class TransferAction extends AbstractOgRepositoryController
$image = $imageImageRepository->getImage();
if (!$imageImageRepository->getImageFullsum()) {
throw new ValidatorException('Fullsum is required');
throw new BadRequestHttpException('Fullsum is required');
}
$params = [
@ -56,8 +56,8 @@ class TransferAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params);
if (!isset($content['job_id'])) {
throw new ValidatorException('Job ID not found');
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
throw new BadRequestHttpException('Error transferring image: ' . $content['error']);
}
$inputData = [

View File

@ -14,7 +14,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -58,7 +58,7 @@ class TransferGlobalAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params);
if (!isset($content['job_id'])) {
throw new ValidatorException('Job ID not found');
throw new BadRequestHttpException('Job ID not found');
}
$inputData = [

View File

@ -6,6 +6,7 @@ use App\Entity\ImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -25,6 +26,10 @@ class StatusAction extends AbstractOgRepositoryController
{
$content = $this->createRequest('GET', 'http://'.$data->getIp(). ':8006/ogrepository/v1/status');
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('An error occurred while fetching the status: ' . $content['details']);
}
return new JsonResponse( data: $content, status: Response::HTTP_OK);
}
}

View File

@ -20,6 +20,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -44,7 +45,7 @@ class WoLAction extends AbstractOgRepositoryController
$repository = $client->getRepository();
if (!$repository->getIp()) {
throw new ValidatorException('IP is required');
throw new BadRequestHttpException('IP is required');
}
$params = [
@ -58,7 +59,7 @@ class WoLAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp(). ':8006/ogrepository/v1/wol', $params);
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
$this->logger->error('Error sending WoL to client', ['mac' => $client->getMac()]);
continue;
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Dto\Input;
use App\Dto\Output\PartitionOutput;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
class SoftwareInventoryPartitionInput
{
#[Assert\NotNull]
#[Groups(['client:write'])]
public ?PartitionOutput $partition = null;
}

View File

@ -39,7 +39,7 @@ class Partition extends AbstractEntity
private ?OperativeSystem $operativeSystem = null;
#[ORM\ManyToOne(inversedBy: 'partitions')]
#[ORM\JoinColumn(nullable: true)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?ImageImageRepository $image = null;
public function getDiskNumber(): ?int

View File

@ -0,0 +1,49 @@
<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\KernelInterface;
readonly class ApiExceptionSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly RequestStack $requestStack,
private readonly KernelInterface $kernel,
)
{
}
public static function getSubscribedEvents(): array
{
return [
ExceptionEvent::class => 'onKernelException',
];
}
public function onKernelException(ExceptionEvent $event): void
{
if ($this->kernel->getEnvironment() === 'dev') {
return;
}
$exception = $event->getThrowable();
$statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$message = $exception->getMessage();
$data = [
'@context' => '/contexts/Error',
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $message,
];
$response = new JsonResponse($data, $statusCode);
$event->setResponse($response);
}
}

View File

@ -67,6 +67,10 @@ final readonly class ClientSubscriber implements EventSubscriberInterface
}
$this->postAction->__invoke($client, $template);
if (!$client->getSubnet()) {
return;
}
$this->putHostAction->__invoke($client->getMac(), $client);
}
}

View File

@ -59,7 +59,7 @@ final readonly class OrganizationalUnitSubscriber implements EventSubscriberInte
return;
}
$newNetworkSettings = $this->buildNetworkSettings($organizationalUnitEntity);
$newNetworkSettings = $this->cloneNetworkSettings($organizationalUnitEntity->getNetworkSettings());
$this->updateChildrenNetworkSettings($organizationalUnitEntity, $newNetworkSettings);
@ -76,6 +76,7 @@ final readonly class OrganizationalUnitSubscriber implements EventSubscriberInte
if ($childUnit->isExcludeParentChanges()) {
$childUnit->setNetworkSettings(null);
} else{
$childUnit->setNetworkSettings($networkSettings);
foreach ($childUnit->getClients() as $client) {
@ -85,7 +86,6 @@ final readonly class OrganizationalUnitSubscriber implements EventSubscriberInte
$client->setTemplate($networkSettings->getPxeTemplate());
$this->entityManager->persist($client);
}
}
$this->entityManager->persist($childUnit);
$this->entityManager->flush();
@ -94,6 +94,31 @@ final readonly class OrganizationalUnitSubscriber implements EventSubscriberInte
}
}
private function cloneNetworkSettings(NetworkSettings $original): NetworkSettings
{
$cloned = new NetworkSettings();
$cloned->setNextServer($original->getNextServer());
$cloned->setBootFileName($original->getBootFileName());
$cloned->setProxy($original->getProxy());
$cloned->setDns($original->getDns());
$cloned->setNetmask($original->getNetmask());
$cloned->setRouter($original->getRouter());
$cloned->setP2pTime($original->getP2pTime());
$cloned->setP2pMode($original->getP2pMode());
$cloned->setMcastMode($original->getMcastMode());
$cloned->setMcastIp($original->getMcastIp());
$cloned->setMcastPort($original->getMcastPort());
$cloned->setMcastSpeed($original->getMcastSpeed());
$cloned->setMenu($original->getMenu());
$cloned->setRepository($original->getRepository());
$cloned->setOgLive($original->getOgLive());
$cloned->setPxeTemplate($original->getPxeTemplate());
$cloned->setNetiface($original->getNetiface());
return $cloned;
}
private function buildNetworkSettings($organizationalUnitEntity): NetworkSettings
{
if ($organizationalUnitEntity->getNetworkSettings() === null) {

View File

@ -0,0 +1,43 @@
<?php
namespace App\Filter;
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
use Symfony\Component\PropertyInfo\Type;
use Doctrine\ORM\QueryBuilder;
class SoftwareProfileSearchSoftwareFilter extends AbstractFilter
{
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
{
if ($property !== 'softwareProfileId') {
return;
}
if (null === $value || '' === $value || 'undefined' === $value) {
return;
}
$alias = $queryBuilder->getRootAliases()[0];
$joinAlias = $queryNameGenerator->generateJoinAlias('softwareProfileId');
$queryBuilder
->innerJoin(sprintf('%s.softwareProfiles', $alias), $joinAlias)
->andWhere(sprintf('%s.id = :softwareProfileId', $joinAlias))
->setParameter('softwareProfileId', $value);
}
public function getDescription(string $resourceClass): array
{
return [
'softwareProfileId' => [
'property' => 'softwareProfileId',
'type' => Type::BUILTIN_TYPE_INT,
'required' => false,
'description' => 'Filter software profiles by ID.',
],
];
}
}

View File

@ -23,6 +23,9 @@ final class CommandTypes
public const string PARTITION_AND_FORMAT = 'partition-and-format';
public const string INSTALL_OGLIVE = 'install-oglive';
public const string RUN_SCRIPT = 'run-script';
public const string REMOVE_CACHE_IMAGE = 'remove-cache-image';
public const string HARDWARE_INVENTORY = 'hardware-inventory';
public const string SOFTWARE_INVENTORY = 'software-inventory';
private const array COMMAND_TYPES = [
self::DEPLOY_IMAGE => 'Deploy Image',
@ -44,6 +47,9 @@ final class CommandTypes
self::TRANSFER_IMAGE => 'Transfer Image',
self::INSTALL_OGLIVE => 'Instalar OgLive',
self::RUN_SCRIPT => 'Run Script',
self::REMOVE_CACHE_IMAGE => 'Remove Cache Image',
self::HARDWARE_INVENTORY => 'Hardware Inventory',
self::SOFTWARE_INVENTORY => 'Software Inventory',
];
public static function getCommandTypes(): array

View File

@ -40,15 +40,25 @@ readonly class StatusService
]);
try {
$response = $httpClient->request('GET', 'http://'.$this->ogBootIp.':'.$this->ogBootApiPort.'/ogboot/v1/status', [
'headers' => [
'accept' => 'application/json',
],
$response = $httpClient->request('GET', 'http://' . $this->ogBootIp . ':' . $this->ogBootApiPort . '/ogboot/v1/status', [
'headers' => ['accept' => 'application/json'],
]);
} catch (TransportExceptionInterface $e) {
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
}
return json_decode($response->getContent(), true);
return json_decode($response->getContent(), true);
} catch (ClientExceptionInterface | ServerExceptionInterface $e) {
return [
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
'error' => 'Client/Server error',
'details' => $e->getMessage(),
];
} catch (TransportExceptionInterface $e) {
return [
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
'error' => 'Transport error',
'details' => $e->getMessage(),
];
}
}
}

View File

@ -76,15 +76,15 @@ readonly class ClientProcessor implements ProcessorInterface
$client = $data->createOrUpdateEntity($entity);
if ($defaultMenu) {
if ($defaultMenu && !$client->getMenu()) {
$client->setMenu($defaultMenu);
}
if ($defaultPxe) {
if ($defaultPxe && !$client->getTemplate()) {
$client->setTemplate($defaultPxe);
}
if ($defaultPxeOgLive) {
if ($defaultPxeOgLive && !$client->getOgLive()) {
$client->setOgLive($defaultPxeOgLive);
}
@ -106,7 +106,10 @@ readonly class ClientProcessor implements ProcessorInterface
$this->clientRepository->delete($client);
if ($this->kernel->getEnvironment() !== 'test') {
$this->deleteHostAction->__invoke($client->getSubnet(), $client->getUuid());
if ($client->getSubnet()) {
$this->deleteHostAction->__invoke($client->getSubnet(), $client->getUuid());
}
$this->deletePxeAction->__invoke($client->getUuid());
}

View File

@ -9,15 +9,26 @@ use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\Validator\ValidatorInterface;
use App\Controller\OgBoot\OgLive\InstallAction;
use App\Controller\OgBoot\OgLive\UninstallAction;
use App\Dto\Input\OgLiveInput;
use App\Dto\Output\OgLiveOutput;
use App\Model\OgLiveStatus;
use App\Repository\OgLiveRepository;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
readonly class OgLiveProcessor implements ProcessorInterface
{
public function __construct(
private OgLiveRepository $ogLiveRepository,
private ValidatorInterface $validator
private ValidatorInterface $validator,
private InstallAction $installAction,
private UninstallAction $uninstallAction,
private KernelInterface $kernel,
)
{
}
@ -39,6 +50,7 @@ readonly class OgLiveProcessor implements ProcessorInterface
/**
* @throws \Exception
* @throws TransportExceptionInterface
*/
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): OgLiveOutput
{
@ -55,12 +67,30 @@ readonly class OgLiveProcessor implements ProcessorInterface
$this->validator->validate($ogLive);
$this->ogLiveRepository->save($ogLive);
if ($this->kernel->getEnvironment() !== 'test') {
if ($operation instanceof Post) {
$this->installAction->__invoke($ogLive);
}
}
return new OgLiveOutput($ogLive);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
{
$ogLive = $this->ogLiveRepository->findOneByUuid($uriVariables['uuid']);
if ($this->kernel->getEnvironment() !== 'test') {
if ($ogLive->getStatus() === OgLiveStatus::ACTIVE) {
$this->uninstallAction->__invoke($ogLive);
}
}
$this->ogLiveRepository->delete($ogLive);
return null;

View File

@ -60,7 +60,7 @@ readonly class OrganizationalUnitProcessor implements ProcessorInterface
$this->validator->validate($organizationalUnit, ['groups' => ['organizational-unit:write']]);
$this->organizationalUnitRepository->save($organizationalUnit);
$this->changeClientNetworkSettingsService->__invoke($organizationalUnit);
//$this->changeClientNetworkSettingsService->__invoke($organizationalUnit);
return new OrganizationalUnitOutput($organizationalUnit);
}