Updated repo webhook
testing/ogcore-api/pipeline/head This commit looks good Details
testing/ogcore-api/pipeline/pr-main There was a failure building this commit Details

pull/20/head
Manuel Aranda Rosales 2025-02-03 21:47:41 +01:00
parent f22fde5ecd
commit e0dfcd0f63
3 changed files with 32 additions and 80 deletions

View File

@ -59,8 +59,6 @@ class ExportAction extends AbstractOgRepositoryController
$this->createService->__invoke($image->getClient(), CommandTypes::EXPORT_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
$this->logger->info('Image exported successfully', ['image' => $image->getName()]);
$image->setStatus(ImageStatus::TRANSFERING);
$this->entityManager->persist($image);
$this->entityManager->flush();

View File

@ -59,8 +59,6 @@ class ImportAction extends AbstractOgRepositoryController
$this->createService->__invoke($image->getClient(), CommandTypes::IMPORT_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
$this->logger->info('Image imported successfully', ['image' => $image->getName()]);
$image->setStatus(ImageStatus::TRANSFERING);
$this->entityManager->persist($image);
$this->entityManager->flush();

View File

@ -6,6 +6,7 @@ use App\Controller\OgRepository\AbstractOgRepositoryController;
use App\Entity\Image;
use App\Entity\ImageRepository;
use App\Entity\Trace;
use App\Model\CommandTypes;
use App\Model\ImageStatus;
use App\Model\TraceStatus;
use Doctrine\ORM\EntityManagerInterface;
@ -42,11 +43,11 @@ class ResponseController extends AbstractOgRepositoryController
$action = $data['job_id'];
if (str_starts_with($action, "CreateAuxiliarFiles_")) {
$this->handleCreateAuxFiles($action, $data);
$this->handleCreateAuxFiles($data);
} elseif (str_starts_with($action, "ExportImage_")) {
$this->handleExportImage($action, $data);
$this->processImageAction($data, 'export');
} elseif (str_starts_with($action, "ImportImage_")) {
$this->handleImportImage($action, $data);
$this->processImageAction($data, 'import');
} else {
return new JsonResponse(['message' => 'Invalid action'], Response::HTTP_BAD_REQUEST);
}
@ -54,7 +55,7 @@ class ResponseController extends AbstractOgRepositoryController
return new JsonResponse($data, Response::HTTP_OK);
}
private function handleCreateAuxFiles(string $action, array $data): void
private function handleCreateAuxFiles(array $data): void
{
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
$imageUuid = $trace->getInput()['imageUuid'];
@ -62,13 +63,7 @@ class ResponseController extends AbstractOgRepositoryController
$image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $imageUuid]);
if ($image === null) {
$trace->setStatus(TraceStatus::FAILED);
$trace->setFinishedAt(new \DateTime());
$trace->setOutput('Image not found');
$this->entityManager->persist($trace);
$this->entityManager->flush();
new JsonResponse(['message' => 'Image not found'], Response::HTTP_NOT_FOUND);
$this->updateTraceStatus($trace, TraceStatus::FAILED, 'Image not found');
return;
}
@ -76,41 +71,31 @@ class ResponseController extends AbstractOgRepositoryController
$image->setStatus(ImageStatus::SUCCESS);
$this->entityManager->persist($image);
$trace->setStatus(TraceStatus::SUCCESS);
$trace->setFinishedAt(new \DateTime());
$this->entityManager->persist($trace);
$this->entityManager->flush();
$this->updateTraceStatus($trace, TraceStatus::SUCCESS);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
private function handleExportImage(string $action, array $data): void
private function processImageAction(array $data, string $actionType): void
{
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
$imageUuid = $trace->getInput()['imageUuid'];
$image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $imageUuid]);
$repositoryUuid = $trace->getInput()['repositoryUuid'];
$image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $imageUuid]);
$repository = $this->entityManager->getRepository(ImageRepository::class)->findOneBy(['uuid' => $repositoryUuid]);
if ($image === null) {
$trace->setStatus(TraceStatus::FAILED);
$trace->setFinishedAt(new \DateTime());
$trace->setOutput('Image not found');
$this->entityManager->persist($trace);
$this->entityManager->flush();
new JsonResponse(['message' => 'Image not found'], Response::HTTP_NOT_FOUND);
$this->updateTraceStatus($trace, TraceStatus::FAILED, 'Image not found');
return;
}
$this->logger->info('Image exported', ['image' => $image->getName()]);
$this->logger->info("Image $actionType", ['image' => $image->getName()]);
$params = [
'json' => [
@ -121,63 +106,34 @@ class ResponseController extends AbstractOgRepositoryController
$this->logger->info('Creating aux files', ['image' => $image->getName()]);
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params);
$image->setRepository($repository);
$image->setStatus(ImageStatus::SUCCESS);
$this->entityManager->persist($image);
$trace->setStatus(TraceStatus::SUCCESS);
$trace->setFinishedAt(new \DateTime());
$this->entityManager->persist($trace);
$this->entityManager->flush();
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
private function handleImportImage(string $action, array $data): void
{
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
$imageUuid = $trace->getInput()['imageUuid'];
$image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $imageUuid]);
$repositoryUuid = $trace->getInput()['repositoryUuid'];
$repository = $this->entityManager->getRepository(ImageRepository::class)->findOneBy(['uuid' => $repositoryUuid]);
if ($image === null) {
$trace->setStatus(TraceStatus::FAILED);
$trace->setFinishedAt(new \DateTime());
$trace->setOutput('Image not found');
$this->entityManager->persist($trace);
$this->entityManager->flush();
new JsonResponse(['message' => 'Image not found'], Response::HTTP_NOT_FOUND);
return;
}
$this->logger->info('Image imported', ['image' => $image->getName()]);
$params = [
'json' => [
'image' => $image->getName().'.img'
]
$inputData = [
'imageName' => $image->getName(),
'imageUuid' => $image->getUuid(),
];
$this->logger->info('Creating aux files', ['image' => $image->getName()]);
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params);
$this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
$image->setRepository($repository);
$image->setStatus(ImageStatus::SUCCESS);
$this->entityManager->persist($image);
$trace->setStatus(TraceStatus::SUCCESS);
$this->updateTraceStatus($trace, TraceStatus::SUCCESS);
}
private function updateTraceStatus(Trace $trace, string $status, string $output = null): void
{
$trace->setStatus($status);
$trace->setFinishedAt(new \DateTime());
if ($output !== null) {
$trace->setOutput($output);
}
$this->entityManager->persist($trace);
$this->entityManager->flush();
if ($status === TraceStatus::FAILED) {
new JsonResponse(['message' => $output], Response::HTTP_NOT_FOUND);
}
}
}
}