diff --git a/config/api_platform/GitImageRepository.yaml b/config/api_platform/GitImageRepository.yaml index 9261f82..b1997a2 100644 --- a/config/api_platform/GitImageRepository.yaml +++ b/config/api_platform/GitImageRepository.yaml @@ -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: diff --git a/migrations/Version20250513050921.php b/migrations/Version20250513050921.php new file mode 100644 index 0000000..bd9ff66 --- /dev/null +++ b/migrations/Version20250513050921.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/migrations/Version20250513055057.php b/migrations/Version20250513055057.php new file mode 100644 index 0000000..c96a29d --- /dev/null +++ b/migrations/Version20250513055057.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/src/Controller/OgAgent/CreateImageAction.php b/src/Controller/OgAgent/CreateImageAction.php index d17f33c..ed3bb96 100644 --- a/src/Controller/OgAgent/CreateImageAction.php +++ b/src/Controller/OgAgent/CreateImageAction.php @@ -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); } diff --git a/src/Controller/OgRepository/Git/GetTagsAction.php b/src/Controller/OgRepository/Git/GetTagsAction.php new file mode 100644 index 0000000..213dd01 --- /dev/null +++ b/src/Controller/OgRepository/Git/GetTagsAction.php @@ -0,0 +1,38 @@ +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); + } +} \ No newline at end of file diff --git a/src/Dto/Input/GitImageRepositoryInput.php b/src/Dto/Input/GitImageRepositoryInput.php index d391f90..8c8ed1b 100644 --- a/src/Dto/Input/GitImageRepositoryInput.php +++ b/src/Dto/Input/GitImageRepositoryInput.php @@ -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; } diff --git a/src/Dto/Output/GitImageRepositoryOutput.php b/src/Dto/Output/GitImageRepositoryOutput.php index 0ac9ae8..aeceb17 100644 --- a/src/Dto/Output/GitImageRepositoryOutput.php +++ b/src/Dto/Output/GitImageRepositoryOutput.php @@ -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(); diff --git a/src/Dto/Output/ImageImageRepositoryOutput.php b/src/Dto/Output/ImageImageRepositoryOutput.php index 0877055..ba15f15 100644 --- a/src/Dto/Output/ImageImageRepositoryOutput.php +++ b/src/Dto/Output/ImageImageRepositoryOutput.php @@ -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(); diff --git a/src/Dto/Output/ImageOutput.php b/src/Dto/Output/ImageOutput.php index a5cbcea..a5cf26f 100644 --- a/src/Dto/Output/ImageOutput.php +++ b/src/Dto/Output/ImageOutput.php @@ -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; diff --git a/src/Entity/GitImageRepository.php b/src/Entity/GitImageRepository.php index 2429985..2a56010 100644 --- a/src/Entity/GitImageRepository.php +++ b/src/Entity/GitImageRepository.php @@ -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; diff --git a/src/Entity/ImageImageRepository.php b/src/Entity/ImageImageRepository.php index 6de9f49..69c9116 100644 --- a/src/Entity/ImageImageRepository.php +++ b/src/Entity/ImageImageRepository.php @@ -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; diff --git a/src/State/Processor/ImageProcessor.php b/src/State/Processor/ImageProcessor.php index 5d72a40..dbc5302 100644 --- a/src/State/Processor/ImageProcessor.php +++ b/src/State/Processor/ImageProcessor.php @@ -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);