Merge branch 'main' into develop
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
commit
4a97bc8aff
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## [1.7.3] - 2026-05-05
|
||||
### Fixed
|
||||
- Modificada funcion para borrar imagen de cache, no se hace usando la partición que contenga un deploy de imagen, se borra el fichero real de la cache
|
||||
|
||||
## [1.7.2] - 2026-05-04
|
||||
### Fixed
|
||||
- Corregida llamada a instalar/desinstalar oglives en servidores ogboot
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ resources:
|
|||
remove_cache_image:
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: App\Dto\Input\BootClientsInput
|
||||
input: App\Dto\Input\RemoveCacheImageInput
|
||||
uriTemplate: /clients/server/remove-cache-image
|
||||
controller: App\Controller\OgAgent\RemoveCacheImageAction
|
||||
|
||||
|
|
|
|||
|
|
@ -425,16 +425,8 @@ class ExecutePendingTracesCommand extends Command
|
|||
|
||||
try {
|
||||
$response = $this->runScriptAction->__invoke($commandExecuteInput, $trace);
|
||||
|
||||
if (json_decode($response->getContent(), true)['status'] === 200) {
|
||||
$trace->setStatus(TraceStatus::SUCCESS);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
return $response->getStatusCode() === 200;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Error executing run script', [
|
||||
'input' => $commandExecuteInput,
|
||||
|
|
@ -464,15 +456,15 @@ class ExecutePendingTracesCommand extends Command
|
|||
|
||||
try {
|
||||
$response = $this->rebootAction->__invoke($multipleClientsInput);
|
||||
|
||||
if (json_decode($response->getContent(), true)['status'] === 200) {
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$trace->setStatus(TraceStatus::SUCCESS);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class RunScheduledCommandTasksCommand extends Command
|
|||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$now = new \DateTimeImmutable('now');
|
||||
$now = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
|
||||
|
||||
$tasks = $this->commandTaskRepository->findAll();
|
||||
|
||||
|
|
@ -68,7 +68,12 @@ class RunScheduledCommandTasksCommand extends Command
|
|||
$output->writeln("NextExecution: " . $nextExecution->format('Y-m-d H:i:s T'));
|
||||
$output->writeln("Diferencia: $difference segundos para la tarea {$task->getName()}");
|
||||
|
||||
if (abs($difference) < 30) {
|
||||
$lastExecution = $task->getLastExecution();
|
||||
$isDue = $difference >= 0;
|
||||
$notYetExecuted = $lastExecution === null
|
||||
|| $lastExecution->getTimestamp() < $nextExecution->getTimestamp();
|
||||
|
||||
if ($isDue && $notYetExecuted) {
|
||||
$output->writeln("Ejecutando tarea: " . $task->getName());
|
||||
|
||||
$scripts = $task->getCommandTaskScripts()->toArray();
|
||||
|
|
@ -80,7 +85,7 @@ class RunScheduledCommandTasksCommand extends Command
|
|||
$this->createTraceForScript($script, $task, $output);
|
||||
}
|
||||
|
||||
$task->setLastExecution(new \DateTimeImmutable('now'));
|
||||
$task->setLastExecution(new \DateTimeImmutable('now', new \DateTimeZone('UTC')));
|
||||
$task->setNextExecution($task->calculateNextExecutionDate());
|
||||
|
||||
$this->entityManager->persist($task);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
namespace App\Controller\OgAgent;
|
||||
|
||||
use App\Dto\Input\BootClientsInput;
|
||||
use App\Dto\Input\RemoveCacheImageInput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Partition;
|
||||
use App\Model\ClientStatus;
|
||||
use App\Model\CommandTypes;
|
||||
use App\Model\TraceStatus;
|
||||
|
|
@ -24,19 +23,16 @@ class RemoveCacheImageAction extends AbstractOgAgentController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(BootClientsInput $input): JsonResponse
|
||||
public function __invoke(RemoveCacheImageInput $input): JsonResponse
|
||||
{
|
||||
/** @var Partition $partition */
|
||||
$partition = $input->partition->getEntity();
|
||||
if (!$input->imageName) {
|
||||
throw new BadRequestHttpException('Image name is required');
|
||||
}
|
||||
|
||||
foreach ($input->clients as $clientEntity) {
|
||||
/** @var Client $client */
|
||||
$client = $clientEntity->getEntity();
|
||||
|
||||
if (!$partition->getImage()) {
|
||||
throw new BadRequestHttpException('Image is required');
|
||||
}
|
||||
|
||||
if (!$client->getIp()) {
|
||||
throw new BadRequestHttpException('IP is required');
|
||||
}
|
||||
|
|
@ -46,7 +42,7 @@ class RemoveCacheImageAction extends AbstractOgAgentController
|
|||
continue;
|
||||
}
|
||||
|
||||
$script = 'rm -r /opt/opengnsys/cache/opt/opengnsys/images/' . $partition->getImage()->getName() . '.*';
|
||||
$script = 'rm -r /opt/opengnsys/cache/opt/opengnsys/images/' . escapeshellarg($input->imageName) . '*';
|
||||
|
||||
$data = [
|
||||
'nfn' => 'EjecutarScript',
|
||||
|
|
|
|||
|
|
@ -74,12 +74,22 @@ final class CommandTaskScheduleInput
|
|||
$commandTaskSchedule = new CommandTaskSchedule();
|
||||
}
|
||||
|
||||
$utc = new \DateTimeZone('UTC');
|
||||
|
||||
if ($this->commandTask) {
|
||||
$commandTaskSchedule->setCommandTask($this->commandTask->getEntity());
|
||||
}
|
||||
$commandTaskSchedule->setRecurrenceType($this->recurrenceType);
|
||||
$commandTaskSchedule->setExecutionTime($this->executionTime);
|
||||
$commandTaskSchedule->setExecutionDate($this->executionDate);
|
||||
$commandTaskSchedule->setExecutionTime(
|
||||
$this->executionTime
|
||||
? \DateTime::createFromInterface($this->executionTime)->setTimezone($utc)
|
||||
: null
|
||||
);
|
||||
$commandTaskSchedule->setExecutionDate(
|
||||
$this->executionDate
|
||||
? \DateTime::createFromInterface($this->executionDate)->setTimezone($utc)
|
||||
: null
|
||||
);
|
||||
$commandTaskSchedule->setRecurrenceDetails($this->recurrenceDetails);
|
||||
$commandTaskSchedule->setEnabled($this->enabled);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
final class RemoveCacheImageInput
|
||||
{
|
||||
/**
|
||||
* @var ClientOutput[]
|
||||
*/
|
||||
#[Groups(['client:write'])]
|
||||
#[ApiProperty(
|
||||
description: 'Los clientes a los que se les borrará la imagen de caché',
|
||||
example: []
|
||||
)]
|
||||
public array $clients = [];
|
||||
|
||||
#[Groups(['client:write'])]
|
||||
#[ApiProperty(
|
||||
description: 'El nombre de la imagen a borrar de la caché',
|
||||
example: 'windows10-ltsc_v1.img'
|
||||
)]
|
||||
public ?string $imageName = null;
|
||||
}
|
||||
|
|
@ -219,7 +219,8 @@ class CommandTask extends AbstractEntity
|
|||
*/
|
||||
public function calculateNextExecutionDate(): ?\DateTimeInterface
|
||||
{
|
||||
$now = new \DateTime();
|
||||
$utc = new \DateTimeZone('UTC');
|
||||
$now = new \DateTime('now', $utc);
|
||||
$closestDateTime = null;
|
||||
|
||||
foreach ($this->getCommandTaskSchedules() as $schedule) {
|
||||
|
|
@ -231,13 +232,14 @@ class CommandTask extends AbstractEntity
|
|||
if ($executionTime !== null) {
|
||||
$execDateTime = \DateTime::createFromFormat(
|
||||
'Y-m-d H:i:s',
|
||||
$execDate->format('Y-m-d') . ' ' . $executionTime->format('H:i:s')
|
||||
$execDate->format('Y-m-d') . ' ' . $executionTime->format('H:i:s'),
|
||||
$utc
|
||||
);
|
||||
} else {
|
||||
$execDateTime = $execDate;
|
||||
$execDateTime = \DateTime::createFromInterface($execDate)->setTimezone($utc);
|
||||
}
|
||||
|
||||
if ($closestDateTime === null || $execDateTime < $closestDateTime) {
|
||||
if ($execDateTime > $now && ($closestDateTime === null || $execDateTime < $closestDateTime)) {
|
||||
$closestDateTime = $execDateTime;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -246,13 +248,13 @@ class CommandTask extends AbstractEntity
|
|||
continue;
|
||||
}
|
||||
|
||||
$init = (new \DateTime($details['initDate'] ?? 'now'))->setTime(0, 0);
|
||||
$end = (new \DateTime($details['endDate'] ?? '+1 year'))->setTime(0, 0);
|
||||
$init = (new \DateTime($details['initDate'] ?? 'now', $utc))->setTime(0, 0);
|
||||
$end = (new \DateTime($details['endDate'] ?? '+1 year', $utc))->setTime(0, 0);
|
||||
|
||||
$validDays = array_map('mb_strtolower', $details['daysOfWeek'] ?? []);
|
||||
$validMonths = array_map('mb_strtolower', $details['months'] ?? []);
|
||||
|
||||
$current = (new \DateTime())->setTime(0, 0);
|
||||
$current = (new \DateTime('now', $utc))->setTime(0, 0);
|
||||
|
||||
while ($current <= $end) {
|
||||
if ($current < $init) {
|
||||
|
|
@ -267,7 +269,8 @@ class CommandTask extends AbstractEntity
|
|||
if ($executionTime !== null) {
|
||||
$execDateTime = \DateTime::createFromFormat(
|
||||
'Y-m-d H:i:s',
|
||||
$current->format('Y-m-d') . ' ' . $executionTime->format('H:i:s')
|
||||
$current->format('Y-m-d') . ' ' . $executionTime->format('H:i:s'),
|
||||
$utc
|
||||
);
|
||||
} else {
|
||||
$execDateTime = clone $current;
|
||||
|
|
|
|||
Loading…
Reference in New Issue