refs #1473. Changes in ogRepo. Import
testing/ogcore-api/pipeline/head This commit looks good Details

hotfix-timeout
Manuel Aranda Rosales 2025-02-07 11:58:28 +01:00
parent 95b85ccca1
commit d5c75f6c45
6 changed files with 57 additions and 26 deletions

View File

@ -13,6 +13,8 @@ resources:
filters: filters:
- 'api_platform.filter.repository.order' - 'api_platform.filter.repository.order'
- 'api_platform.filter.repository.search' - 'api_platform.filter.repository.search'
- 'repository.not_equal_filter'
ApiPlatform\Metadata\Get: ApiPlatform\Metadata\Get:
provider: App\State\Provider\ImageRepositoryProvider provider: App\State\Provider\ImageRepositoryProvider
ApiPlatform\Metadata\Put: ApiPlatform\Metadata\Put:
@ -64,14 +66,14 @@ resources:
uriTemplate: /image-repositories/{uuid}/export-image uriTemplate: /image-repositories/{uuid}/export-image
controller: App\Controller\OgRepository\Image\ExportAction controller: App\Controller\OgRepository\Image\ExportAction
import_image_ogrepository: transfer_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\ExportImportImageRepositoryInput
uriTemplate: /image-repositories/{uuid}/import-image uriTemplate: /image-repositories/{uuid}/transfer-image
controller: App\Controller\OgRepository\Image\ImportAction controller: App\Controller\OgRepository\Image\TransferAction
properties: properties:
App\Entity\ImageRepository: App\Entity\ImageRepository:

View File

@ -55,7 +55,7 @@ services:
api_platform.filter.image.order: api_platform.filter.image.order:
parent: 'api_platform.doctrine.orm.order_filter' parent: 'api_platform.doctrine.orm.order_filter'
arguments: arguments:
$properties: { 'id': ~, 'name': ~, 'createdAt': ~ } $properties: { 'id': ~, 'name': ~ }
$orderParameterName: 'order' $orderParameterName: 'order'
tags: [ 'api_platform.filter' ] tags: [ 'api_platform.filter' ]
@ -190,6 +190,10 @@ services:
arguments: [ { 'id': 'exact', 'name': 'partial'} ] arguments: [ { 'id': 'exact', 'name': 'partial'} ]
tags: [ 'api_platform.filter' ] tags: [ 'api_platform.filter' ]
repository.not_equal_filter:
parent: 'App\Filter\NotEqualIdFilter'
tags: [ 'api_platform.filter' ]
api_platform.filter.software.order: api_platform.filter.software.order:
parent: 'api_platform.doctrine.orm.order_filter' parent: 'api_platform.doctrine.orm.order_filter'
arguments: arguments:

View File

@ -19,7 +19,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
#[AsController] #[AsController]
class ImportAction extends AbstractOgRepositoryController class TransferAction extends AbstractOgRepositoryController
{ {
/** /**
* @throws TransportExceptionInterface * @throws TransportExceptionInterface
@ -53,13 +53,17 @@ class ImportAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params); $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 = [ $inputData = [
'imageName' => $image->getName(), 'imageName' => $image->getName(),
'imageUuid' => $image->getUuid(), 'imageUuid' => $image->getUuid(),
'repositoryUuid' => $repository->getUuid(), 'repositoryUuid' => $repository->getUuid(),
]; ];
$this->createService->__invoke($image->getClient(), CommandTypes::IMPORT_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); $this->createService->__invoke($image->getClient(), CommandTypes::TRANSFER_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
$image->setStatus(ImageStatus::TRANSFERRING); $image->setStatus(ImageStatus::TRANSFERRING);
$this->entityManager->persist($image); $this->entityManager->persist($image);

View File

@ -44,10 +44,10 @@ class ResponseController extends AbstractOgRepositoryController
if (str_starts_with($action, "CreateAuxiliarFiles_")) { if (str_starts_with($action, "CreateAuxiliarFiles_")) {
$this->handleCreateAuxFiles($data); $this->handleCreateAuxFiles($data);
} elseif (str_starts_with($action, "TransferImage_")) {
$this->processImageAction($data, 'transfer');
} elseif (str_starts_with($action, "ExportImage_")) { } elseif (str_starts_with($action, "ExportImage_")) {
$this->processImageAction($data, 'export'); $this->processImageAction($data, 'export');
} elseif (str_starts_with($action, "ImportImage_")) {
$this->processImageAction($data, 'import');
} else { } else {
return new JsonResponse(['message' => 'Invalid action'], Response::HTTP_BAD_REQUEST); return new JsonResponse(['message' => 'Invalid action'], Response::HTTP_BAD_REQUEST);
} }
@ -95,25 +95,9 @@ class ResponseController extends AbstractOgRepositoryController
return; return;
} }
$this->logger->info("Image $actionType", ['image' => $image->getName()]); $this->logger->info("Image $actionType successful", ['image' => $image->getName()]);
$params = [ $image->addRepository($repository);
'json' => [
'image' => $image->getName().'.img'
]
];
$this->logger->info('Creating aux files', ['image' => $image->getName()]);
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params);
$inputData = [
'imageName' => $image->getName(),
'imageUuid' => $image->getUuid(),
];
$this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
$image->setRepository($repository);
$image->setStatus(ImageStatus::SUCCESS); $image->setStatus(ImageStatus::SUCCESS);
$this->entityManager->persist($image); $this->entityManager->persist($image);

View File

@ -0,0 +1,36 @@
<?php
namespace App\Filter;
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\PropertyInfo\Type;
class NotEqualIdFilter extends AbstractFilter
{
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
{
if ($property !== 'id') {
return;
}
$alias = $queryBuilder->getRootAliases()[0];
$queryBuilder
->andWhere(sprintf('%s.%s != :id', $alias, $property))
->setParameter('id', $value);
}
public function getDescription(string $resourceClass): array
{
return [
'id[neq]' => [
'property' => 'id',
'type' => Type::BUILTIN_TYPE_INT,
'required' => false,
'description' => 'Filter records where id is not equal to the given value.',
],
];
}
}

View File

@ -10,6 +10,7 @@ final class CommandTypes
public const string CREATE_IMAGE_AUX_FILE = 'create-image-aux-file'; public const string CREATE_IMAGE_AUX_FILE = 'create-image-aux-file';
public const string IMPORT_IMAGE = 'import-image'; public const string IMPORT_IMAGE = 'import-image';
public const string EXPORT_IMAGE = 'export-image'; public const string EXPORT_IMAGE = 'export-image';
public const string TRANSFER_IMAGE = 'transfer-image';
public const string POWER_ON = 'power-on'; public const string POWER_ON = 'power-on';
public const string REBOOT = 'reboot'; public const string REBOOT = 'reboot';
public const string SHUTDOWN = 'shutdown'; public const string SHUTDOWN = 'shutdown';