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
|
uriTemplate: /image-image-repositories/server/{uuid}/get
|
||||||
controller: App\Controller\OgRepository\Image\GetAction
|
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:
|
properties:
|
||||||
App\Entity\GitImageRepository:
|
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 RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @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()) {
|
if (!$image->getClient()->getIp()) {
|
||||||
throw new ValidatorException('IP is required');
|
throw new ValidatorException('IP is required');
|
||||||
|
@ -73,7 +73,6 @@ class CreateImageAction extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($image->getType() === 'monolithic') {
|
if ($image->getType() === 'monolithic') {
|
||||||
|
|
||||||
$repository = $image->getClient()->getRepository();
|
$repository = $image->getClient()->getRepository();
|
||||||
$latestImageRepo = $this->entityManager->getRepository(ImageImageRepository::class)->findLatestVersionByImageAndRepository($image, $repository);
|
$latestImageRepo = $this->entityManager->getRepository(ImageImageRepository::class)->findLatestVersionByImageAndRepository($image, $repository);
|
||||||
|
|
||||||
|
@ -83,10 +82,11 @@ class CreateImageAction extends AbstractController
|
||||||
$imageImageRepository->setRepository($repository);
|
$imageImageRepository->setRepository($repository);
|
||||||
$imageImageRepository->setStatus(ImageStatus::IN_PROGRESS);
|
$imageImageRepository->setStatus(ImageStatus::IN_PROGRESS);
|
||||||
$imageImageRepository->setVersion($latestImageRepo ? $latestImageRepo->getVersion() + 1 : 1);
|
$imageImageRepository->setVersion($latestImageRepo ? $latestImageRepo->getVersion() + 1 : 1);
|
||||||
|
$imageImageRepository->setPartitionInfo(json_encode($partitionInfo));
|
||||||
|
|
||||||
$this->entityManager->persist($imageImageRepository);
|
$this->entityManager->persist($imageImageRepository);
|
||||||
|
|
||||||
return $this->createMonolithicImage($imageImageRepository, $partitionInfo, $image, $repository);
|
return $this->createMonolithicImage($imageImageRepository, $partitionInfo, $image, $repository, $client);
|
||||||
} else {
|
} else {
|
||||||
$repository = $image->getClient()->getRepository();
|
$repository = $image->getClient()->getRepository();
|
||||||
$latestImageRepo = $this->entityManager->getRepository(GitImageRepository::class)->findLatestVersionByImageAndRepository($image, $repository);
|
$latestImageRepo = $this->entityManager->getRepository(GitImageRepository::class)->findLatestVersionByImageAndRepository($image, $repository);
|
||||||
|
@ -101,6 +101,7 @@ class CreateImageAction extends AbstractController
|
||||||
$gitImageRepository->setCreated(false);
|
$gitImageRepository->setCreated(false);
|
||||||
|
|
||||||
$this->entityManager->persist($gitImageRepository);
|
$this->entityManager->persist($gitImageRepository);
|
||||||
|
$this->entityManager->persist($image);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
return $this->createGitImage($gitImageRepository, $partitionInfo, $image, $repository);
|
return $this->createGitImage($gitImageRepository, $partitionInfo, $image, $repository);
|
||||||
|
@ -117,7 +118,8 @@ class CreateImageAction extends AbstractController
|
||||||
ImageImageRepository $imageImageRepository,
|
ImageImageRepository $imageImageRepository,
|
||||||
array $partitionInfo,
|
array $partitionInfo,
|
||||||
Image $image,
|
Image $image,
|
||||||
ImageRepository $repository
|
ImageRepository $repository,
|
||||||
|
?Client $client = null
|
||||||
): JsonResponse
|
): JsonResponse
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -146,8 +148,10 @@ class CreateImageAction extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
$client = $client ?? $image->getClient();
|
||||||
$this->logger->info('Creating image', ['image' => $image->getId()]);
|
$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_peer' => false,
|
||||||
'verify_host' => false,
|
'verify_host' => false,
|
||||||
'headers' => [
|
'headers' => [
|
||||||
|
@ -167,12 +171,22 @@ class CreateImageAction extends AbstractController
|
||||||
|
|
||||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||||
|
|
||||||
$client = $image->getClient();
|
|
||||||
$client->setStatus(ClientStatus::BUSY);
|
$client->setStatus(ClientStatus::BUSY);
|
||||||
$this->entityManager->persist($client);
|
$this->entityManager->persist($client);
|
||||||
$this->entityManager->flush();
|
$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);
|
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
|
final class GitImageRepositoryInput
|
||||||
{
|
{
|
||||||
#[Groups(['git-image-repository:write'])]
|
#[Groups(['git-image-repository:write'])]
|
||||||
public ?string $name = '';
|
public ?string $description = '';
|
||||||
|
|
||||||
public function __construct(?GitImageRepository $gitImageRepository = null)
|
public function __construct(?GitImageRepository $gitImageRepository = null)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ final class GitImageRepositoryInput
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->name = $gitImageRepository->getName();
|
$this->description = $gitImageRepository->getDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createOrUpdateEntity(?GitImageRepository $gitImageRepository = null): GitImageRepository
|
public function createOrUpdateEntity(?GitImageRepository $gitImageRepository = null): GitImageRepository
|
||||||
|
@ -26,7 +26,7 @@ final class GitImageRepositoryInput
|
||||||
$gitImageRepository = new GitImageRepository();
|
$gitImageRepository = new GitImageRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
$gitImageRepository->setName($this->name);
|
$gitImageRepository->setDescription($this->description);
|
||||||
|
|
||||||
return $gitImageRepository;
|
return $gitImageRepository;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ final class GitImageRepositoryOutput extends AbstractOutput
|
||||||
#[Groups(['git-image-repository:read', 'image:read'])]
|
#[Groups(['git-image-repository:read', 'image:read'])]
|
||||||
public string $status = '';
|
public string $status = '';
|
||||||
|
|
||||||
|
#[Groups(['git-image-repository:read', 'image:read'])]
|
||||||
|
public ?string $description = '';
|
||||||
|
|
||||||
#[Groups(['git-image-repository:read', 'image:read'])]
|
#[Groups(['git-image-repository:read', 'image:read'])]
|
||||||
public string $name = '';
|
public string $name = '';
|
||||||
|
|
||||||
|
@ -49,6 +52,7 @@ final class GitImageRepositoryOutput extends AbstractOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->name = $gitImageRepository->getName();
|
$this->name = $gitImageRepository->getName();
|
||||||
|
$this->description = $gitImageRepository->getDescription();
|
||||||
$this->status = $gitImageRepository->getStatus();
|
$this->status = $gitImageRepository->getStatus();
|
||||||
$this->branch = $gitImageRepository->getBranch();
|
$this->branch = $gitImageRepository->getBranch();
|
||||||
$this->tag = $gitImageRepository->getTag();
|
$this->tag = $gitImageRepository->getTag();
|
||||||
|
|
|
@ -24,6 +24,9 @@ class ImageImageRepositoryOutput extends AbstractOutput
|
||||||
#[Groups(['image-image-repository:read', 'image:read'])]
|
#[Groups(['image-image-repository:read', 'image:read'])]
|
||||||
public ?string $imageFullsum = null;
|
public ?string $imageFullsum = null;
|
||||||
|
|
||||||
|
#[Groups(['image-image-repository:read', 'image:read'])]
|
||||||
|
public ?array $partitionInfo = null;
|
||||||
|
|
||||||
#[Groups(['image-image-repository:read', 'image:read'])]
|
#[Groups(['image-image-repository:read', 'image:read'])]
|
||||||
public ?string $datasize = null;
|
public ?string $datasize = null;
|
||||||
|
|
||||||
|
@ -55,6 +58,7 @@ class ImageImageRepositoryOutput extends AbstractOutput
|
||||||
|
|
||||||
$this->name = $imageImageRepository->getName();
|
$this->name = $imageImageRepository->getName();
|
||||||
$this->version = $imageImageRepository->getVersion();
|
$this->version = $imageImageRepository->getVersion();
|
||||||
|
$this->partitionInfo = json_decode($imageImageRepository->getPartitionInfo(), true);
|
||||||
$this->status = $imageImageRepository->getStatus();
|
$this->status = $imageImageRepository->getStatus();
|
||||||
$this->imageFullsum = $imageImageRepository->getImageFullsum();
|
$this->imageFullsum = $imageImageRepository->getImageFullsum();
|
||||||
$this->datasize = $imageImageRepository->getDatasize();
|
$this->datasize = $imageImageRepository->getDatasize();
|
||||||
|
|
|
@ -12,7 +12,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
#[Get(shortName: 'Image')]
|
#[Get(shortName: 'Image')]
|
||||||
final class ImageOutput extends AbstractOutput
|
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 = '';
|
public ?string $name = '';
|
||||||
#[Groups(['image:read', 'image-image-repository:read'])]
|
#[Groups(['image:read', 'image-image-repository:read'])]
|
||||||
public ?bool $remotePc = null;
|
public ?bool $remotePc = null;
|
||||||
|
|
|
@ -20,6 +20,9 @@ class GitImageRepository extends AbstractEntity
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
private ?string $status = null;
|
private ?string $status = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $description = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
private ?string $branch = null;
|
private ?string $branch = null;
|
||||||
|
|
||||||
|
@ -57,6 +60,18 @@ class GitImageRepository extends AbstractEntity
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDescription(): ?string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(?string $description): static
|
||||||
|
{
|
||||||
|
$this->description = $description;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getBranch(): ?string
|
public function getBranch(): ?string
|
||||||
{
|
{
|
||||||
return $this->branch;
|
return $this->branch;
|
||||||
|
|
|
@ -23,6 +23,9 @@ class ImageImageRepository extends AbstractEntity
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
private ?bool $created = null;
|
private ?bool $created = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $partitionInfo = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
private ?string $imageFullsum = null;
|
private ?string $imageFullsum = null;
|
||||||
|
|
||||||
|
@ -86,6 +89,18 @@ class ImageImageRepository extends AbstractEntity
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPartitionInfo(): ?string
|
||||||
|
{
|
||||||
|
return $this->partitionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPartitionInfo(?string $partitionInfo): static
|
||||||
|
{
|
||||||
|
$this->partitionInfo = $partitionInfo;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getImageFullsum(): ?string
|
public function getImageFullsum(): ?string
|
||||||
{
|
{
|
||||||
return $this->imageFullsum;
|
return $this->imageFullsum;
|
||||||
|
|
|
@ -65,9 +65,7 @@ readonly class ImageProcessor implements ProcessorInterface
|
||||||
|
|
||||||
|
|
||||||
if ($data->selectedImage){
|
if ($data->selectedImage){
|
||||||
|
$response = $this->createImageActionController->__invoke($data->selectedImage->getEntity(), $data->partition->getEntity(), $data->client->getEntity());
|
||||||
$response = $this->createImageActionController->__invoke($data->selectedImage->getEntity(), $data->partition->getEntity());
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$image = $data->createOrUpdateEntity($entity);
|
$image = $data->createOrUpdateEntity($entity);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue