From 8569e73fea154f52aee333ba7350d0bc1d91af5b Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 29 Apr 2026 10:54:52 +0200 Subject: [PATCH] investigar --- src/Command/ExecutePendingTracesCommand.php | 33 ++++++++++++++++----- src/Controller/OgAgent/LoginAction.php | 9 ++++-- src/Controller/UDS/RemotePcController.php | 33 ++++++++++++++++----- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/Command/ExecutePendingTracesCommand.php b/src/Command/ExecutePendingTracesCommand.php index 91919d4..378f5b5 100644 --- a/src/Command/ExecutePendingTracesCommand.php +++ b/src/Command/ExecutePendingTracesCommand.php @@ -507,16 +507,33 @@ class ExecutePendingTracesCommand extends Command private function executeLogin(Trace $trace, array $input): bool { $client = $trace->getClient(); - - if (!isset($input['partition'])) { - throw new \Exception("Partition not found in trace input"); + + if ($client->getStatus() !== ClientStatus::OG_LIVE) { + $this->logger->info('Login trace deferred: client not in OGLive', [ + 'client' => $client->getUuid(), + 'status' => $client->getStatus(), + ]); + return false; } - $partition = $this->entityManager->getRepository(\App\Entity\Partition::class) - ->findOneBy(['uuid' => $input['partition']]); - - if (!$partition) { - throw new \Exception("Partition not found with UUID: {$input['partition']}"); + if (isset($input['partition'])) { + $partition = $this->entityManager->getRepository(Partition::class) + ->findOneBy(['uuid' => $input['partition']]); + if (!$partition) { + throw new \Exception("Partition not found with UUID: {$input['partition']}"); + } + } elseif (isset($input['dsk']) && isset($input['par'])) { + $partition = $this->entityManager->getRepository(Partition::class) + ->findOneBy([ + 'client' => $client, + 'diskNumber' => $input['dsk'], + 'partitionNumber' => $input['par'], + ]); + if (!$partition) { + throw new \Exception("Partition not found for disk {$input['dsk']} partition {$input['par']}"); + } + } else { + throw new \Exception("Partition not found in trace input"); } $bootClientsInput = new BootClientsInput(); diff --git a/src/Controller/OgAgent/LoginAction.php b/src/Controller/OgAgent/LoginAction.php index 7730767..7b3d7f8 100644 --- a/src/Controller/OgAgent/LoginAction.php +++ b/src/Controller/OgAgent/LoginAction.php @@ -52,8 +52,13 @@ class LoginAction extends AbstractOgAgentController throw new BadRequestHttpException('IP is required'); } + $partitionInput = [ + 'dsk' => $partition->getDiskNumber(), + 'par' => $partition->getPartitionNumber(), + ]; + if ($client->getStatus() !== ClientStatus::OG_LIVE) { - $this->createService->__invoke($client, CommandTypes::LOGIN, TraceStatus::PENDING, null, []); + $this->createService->__invoke($client, CommandTypes::LOGIN, TraceStatus::PENDING, null, $partitionInput); continue; } @@ -74,7 +79,7 @@ class LoginAction extends AbstractOgAgentController ); if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) { - $this->createService->__invoke($client, CommandTypes::LOGIN, TraceStatus::PENDING, null, []); + $this->createService->__invoke($client, CommandTypes::LOGIN, TraceStatus::PENDING, null, $partitionInput); continue; } diff --git a/src/Controller/UDS/RemotePcController.php b/src/Controller/UDS/RemotePcController.php index 7921f5f..1cbe04b 100644 --- a/src/Controller/UDS/RemotePcController.php +++ b/src/Controller/UDS/RemotePcController.php @@ -6,6 +6,7 @@ use App\Entity\AgentQueue; use App\Entity\Client; use App\Entity\Partition; use App\Entity\RemotePC; +use App\Entity\Trace; use App\Model\ClientStatus; use App\Model\CommandTypes; use App\Model\TraceStatus; @@ -20,6 +21,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Attribute\Route; +use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -102,6 +104,17 @@ class RemotePcController extends AbstractController $queueRepo = $this->entityManager->getRepository(AgentQueue::class); $queueRepo->deleteByClientAndOperations($client, self::QUEUE_OPERATIONS); + $this->entityManager->createQuery( + 'DELETE FROM App\Entity\Trace t + WHERE t.client = :client + AND t.command = :command + AND t.status = :status' + ) + ->setParameter('client', $client) + ->setParameter('command', CommandTypes::LOGIN) + ->setParameter('status', TraceStatus::PENDING) + ->execute(); + $this->sendPowerOff($client); $this->logger->info('RemotePC: client unreserved', ['client_id' => $client->getId()]); @@ -230,18 +243,20 @@ class RemotePcController extends AbstractController $repository = $client->getRepository(); if ($repository?->getIp()) { $this->httpClient->request('POST', 'http://' . $repository->getIp() . ':8006/ogrepository/v1/wol', [ - 'json' => ['broadcast_ip' => '255.255.255.255', 'mac' => $client->getMac()], - ]); + 'json' => ['broadcast_ip' => '255.255.255.255', 'mac' => $client->getMac()], + 'timeout' => 2.0, + ])->getStatusCode(); $this->logger->info('RemotePC: WoL sent', ['mac' => $client->getMac()]); } } else { $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/Reiniciar', [ 'verify_host' => false, + 'timeout' => 2.0, 'headers' => ['Authorization' => $client->getToken()], - ]); + ])->getStatusCode(); $this->logger->info('RemotePC: reboot sent', ['ip' => $client->getIp()]); } - } catch (TransportExceptionInterface $e) { + } catch (TransportExceptionInterface | HttpExceptionInterface $e) { $this->logger->warning('RemotePC: boot command failed', ['client_id' => $client->getId(), 'error' => $e->getMessage()]); } @@ -258,6 +273,7 @@ class RemotePcController extends AbstractController try { $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/IniciarSesion', [ 'verify_host' => false, + 'timeout' => 2.0, 'json' => [ 'nfn' => 'IniciarSesion', 'dsk' => (string) $partition->getDiskNumber(), @@ -265,11 +281,11 @@ class RemotePcController extends AbstractController 'ids' => '0', ], 'headers' => ['Authorization' => $client->getToken()], - ]); + ])->getStatusCode(); $client->setStatus(ClientStatus::INITIALIZING); $this->entityManager->persist($client); $this->logger->info('RemotePC: IniciarSesion sent', ['ip' => $client->getIp()]); - } catch (TransportExceptionInterface $e) { + } catch (TransportExceptionInterface | HttpExceptionInterface $e) { $this->logger->warning('RemotePC: IniciarSesion failed', ['client_id' => $client->getId(), 'error' => $e->getMessage()]); $this->createService->__invoke($client, CommandTypes::LOGIN, TraceStatus::PENDING, null, [ 'dsk' => $partition->getDiskNumber(), @@ -283,9 +299,10 @@ class RemotePcController extends AbstractController try { $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/Apagar', [ 'verify_host' => false, + 'timeout' => 2.0, 'headers' => ['Authorization' => $client->getToken()], - ]); - } catch (TransportExceptionInterface $e) { + ])->getStatusCode(); + } catch (TransportExceptionInterface | HttpExceptionInterface $e) { $this->logger->warning('RemotePC: poweroff failed', ['client_id' => $client->getId(), 'error' => $e->getMessage()]); } }