Añadida accion Refresh para actualizar el estado de un cliente o clientes. #83
|
|
@ -1,4 +1,7 @@
|
|||
# Changelog
|
||||
## [1.3.0] - 2026-03-31
|
||||
### Added
|
||||
Añadida acción Refresh para actualizar el estado de un cliente o clientes. Se actualiza su configuración de discos y se recarga el ogBrowser por si hubiese cambio del menu.
|
||||
|
||||
## [1.2.11] - 2026-03-25
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -100,6 +100,13 @@ resources:
|
|||
uriTemplate: /clients/server/power-off
|
||||
controller: App\Controller\OgAgent\PowerOffAction
|
||||
|
||||
refresh_client:
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: App\Dto\Input\MultipleClientsInput
|
||||
uriTemplate: /clients/server/refresh
|
||||
controller: App\Controller\OgAgent\RefreshAction
|
||||
|
||||
check_partition_sizes:
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\OgAgent;
|
||||
|
||||
use App\Dto\Input\MultipleClientsInput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Command;
|
||||
use App\Entity\Image;
|
||||
use App\Entity\Trace;
|
||||
use App\Model\ClientStatus;
|
||||
use App\Model\CommandTypes;
|
||||
use App\Model\ImageStatus;
|
||||
use App\Model\TraceStatus;
|
||||
use App\Service\Trace\CreateService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class RefreshAction extends AbstractOgAgentController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(MultipleClientsInput $input): JsonResponse
|
||||
{
|
||||
foreach ($input->clients as $clientEntity) {
|
||||
/** @var Client $client */
|
||||
$client = $clientEntity->getEntity();
|
||||
|
||||
if (!$client->getIp()) {
|
||||
throw new BadRequestHttpException('IP is required');
|
||||
}
|
||||
|
||||
// ONLY execute if the client is in OG_LIVE state
|
||||
if ($client->getStatus() !== ClientStatus::OG_LIVE) {
|
||||
$this->logger->info('Skipping refresh for client not in OG_LIVE state', ['client' => $client->getId(), 'status' => $client->getStatus()]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'nfn' => 'Actualizar',
|
||||
'ids' => '0'
|
||||
];
|
||||
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://'.$client->getIp().':8000/ogAdmClient/Actualizar',
|
||||
params: [
|
||||
'json' => $data,
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
$this->logger->error('Error refreshing client', ['client' => $client->getId(), 'error' => $response['error']]);
|
||||
|
||||
if ($input->queue) {
|
||||
$this->createService->__invoke($client, CommandTypes::REFRESH, TraceStatus::PENDING, null, []);
|
||||
continue;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->logger->info('Refreshing client menu and disk configuration', ['client' => $client->getId()]);
|
||||
|
||||
$jobId = $response['job_id'] ?? null;
|
||||
|
||||
// We do not change the status here, it remains OG_LIVE
|
||||
// $client->setStatus(ClientStatus::OG_LIVE);
|
||||
|
||||
$this->createService->__invoke($client, CommandTypes::REFRESH, TraceStatus::SUCCESS, $jobId, []);
|
||||
}
|
||||
|
||||
return new JsonResponse(data: [], status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ final class CommandTypes
|
|||
public const string HARDWARE_INVENTORY = 'hardware-inventory';
|
||||
public const string SOFTWARE_INVENTORY = 'software-inventory';
|
||||
public const string KILL_JOB = 'kill-job';
|
||||
public const string REFRESH = 'refresh';
|
||||
|
||||
private const array COMMAND_TYPES = [
|
||||
self::DEPLOY_IMAGE => 'Deploy Image',
|
||||
|
|
@ -56,6 +57,7 @@ final class CommandTypes
|
|||
self::HARDWARE_INVENTORY => 'Hardware Inventory',
|
||||
self::SOFTWARE_INVENTORY => 'Software Inventory',
|
||||
self::KILL_JOB => 'Kill Job',
|
||||
self::REFRESH => 'Refresh',
|
||||
];
|
||||
|
||||
public static function getCommandTypes(): array
|
||||
|
|
|
|||
Loading…
Reference in New Issue