refs #1091. DeployImage Multicast mode
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
8949dcd865
commit
6329ae9d2b
|
@ -18,6 +18,9 @@ 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;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class DeployImageAction extends AbstractController
|
||||
|
@ -32,6 +35,11 @@ class DeployImageAction extends AbstractController
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
*/
|
||||
public function __invoke(DeployImageInput $input, Image $image): JsonResponse
|
||||
{
|
||||
/** @var Partition $partition */
|
||||
|
@ -58,9 +66,17 @@ class DeployImageAction extends AbstractController
|
|||
|
||||
break;
|
||||
|
||||
case DeployMethodTypes::MULTICAST_UFTP:
|
||||
case DeployMethodTypes::MULTICAST_UDPCAST:
|
||||
case DeployMethodTypes::MULTICAST:
|
||||
try {
|
||||
$this->deployImageOgRepositoryAction->__invoke($input, $image, $this->httpClient);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse(data: ['error' => $e->getMessage()], status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::MULTICAST);
|
||||
$this->createService->__invoke($image->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
||||
$this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use App\Entity\Image;
|
|||
use App\Entity\Partition;
|
||||
use App\Entity\Trace;
|
||||
use App\Model\ClientStatus;
|
||||
use App\Model\DeployMethodTypes;
|
||||
use App\Model\TraceStatus;
|
||||
use App\Service\Trace\CreateService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
@ -50,6 +51,15 @@ class DeployImageAction extends AbstractController
|
|||
/** @var Partition $partition */
|
||||
$partition = $input->partition->getEntity();
|
||||
|
||||
$method = match ($input->method) {
|
||||
DeployMethodTypes::MULTICAST, DeployMethodTypes::MULTICAST_UFTP, DeployMethodTypes::MULTICAST_UDPCAST => 'multicast',
|
||||
DeployMethodTypes::UNICAST => 'unicast',
|
||||
DeployMethodTypes::TORRENT => 'torrent',
|
||||
default => throw new ValidatorException('Invalid method'),
|
||||
};
|
||||
|
||||
$ptcValue = "$method $input->mcastPort:$input->mcastMode:$input->mcastIp:$input->mcastSpeed:$input->maxClients:$input->maxTime";
|
||||
|
||||
$data = [
|
||||
'dsk' => (string) $partition->getDiskNumber(),
|
||||
'par' => (string) $partition->getPartitionNumber(),
|
||||
|
@ -58,7 +68,7 @@ class DeployImageAction extends AbstractController
|
|||
'nci' => $image->getName(),
|
||||
'ipr' => $image->getRepository()->getIp(),
|
||||
'nfn' => 'RestaurarImagen',
|
||||
'ptc' => $method,
|
||||
'ptc' => $ptcValue,
|
||||
'ids' => '0'
|
||||
];
|
||||
|
||||
|
|
|
@ -113,34 +113,7 @@ class ClientsController extends AbstractController
|
|||
$this->logger->info('Image updated. Success.', ['image' => (string) $image->getUuid()]);
|
||||
}
|
||||
|
||||
if ($data['nfn'] === 'RESPUESTA_RestaurarImagen') {
|
||||
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
|
||||
$image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $data['idi']]);
|
||||
|
||||
$client = $trace->getClient();
|
||||
|
||||
if ($data['res'] === 1) {
|
||||
$trace->setStatus(TraceStatus::SUCCESS);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$image->setStatus(ImageStatus::PENDING);
|
||||
$client->setStatus(ClientStatus::OG_LIVE);
|
||||
if (isset($data['cfg'])) {
|
||||
$this->createPartitionService->__invoke($data,$client);
|
||||
}
|
||||
} else {
|
||||
$trace->setStatus(TraceStatus::FAILED);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$trace->setOutput($data['der']);
|
||||
}
|
||||
|
||||
$client->setStatus(ClientStatus::OG_LIVE);
|
||||
$this->entityManager->persist($client);
|
||||
$this->entityManager->persist($image);
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
if ($data['nfn'] === 'RESPUESTA_Configurar') {
|
||||
if ($data['nfn'] === 'RESPUESTA_RestaurarImagen'|| $data['nfn'] === 'RESPUESTA_Configurar') {
|
||||
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
|
||||
|
||||
$client = $trace->getClient();
|
||||
|
@ -158,7 +131,6 @@ class ClientsController extends AbstractController
|
|||
}
|
||||
|
||||
$client->setStatus(ClientStatus::OG_LIVE);
|
||||
|
||||
$this->entityManager->persist($client);
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -28,6 +28,14 @@ class PostAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(Client $client, PxeTemplate $pxeTemplate): JsonResponse
|
||||
{
|
||||
$ogRepoIp = $this->ogBootApiUrl;
|
||||
|
||||
if ($client->getRepository()) {
|
||||
$ogRepoIp = $client->getRepository()->getIp();
|
||||
} else if ($client->getOrganizationalUnit()->getNetworkSettings()->getRepository()) {
|
||||
$ogRepoIp = $client->getOrganizationalUnit()->getNetworkSettings()->getRepository()->getIp();
|
||||
}
|
||||
|
||||
$params = [
|
||||
'json' => [
|
||||
'template_name' => $pxeTemplate->getName(),
|
||||
|
@ -40,7 +48,7 @@ class PostAction extends AbstractOgBootController
|
|||
'computer_name' => $client->getName(),
|
||||
'netiface' => $client->getNetiface(),
|
||||
'group' => $client->getOrganizationalUnit()->getName(),
|
||||
'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : $client->getOrganizationalUnit()->getNetworkSettings()->getRepository()->getIp(),
|
||||
'ogrepo' => $ogRepoIp,
|
||||
'ogcore' => $this->ogCoreIP,
|
||||
'oglive' => $this->ogBootApiUrl,
|
||||
'oglog' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgLog(),
|
||||
|
|
|
@ -7,6 +7,8 @@ use App\Dto\Input\DeployImageInput;
|
|||
use App\Entity\Command;
|
||||
use App\Entity\Image;
|
||||
use App\Model\CommandTypes;
|
||||
use App\Model\DeployImageTypes;
|
||||
use App\Model\DeployMethodTypes;
|
||||
use App\Model\TraceStatus;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -24,12 +26,31 @@ class DeployImageAction extends AbstractOgRepositoryController
|
|||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function __invoke(DeployImageInput $input, Image $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
$client = $input->client;
|
||||
|
||||
$this->createService->__invoke($data->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, null);
|
||||
$params = [
|
||||
'json' => [
|
||||
'ID_img' => $data->getImageFullsum(),
|
||||
'bitrate' => (string) $input->mcastSpeed.'M',
|
||||
'ip' => $input->mcastIp,
|
||||
'port' => $input->mcastPort,
|
||||
'method' => 'full',
|
||||
'nclients' => 20,
|
||||
'maxtime' => 120
|
||||
]
|
||||
];
|
||||
|
||||
$type = match ($input->method) {
|
||||
'udpcast' => DeployMethodTypes::MULTICAST_UDPCAST,
|
||||
'p2p' => DeployMethodTypes::TORRENT,
|
||||
default => DeployMethodTypes::MULTICAST_UFTP,
|
||||
};
|
||||
|
||||
$content = $this->createRequest('POST', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/'.$type, $params);
|
||||
|
||||
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -40,14 +40,20 @@ class DeployImageInput
|
|||
public ?string $mcastIp = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
public ?string $mcastSpeed = null;
|
||||
public ?int $mcastSpeed = null;
|
||||
|
||||
#[OrganizationalUnitMulticastPort]
|
||||
#[Groups(['image:write'])]
|
||||
public ?string $mcastPort = null;
|
||||
public ?int $mcastPort = null;
|
||||
|
||||
#[OrganizationalUnitMulticastMode]
|
||||
#[Groups(['image:write'])]
|
||||
public ?string $mcastMode = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
public ?int $maxClients = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
public ?int $maxTime = null;
|
||||
|
||||
}
|
|
@ -6,8 +6,8 @@ final class DeployMethodTypes
|
|||
{
|
||||
public const string MULTICAST = 'multicast';
|
||||
|
||||
public const string MULTICAST_UFTP = 'multicast-uftp';
|
||||
public const string MULTICAST_UDPCAST = 'multicast-udpcast';
|
||||
public const string MULTICAST_UFTP = 'uftp';
|
||||
public const string MULTICAST_UDPCAST = 'udpcast';
|
||||
public const string UNICAST = 'unicast';
|
||||
public const string TORRENT = 'p2p';
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ namespace App\Model;
|
|||
|
||||
final class OrganizationalUnitMulticastModes
|
||||
{
|
||||
public const string HALF_DUPLEX = 'half-duplex';
|
||||
public const string FULL_DUPLEX = 'full-duplex';
|
||||
public const string HALF_DUPLEX = 'half';
|
||||
public const string FULL_DUPLEX = 'full';
|
||||
|
||||
private const array MCAST_MODES = [
|
||||
self::HALF_DUPLEX => 'Half Duplex',
|
||||
|
|
Loading…
Reference in New Issue