71 lines
2.6 KiB
PHP
71 lines
2.6 KiB
PHP
<?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\Entity\Partition;
|
|
use App\Model\CommandTypes;
|
|
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
|
|
{
|
|
/** @var Partition $partition */
|
|
$partition = $input->partition->getEntity();
|
|
|
|
$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) $partition->getDiskNumber(),
|
|
'numPartition' => (string) $partition->getPartitionNumber(),
|
|
];
|
|
|
|
switch ($input->method){
|
|
case DeployMethodTypes::UNICAST:
|
|
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::UNICAST);
|
|
$this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
|
|
|
break;
|
|
|
|
case DeployMethodTypes::MULTICAST:
|
|
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::MULTICAST);
|
|
$this->createService->__invoke($image->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
|
|
|
break;
|
|
}
|
|
|
|
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
|
}
|
|
}
|