refs #1087. CreateImage
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
parent
0545add493
commit
a0ae000dca
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Dto\Input\DeployImageInput;
|
||||
use App\Entity\Command;
|
||||
use App\Entity\Image;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Model\DeployMethodTypes;
|
||||
use App\Model\TraceStatus;
|
||||
use App\Service\Trace\CreateService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class DeployImageAction extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
public readonly \App\Controller\OgAgent\DeployImageAction $deployImageOgAgentAction,
|
||||
public readonly \App\Controller\OgRepository\Image\DeployImageAction $deployImageOgRepositoryAction,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function __invoke(DeployImageInput $input, Image $image): JsonResponse
|
||||
{
|
||||
$command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Restaurar Imagen']);
|
||||
|
||||
$partitionInfo = json_decode($image->getPartitionInfo(), true);
|
||||
|
||||
$inputData = [
|
||||
'method' => $input->method,
|
||||
'client' => $input->client->getEntity()->getUuid(),
|
||||
'image' => $image->getUuid(),
|
||||
'p2pMode' => $input->p2pMode,
|
||||
'p2pTime' => $input->p2pTime,
|
||||
'mcastIp' => $input->mcastIp,
|
||||
'mcastPort' => $input->mcastPort,
|
||||
'mcastSpeed' => $input->mcastSpeed,
|
||||
'mcastMode' => $input->mcastMode,
|
||||
'numDisk' => (string) $partitionInfo['numDisk'],
|
||||
'numPartition' => (string) $partitionInfo['numPartition'],
|
||||
];
|
||||
|
||||
switch ($input->method){
|
||||
case DeployMethodTypes::UNICAST:
|
||||
$data = [
|
||||
'dsk' => (string) $partitionInfo['numDisk'],
|
||||
'par' => (string) $partitionInfo['numPartition'],
|
||||
'ifs' => "1",
|
||||
'cpt' => "83",
|
||||
'idi' => $image->getUuid(),
|
||||
'nci' => $image->getName(),
|
||||
'ipr' => $image->getRepository()->getIp(),
|
||||
'nfn' => 'RestaurarImagen',
|
||||
'ptc' => DeployMethodTypes::UNICAST,
|
||||
'ids' => '0'
|
||||
];
|
||||
|
||||
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command, $input->client->getEntity());
|
||||
$this->createService->__invoke($input->client->getEntity(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
||||
|
||||
break;
|
||||
|
||||
case DeployMethodTypes::MULTICAST:
|
||||
$data = [
|
||||
'dsk' => (string) $image->getPartitionInfo()['numDisk'],
|
||||
'par' => (string) $image->getPartitionInfo()['numPartition'],
|
||||
'cpt' => "83",
|
||||
'idi' => $image->getUuid(),
|
||||
'nci' => $image->getName(),
|
||||
'ipr' => $image->getRepository()->getIp(),
|
||||
'nfn' => 'CrearImagen',
|
||||
'ids' => '0'
|
||||
];
|
||||
|
||||
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command);
|
||||
$this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,8 @@ use App\Entity\Command;
|
|||
use App\Entity\Image;
|
||||
use App\Entity\Trace;
|
||||
use App\Model\ClientStatus;
|
||||
use App\Model\TraceStatus;
|
||||
use App\Service\Trace\CreateService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
@ -21,16 +23,16 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class CreateImageActionController extends AbstractController
|
||||
class CreateImageAction extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function __invoke(Image $image): JsonResponse
|
||||
{
|
||||
if (!$image->getClient()->getIp()) {
|
||||
|
@ -51,7 +53,7 @@ class CreateImageActionController extends AbstractController
|
|||
];
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://localhost:4444/CloningEngine/CrearImagen', [
|
||||
$response = $this->httpClient->request('POST', 'https://'.$image->getClient()->getIp().':8000/CloningEngine/CrearImagen', [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
|
@ -74,17 +76,10 @@ class CreateImageActionController extends AbstractController
|
|||
$client = $image->getClient();
|
||||
$client->setStatus(ClientStatus::BUSY);
|
||||
$this->entityManager->persist($client);
|
||||
|
||||
$trace = new Trace();
|
||||
$trace->setClient($image->getClient());
|
||||
$trace->setCommand($command ?? null);
|
||||
$trace->setStatus('pending');
|
||||
$trace->setJobId($jobId);
|
||||
$trace->setExecutedAt(new \DateTime());
|
||||
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(status: Response::HTTP_OK);
|
||||
$this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $jobId, []);
|
||||
|
||||
return new JsonResponse(data: $image, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository;
|
||||
|
||||
class AbstractOgRepositoryController
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
use App\Controller\OgBoot\AbstractOgBootController;
|
||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class GetCollectionAction extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $httpClient->request('GET', $this->ogRepositoryApiUrl.'/ogrepository/v1/images', [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
class CreateAuxFilesAction
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
class DeletePermanentAction
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||
use App\Entity\Image;
|
||||
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;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class DeleteAction extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Image $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
if (!$data->getImageFullsum()) {
|
||||
throw new ValidatorException('Fullsum is required');
|
||||
}
|
||||
|
||||
$content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash');
|
||||
|
||||
$this->entityManager->remove($data);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||
use App\Dto\Input\DeployImageInput;
|
||||
use App\Entity\Command;
|
||||
use App\Entity\Image;
|
||||
use App\Model\TraceStatus;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class DeployImage extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(DeployImageInput $input, Image $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
$client = $input->client;
|
||||
|
||||
$command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Deploy Imagen']);
|
||||
$this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, null);
|
||||
|
||||
|
||||
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
class GetAction
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository;
|
||||
|
||||
use App\Entity\ImageRepository;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class StatusAction extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(ImageRepository $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $httpClient->request('GET', $data->getIp().'/ogrepository/v1/status', [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Image;
|
||||
|
||||
use App\Controller\OgBoot\AbstractOgBootController;
|
||||
use App\Controller\OgRepository\AbstractOgRepositoryController;
|
||||
use App\Entity\Image;
|
||||
use App\Entity\OgLive;
|
||||
use App\Model\OgLiveStatus;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
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;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class SyncAction extends AbstractOgRepositoryController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest($httpClient, 'GET', $this->ogRepositoryApiUrl . '/ogrepository/v1/images');
|
||||
|
||||
if (!isset($content['output']['REPOSITORY']['images'])) {
|
||||
return new JsonResponse(data: 'No images found', status: Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
foreach ($content['output']['REPOSITORY']['images'] as $image) {
|
||||
$imageEntity = $this->entityManager->getRepository(Image::class)->findOneBy(['imageFullsum' => $image['fullsum']]);
|
||||
if (!$imageEntity) {
|
||||
$imageEntity = new Image();
|
||||
$imageEntity->setName($image['name'].$image['type']);
|
||||
$imageEntity->setImageFullsum($image['fullsum']);
|
||||
$imageEntity->setRemotePc(false);
|
||||
}
|
||||
$this->entityManager->persist($imageEntity);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgRepository\Webhook;
|
||||
|
||||
class ResponseController
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
class DeployImageInput
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
class DeployImageTypes
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
class DeployMethodTypes
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
class ImageStatus
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service\OgRepository;
|
||||
|
||||
class StatusService
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service\Trace;
|
||||
|
||||
class CreateService
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue