refs #1693. Convert 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
b180d32843
commit
dc9e21b61e
|
@ -66,6 +66,15 @@ resources:
|
|||
uriTemplate: /image-repositories/{uuid}/import-image
|
||||
controller: App\Controller\OgRepository\Image\ImportAction
|
||||
|
||||
convert_image_ogrepository:
|
||||
shortName: OgRepository Server
|
||||
description: Convert Image in OgRepository
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: App\Dto\Input\ConvertImageRepositoryInput
|
||||
uriTemplate: /image-repositories/{uuid}/convert-image
|
||||
controller: App\Controller\OgRepository\Image\ConvertAction
|
||||
|
||||
properties:
|
||||
App\Entity\ImageRepository:
|
||||
id:
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?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 ConvertAction extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(ImportImageRepositoryInput $input, ImageRepository $repository): JsonResponse
|
||||
{
|
||||
$image = $input->name;
|
||||
|
||||
$params = [
|
||||
'json' => [
|
||||
'filesystem' => 'ext4',
|
||||
'virtual_image' => $image
|
||||
]
|
||||
];
|
||||
|
||||
$this->logger->info('Converting image', ['image' => $image]);
|
||||
|
||||
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/virtual', $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::CONVERT_IMAGE, 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::PENDING);
|
||||
$imageImageRepositoryEntity->setImage($imageEntity);
|
||||
$imageImageRepositoryEntity->setRepository($repository);
|
||||
|
||||
$this->entityManager->persist($imageImageRepositoryEntity);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -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 ConvertImageRepositoryInput
|
||||
{
|
||||
#[Assert\NotNull]
|
||||
#[Groups(['repository:write'])]
|
||||
public ?string $name = '';
|
||||
}
|
|
@ -7,6 +7,7 @@ final class CommandTypes
|
|||
public const string DEPLOY_IMAGE = 'deploy-image';
|
||||
public const string RESTORE_IMAGE = 'restore-image';
|
||||
public const string CREATE_IMAGE = 'create-image';
|
||||
public const string CONVERT_IMAGE = 'convert-image';
|
||||
public const string CREATE_IMAGE_AUX_FILE = 'create-image-aux-file';
|
||||
public const string BACKUP_IMAGE = 'backup-image';
|
||||
public const string IMPORT_IMAGE = 'import-image';
|
||||
|
@ -18,13 +19,13 @@ final class CommandTypes
|
|||
public const string LOGIN = 'login';
|
||||
public const string LOGOUT = 'logout';
|
||||
public const string PARTITION_AND_FORMAT = 'partition-and-format';
|
||||
|
||||
public const string INSTALL_OGLIVE = 'install-oglive';
|
||||
|
||||
private const array COMMAND_TYPES = [
|
||||
self::DEPLOY_IMAGE => 'Deploy Image',
|
||||
self::RESTORE_IMAGE => 'Update Cache',
|
||||
self::CREATE_IMAGE => 'Create Image',
|
||||
self::CONVERT_IMAGE => 'Convert Image',
|
||||
self::CREATE_IMAGE_AUX_FILE => 'Crear fichero auxiliar en repositorio',
|
||||
self::BACKUP_IMAGE => 'Crear backup de imagen',
|
||||
self::IMPORT_IMAGE => 'Importar imagen',
|
||||
|
|
Loading…
Reference in New Issue