refs #1516. Changed form and global import
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
7ede1a646a
commit
d61be99b84
|
@ -2,6 +2,7 @@ lexik_jwt_authentication:
|
|||
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
|
||||
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
|
||||
pass_phrase: '%env(JWT_PASSPHRASE)%'
|
||||
token_ttl: 86400 # 1 day
|
||||
api_platform:
|
||||
check_path: /auth/login
|
||||
username_path: username
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||
use App\Dto\Input\ExportImportImageRepositoryInput;
|
||||
use App\Entity\Image;
|
||||
use App\Entity\ImageImageRepository;
|
||||
use App\Entity\ImageRepository;
|
||||
use App\Model\CommandTypes;
|
||||
use App\Model\ImageStatus;
|
||||
use App\Model\TraceStatus;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
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 TransferIsGlobalAction extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(?array $repositories = [], Image $image): JsonResponse
|
||||
{
|
||||
foreach ($repositories as $repository) {
|
||||
try {
|
||||
$imageImageRepository = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['image' => $image, 'repository' => $repository]);
|
||||
$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) {
|
||||
|
||||
}
|
||||
|
||||
/* @var Image $image */
|
||||
$image = $imageImageRepository->getImage();
|
||||
|
||||
if (!$imageImageRepository->getImageFullsum()) {
|
||||
throw new ValidatorException('Fullsum is required');
|
||||
}
|
||||
|
||||
$params = [
|
||||
'json' => [
|
||||
'image' => $image->getName().'.img',
|
||||
'repo_ip' => $image->getClient()->getRepository()->getIp(),
|
||||
'user' => 'opengnsys',
|
||||
]
|
||||
];
|
||||
|
||||
$this->logger->info('Importing image', ['image' => $image->getName(), 'repository' => $repository->getIp()]);
|
||||
|
||||
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params);
|
||||
|
||||
if (!isset($content['job_id'])) {
|
||||
throw new ValidatorException('Job ID not found');
|
||||
}
|
||||
|
||||
$inputData = [
|
||||
'imageName' => $image->getName(),
|
||||
'imageUuid' => $image->getUuid(),
|
||||
'imageImageRepositoryUuid' => $imageImageRepository->getUuid(),
|
||||
'repositoryUuid' => $repository->getUuid(),
|
||||
];
|
||||
|
||||
$this->createService->__invoke($image->getClient(), CommandTypes::TRANSFER_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
||||
|
||||
$imageImageRepository->setStatus(ImageStatus::TRANSFERRING);
|
||||
$this->entityManager->persist($image);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -10,24 +10,31 @@ use ApiPlatform\Metadata\Put;
|
|||
use ApiPlatform\State\ProcessorInterface;
|
||||
use ApiPlatform\Validator\ValidatorInterface;
|
||||
use App\Controller\OgAgent\CreateImageAction;
|
||||
use App\Controller\OgRepository\Image\TransferAction;
|
||||
use App\Controller\OgRepository\Image\TransferIsGlobalAction;
|
||||
use App\Dto\Input\ImageInput;
|
||||
use App\Dto\Input\ImageRepositoryInput;
|
||||
use App\Dto\Output\ImageOutput;
|
||||
use App\Entity\ImageImageRepository;
|
||||
use App\Repository\ImageRepository;
|
||||
use App\Repository\ImageRepositoryRepository as ImageRepositoryRepository;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
readonly class ImageProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ImageRepository $imageRepository,
|
||||
private ValidatorInterface $validator,
|
||||
private CreateImageAction $createImageActionController
|
||||
private ImageRepositoryRepository $imageRepositoryRepository,
|
||||
private ImageRepository $imageRepository,
|
||||
private ValidatorInterface $validator,
|
||||
private CreateImageAction $createImageActionController,
|
||||
private TransferIsGlobalAction $transferActionController
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput|null
|
||||
{
|
||||
|
@ -43,6 +50,7 @@ readonly class ImageProcessor implements ProcessorInterface
|
|||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput
|
||||
{
|
||||
|
@ -60,6 +68,11 @@ readonly class ImageProcessor implements ProcessorInterface
|
|||
|
||||
if ($data->source !== 'input') {
|
||||
$response = $this->createImageActionController->__invoke($image);
|
||||
} else {
|
||||
if ($data->isGlobal === true) {
|
||||
$repositories = $this->imageRepositoryRepository->findAll();
|
||||
$this->transferActionController->__invoke($repositories, $image);
|
||||
}
|
||||
}
|
||||
|
||||
$this->imageRepository->save($image);
|
||||
|
|
Loading…
Reference in New Issue