refs #2754. Deploy bug fixed
parent
5debf35b0d
commit
8cad4fef09
|
@ -6,6 +6,7 @@ namespace App\Controller;
|
|||
|
||||
use ApiPlatform\Validator\ValidatorInterface;
|
||||
use App\Dto\Input\DeployImageInput;
|
||||
use App\Entity\Trace;
|
||||
use App\Model\ImageStatus;
|
||||
use App\Entity\ImageImageRepository;
|
||||
use App\Model\CommandTypes;
|
||||
|
@ -16,7 +17,6 @@ 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\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
|
@ -40,7 +40,7 @@ class DeployImageAction extends AbstractController
|
|||
* @throws ClientExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
*/
|
||||
public function __invoke(DeployImageInput $input, ImageImageRepository $image): JsonResponse
|
||||
public function __invoke(DeployImageInput $input, ImageImageRepository $image, ?Trace $trace = null): JsonResponse
|
||||
{
|
||||
if ($image->getStatus() !== ImageStatus::SUCCESS) {
|
||||
throw new BadRequestHttpException('Image is not ready to be deployed');
|
||||
|
@ -51,42 +51,42 @@ class DeployImageAction extends AbstractController
|
|||
$clientJobs = [];
|
||||
|
||||
if ($input->type === 'monolithic') {
|
||||
$clientJobs = $this->handleMonolithicDeployment($input, $image);
|
||||
$clientJobs = $this->handleMonolithicDeployment($input, $image, $trace);
|
||||
}
|
||||
|
||||
return new JsonResponse(data: $clientJobs, status: Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function handleMonolithicDeployment(DeployImageInput $input, ImageImageRepository $image): array
|
||||
private function handleMonolithicDeployment(DeployImageInput $input, ImageImageRepository $image, ?Trace $trace = null): array
|
||||
{
|
||||
$clientJobs = [];
|
||||
|
||||
switch ($input->method) {
|
||||
case DeployMethodTypes::UNICAST:
|
||||
case DeployMethodTypes::UNICAST_DIRECT:
|
||||
$clientJobs = $this->handleUnicastDeployment($input, $image);
|
||||
$clientJobs = $this->handleUnicastDeployment($input, $image, $trace);
|
||||
break;
|
||||
case DeployMethodTypes::MULTICAST_UFTP:
|
||||
case DeployMethodTypes::MULTICAST_UFTP_DIRECT:
|
||||
case DeployMethodTypes::MULTICAST_UDPCAST:
|
||||
case DeployMethodTypes::MULTICAST_UDPCAST_DIRECT:
|
||||
$clientJobs = $this->handleMulticastDeployment($input, $image);
|
||||
$clientJobs = $this->handleMulticastDeployment($input, $image, $trace);
|
||||
break;
|
||||
case DeployMethodTypes::TORRENT:
|
||||
$clientJobs = $this->handleTorrentDeployment($input, $image);
|
||||
$clientJobs = $this->handleTorrentDeployment($input, $image, $trace);
|
||||
break;
|
||||
}
|
||||
|
||||
return $clientJobs;
|
||||
}
|
||||
|
||||
private function handleUnicastDeployment(DeployImageInput $input, ImageImageRepository $image): array
|
||||
private function handleUnicastDeployment(DeployImageInput $input, ImageImageRepository $image, ?Trace $trace = null): array
|
||||
{
|
||||
$clientJobs = [];
|
||||
|
||||
foreach ($input->clients as $client) {
|
||||
$inputData = $this->createInputData($input, $image, $client->getEntity());
|
||||
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::UNICAST);
|
||||
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::UNICAST, $trace);
|
||||
|
||||
if ($jobId) {
|
||||
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
||||
|
@ -96,7 +96,7 @@ class DeployImageAction extends AbstractController
|
|||
return $clientJobs;
|
||||
}
|
||||
|
||||
private function handleMulticastDeployment(DeployImageInput $input, ImageImageRepository $image): array
|
||||
private function handleMulticastDeployment(DeployImageInput $input, ImageImageRepository $image, ?Trace $trace = null): array
|
||||
{
|
||||
$clientJobs = [];
|
||||
|
||||
|
@ -109,7 +109,7 @@ class DeployImageAction extends AbstractController
|
|||
continue;
|
||||
}
|
||||
|
||||
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::MULTICAST);
|
||||
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::MULTICAST, $trace);
|
||||
|
||||
if ($jobId) {
|
||||
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
||||
|
@ -119,7 +119,7 @@ class DeployImageAction extends AbstractController
|
|||
return $clientJobs;
|
||||
}
|
||||
|
||||
private function handleTorrentDeployment(DeployImageInput $input, ImageImageRepository $image): array
|
||||
private function handleTorrentDeployment(DeployImageInput $input, ImageImageRepository $image, ?Trace $trace = null): array
|
||||
{
|
||||
$clientJobs = [];
|
||||
|
||||
|
@ -137,7 +137,7 @@ class DeployImageAction extends AbstractController
|
|||
throw $e;
|
||||
}
|
||||
|
||||
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::TORRENT);
|
||||
$jobId = $this->processDeployment($client->getEntity(), $input, $image, $inputData, DeployMethodTypes::TORRENT, $trace);
|
||||
|
||||
if ($jobId) {
|
||||
$clientJobs[(string) '/clients/' . $client->getEntity()->getUuid()] = $jobId;
|
||||
|
@ -147,18 +147,34 @@ class DeployImageAction extends AbstractController
|
|||
return $clientJobs;
|
||||
}
|
||||
|
||||
private function processDeployment($client, DeployImageInput $input, ImageImageRepository $image, array $inputData, string $deployType): ?string
|
||||
private function processDeployment($client, DeployImageInput $input, ImageImageRepository $image, array $inputData, string $deployType, ?Trace $trace = null): ?string
|
||||
{
|
||||
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, $client, $deployType);
|
||||
|
||||
if (!$agentJobId) {
|
||||
if ($input->queue) {
|
||||
$this->createService->__invoke($client, CommandTypes::DEPLOY_IMAGE, TraceStatus::PENDING, null, $inputData);
|
||||
if ($trace) {
|
||||
$trace->setStatus(TraceStatus::PENDING);
|
||||
$trace->setJobId(null);
|
||||
$trace->setInput($inputData);
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
} else {
|
||||
$this->createService->__invoke($client, CommandTypes::DEPLOY_IMAGE, TraceStatus::PENDING, null, $inputData);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->createService->__invoke($client, CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
||||
if ($trace) {
|
||||
$trace->setStatus(TraceStatus::IN_PROGRESS);
|
||||
$trace->setJobId($agentJobId);
|
||||
$trace->setInput($inputData);
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
} else {
|
||||
$this->createService->__invoke($client, CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
||||
}
|
||||
|
||||
return $agentJobId;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue