refs #1088. Deploy Image. Improvements
testing/ogcore-api/pipeline/head This commit looks good Details

pull/18/head
Manuel Aranda Rosales 2025-01-07 18:02:51 +01:00
parent 59ce82ef43
commit 40c34a0112
8 changed files with 66 additions and 24 deletions

View File

@ -45,22 +45,17 @@ class DeployImageAction extends AbstractController
/** @var Partition $partition */ /** @var Partition $partition */
$partition = $input->partition->getEntity(); $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){ switch ($input->method){
case DeployMethodTypes::UNICAST: case DeployMethodTypes::UNICAST:
case DeployMethodTypes::UNICAST_DIRECT:
$inputData = [
'method' => $input->method,
'client' => $input->client->getEntity()->getUuid(),
'image' => $image->getUuid(),
'numDisk' => (string) $partition->getDiskNumber(),
'numPartition' => (string) $partition->getPartitionNumber(),
];
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::UNICAST); $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::UNICAST);
$this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); $this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
@ -69,6 +64,21 @@ class DeployImageAction extends AbstractController
case DeployMethodTypes::MULTICAST_UFTP: case DeployMethodTypes::MULTICAST_UFTP:
case DeployMethodTypes::MULTICAST_UDPCAST: case DeployMethodTypes::MULTICAST_UDPCAST:
case DeployMethodTypes::MULTICAST: case DeployMethodTypes::MULTICAST:
case DeployMethodTypes::MULTICAST_UFTP_DIRECT:
case DeployMethodTypes::MULTICAST_UDPCAST_DIRECT:
$inputData = [
'method' => $input->method,
'client' => $input->client->getEntity()->getUuid(),
'image' => $image->getUuid(),
'mcastIp' => $input->mcastIp,
'mcastPort' => $input->mcastPort,
'mcastSpeed' => $input->mcastSpeed,
'mcastMode' => $input->mcastMode,
'numDisk' => (string) $partition->getDiskNumber(),
'numPartition' => (string) $partition->getPartitionNumber(),
];
try { try {
$this->deployImageOgRepositoryAction->__invoke($input, $image, $this->httpClient); $this->deployImageOgRepositoryAction->__invoke($input, $image, $this->httpClient);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -78,6 +88,22 @@ class DeployImageAction extends AbstractController
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::MULTICAST); $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::MULTICAST);
$this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); $this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
break;
case DeployMethodTypes::TORRENT:
$inputData = [
'method' => $input->method,
'client' => $input->client->getEntity()->getUuid(),
'image' => $image->getUuid(),
'p2pMode' => $input->p2pMode,
'p2pTime' => $input->p2pTime,
'numDisk' => (string) $partition->getDiskNumber(),
'numPartition' => (string) $partition->getPartitionNumber(),
];
$agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::TORRENT);
$this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
break; break;
} }

View File

