|
|
|
@ -6,6 +6,7 @@ namespace App\Controller;
|
|
|
|
|
|
|
|
|
|
use ApiPlatform\Validator\ValidatorInterface;
|
|
|
|
|
use App\Dto\Input\DeployImageInput;
|
|
|
|
|
use App\Dto\Output\ClientOutput;
|
|
|
|
|
use App\Entity\Trace;
|
|
|
|
|
use App\Model\ImageStatus;
|
|
|
|
|
use App\Entity\ImageImageRepository;
|
|
|
|
@ -13,7 +14,9 @@ use App\Model\CommandTypes;
|
|
|
|
|
use App\Model\DeployMethodTypes;
|
|
|
|
|
use App\Model\TraceStatus;
|
|
|
|
|
use App\Service\Trace\CreateService;
|
|
|
|
|
use App\Repository\ClientRepository;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
@ -30,6 +33,8 @@ class DeployImageAction extends AbstractController
|
|
|
|
|
protected readonly HttpClientInterface $httpClient,
|
|
|
|
|
protected readonly CreateService $createService,
|
|
|
|
|
protected readonly ValidatorInterface $validator,
|
|
|
|
|
protected readonly ClientRepository $clientRepository,
|
|
|
|
|
protected readonly LoggerInterface $logger,
|
|
|
|
|
public readonly \App\Controller\OgAgent\DeployImageAction $deployImageOgAgentAction,
|
|
|
|
|
public readonly \App\Controller\OgRepository\Image\DeployImageAction $deployImageOgRepositoryAction,
|
|
|
|
|
) {
|
|
|
|
@ -47,7 +52,6 @@ class DeployImageAction extends AbstractController
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->validator->validate($input);
|
|
|
|
|
|
|
|
|
|
$clientJobs = [];
|
|
|
|
|
|
|
|
|
|
if ($input->type === 'monolithic') {
|
|
|
|
@ -57,6 +61,7 @@ class DeployImageAction extends AbstractController
|
|
|
|
|
return new JsonResponse(data: $clientJobs, status: Response::HTTP_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function handleMonolithicDeployment(DeployImageInput $input, ImageImageRepository $image, ?Trace $trace = null): array
|
|
|
|
|
{
|
|
|
|
|
$clientJobs = [];
|
|
|
|
@ -85,11 +90,25 @@ class DeployImageAction extends AbstractController
|
|
|
|
|
$clientJobs = [];
|
|
|
|
|
|
|
|
|
|
foreach ($input->clients as $client) {
|
|
|
|
|
$inputData = $this->createInputData($input, $image, $client->getEntity());
|
|
|
|
|
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::UNICAST, $trace);
|
|
|
|
|
|
|
|
|
|
if ($jobId) {
|
|
|
|
|
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
|
|
|
|
try {
|
|
|
|
|
$inputData = $this->createInputData($input, $image, $client->getEntity());
|
|
|
|
|
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::UNICAST, $trace);
|
|
|
|
|
|
|
|
|
|
if ($jobId) {
|
|
|
|
|
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->logger->warning('Error deploying to client (unicast)', [
|
|
|
|
|
'client_uuid' => $client->getEntity()->getUuid(),
|
|
|
|
|
'error' => $e->getMessage()
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($input->queue) {
|
|
|
|
|
$inputData = $this->createInputData($input, $image, $client->getEntity());
|
|
|
|
|
$this->createService->__invoke($client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::PENDING, null, $inputData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -101,18 +120,41 @@ class DeployImageAction extends AbstractController
|
|
|
|
|
$clientJobs = [];
|
|
|
|
|
|
|
|
|
|
foreach ($input->clients as $client) {
|
|
|
|
|
$inputData = $this->createMulticastInputData($input, $image, $client->getEntity());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->deployImageOgRepositoryAction->__invoke($input, $image, $client->getEntity());
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$inputData = $this->createMulticastInputData($input, $image, $client->getEntity());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->deployImageOgRepositoryAction->__invoke($input, $image, $client->getEntity());
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->logger->warning('Error with OgRepository for client (multicast)', [
|
|
|
|
|
'client_uuid' => $client->getEntity()->getUuid(),
|
|
|
|
|
'error' => $e->getMessage()
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($input->queue) {
|
|
|
|
|
$this->createService->__invoke($client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::PENDING, null, $inputData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::MULTICAST, $trace);
|
|
|
|
|
|
|
|
|
|
if ($jobId) {
|
|
|
|
|
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
|
|
|
|
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::MULTICAST, $trace);
|
|
|
|
|
|
|
|
|
|
if ($jobId) {
|
|
|
|
|
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->logger->warning('Error deploying to client (multicast)', [
|
|
|
|
|
'client_uuid' => $client->getEntity()->getUuid(),
|
|
|
|
|
'error' => $e->getMessage()
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($input->queue) {
|
|
|
|
|
$inputData = $this->createMulticastInputData($input, $image, $client->getEntity());
|
|
|
|
|
$this->createService->__invoke($client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::PENDING, null, $inputData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -124,23 +166,45 @@ class DeployImageAction extends AbstractController
|
|
|
|
|
$clientJobs = [];
|
|
|
|
|
|
|
|
|
|
foreach ($input->clients as $client) {
|
|
|
|
|
$inputData = $this->createTorrentInputData($input, $image, $client->getEntity());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->deployImageOgRepositoryAction->__invoke($input, $image, $client->getEntity(), $this->httpClient);
|
|
|
|
|
$inputData = $this->createTorrentInputData($input, $image, $client->getEntity());
|
|
|
|
|
|
|
|
|
|
if (is_array($response) && isset($response['code']) && $response['code'] === 500) {
|
|
|
|
|
throw new \Exception('Error del servidor OgRepository: ' . ($response['error'] ?? 'Error desconocido') . ' - ' . ($response['details'] ?? ''));
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->deployImageOgRepositoryAction->__invoke($input, $image, $client->getEntity(), $this->httpClient);
|
|
|
|
|
|
|
|
|
|
if (is_array($response) && isset($response['code']) && $response['code'] === 500) {
|
|
|
|
|
throw new \Exception('Error del servidor OgRepository: ' . ($response['error'] ?? 'Error desconocido') . ' - ' . ($response['details'] ?? ''));
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->logger->warning('Error with OgRepository for client (torrent)', [
|
|
|
|
|
'client_uuid' => $client->getEntity()->getUuid(),
|
|
|
|
|
'error' => $e->getMessage()
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($input->queue) {
|
|
|
|
|
$this->createService->__invoke($client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::PENDING, null, $inputData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::TORRENT, $trace);
|
|
|
|
|
|
|
|
|
|
if ($jobId) {
|
|
|
|
|
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->logger->warning('Error deploying to client (torrent)', [
|
|
|
|
|
'client_uuid' => $client->getEntity()->getUuid(),
|
|
|
|
|
'error' => $e->getMessage()
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($input->queue) {
|
|
|
|
|
$inputData = $this->createTorrentInputData($input, $image, $client->getEntity());
|
|
|
|
|
$this->createService->__invoke($client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::PENDING, null, $inputData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::TORRENT, $trace);
|
|
|
|
|
|
|
|
|
|
if ($jobId) {
|
|
|
|
|
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|