refs #1692. Import Image. Refactor old code
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
b0bf22a2eb
commit
b180d32843
|
@ -57,14 +57,14 @@ resources:
|
||||||
uriTemplate: /image-repositories/server/{uuid}/status
|
uriTemplate: /image-repositories/server/{uuid}/status
|
||||||
controller: App\Controller\OgRepository\StatusAction
|
controller: App\Controller\OgRepository\StatusAction
|
||||||
|
|
||||||
export_image_ogrepository:
|
import_image_ogrepository:
|
||||||
shortName: OgRepository Server
|
shortName: OgRepository Server
|
||||||
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\ImportImageRepositoryInput
|
||||||
uriTemplate: /image-repositories/{uuid}/export-image
|
uriTemplate: /image-repositories/{uuid}/import-image
|
||||||
controller: App\Controller\OgRepository\Image\ExportAction
|
controller: App\Controller\OgRepository\Image\ImportAction
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
App\Entity\ImageRepository:
|
App\Entity\ImageRepository:
|
||||||
|
|
|
@ -54,7 +54,7 @@ class CancelTransmissionAction extends AbstractOgRepositoryController
|
||||||
|
|
||||||
$content = $this->createRequest('DELETE', 'http://'.$image->getRepository()->getIp().':8006/ogrepository/v1/'.$method.'/images/'.$image->getImageFullsum());
|
$content = $this->createRequest('DELETE', 'http://'.$image->getRepository()->getIp().':8006/ogrepository/v1/'.$method.'/images/'.$image->getImageFullsum());
|
||||||
|
|
||||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
throw new ValidatorException('Error cancelling transmission');
|
throw new ValidatorException('Error cancelling transmission');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\OgRepository\Image;
|
|
||||||
|
|
||||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
|
||||||
use App\Dto\Input\ExportImportImageRepositoryInput;
|
|
||||||
use App\Entity\Image;
|
|
||||||
use App\Entity\ImageRepository;
|
|
||||||
use App\Model\CommandTypes;
|
|
||||||
use App\Model\ImageStatus;
|
|
||||||
use App\Model\TraceStatus;
|
|
||||||
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 ExportAction extends AbstractOgRepositoryController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @throws TransportExceptionInterface
|
|
||||||
* @throws ServerExceptionInterface
|
|
||||||
* @throws RedirectionExceptionInterface
|
|
||||||
* @throws ClientExceptionInterface
|
|
||||||
*/
|
|
||||||
public function __invoke(ExportImportImageRepositoryInput $input, ImageRepository $repository): JsonResponse
|
|
||||||
{
|
|
||||||
$images = $input->images;
|
|
||||||
|
|
||||||
foreach ($images as $imageEntity) {
|
|
||||||
/** @var Image $image */
|
|
||||||
$image = $imageEntity->getEntity();
|
|
||||||
|
|
||||||
if (!$image->getImageFullsum()) {
|
|
||||||
throw new ValidatorException('Fullsum is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
'json' => [
|
|
||||||
'ID_img' => $image->getImageFullsum(),
|
|
||||||
'repo_ip' => $repository->getIp(),
|
|
||||||
'user' => 'opengnsys',
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->logger->info('Exporting image', ['image' => $image->getName(), 'repository' => $repository->getIp()]);
|
|
||||||
|
|
||||||
$content = $this->createRequest('PUT', 'http://'.$image->getRepository()->getIp().':8006/ogrepository/v1/repo/images', $params);
|
|
||||||
|
|
||||||
$inputData = [
|
|
||||||
'imageName' => $image->getName(),
|
|
||||||
'imageUuid' => $image->getUuid(),
|
|
||||||
'repositoryUuid' => $repository->getUuid(),
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->createService->__invoke($image->getClient(), CommandTypes::EXPORT_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
|
||||||
|
|
||||||
$image->setStatus(ImageStatus::TRANSFERING);
|
|
||||||
$this->entityManager->persist($image);
|
|
||||||
$this->entityManager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\OgRepository\Image;
|
||||||
|
|
||||||
|
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||||
|
use App\Dto\Input\ImportImageRepositoryInput;
|
||||||
|
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 Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
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 ImportAction extends AbstractOgRepositoryController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
* @throws ServerExceptionInterface
|
||||||
|
* @throws RedirectionExceptionInterface
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
*/
|
||||||
|
public function __invoke(ImportImageRepositoryInput $input, ImageRepository $repository): JsonResponse
|
||||||
|
{
|
||||||
|
$image = $input->name;
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'json' => [
|
||||||
|
'image' => $image.'.img'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->logger->info('Creating aux files', ['image' => $image]);
|
||||||
|
|
||||||
|
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params);
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('Error importing image');
|
||||||
|
}
|
||||||
|
|
||||||
|
$inputData = [
|
||||||
|
'imageName' => $image
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->createService->__invoke(null, CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
||||||
|
|
||||||
|
$imageEntity = $this->entityManager->getRepository(Image::class)->findOneBy(['name' => $image]);
|
||||||
|
|
||||||
|
if (!$imageEntity){
|
||||||
|
$imageEntity = new Image();
|
||||||
|
$imageEntity->setName($image);
|
||||||
|
$imageEntity->setRemotePc(false);
|
||||||
|
$imageEntity->setIsGlobal(false);
|
||||||
|
|
||||||
|
$this->entityManager->persist($imageEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
$imageImageRepositoryEntity = new ImageImageRepository();
|
||||||
|
$imageImageRepositoryEntity->setStatus(ImageStatus::AUX_FILES_PENDING);
|
||||||
|
$imageImageRepositoryEntity->setImage($imageEntity);
|
||||||
|
$imageImageRepositoryEntity->setRepository($repository);
|
||||||
|
|
||||||
|
$this->entityManager->persist($imageImageRepositoryEntity);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,6 @@ class ExportImportImageRepositoryInput
|
||||||
* @var ImageOutput[]
|
* @var ImageOutput[]
|
||||||
*/
|
*/
|
||||||
#[Assert\NotNull]
|
#[Assert\NotNull]
|
||||||
#[Groups(['image-image-repository:write'])]
|
#[Groups(['repository:write'])]
|
||||||
public array $repositories = [];
|
public array $images = [];
|
||||||
}
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?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 ImportImageRepositoryInput
|
||||||
|
{
|
||||||
|
#[Assert\NotNull]
|
||||||
|
#[Groups(['repository:write'])]
|
||||||
|
public ?string $name = '';
|
||||||
|
}
|
Loading…
Reference in New Issue