Test refactor transferImage
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
88ffad3841
commit
4a76186e97
|
@ -88,7 +88,7 @@ resources:
|
||||||
description: Export Image in OgRepository
|
description: Export Image in OgRepository
|
||||||
class: ApiPlatform\Metadata\Post
|
class: ApiPlatform\Metadata\Post
|
||||||
method: POST
|
method: POST
|
||||||
input: App\Dto\Input\ExportImportImageRepositoryInput
|
input: App\Dto\Input\TransferGlobalImageInput
|
||||||
uriTemplate: /image-image-repositories/{uuid}/transfer-image
|
uriTemplate: /image-image-repositories/{uuid}/transfer-image
|
||||||
controller: App\Controller\OgRepository\Image\TransferAction
|
controller: App\Controller\OgRepository\Image\TransferAction
|
||||||
|
|
||||||
|
@ -101,6 +101,15 @@ resources:
|
||||||
uriTemplate: /image-image-repositories/server/{uuid}/status
|
uriTemplate: /image-image-repositories/server/{uuid}/status
|
||||||
controller: App\Controller\OgRepository\Image\GetStatusAction
|
controller: App\Controller\OgRepository\Image\GetStatusAction
|
||||||
|
|
||||||
|
transfer_global_image_repository:
|
||||||
|
shortName: OgRepository Server
|
||||||
|
description: Transfer Global Image in OgRepository
|
||||||
|
class: ApiPlatform\Metadata\Post
|
||||||
|
method: POST
|
||||||
|
input: false
|
||||||
|
uriTemplate: /image-image-repositories/server/{uuid}/transfer-global
|
||||||
|
controller: App\Controller\OgRepository\Image\TransferGlobalAction
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
App\Entity\ImageImageRepository:
|
App\Entity\ImageImageRepository:
|
||||||
id:
|
id:
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Controller\OgRepository\Image;
|
||||||
|
|
||||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||||
use App\Dto\Input\ExportImportImageRepositoryInput;
|
use App\Dto\Input\ExportImportImageRepositoryInput;
|
||||||
|
use App\Dto\Input\TransferGlobalImageInput;
|
||||||
use App\Entity\Image;
|
use App\Entity\Image;
|
||||||
use App\Entity\ImageImageRepository;
|
use App\Entity\ImageImageRepository;
|
||||||
use App\Entity\ImageRepository;
|
use App\Entity\ImageRepository;
|
||||||
|
@ -28,7 +29,7 @@ class TransferAction extends AbstractOgRepositoryController
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __invoke(ExportImportImageRepositoryInput $input, ImageImageRepository $imageImageRepository): JsonResponse
|
public function __invoke(TransferGlobalImageInput $input, ImageImageRepository $imageImageRepository): JsonResponse
|
||||||
{
|
{
|
||||||
$repositories = $input->repositories;
|
$repositories = $input->repositories;
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ class TransferAction extends AbstractOgRepositoryController
|
||||||
$params = [
|
$params = [
|
||||||
'json' => [
|
'json' => [
|
||||||
'image' => $image->getName().'.img',
|
'image' => $image->getName().'.img',
|
||||||
'repo_ip' => $image->getClient()->getRepository()->getIp(),
|
'repo_ip' => $imageImageRepository->getRepository()->getIp(),
|
||||||
'user' => 'opengnsys',
|
'user' => 'opengnsys',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
@ -21,7 +21,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class TransferIsGlobalAction extends AbstractOgRepositoryController
|
class TransferGlobalAction extends AbstractOgRepositoryController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -29,26 +29,17 @@ class TransferIsGlobalAction extends AbstractOgRepositoryController
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __invoke(?array $repositories = [], Image $image): JsonResponse
|
public function __invoke(ImageImageRepository $imageImageRepository): JsonResponse
|
||||||
{
|
{
|
||||||
|
$repositories = $this->entityManager->getRepository(ImageRepository::class)->findAll();
|
||||||
|
|
||||||
foreach ($repositories as $repository) {
|
foreach ($repositories as $repository) {
|
||||||
try {
|
$image = $imageImageRepository->getImage();
|
||||||
$imageImageRepository = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['image' => $image, 'repository' => $repository]);
|
|
||||||
|
|
||||||
if ($imageImageRepository) {
|
|
||||||
$content = $this->createRequest('GET', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/'.$imageImageRepository->getImageFullsum());
|
|
||||||
|
|
||||||
$this->logger->info('Image already exists', ['image' => $imageImageRepository->getImage()->getName(), 'repository' => $repository->getIp()]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} catch ( \Exception $e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'json' => [
|
'json' => [
|
||||||
'image' => $image->getName().'.img',
|
'image' => $image->getName().'.img',
|
||||||
'repo_ip' => $image->getClient()->getRepository()->getIp(),
|
'repo_ip' => $imageImageRepository->getRepository()->getIp(),
|
||||||
'user' => 'opengnsys',
|
'user' => 'opengnsys',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
@ -64,13 +55,13 @@ class TransferIsGlobalAction extends AbstractOgRepositoryController
|
||||||
$inputData = [
|
$inputData = [
|
||||||
'imageName' => $image->getName(),
|
'imageName' => $image->getName(),
|
||||||
'imageUuid' => $image->getUuid(),
|
'imageUuid' => $image->getUuid(),
|
||||||
//'imageImageRepositoryUuid' => $imageImageRepository?->getUuid(),
|
'imageImageRepositoryUuid' => $imageImageRepository?->getUuid(),
|
||||||
'repositoryUuid' => $repository->getUuid(),
|
'repositoryUuid' => $repository->getUuid(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->createService->__invoke($image->getClient(), CommandTypes::TRANSFER_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
$this->createService->__invoke($image->getClient(), CommandTypes::TRANSFER_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
||||||
|
|
||||||
//$imageImageRepository->setStatus(ImageStatus::TRANSFERRING);
|
$imageImageRepository->setStatus(ImageStatus::TRANSFERRING);
|
||||||
$this->entityManager->persist($image);
|
$this->entityManager->persist($image);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
}
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Dto\Input;
|
||||||
|
|
||||||
|
use App\Dto\Output\ImageOutput;
|
||||||
|
use App\Dto\Output\ImageRepositoryOutput;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
class TransferGlobalImageInput
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var ImageOutput[]
|
||||||
|
*/
|
||||||
|
#[Assert\NotNull]
|
||||||
|
#[Groups(['image-image-repository:write'])]
|
||||||
|
public array $repositories = [];
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\EventSubscriber;
|
namespace App\EventSubscriber;
|
||||||
|
|
||||||
use ApiPlatform\Symfony\EventListener\EventPriorities;
|
use ApiPlatform\Symfony\EventListener\EventPriorities;
|
||||||
use App\Controller\OgRepository\Image\TransferIsGlobalAction;
|
use App\Controller\OgRepository\Image\TransferGlobalAction;
|
||||||
use App\Dto\Output\ImageRepositoryOutput;
|
use App\Dto\Output\ImageRepositoryOutput;
|
||||||
use App\Dto\Output\OrganizationalUnitOutput;
|
use App\Dto\Output\OrganizationalUnitOutput;
|
||||||
use App\Entity\Image;
|
use App\Entity\Image;
|
||||||
|
@ -21,8 +21,8 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
final readonly class ImageRepositorySubscriber implements EventSubscriberInterface
|
final readonly class ImageRepositorySubscriber implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private EntityManagerInterface $entityManager,
|
private EntityManagerInterface $entityManager,
|
||||||
private readonly TransferIsGlobalAction $transferIsGlobalAction,
|
private readonly TransferGlobalAction $transferIsGlobalAction,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ use ApiPlatform\State\ProcessorInterface;
|
||||||
use ApiPlatform\Validator\ValidatorInterface;
|
use ApiPlatform\Validator\ValidatorInterface;
|
||||||
use App\Controller\OgAgent\CreateImageAction;
|
use App\Controller\OgAgent\CreateImageAction;
|
||||||
use App\Controller\OgRepository\Image\TransferAction;
|
use App\Controller\OgRepository\Image\TransferAction;
|
||||||
use App\Controller\OgRepository\Image\TransferIsGlobalAction;
|
|
||||||
use App\Dto\Input\ImageInput;
|
use App\Dto\Input\ImageInput;
|
||||||
use App\Dto\Input\ImageRepositoryInput;
|
use App\Dto\Input\ImageRepositoryInput;
|
||||||
use App\Dto\Output\ImageOutput;
|
use App\Dto\Output\ImageOutput;
|
||||||
|
@ -27,7 +26,6 @@ readonly class ImageProcessor implements ProcessorInterface
|
||||||
private ImageRepository $imageRepository,
|
private ImageRepository $imageRepository,
|
||||||
private ValidatorInterface $validator,
|
private ValidatorInterface $validator,
|
||||||
private CreateImageAction $createImageActionController,
|
private CreateImageAction $createImageActionController,
|
||||||
private TransferIsGlobalAction $transferActionController
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -68,11 +66,6 @@ readonly class ImageProcessor implements ProcessorInterface
|
||||||
|
|
||||||
if ($data->source !== 'input') {
|
if ($data->source !== 'input') {
|
||||||
$response = $this->createImageActionController->__invoke($image);
|
$response = $this->createImageActionController->__invoke($image);
|
||||||
} else {
|
|
||||||
if ($data->isGlobal === true) {
|
|
||||||
$repositories = $this->imageRepositoryRepository->findAll();
|
|
||||||
$this->transferActionController->__invoke($repositories, $image);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->imageRepository->save($image);
|
$this->imageRepository->save($image);
|
||||||
|
|
Loading…
Reference in New Issue