From 5debf35b0d6634376e889b2154baffe01d3961b3 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 4 Sep 2025 13:56:19 +0200 Subject: [PATCH] refs #2754. Deploy bug fixed --- src/Command/ExecutePendingTracesCommand.php | 106 +++++++++++++++--- .../RunScheduledCommandTasksCommand.php | 64 ++++++++--- 2 files changed, 137 insertions(+), 33 deletions(-) diff --git a/src/Command/ExecutePendingTracesCommand.php b/src/Command/ExecutePendingTracesCommand.php index 383ffbd..36665be 100644 --- a/src/Command/ExecutePendingTracesCommand.php +++ b/src/Command/ExecutePendingTracesCommand.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace App\Command; use App\Controller\OgAgent\CreateImageAction; -use App\Controller\OgAgent\DeployImageAction; +use App\Controller\DeployImageAction; use App\Controller\OgAgent\PartitionAssistantAction; use App\Controller\OgAgent\RunScriptAction; use App\Dto\Input\CommandExecuteInput; @@ -14,7 +14,6 @@ use App\Dto\Input\PartitionInput; use App\Dto\Input\PartitionPostInput; use App\Dto\Input\MultipleClientsInput; use App\Dto\Input\BootClientsInput; -use App\Dto\Input\SoftwareInventoryPartitionInput; use App\Dto\Output\ClientOutput; use App\Dto\Output\PartitionOutput; use App\Entity\Client; @@ -30,6 +29,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Psr\Log\LoggerInterface; #[AsCommand(name: 'opengnsys:execute-pending-traces', description: 'Execute pending traces')] class ExecutePendingTracesCommand extends Command @@ -43,6 +43,7 @@ class ExecutePendingTracesCommand extends Command private readonly \App\Controller\OgAgent\RebootAction $rebootAction, private readonly \App\Controller\OgAgent\PowerOffAction $powerOffAction, private readonly \App\Controller\OgAgent\LoginAction $loginAction, + private readonly LoggerInterface $logger, ) { parent::__construct(); } @@ -52,6 +53,8 @@ class ExecutePendingTracesCommand extends Command $io = new SymfonyStyle($input, $output); $startTime = microtime(true); + $this->logger->info('Executing pending traces command'); + $traces = $this->entityManager->getRepository(Trace::class) ->createQueryBuilder('t') ->select('t') @@ -112,6 +115,12 @@ class ExecutePendingTracesCommand extends Command $input = $trace->getInput() ?? []; $client = $trace->getClient(); + $this->logger->info('Executing trace', [ + 'command' => $command, + 'input' => $input, + 'client' => $client->getUuid() + ]); + if (!$client) { throw new \Exception("No client associated with trace"); } @@ -123,27 +132,59 @@ class ExecutePendingTracesCommand extends Command try { switch ($command) { case CommandTypes::CREATE_IMAGE: + $this->logger->info('Executing create image trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executeCreateImage($trace, $input); case CommandTypes::DEPLOY_IMAGE: + $this->logger->info('Executing deploy image trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executeDeployImage($trace, $input); case CommandTypes::PARTITION_AND_FORMAT: + $this->logger->info('Executing partition and format trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executePartitionAssistant($trace, $input); case CommandTypes::RUN_SCRIPT: + $this->logger->info('Executing run script trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executeRunScript($trace, $input); case CommandTypes::POWER_ON: + $this->logger->info('Executing power on trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executePowerOn($trace, $input); case CommandTypes::REBOOT: + $this->logger->info('Executing reboot trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executeReboot($trace, $input); case CommandTypes::SHUTDOWN: + $this->logger->info('Executing shutdown trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executeShutdown($trace, $input); case CommandTypes::LOGIN: + $this->logger->info('Executing login trace', [ + 'input' => $input, + 'client' => $client->getUuid() + ]); return $this->executeLogin($trace, $input); @@ -151,6 +192,12 @@ class ExecutePendingTracesCommand extends Command throw new \Exception("Unsupported command type: $command"); } } catch (\Exception $e) { + $this->logger->error('Error executing trace', [ + 'command' => $command, + 'input' => $input, + 'client' => $client->getUuid(), + 'error' => $e->getMessage() + ]); $trace->setStatus(TraceStatus::FAILED); $trace->setOutput($e->getMessage()); $trace->setFinishedAt(new \DateTime()); @@ -214,6 +261,12 @@ class ExecutePendingTracesCommand extends Command } } + $this->logger->info('Creating image', [ + 'image' => $image, + 'partition' => $partition, + 'client' => $client->getUuid() + ]); + try { $response = $this->createImageAction->__invoke( queue: false, @@ -259,22 +312,33 @@ class ExecutePendingTracesCommand extends Command $deployInput->type = $input['type'] ?? 'monolithic'; $deployInput->diskNumber = $input['diskNumber'] ?? 1; $deployInput->partitionNumber = $input['partitionNumber'] ?? 1; - $deployInput->mcastMode = $input['mcastMode'] ?? 'duplex'; - $deployInput->mcastSpeed = $input['mcastSpeed'] ?? 100; - $deployInput->mcastPort = $input['mcastPort'] ?? 8000; - $deployInput->mcastIp = $input['mcastIp'] ?? '224.0.0.1'; - $deployInput->maxClients = $input['maxClients'] ?? 10; - $deployInput->maxTime = $input['maxTime'] ?? 3600; - $deployInput->p2pMode = $input['p2pMode'] ?? 'seed'; - $deployInput->p2pTime = $input['p2pTime'] ?? 300; + $deployInput->mcastMode = $input['mcastMode'] ?? null; + $deployInput->mcastSpeed = $input['mcastSpeed'] ?? null; + $deployInput->mcastPort = $input['mcastPort'] ?? null; + $deployInput->mcastIp = $input['mcastIp'] ?? null; + $deployInput->maxClients = $input['maxClients'] ?? null; + $deployInput->maxTime = $input['maxTime'] ?? null; + $deployInput->p2pMode = $input['p2pMode'] ?? null; + $deployInput->p2pTime = $input['p2pTime'] ?? null; + $deployInput->queue = $input['queue'] ?? false; + + $deployInput->clients = [new ClientOutput($client)]; - $jobId = $this->deployImageAction->__invoke( - imageImageRepository: $imageImageRepository, - input: $deployInput, - client: $client - ); + $this->logger->info('Deploying image', [ + 'input' => $deployInput, + 'client' => $client->getUuid() + ]); - $trace->setJobId($jobId); + $response = $this->deployImageAction->__invoke($deployInput, $imageImageRepository, $trace); + + $clientJobs = $response['data']; + + $clientKey = '/clients/' . $client->getUuid(); + $jobId = $clientJobs[$clientKey] ?? []; + + $trace->setJobId($jobId['jobId']); + $trace->setStatus(TraceStatus::IN_PROGRESS); + $trace->setFinishedAt(new \DateTime()); $this->entityManager->persist($trace); $this->entityManager->flush(); @@ -304,6 +368,11 @@ class ExecutePendingTracesCommand extends Command $partitionInput->partitions = $partitions; $partitionInput->queue = false; + $this->logger->info('Executing partition assistant', [ + 'input' => $partitionInput, + 'client' => $client->getUuid() + ]); + try { $response = $this->partitionAssistantAction->__invoke($partitionInput, $trace); @@ -335,6 +404,11 @@ class ExecutePendingTracesCommand extends Command $commandExecuteInput->script = $input['script']; $commandExecuteInput->queue = false; + $this->logger->info('Executing run script', [ + 'input' => $commandExecuteInput, + 'client' => $client->getUuid() + ]); + try { $response = $this->runScriptAction->__invoke($commandExecuteInput, $trace); diff --git a/src/Command/RunScheduledCommandTasksCommand.php b/src/Command/RunScheduledCommandTasksCommand.php index 2dd20f3..4385c3d 100644 --- a/src/Command/RunScheduledCommandTasksCommand.php +++ b/src/Command/RunScheduledCommandTasksCommand.php @@ -117,31 +117,61 @@ class RunScheduledCommandTasksCommand extends Command case 'deploy-image': $trace->setCommand(CommandTypes::DEPLOY_IMAGE); - $trace->setInput([ - 'imageImageRepository' => $scriptParameters['imageImageRepositoryUuid'], - 'method' => $scriptParameters['method'] ?? 'unicast', - 'type' => $scriptParameters['type'] ?? 'monolithic', - 'diskNumber' => $scriptParameters['diskNumber'] ?? 1, - 'partitionNumber' => $scriptParameters['partitionNumber'] ?? 1, - 'mcastMode' => $scriptParameters['mcastMode'] ?? 'duplex', - 'mcastSpeed' => $scriptParameters['mcastSpeed'] ?? 100, - 'mcastPort' => $scriptParameters['mcastPort'] ?? 8000, - 'mcastIp' => $scriptParameters['mcastIp'] ?? '224.0.0.1', - 'maxClients' => $scriptParameters['maxClients'] ?? 10, - 'maxTime' => $scriptParameters['maxTime'] ?? 3600, - 'p2pMode' => $scriptParameters['p2pMode'] ?? 'seed', - 'p2pTime' => $scriptParameters['p2pTime'] ?? 300 - ]); + + $input = [ + 'imageImageRepository' => $scriptParameters['imageUuid'] + ]; + + if (isset($scriptParameters['method'])) { + $input['method'] = $scriptParameters['method']; + } + if (isset($scriptParameters['type'])) { + $input['type'] = $scriptParameters['type']; + } + if (isset($scriptParameters['diskNumber'])) { + $input['diskNumber'] = $scriptParameters['diskNumber']; + } + if (isset($scriptParameters['partitionNumber'])) { + $input['partitionNumber'] = $scriptParameters['partitionNumber']; + } + if (isset($scriptParameters['mcastMode'])) { + $input['mcastMode'] = $scriptParameters['mcastMode']; + } + if (isset($scriptParameters['mcastSpeed'])) { + $input['mcastSpeed'] = $scriptParameters['mcastSpeed']; + } + if (isset($scriptParameters['mcastPort'])) { + $input['mcastPort'] = $scriptParameters['mcastPort']; + } + if (isset($scriptParameters['mcastIp'])) { + $input['mcastIp'] = $scriptParameters['mcastIp']; + } + if (isset($scriptParameters['maxClients'])) { + $input['maxClients'] = $scriptParameters['maxClients']; + } + if (isset($scriptParameters['maxTime'])) { + $input['maxTime'] = $scriptParameters['maxTime']; + } + if (isset($scriptParameters['p2pMode'])) { + $input['p2pMode'] = $scriptParameters['p2pMode']; + } + if (isset($scriptParameters['p2pTime'])) { + $input['p2pTime'] = $scriptParameters['p2pTime']; + } + + $trace->setInput($input); break; case 'create-image': $trace->setCommand(CommandTypes::CREATE_IMAGE); $trace->setInput([ 'type' => $scriptParameters['type'], - 'name' => $scriptParameters['imageName'], + 'imageName' => $scriptParameters['imageName'], + 'imageUuid' => $scriptParameters['imageUuid'] ?? null, 'diskNumber' => $scriptParameters['diskNumber'] ?? null, 'partitionNumber' => $scriptParameters['partitionNumber'] ?? null, - 'gitRepositoryName' => $scriptParameters['gitRepositoryName'] ?? null + 'gitRepositoryName' => $scriptParameters['gitRepositoryName'] ?? null, + 'action' => $scriptParameters['action'] ?? 'create' ]); break;