@ -36,7 +36,6 @@ class DeployImageAction extends AbstractController
{ {
} }
public function __invoke(Image $image, DeployImageInput $input, string $method) public function __invoke(Image $image, DeployImageInput $input, string $method)
{ {
if (!$image->getClient()->getIp()) { if (!$image->getClient()->getIp()) {
@ -52,13 +51,24 @@ class DeployImageAction extends AbstractController
$partition = $input->partition->getEntity(); $partition = $input->partition->getEntity();
$method = match ($input->method) { $method = match ($input->method) {
DeployMethodTypes::MULTICAST_UFTP_DIRECT, DeployMethodTypes::MULTICAST_UDPCAST_DIRECT, => 'multicast-direct',
DeployMethodTypes::MULTICAST, DeployMethodTypes::MULTICAST_UFTP, DeployMethodTypes::MULTICAST_UDPCAST => 'multicast', DeployMethodTypes::MULTICAST, DeployMethodTypes::MULTICAST_UFTP, DeployMethodTypes::MULTICAST_UDPCAST => 'multicast',
DeployMethodTypes::UNICAST_DIRECT => 'unicast-direct',
DeployMethodTypes::UNICAST => 'unicast', DeployMethodTypes::UNICAST => 'unicast',
DeployMethodTypes::TORRENT => 'torrent', DeployMethodTypes::TORRENT => 'torrent',
default => throw new ValidatorException('Invalid method'), default => throw new ValidatorException('Invalid method'),
}; };
$ptcValue = "$method $input->mcastPort:$input->mcastMode:$input->mcastIp:$input->mcastSpeed:$input->maxClients:$input->maxTime"; $ptcMulticastValue = "$method $input->mcastPort:$input->mcastMode:$input->mcastIp:$input->mcastSpeed:$input->maxClients:$input->maxTime";
$ptcTorrentValue = "$method $input->p2pMode:$input->p2pTime";
$ptcUnicastValue = $method;
$ptcValue = match ($input->method) {
DeployMethodTypes::MULTICAST, DeployMethodTypes::MULTICAST_UFTP, DeployMethodTypes::MULTICAST_UFTP_DIRECT, DeployMethodTypes::MULTICAST_UDPCAST, DeployMethodTypes::MULTICAST_UDPCAST_DIRECT => $ptcMulticastValue,
DeployMethodTypes::UNICAST, DeployMethodTypes::UNICAST_DIRECT => $ptcUnicastValue,
DeployMethodTypes::TORRENT => $ptcTorrentValue,
default => throw new ValidatorException('Invalid method'),
};
$data = [ $data = [
'dsk' => (string) $partition->getDiskNumber(), 'dsk' => (string) $partition->getDiskNumber(),

View File

@ -47,7 +47,7 @@ class StatusAction extends AbstractController
throw new ValidatorException('IP is required'); throw new ValidatorException('IP is required');
} }
if ($client->getStatus() === ClientStatus::OG_LIVE || $client->getStatus() === ClientStatus::OFF || $client->getStatus() === ClientStatus::BUSY) { if ($client->getStatus() === ClientStatus::OG_LIVE || $client->getStatus() === ClientStatus::OFF || $client->getStatus() === ClientStatus::BUSY || $client->getStatus() === ClientStatus::INITIALIZING) {
$response = $this->getOgLiveStatus($client); $response = $this->getOgLiveStatus($client);
} }

View File

@ -7,6 +7,7 @@ namespace App\Controller\OgAgent\Webhook;
use App\Entity\Client; use App\Entity\Client;
use App\Entity\OrganizationalUnit; use App\Entity\OrganizationalUnit;
use App\Entity\Partition; use App\Entity\Partition;
use App\Model\ClientStatus;
use App\Service\CreatePartitionService; use App\Service\CreatePartitionService;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -47,6 +48,9 @@ class AgentController extends AbstractController
return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND);
} }
$clientEntity->setStatus(ClientStatus::OG_LIVE);
$this->entityManager->persist($clientEntity);
if (isset($data['cfg'])) { if (isset($data['cfg'])) {
$this->createPartitionService->__invoke($data, $clientEntity); $this->createPartitionService->__invoke($data, $clientEntity);
} }

View File

@ -157,7 +157,7 @@ class ClientsController extends AbstractController
} }
$softwareProfile = new SoftwareProfile(); $softwareProfile = new SoftwareProfile();
$softwareProfile->setDescription('Perfil: ' . $image->getName()); $softwareProfile->setDescription('Perfil software: ' . $image->getClient()->getName());
$softwareProfile->setOrganizationalUnit($image->getClient()->getOrganizationalUnit()); $softwareProfile->setOrganizationalUnit($image->getClient()->getOrganizationalUnit());
foreach ($existingSoftware as $softwareEntity) { foreach ($existingSoftware as $softwareEntity) {

View File

@ -38,14 +38,14 @@ class DeployImageAction extends AbstractOgRepositoryController
'bitrate' => (string) $input->mcastSpeed.'M', 'bitrate' => (string) $input->mcastSpeed.'M',
'ip' => $input->mcastIp, 'ip' => $input->mcastIp,
'port' => $input->mcastPort, 'port' => $input->mcastPort,
'method' => 'full', 'method' => $input->mcastMode,
'nclients' => 20, 'nclients' => $input->maxClients,
'maxtime' => 120 'maxtime' => $input->maxTime
] ]
]; ];
$type = match ($input->method) { $type = match ($input->method) {
'udpcast' => DeployMethodTypes::MULTICAST_UDPCAST, 'udpcast', 'udpcast_direct' => DeployMethodTypes::MULTICAST_UDPCAST,
'p2p' => DeployMethodTypes::TORRENT, 'p2p' => DeployMethodTypes::TORRENT,
default => DeployMethodTypes::MULTICAST_UFTP, default => DeployMethodTypes::MULTICAST_UFTP,
}; };

View File

@ -55,7 +55,7 @@ class WoLAction extends AbstractOgRepositoryController
$content = $this->createRequest('POST', 'http://'.$repository->getIp(). ':8006/ogrepository/v1/wol', $params); $content = $this->createRequest('POST', 'http://'.$repository->getIp(). ':8006/ogrepository/v1/wol', $params);
$client->setStatus(ClientStatus::OFF); $client->setStatus(ClientStatus::INITIALIZING);
$this->entityManager->persist($client); $this->entityManager->persist($client);
$this->entityManager->flush(); $this->entityManager->flush();

View File

@ -5,10 +5,12 @@ namespace App\Model;
final class DeployMethodTypes final class DeployMethodTypes
{ {
public const string MULTICAST = 'multicast'; public const string MULTICAST = 'multicast';
public const string MULTICAST_UFTP = 'uftp'; public const string MULTICAST_UFTP = 'uftp';
public const string MULTICAST_UFTP_DIRECT = 'uftp-direct';
public const string MULTICAST_UDPCAST = 'udpcast'; public const string MULTICAST_UDPCAST = 'udpcast';
public const string MULTICAST_UDPCAST_DIRECT = 'udp-direct';
public const string UNICAST = 'unicast'; public const string UNICAST = 'unicast';
public const string UNICAST_DIRECT = 'unicast-direct';
public const string TORRENT = 'p2p'; public const string TORRENT = 'p2p';
private const array DEPLOYMENT_METHOD_TYPES = [ private const array DEPLOYMENT_METHOD_TYPES = [