develop #48
|
@ -1,4 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## [0.21.0] - 2025-08-28
|
||||
### Added
|
||||
- Se ha incluido una integracion con el agente, para generar los scripts que se llaman al particionar. Nuevo servicio.
|
||||
|
||||
---
|
||||
## [0.20.0] - 2025-08-25
|
||||
### Added
|
||||
- Se ha incorporado un servicio para marcar las trazas como completadas.
|
||||
|
|
|
@ -99,6 +99,13 @@ resources:
|
|||
uriTemplate: /clients/{uuid}/check-partition-sizes
|
||||
controller: App\Controller\OgAgent\CheckPartitionSizesAction
|
||||
|
||||
get_partition_script_data:
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: App\Dto\Input\GetPartitionScriptDataInput
|
||||
uriTemplate: /clients/{uuid}/get-partition-script-data
|
||||
controller: App\Controller\OgAgent\GetPartitionScriptDataAction
|
||||
|
||||
|
||||
properties:
|
||||
App\Entity\Client:
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\OgAgent;
|
||||
|
||||
use App\Dto\Input\GetPartitionScriptDataInput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Command;
|
||||
use App\Entity\Image;
|
||||
use App\Entity\Partition;
|
||||
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\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 GetPartitionScriptDataAction extends AbstractOgAgentController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(GetPartitionScriptDataInput $input, Client $client): JsonResponse
|
||||
{
|
||||
$partitions = $input->partitions;
|
||||
|
||||
if (empty($partitions)) {
|
||||
throw new BadRequestHttpException('Partitions is required');
|
||||
}
|
||||
|
||||
$this->logger->info('Input received', [
|
||||
'partitions_count' => count($partitions),
|
||||
'input_type' => gettype($input),
|
||||
'partitions_type' => gettype($partitions)
|
||||
]);
|
||||
|
||||
$disks = [];
|
||||
foreach ($partitions as $index => $partition) {
|
||||
$diskNumber = $partition->diskNumber;
|
||||
|
||||
$partitionEntity = $this->entityManager->getRepository(Partition::class)->findOneBy([
|
||||
'client' => $client,
|
||||
'partitionNumber' => $partition->partitionNumber,
|
||||
'diskNumber' => $partition->diskNumber,
|
||||
]);
|
||||
|
||||
if ($partitionEntity) {
|
||||
$partitionEntity->setClient($client);
|
||||
$this->entityManager->persist($partitionEntity);
|
||||
}
|
||||
|
||||
if (!isset($disks[$diskNumber])) {
|
||||
$disks[$diskNumber] = [
|
||||
'diskData' => [],
|
||||
'partitionData' => []
|
||||
];
|
||||
}
|
||||
|
||||
$disks[$diskNumber]['diskData'] = [
|
||||
'dis' => (string) $diskNumber,
|
||||
'tch' => (string) ($partition->size * 1024),
|
||||
];
|
||||
|
||||
$disks[$diskNumber]['partitionData'][] = [
|
||||
'par' => (string) $partition->partitionNumber,
|
||||
'cpt' => $partition->partitionCode,
|
||||
'sfi' => $partition->filesystem,
|
||||
'tam' => (string) (integer) ($partition->size * 1024),
|
||||
'ope' => $partition->format ? "1" : "0",
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($disks as $diskNumber => $diskInfo) {
|
||||
$data = [];
|
||||
if (!empty($diskInfo['diskData'])) {
|
||||
$data[] = $diskInfo['diskData'];
|
||||
}
|
||||
$data = array_merge($data, $diskInfo['partitionData']);
|
||||
|
||||
$result = [
|
||||
"nfn" => "Configurar",
|
||||
"dsk" => (string) $diskNumber,
|
||||
"cfg" => $data,
|
||||
"check-sizes" => "false",
|
||||
"gen-script" => "true",
|
||||
"ids" => "0"
|
||||
];
|
||||
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://'.$client->getIp().':8000/opengnsys/Configurar',
|
||||
params: [
|
||||
'json' => $result,
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
if (isset($response['script'])) {
|
||||
$decodedScript = base64_decode((string) $response['script'], true);
|
||||
if ($decodedScript !== false) {
|
||||
$response['script'] = $decodedScript;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new JsonResponse(data: $response, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
final class GetPartitionScriptDataInput
|
||||
{
|
||||
/**
|
||||
* @var PartitionInput[]
|
||||
*/
|
||||
#[Groups(['client:write'])]
|
||||
public array $partitions = [];
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue