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\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
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;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
class DeployImageAction extends AbstractController
|
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
|
public function __invoke(DeployImageInput $input, Image $image): JsonResponse
|
||||||
{
|
{
|
||||||
/** @var Partition $partition */
|
/** @var Partition $partition */
|
||||||
|
@ -58,9 +66,17 @@ class DeployImageAction extends AbstractController
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DeployMethodTypes::MULTICAST_UFTP:
|
||||||
|
case DeployMethodTypes::MULTICAST_UDPCAST:
|
||||||
case DeployMethodTypes::MULTICAST:
|
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);
|
$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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ use App\Entity\Image;
|
||||||
use App\Entity\Partition;
|
use App\Entity\Partition;
|
||||||
use App\Entity\Trace;
|
use App\Entity\Trace;
|
||||||
use App\Model\ClientStatus;
|
use App\Model\ClientStatus;
|
||||||
|
use App\Model\DeployMethodTypes;
|
||||||
use App\Model\TraceStatus;
|
use App\Model\TraceStatus;
|
||||||
use App\Service\Trace\CreateService;
|
use App\Service\Trace\CreateService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
@ -50,6 +51,15 @@ class DeployImageAction extends AbstractController
|
||||||
/** @var Partition $partition */
|
/** @var Partition $partition */
|
||||||
$partition = $input->partition->getEntity();
|
$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 = [
|
$data = [
|
||||||
'dsk' => (string) $partition->getDiskNumber(),
|
'dsk' => (string) $partition->getDiskNumber(),
|
||||||
'par' => (string) $partition->getPartitionNumber(),
|
'par' => (string) $partition->getPartitionNumber(),
|
||||||
|
@ -58,7 +68,7 @@ class DeployImageAction extends AbstractController
|
||||||
'nci' => $image->getName(),
|
'nci' => $image->getName(),
|
||||||
'ipr' => $image->getRepository()->getIp(),
|
'ipr' => $image->getRepository()->getIp(),
|
||||||
'nfn' => 'RestaurarImagen',
|
'nfn' => 'RestaurarImagen',
|
||||||
'ptc' => $method,
|
'ptc' => $ptcValue,
|
||||||
'ids' => '0'
|
'ids' => '0'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -113,34 +113,7 @@ class ClientsController extends AbstractController
|
||||||
$this->logger->info('Image updated. Success.', ['image' => (string) $image->getUuid()]);
|
$this->logger->info('Image updated. Success.', ['image' => (string) $image->getUuid()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data['nfn'] === 'RESPUESTA_RestaurarImagen') {
|
if ($data['nfn'] === 'RESPUESTA_RestaurarImagen'|| $data['nfn'] === 'RESPUESTA_Configurar') {
|
||||||
$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') {
|
|
||||||
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
|
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
|
||||||
|
|
||||||
$client = $trace->getClient();
|
$client = $trace->getClient();
|
||||||
|
@ -158,7 +131,6 @@ class ClientsController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
$client->setStatus(ClientStatus::OG_LIVE);
|
$client->setStatus(ClientStatus::OG_LIVE);
|
||||||
|
|
||||||
$this->entityManager->persist($client);
|
$this->entityManager->persist($client);
|
||||||
$this->entityManager->persist($trace);
|
$this->entityManager->persist($trace);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
|
@ -28,6 +28,14 @@ class PostAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(Client $client, PxeTemplate $pxeTemplate): JsonResponse
|
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 = [
|
$params = [
|
||||||
'json' => [
|
'json' => [
|
||||||
'template_name' => $pxeTemplate->getName(),
|
'template_name' => $pxeTemplate->getName(),
|
||||||
|
@ -40,7 +48,7 @@ class PostAction extends AbstractOgBootController
|
||||||
'computer_name' => $client->getName(),
|
'computer_name' => $client->getName(),
|
||||||
'netiface' => $client->getNetiface(),
|
'netiface' => $client->getNetiface(),
|
||||||
'group' => $client->getOrganizationalUnit()->getName(),
|
'group' => $client->getOrganizationalUnit()->getName(),
|
||||||
'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : $client->getOrganizationalUnit()->getNetworkSettings()->getRepository()->getIp(),
|
'ogrepo' => $ogRepoIp,
|
||||||
'ogcore' => $this->ogCoreIP,
|
'ogcore' => $this->ogCoreIP,
|
||||||
'oglive' => $this->ogBootApiUrl,
|
'oglive' => $this->ogBootApiUrl,
|
||||||
'oglog' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgLog(),
|
'oglog' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgLog(),
|
||||||
|
|
|
@ -7,6 +7,8 @@ use App\Dto\Input\DeployImageInput;
|
||||||
use App\Entity\Command;
|
use App\Entity\Command;
|
||||||
use App\Entity\Image;
|
use App\Entity\Image;
|
||||||
use App\Model\CommandTypes;
|
use App\Model\CommandTypes;
|
||||||
|
use App\Model\DeployImageTypes;
|
||||||
|
use App\Model\DeployMethodTypes;
|
||||||
use App\Model\TraceStatus;
|
use App\Model\TraceStatus;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -24,12 +26,31 @@ class DeployImageAction extends AbstractOgRepositoryController
|
||||||
* @throws ServerExceptionInterface
|
* @throws ServerExceptionInterface
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __invoke(DeployImageInput $input, Image $data, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(DeployImageInput $input, Image $data, HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
$client = $input->client;
|
$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);
|
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,20 @@ class DeployImageInput
|
||||||
public ?string $mcastIp = null;
|
public ?string $mcastIp = null;
|
||||||
|
|
||||||
#[Groups(['image:write'])]
|
#[Groups(['image:write'])]
|
||||||
public ?string $mcastSpeed = null;
|
public ?int $mcastSpeed = null;
|
||||||
|
|
||||||
#[OrganizationalUnitMulticastPort]
|
#[OrganizationalUnitMulticastPort]
|
||||||
#[Groups(['image:write'])]
|
#[Groups(['image:write'])]
|
||||||
public ?string $mcastPort = null;
|
public ?int $mcastPort = null;
|
||||||
|
|
||||||
#[OrganizationalUnitMulticastMode]
|
#[OrganizationalUnitMulticastMode]
|
||||||
#[Groups(['image:write'])]
|
#[Groups(['image:write'])]
|
||||||
public ?string $mcastMode = null;
|
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 = 'multicast';
|
||||||
|
|
||||||
public const string MULTICAST_UFTP = 'multicast-uftp';
|
public const string MULTICAST_UFTP = 'uftp';
|
||||||
public const string MULTICAST_UDPCAST = 'multicast-udpcast';
|
public const string MULTICAST_UDPCAST = 'udpcast';
|
||||||
public const string UNICAST = 'unicast';
|
public const string UNICAST = 'unicast';
|
||||||
public const string TORRENT = 'p2p';
|
public const string TORRENT = 'p2p';
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ namespace App\Model;
|
||||||
|
|
||||||
final class OrganizationalUnitMulticastModes
|
final class OrganizationalUnitMulticastModes
|
||||||
{
|
{
|
||||||
public const string HALF_DUPLEX = 'half-duplex';
|
public const string HALF_DUPLEX = 'half';
|
||||||
public const string FULL_DUPLEX = 'full-duplex';
|
public const string FULL_DUPLEX = 'full';
|
||||||
|
|
||||||
private const array MCAST_MODES = [
|
private const array MCAST_MODES = [
|
||||||
self::HALF_DUPLEX => 'Half Duplex',
|
self::HALF_DUPLEX => 'Half Duplex',
|
||||||
|
|
Loading…
Reference in New Issue