From e3b5bc202cac5fc65dba35bffa2ff07f96da069a Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 27 Nov 2024 11:21:03 +0100 Subject: [PATCH] Updated ogLive API. OgAgent deploy-image fixed bug in partitionInfo --- src/Controller/DeployImageAction.php | 8 +++++--- src/Controller/OgAgent/DeployImageAction.php | 8 ++++++-- src/Controller/OgAgent/Webhook/ClientsController.php | 8 ++++++++ src/Controller/OgBoot/OgLive/GetAction.php | 4 ++-- src/Controller/OgBoot/OgLive/GetCollectionAction.php | 5 ++--- src/Controller/OgBoot/OgLive/GetDefaultAction.php | 5 ++--- src/Controller/OgBoot/OgLive/GetIsosAction.php | 5 ++--- src/Controller/OgBoot/OgLive/InstallAction.php | 8 ++++---- src/Controller/OgBoot/OgLive/SetDefaultAction.php | 8 ++++---- src/Controller/OgBoot/OgLive/SyncAction.php | 4 ++-- src/Controller/OgBoot/OgLive/UninstallAction.php | 8 ++++---- src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php | 2 +- 12 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/Controller/DeployImageAction.php b/src/Controller/DeployImageAction.php index 7b8cf9e..4df160f 100644 --- a/src/Controller/DeployImageAction.php +++ b/src/Controller/DeployImageAction.php @@ -8,6 +8,7 @@ use App\Dto\Input\DeployImageInput; use App\Entity\Command; use App\Entity\Image; use App\Entity\OrganizationalUnit; +use App\Entity\Partition; use App\Model\CommandTypes; use App\Model\DeployMethodTypes; use App\Model\TraceStatus; @@ -33,7 +34,8 @@ class DeployImageAction extends AbstractController public function __invoke(DeployImageInput $input, Image $image): JsonResponse { - $partitionInfo = json_decode($image->getPartitionInfo(), true); + /** @var Partition $partition */ + $partition = $input->partition->getEntity(); $inputData = [ 'method' => $input->method, @@ -45,8 +47,8 @@ class DeployImageAction extends AbstractController 'mcastPort' => $input->mcastPort, 'mcastSpeed' => $input->mcastSpeed, 'mcastMode' => $input->mcastMode, - 'numDisk' => (string) $partitionInfo['numDisk'], - 'numPartition' => (string) $partitionInfo['numPartition'], + 'numDisk' => (string) $partition->getDiskNumber(), + 'numPartition' => (string) $partition->getPartitionNumber(), ]; switch ($input->method){ diff --git a/src/Controller/OgAgent/DeployImageAction.php b/src/Controller/OgAgent/DeployImageAction.php index c8e2d01..495da2b 100644 --- a/src/Controller/OgAgent/DeployImageAction.php +++ b/src/Controller/OgAgent/DeployImageAction.php @@ -8,6 +8,7 @@ use App\Dto\Input\DeployImageInput; use App\Entity\Client; use App\Entity\Command; use App\Entity\Image; +use App\Entity\Partition; use App\Entity\Trace; use App\Model\ClientStatus; use App\Model\TraceStatus; @@ -46,9 +47,12 @@ class DeployImageAction extends AbstractController /** @var Client $client */ $client = $input->client->getEntity(); + /** @var Partition $partition */ + $partition = $input->partition->getEntity(); + $data = [ - 'dsk' => (string) $partitionInfo['numDisk'], - 'par' => (string) $partitionInfo['numPartition'], + 'dsk' => (string) $partition->getDiskNumber(), + 'par' => (string) $partition->getPartitionNumber(), 'ifs' => "1", 'idi' => $image->getUuid(), 'nci' => $image->getName(), diff --git a/src/Controller/OgAgent/Webhook/ClientsController.php b/src/Controller/OgAgent/Webhook/ClientsController.php index 1f236d7..1fe5dd1 100644 --- a/src/Controller/OgAgent/Webhook/ClientsController.php +++ b/src/Controller/OgAgent/Webhook/ClientsController.php @@ -107,6 +107,7 @@ class ClientsController extends AbstractController $this->entityManager->persist($image); $client = $trace->getClient(); $client->setStatus(ClientStatus::OG_LIVE); + $this->entityManager->persist($client); $this->entityManager->persist($trace); $this->entityManager->flush(); $this->logger->info('Image updated. Success.', ['image' => (string) $image->getUuid()]); @@ -116,6 +117,8 @@ class ClientsController extends AbstractController $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); $image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $data['idi']]); + $client = $trace->getClient(); + if ($data['res'] === 1) { $trace->setStatus(TraceStatus::SUCCESS); $trace->setFinishedAt(new \DateTime()); @@ -126,6 +129,8 @@ class ClientsController extends AbstractController $trace->setOutput($data['der']); } + $client->setStatus(ClientStatus::OG_LIVE); + $this->entityManager->persist($client); $this->entityManager->persist($image); $this->entityManager->persist($trace); $this->entityManager->flush(); @@ -159,6 +164,9 @@ class ClientsController extends AbstractController $softwareEntity->addSoftwareProfile($softwareProfile); } + $image->setSoftwareProfile($softwareProfile); + + $this->entityManager->persist($image); $this->entityManager->persist($softwareProfile); $this->entityManager->flush(); } diff --git a/src/Controller/OgBoot/OgLive/GetAction.php b/src/Controller/OgBoot/OgLive/GetAction.php index 54ebe45..0417416 100644 --- a/src/Controller/OgBoot/OgLive/GetAction.php +++ b/src/Controller/OgBoot/OgLive/GetAction.php @@ -23,13 +23,13 @@ class GetAction extends AbstractOgBootController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(OgLive $data, HttpClientInterface $httpClient): JsonResponse + public function __invoke(OgLive $data): JsonResponse { if (!$data->getChecksum()) { throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); + $content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetCollectionAction.php b/src/Controller/OgBoot/OgLive/GetCollectionAction.php index 41cacdf..91204ac 100644 --- a/src/Controller/OgBoot/OgLive/GetCollectionAction.php +++ b/src/Controller/OgBoot/OgLive/GetCollectionAction.php @@ -11,7 +11,6 @@ use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] class GetCollectionAction extends AbstractOgBootController @@ -22,9 +21,9 @@ class GetCollectionAction extends AbstractOgBootController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(HttpClientInterface $httpClient): JsonResponse + public function __invoke(): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives'); + $content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetDefaultAction.php b/src/Controller/OgBoot/OgLive/GetDefaultAction.php index 3c77859..e5ef4f5 100644 --- a/src/Controller/OgBoot/OgLive/GetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/GetDefaultAction.php @@ -10,7 +10,6 @@ use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] class GetDefaultAction extends AbstractOgBootController @@ -21,9 +20,9 @@ class GetDefaultAction extends AbstractOgBootController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(HttpClientInterface $httpClient): JsonResponse + public function __invoke(): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default'); + $content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default'); return new JsonResponse(status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetIsosAction.php b/src/Controller/OgBoot/OgLive/GetIsosAction.php index 1acdbd2..80b212b 100644 --- a/src/Controller/OgBoot/OgLive/GetIsosAction.php +++ b/src/Controller/OgBoot/OgLive/GetIsosAction.php @@ -11,7 +11,6 @@ use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] class GetIsosAction extends AbstractOgBootController @@ -22,9 +21,9 @@ class GetIsosAction extends AbstractOgBootController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(HttpClientInterface $httpClient): JsonResponse + public function __invoke(): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/isos'); + $content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/isos'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/InstallAction.php b/src/Controller/OgBoot/OgLive/InstallAction.php index 07b68ac..e0d6be6 100644 --- a/src/Controller/OgBoot/OgLive/InstallAction.php +++ b/src/Controller/OgBoot/OgLive/InstallAction.php @@ -25,7 +25,7 @@ class InstallAction extends AbstractOgBootController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse + public function __invoke(OgLive $data): JsonResponse { if (!$data->getDownloadUrl()) { throw new ValidatorException('Download URL is required'); @@ -38,11 +38,11 @@ class InstallAction extends AbstractOgBootController ] ]; - $content = $this->createRequest($httpClient, 'POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); + $content = $this->createRequest('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); $data->setStatus(OgLiveStatus::PENDING); - $entityManager->persist($data); - $entityManager->flush(); + $this->entityManager->persist($data); + $this->entityManager->flush(); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/SetDefaultAction.php b/src/Controller/OgBoot/OgLive/SetDefaultAction.php index 896ac3b..94bf7b1 100644 --- a/src/Controller/OgBoot/OgLive/SetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/SetDefaultAction.php @@ -24,7 +24,7 @@ class SetDefaultAction extends AbstractOgBootController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse + public function __invoke(OgLive $data): JsonResponse { if (!$data->getChecksum()) { throw new ValidatorException('Checksum URL is required'); @@ -36,7 +36,7 @@ class SetDefaultAction extends AbstractOgBootController ] ]; - $content = $this->createRequest($httpClient, 'PUT', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params); + $content = $this->createRequest('PUT', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params); $oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]); @@ -46,8 +46,8 @@ class SetDefaultAction extends AbstractOgBootController } $data->setIsDefault(true); - $entityManager->persist($data); - $entityManager->flush(); + $this->entityManager->persist($data); + $this->entityManager->flush(); return new JsonResponse(status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/SyncAction.php b/src/Controller/OgBoot/OgLive/SyncAction.php index 8c2d792..20bfb88 100644 --- a/src/Controller/OgBoot/OgLive/SyncAction.php +++ b/src/Controller/OgBoot/OgLive/SyncAction.php @@ -26,9 +26,9 @@ class SyncAction extends AbstractOgBootController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse + public function __invoke(): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/oglives'); + $content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/oglives'); foreach ($content['message']['installed_ogLives'] as $ogLive) { $ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]); diff --git a/src/Controller/OgBoot/OgLive/UninstallAction.php b/src/Controller/OgBoot/OgLive/UninstallAction.php index 70b3c0b..fe64ce8 100644 --- a/src/Controller/OgBoot/OgLive/UninstallAction.php +++ b/src/Controller/OgBoot/OgLive/UninstallAction.php @@ -25,16 +25,16 @@ class UninstallAction extends AbstractOgBootController * @throws ClientExceptionInterface * @throws TransportExceptionInterface */ - public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse + public function __invoke(OgLive $data): JsonResponse { if (!$data->getChecksum()) { throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); + $content = $this->createRequest( 'DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); - $entityManager->remove($data); - $entityManager->flush(); + $this->entityManager->remove($data); + $this->entityManager->flush(); return new JsonResponse(status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php index 3d53a9f..211d548 100644 --- a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php +++ b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php @@ -26,7 +26,7 @@ class GetCollectionAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes'); + $content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes'); return new JsonResponse(data: $content, status: Response::HTTP_OK); }