refs #1603. OGrepo backupImage integration
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
d2961b4439
commit
3ebe5cb1bc
|
@ -48,6 +48,14 @@ resources:
|
||||||
uriTemplate: /image-image-repositories/{uuid}/deploy-image
|
uriTemplate: /image-image-repositories/{uuid}/deploy-image
|
||||||
controller: App\Controller\DeployImageAction
|
controller: App\Controller\DeployImageAction
|
||||||
|
|
||||||
|
backup_image_ogrepository:
|
||||||
|
shortName: OgRepository Server
|
||||||
|
class: ApiPlatform\Metadata\Post
|
||||||
|
method: POST
|
||||||
|
input: App\Dto\Input\BackupImageInput
|
||||||
|
uriTemplate: /image-image-repositories/{uuid}/backup-image
|
||||||
|
controller: App\Controller\OgRepository\Image\BackupImageAction
|
||||||
|
|
||||||
trash_delete_image_ogrepository:
|
trash_delete_image_ogrepository:
|
||||||
shortName: OgRepository Server
|
shortName: OgRepository Server
|
||||||
description: Delete Image in OgRepository
|
description: Delete Image in OgRepository
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\OgRepository\Image;
|
||||||
|
|
||||||
|
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||||
|
use App\Dto\Input\BackupImageInput;
|
||||||
|
use App\Dto\Input\DeleteImageInput;
|
||||||
|
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\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 BackupImageAction extends AbstractOgRepositoryController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
* @throws ServerExceptionInterface
|
||||||
|
* @throws RedirectionExceptionInterface
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
*/
|
||||||
|
public function __invoke(BackupImageInput $input, ImageImageRepository $imageImageRepository): JsonResponse
|
||||||
|
{
|
||||||
|
$image = $imageImageRepository->getImage();
|
||||||
|
|
||||||
|
if (!$image->getName()) {
|
||||||
|
throw new ValidatorException('Name is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'json' => [
|
||||||
|
'ID_img' => $imageImageRepository->getImageFullsum(),
|
||||||
|
'repo_ip' => $input->repoIp,
|
||||||
|
'remote_path' => $input->remotePath,
|
||||||
|
'user' => 'opengnsys'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->logger->info('Create backup image', ['image' => $image->getName()]);
|
||||||
|
|
||||||
|
$repository = $imageImageRepository->getRepository();
|
||||||
|
|
||||||
|
$content = $this->createRequest('PUT', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params);
|
||||||
|
|
||||||
|
$inputData = [
|
||||||
|
'imageName' => $image->getName(),
|
||||||
|
'imageUuid' => $imageImageRepository->getUuid(),
|
||||||
|
'ID_img' => $imageImageRepository->getImageFullsum(),
|
||||||
|
'repo_ip' => $imageImageRepository->getRepository()->getIp(),
|
||||||
|
'remote_path' => '/var/lib/ogrepository/images',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->createService->__invoke($image->getClient(), CommandTypes::BACKUP_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
||||||
|
|
||||||
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,8 +56,6 @@ class CreateAuxFilesAction extends AbstractOgRepositoryController
|
||||||
|
|
||||||
$this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
$this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
|
||||||
|
|
||||||
$this->logger->info('Aux files created successfully', ['image' => $image->getName()]);
|
|
||||||
|
|
||||||
$data->setStatus(ImageStatus::AUX_FILES_PENDING);
|
$data->setStatus(ImageStatus::AUX_FILES_PENDING);
|
||||||
$this->entityManager->persist($data);
|
$this->entityManager->persist($data);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
|
@ -49,6 +49,8 @@ class ResponseController extends AbstractOgRepositoryController
|
||||||
$this->processImageAction($data, 'transfer');
|
$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, "BackupImage_")) {
|
||||||
|
$this->processImageAction($data, 'backup');
|
||||||
} else {
|
} else {
|
||||||
return new JsonResponse(['message' => 'Invalid action'], Response::HTTP_BAD_REQUEST);
|
return new JsonResponse(['message' => 'Invalid action'], Response::HTTP_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +86,8 @@ class ResponseController extends AbstractOgRepositoryController
|
||||||
*/
|
*/
|
||||||
private function processImageAction(array $data, string $actionType): void
|
private function processImageAction(array $data, string $actionType): void
|
||||||
{
|
{
|
||||||
|
$imageImageRepository = null;
|
||||||
|
|
||||||
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
|
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
|
||||||
$imageUuid = $trace->getInput()['imageUuid'];
|
$imageUuid = $trace->getInput()['imageUuid'];
|
||||||
$repositoryUuid = $trace->getInput()['repositoryUuid'];
|
$repositoryUuid = $trace->getInput()['repositoryUuid'];
|
||||||
|
@ -118,13 +122,15 @@ class ResponseController extends AbstractOgRepositoryController
|
||||||
|
|
||||||
$this->logger->info("Image $actionType successful", ['image' => $image->getName()]);
|
$this->logger->info("Image $actionType successful", ['image' => $image->getName()]);
|
||||||
|
|
||||||
// Creamos un objeto imagen nuevo, en el repositorio destino
|
|
||||||
$newImageImageRepository = new ImageImageRepository();
|
$newImageImageRepository = new ImageImageRepository();
|
||||||
$newImageImageRepository->setImage($image);
|
$newImageImageRepository->setImage($image);
|
||||||
$newImageImageRepository->setRepository($repository);
|
$newImageImageRepository->setRepository($repository);
|
||||||
$newImageImageRepository->setStatus(ImageStatus::SUCCESS);
|
$newImageImageRepository->setStatus(ImageStatus::SUCCESS);
|
||||||
|
|
||||||
// Cambiamos el estado de la imagen anterior a SUCCESS
|
if ($imageImageRepository){
|
||||||
|
$newImageImageRepository->setImageFullsum($imageImageRepository->getImageFullsum());
|
||||||
|
}
|
||||||
|
|
||||||
$this->entityManager->persist($newImageImageRepository);
|
$this->entityManager->persist($newImageImageRepository);
|
||||||
$this->entityManager->persist($image);
|
$this->entityManager->persist($image);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Dto\Input;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiProperty;
|
||||||
|
use App\Dto\Output\ClientOutput;
|
||||||
|
use App\Dto\Output\ImageOutput;
|
||||||
|
use App\Dto\Output\PartitionOutput;
|
||||||
|
use App\Validator\Constraints\ClientsHaveSamePartitionCount;
|
||||||
|
use App\Validator\Constraints\OrganizationalUnitMulticastMode;
|
||||||
|
use App\Validator\Constraints\OrganizationalUnitMulticastPort;
|
||||||
|
use App\Validator\Constraints\OrganizationalUnitP2PMode;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
|
||||||
|
final class BackupImageInput
|
||||||
|
{
|
||||||
|
#[Groups(['image-image-repository:write'])]
|
||||||
|
#[ApiProperty(description: 'The repository ip', example: "")]
|
||||||
|
public ?string $repoIp = null;
|
||||||
|
|
||||||
|
#[Groups(['image-image-repository:write'])]
|
||||||
|
#[ApiProperty(description: 'The remote path', example: "")]
|
||||||
|
public ?string $remotePath = null;
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ final class CommandTypes
|
||||||
public const string RESTORE_IMAGE = 'restore-image';
|
public const string RESTORE_IMAGE = 'restore-image';
|
||||||
public const string CREATE_IMAGE = 'create-image';
|
public const string CREATE_IMAGE = 'create-image';
|
||||||
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 BACKUP_IMAGE = 'backup-image';
|
||||||
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 TRANSFER_IMAGE = 'transfer-image';
|
||||||
|
@ -25,6 +26,7 @@ final class CommandTypes
|
||||||
self::RESTORE_IMAGE => 'Update Cache',
|
self::RESTORE_IMAGE => 'Update Cache',
|
||||||
self::CREATE_IMAGE => 'Create Image',
|
self::CREATE_IMAGE => 'Create Image',
|
||||||
self::CREATE_IMAGE_AUX_FILE => 'Crear fichero auxiliar en repositorio',
|
self::CREATE_IMAGE_AUX_FILE => 'Crear fichero auxiliar en repositorio',
|
||||||
|
self::BACKUP_IMAGE => 'Crear backup de imagen',
|
||||||
self::IMPORT_IMAGE => 'Importar imagen',
|
self::IMPORT_IMAGE => 'Importar imagen',
|
||||||
self::EXPORT_IMAGE => 'Exportar imagen',
|
self::EXPORT_IMAGE => 'Exportar imagen',
|
||||||
self::POWER_ON => 'Encender',
|
self::POWER_ON => 'Encender',
|
||||||
|
|
Loading…
Reference in New Issue