refs #1975. Integration ogGit. Create table and init API
parent
1f6f4164d0
commit
9673c9c09a
|
@ -32,6 +32,15 @@ resources:
|
|||
uriTemplate: /image-image-repositories/server/{uuid}/get
|
||||
controller: App\Controller\OgRepository\Image\GetAction
|
||||
|
||||
get_image_tags:
|
||||
shortName: OgRepository Server
|
||||
description: Get image tags in OgRepository
|
||||
class: ApiPlatform\Metadata\Get
|
||||
method: GET
|
||||
input: false
|
||||
uriTemplate: /git-image-repositories/server/{uuid}/get-tags
|
||||
controller: App\Controller\OgRepository\Git\GetTagsAction
|
||||
|
||||
|
||||
properties:
|
||||
App\Entity\GitImageRepository:
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?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 Version20250513050921 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 git_image_repository ADD description VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE git_image_repository DROP description');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?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 Version20250513055057 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 image_image_repository ADD partition_info VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE image_image_repository DROP partition_info');
|
||||
}
|
||||
}
|
|
@ -53,7 +53,7 @@ class CreateImageAction extends AbstractController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Image $image, ?Partition $partition = null): JsonResponse
|
||||
public function __invoke(Image $image, ?Partition $partition = null, ?Client $client = null): JsonResponse
|
||||
{
|
||||
if (!$image->getClient()->getIp()) {
|
||||
throw new ValidatorException('IP is required');
|
||||
|
@ -73,7 +73,6 @@ class CreateImageAction extends AbstractController
|
|||
}
|
||||
|
||||
if ($image->getType() === 'monolithic') {
|
||||
|
||||
$repository = $image->getClient()->getRepository();
|
||||
$latestImageRepo = $this->entityManager->getRepository(ImageImageRepository::class)->findLatestVersionByImageAndRepository($image, $repository);
|
||||
|
||||
|
@ -83,10 +82,11 @@ class CreateImageAction extends AbstractController
|
|||
$imageImageRepository->setRepository($repository);
|
||||
$imageImageRepository->setStatus(ImageStatus::IN_PROGRESS);
|
||||
$imageImageRepository->setVersion($latestImageRepo ? $latestImageRepo->getVersion() + 1 : 1);
|
||||
$imageImageRepository->setPartitionInfo(json_encode($partitionInfo));
|
||||
|
||||
$this->entityManager->persist($imageImageRepository);
|
||||
|
||||
return $this->createMonolithicImage($imageImageRepository, $partitionInfo, $image, $repository);
|
||||
return $this->createMonolithicImage($imageImageRepository, $partitionInfo, $image, $repository, $client);
|
||||
} else {
|
||||
$repository = $image->getClient()->getRepository();
|
||||
$latestImageRepo = $this->entityManager->getRepository(GitImageRepository::class)->findLatestVersionByImageAndRepository($image, $repository);
|
||||
|
@ -101,6 +101,7 @@ class CreateImageAction extends AbstractController
|
|||
$gitImageRepository->setCreated(false);
|
||||
|
||||
$this->entityManager->persist($gitImageRepository);
|
||||
$this->entityManager->persist($image);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->createGitImage($gitImageRepository, $partitionInfo, $image, $repository);
|
||||
|
@ -117,7 +118,8 @@ class CreateImageAction extends AbstractController
|
|||
ImageImageRepository $imageImageRepository,
|
||||
array $partitionInfo,
|
||||
Image $image,
|
||||
ImageRepository $repository
|
||||
ImageRepository $repository,
|
||||
?Client $client = null
|
||||
): JsonResponse
|
||||
{
|
||||
$data = [
|
||||
|
@ -146,8 +148,10 @@ class CreateImageAction extends AbstractController
|
|||
}
|
||||
|
||||
try {
|
||||
|
||||
$client = $client ?? $image->getClient();
|
||||
$this->logger->info('Creating image', ['image' => $image->getId()]);
|
||||
$response = $this->httpClient->request('POST', 'https://'.$image->getClient()->getIp().':8000/opengnsys/CrearImagen', [
|
||||
$response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/opengnsys/CrearImagen', [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
|
@ -167,12 +171,22 @@ class CreateImageAction extends AbstractController
|
|||
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
|
||||
$client = $image->getClient();
|
||||
$client->setStatus(ClientStatus::BUSY);
|
||||
$this->entityManager->persist($client);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE, TraceStatus::IN_PROGRESS, $jobId, []);
|
||||
$inputData = [
|
||||
'method' => 'CrearImagen',
|
||||
'type' => 'monolithic',
|
||||
'client' => $client->getUuid(),
|
||||
'image' => $image->getUuid(),
|
||||
'partitionCode' => $partitionInfo['partitionCode'],
|
||||
'partitionType' => $partitionInfo['filesystem'],
|
||||
'repository' => $repository->getIp(),
|
||||
'name' => $image->getName().'_v'.$imageImageRepository->getVersion(),
|
||||
];
|
||||
|
||||
$this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE, TraceStatus::IN_PROGRESS, $jobId, $inputData);
|
||||
|
||||
return new JsonResponse(data: $image, status: Response::HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Git;
|
||||
|
||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||
use App\Entity\GitImageRepository;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
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;
|
||||
|
||||
#[AsController]
|
||||
class GetTagsAction extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(GitImageRepository $gitImageRepository): JsonResponse
|
||||
{
|
||||
$repository = $gitImageRepository->getRepository();
|
||||
$image = $gitImageRepository->getImage();
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
final class GitImageRepositoryInput
|
||||
{
|
||||
#[Groups(['git-image-repository:write'])]
|
||||
public ?string $name = '';
|
||||
public ?string $description = '';
|
||||
|
||||
public function __construct(?GitImageRepository $gitImageRepository = null)
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ final class GitImageRepositoryInput
|
|||
return;
|
||||
}
|
||||
|
||||
$this->name = $gitImageRepository->getName();
|
||||
$this->description = $gitImageRepository->getDescription();
|
||||
}
|
||||
|
||||
public function createOrUpdateEntity(?GitImageRepository $gitImageRepository = null): GitImageRepository
|
||||
|
@ -26,7 +26,7 @@ final class GitImageRepositoryInput
|
|||
$gitImageRepository = new GitImageRepository();
|
||||
}
|
||||
|
||||
$gitImageRepository->setName($this->name);
|
||||
$gitImageRepository->setDescription($this->description);
|
||||
|
||||
return $gitImageRepository;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ final class GitImageRepositoryOutput extends AbstractOutput
|
|||
#[Groups(['git-image-repository:read', 'image:read'])]
|
||||
public string $status = '';
|
||||
|
||||
#[Groups(['git-image-repository:read', 'image:read'])]
|
||||
public ?string $description = '';
|
||||
|
||||
#[Groups(['git-image-repository:read', 'image:read'])]
|
||||
public string $name = '';
|
||||
|
||||
|
@ -49,6 +52,7 @@ final class GitImageRepositoryOutput extends AbstractOutput
|
|||
}
|
||||
|
||||
$this->name = $gitImageRepository->getName();
|
||||
$this->description = $gitImageRepository->getDescription();
|
||||
$this->status = $gitImageRepository->getStatus();
|
||||
$this->branch = $gitImageRepository->getBranch();
|
||||
$this->tag = $gitImageRepository->getTag();
|
||||
|
|
|
@ -24,6 +24,9 @@ class ImageImageRepositoryOutput extends AbstractOutput
|
|||
#[Groups(['image-image-repository:read', 'image:read'])]
|
||||
public ?string $imageFullsum = null;
|
||||
|
||||
#[Groups(['image-image-repository:read', 'image:read'])]
|
||||
public ?array $partitionInfo = null;
|
||||
|
||||
#[Groups(['image-image-repository:read', 'image:read'])]
|
||||
public ?string $datasize = null;
|
||||
|
||||
|
@ -55,6 +58,7 @@ class ImageImageRepositoryOutput extends AbstractOutput
|
|||
|
||||
$this->name = $imageImageRepository->getName();
|
||||
$this->version = $imageImageRepository->getVersion();
|
||||
$this->partitionInfo = json_decode($imageImageRepository->getPartitionInfo(), true);
|
||||
$this->status = $imageImageRepository->getStatus();
|
||||
$this->imageFullsum = $imageImageRepository->getImageFullsum();
|
||||
$this->datasize = $imageImageRepository->getDatasize();
|
||||
|
|
|
@ -12,7 +12,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
#[Get(shortName: 'Image')]
|
||||
final class ImageOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['image:read', 'image-image-repository:read'])]
|
||||
#[Groups(['image:read', 'image-image-repository:read', 'git-image-repository:read'])]
|
||||
public ?string $name = '';
|
||||
#[Groups(['image:read', 'image-image-repository:read'])]
|
||||
public ?bool $remotePc = null;
|
||||
|
|
|
@ -20,6 +20,9 @@ class GitImageRepository extends AbstractEntity
|
|||
#[ORM\Column(length: 255)]
|
||||
private ?string $status = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $branch = null;
|
||||
|
||||
|
@ -57,6 +60,18 @@ class GitImageRepository extends AbstractEntity
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBranch(): ?string
|
||||
{
|
||||
return $this->branch;
|
||||
|
|
|
@ -23,6 +23,9 @@ class ImageImageRepository extends AbstractEntity
|
|||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $created = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $partitionInfo = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $imageFullsum = null;
|
||||
|
||||
|
@ -86,6 +89,18 @@ class ImageImageRepository extends AbstractEntity
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getPartitionInfo(): ?string
|
||||
{
|
||||
return $this->partitionInfo;
|
||||
}
|
||||
|
||||
public function setPartitionInfo(?string $partitionInfo): static
|
||||
{
|
||||
$this->partitionInfo = $partitionInfo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImageFullsum(): ?string
|
||||
{
|
||||
return $this->imageFullsum;
|
||||
|
|
|
@ -65,9 +65,7 @@ readonly class ImageProcessor implements ProcessorInterface
|
|||
|
||||
|
||||
if ($data->selectedImage){
|
||||
|
||||
$response = $this->createImageActionController->__invoke($data->selectedImage->getEntity(), $data->partition->getEntity());
|
||||
|
||||
$response = $this->createImageActionController->__invoke($data->selectedImage->getEntity(), $data->partition->getEntity(), $data->client->getEntity());
|
||||
} else {
|
||||
$image = $data->createOrUpdateEntity($entity);
|
||||
|
||||
|
|
Loading…
Reference in New Issue