refs #658. Added install fully integration

feature/integration-ogboot
Manuel Aranda Rosales 2024-09-05 10:17:10 +02:00
parent ebd3d7e539
commit 1b41814883
8 changed files with 124 additions and 4 deletions

View File

@ -8,7 +8,7 @@ services:
api_platform.filter.client.search:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'id': 'exact', 'name': 'partial', 'serialNumber': 'exact', organizationalUnit.id: 'exact' } ]
arguments: [ { 'id': 'exact', 'name': 'partial', 'serialNumber': 'exact', organizationalUnit.id: 'exact', 'ip': exact, 'mac': exact } ]
tags: [ 'api_platform.filter' ]
api_platform.filter.hardware.order:

View File

@ -0,0 +1,32 @@
<?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 Version20240905080435 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 og_live ADD status VARCHAR(255) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE og_live DROP status');
}
}

View File

@ -4,6 +4,7 @@ namespace App\Controller\OgBoot\OgLive;
use App\Controller\OgBoot\AbstractOgBootController;
use App\Entity\OgLive;
use App\Model\OgLiveStatus;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
@ -32,13 +33,14 @@ class InstallAction extends AbstractOgBootController
$params = [
'json' => [
'url' => $data->getDownloadUrl()
'url' => $data->getDownloadUrl(),
'ogCoreId' => $data->getUuid()
]
];
$content = $this->createRequest($httpClient, 'POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params);
$data->setInstalled(true);
$data->setStatus(OgLiveStatus::PENDING);
$entityManager->persist($data);
$entityManager->flush();

View File

@ -3,6 +3,8 @@
namespace App\Controller\OgBoot\OgLive\Webhook;
use App\Controller\OgBoot\AbstractOgBootController;
use App\Entity\OgLive;
use App\Model\OgLiveStatus;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -31,6 +33,33 @@ class InstallOgLiveResponseAction extends AbstractController
{
$data = json_decode($request->getContent(), true);
return new JsonResponse(data: ['hola caracola'], status: Response::HTTP_OK);
if ($data === null || !isset($data['message'], $data['ogCoreId'], $data['details']['result'])) {
return new JsonResponse(['error' => 'Invalid or incomplete JSON data'], Response::HTTP_BAD_REQUEST);
}
$message = $data['message'];
$ogCoreId = $data['ogCoreId'];
$details = $data['details'];
$result = $details['result'];
$ogLive = $this->entityManager->getRepository(OgLive::class)->findOneBy(['uuid' => $ogCoreId]);
if (!$ogLive) {
return new JsonResponse(['error' => 'OgLive not found'], Response::HTTP_NOT_FOUND);
}
$ogLive->setStatus($details['status'] === 'success' ? OgLiveStatus::ACTIVE : OgLiveStatus::FAILED);
$ogLive->setInstalled($details['status'] === 'success');
$ogLive->setChecksum($result['id']);
$ogLive->setDistribution($result['distribution']);
$ogLive->setKernel($result['kernel']);
$ogLive->setArchitecture($result['architecture']);
$ogLive->setRevision($result['revision']);
$ogLive->setDirectory($result['directory']);
$this->entityManager->persist($ogLive);
$this->entityManager->flush();
return new JsonResponse(data: 'Oglive updated successfully', status: Response::HTTP_OK);
}
}

View File

@ -4,6 +4,7 @@ namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Entity\OgLive;
use App\Model\OgLiveStatus;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
@ -36,6 +37,7 @@ final class OgLiveInput
$ogLive->setName($this->name);
$ogLive->setDownloadUrl($this->downloadUrl);
$ogLive->setStatus(OgLiveStatus::INACTIVE);
return $ogLive;
}

View File

@ -25,6 +25,9 @@ final class OgLiveOutput extends AbstractOutput
#[Groups(['og-live:read'])]
public ?string $downloadUrl = '';
#[Groups(['og-live:read'])]
public ?string $status = '';
#[Groups(['og-live:read'])]
public \DateTime $createdAt;
@ -40,6 +43,7 @@ final class OgLiveOutput extends AbstractOutput
$this->installed = $ogLive->isInstalled();
$this->isDefault = $ogLive->getIsDefault();
$this->downloadUrl = $ogLive->getDownloadUrl();
$this->status = $ogLive->getStatus();
$this->createdAt = $ogLive->getCreatedAt();
$this->createdBy = $ogLive->getCreatedBy();
}

View File

@ -52,6 +52,9 @@ class OgLive extends AbstractEntity
#[ORM\OneToMany(mappedBy: 'ogLive', targetEntity: Client::class)]
private Collection $clients;
#[ORM\Column(length: 255)]
private ?string $status = null;
public function __construct()
{
parent::__construct();
@ -205,4 +208,16 @@ class OgLive extends AbstractEntity
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Model;
final class OgLiveStatus
{
public const string PENDING = 'pending';
public const string ACTIVE = 'active';
public const string INACTIVE = 'inactive';
public const string DELETED = 'deleted';
public const string FAILED = 'failed';
private const array OG_LIVE_STATUSES = [
self::PENDING => 'Pendiente',
self::ACTIVE => 'Activo',
self::INACTIVE => 'Inactivo',
self::DELETED => 'Eliminado',
self::FAILED => 'Fallido',
];
public static function getOgLiveStatuses(): array
{
return self::OG_LIVE_STATUSES;
}
public static function getOgLiveStatus(string $ogLiveStatus): ?string
{
return self::OG_LIVE_STATUSES[$ogLiveStatus] ?? null;
}
public static function getOgLiveStatusKeys(): array
{
return array_keys(self::OG_LIVE_STATUSES);
}
}