refs #949 #943 #969 fix Command output return, add Command in the services.yaml, adds url to the oglives downloables
parent
21409e850b
commit
8264459a6b
|
@ -205,13 +205,14 @@ function downloadMenu() {
|
|||
fi
|
||||
ISOREL=${OGLIVE[i-1]##*-r}; ISOREL=${ISOREL%%.*}
|
||||
[ $ISOREL -ge $MINREL ] && compatible=true
|
||||
|
||||
url="$DOWNLOADURL/${OGLIVE[i-1]}"
|
||||
local DATA=$(jq -n \
|
||||
--arg id "$i" \
|
||||
--arg filename "${OGLIVE[i-1]}" \
|
||||
--arg url "$url" \
|
||||
--argjson installed "$installed" \
|
||||
--argjson compatible "$compatible" \
|
||||
'{id: $id, filename: $filename, installed: $installed, compatible: $compatible}')
|
||||
'{id: $id, filename: $filename, url: $url, installed: $installed, compatible: $compatible}')
|
||||
|
||||
downloads+=("$DATA")
|
||||
done
|
||||
|
|
|
@ -26,5 +26,5 @@ services:
|
|||
resource: '../src/OgBootBundle/Controller'
|
||||
tags: ['controller.service_arguments']
|
||||
# Register the OgLiveInstallCommand explicitly to ensure it's detected
|
||||
OgBootBundle\Command\OgLiveInstallCommand:
|
||||
App\OgBootBundle\Command\OgLiveInstallCommand:
|
||||
tags: ['console.command']
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
namespace App\OgBootBundle\Command;
|
||||
use App\OgBootBundle\Service\CurlRequestService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class OgLiveInstallCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'oglive:install';
|
||||
private $curlRequestService;
|
||||
private $httpClient;
|
||||
private $params;
|
||||
private $logger;
|
||||
|
||||
public function __construct(CurlRequestService $curlRequestService, HttpClientInterface $httpClient, ParameterBagInterface $params, LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->curlRequestService = $curlRequestService;
|
||||
#$this->httpClient = $httpClient;
|
||||
$this->httpClient = HttpClient::create([
|
||||
'verify_peer' => false, // Ignorar la verificación del certificado SSL
|
||||
'verify_host' => false, // Ignorar la verificación del nombre del host
|
||||
]);
|
||||
$this->params = $params;
|
||||
$this->logger = $logger; // Añadimos el logger
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Instala un ogLive en segundo plano')
|
||||
->addArgument('isoUrl', InputArgument::REQUIRED, 'URL del ISO de ogLive')
|
||||
->addArgument('transactionId', InputArgument::REQUIRED, 'ID de la transacción');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
ini_set('memory_limit', '-1');
|
||||
ini_set('max_execution_time', '3000');
|
||||
$isoUrl = $input->getArgument('isoUrl');
|
||||
|
||||
$transactionId = $input->getArgument('transactionId');
|
||||
|
||||
// Iniciamos los logs para rastrear el proceso
|
||||
$this->logger->info('Starting ogLive installation', ['transactionId' => $transactionId]);
|
||||
|
||||
try {
|
||||
// Log: comenzando la descarga del ISO
|
||||
$this->logger->info('Starting download', ['isoUrl' => $isoUrl]);
|
||||
|
||||
// Llamar al servicio para iniciar la instalación
|
||||
$installResult = $this->curlRequestService->callOgLive("download " . escapeshellarg($isoUrl));
|
||||
|
||||
// Log: descarga finalizada
|
||||
$this->logger->info('Download finished', ['transactionId' => $transactionId, 'installResult' => $installResult]);
|
||||
|
||||
// Verificar el resultado de la instalación basado en el output del comando
|
||||
$status = 'success';
|
||||
$messageText = 'ogLive client installed successfully';
|
||||
$exitCode = $installResult['exitCode'];
|
||||
|
||||
if (isset($installResult['output']['error'])) {
|
||||
// Si hay un error, asignar el estado y mensaje adecuado
|
||||
$status = $installResult['output']['error'];
|
||||
$messageText = $installResult['output']['message'];
|
||||
|
||||
// Log: la instalación falló
|
||||
$this->logger->error('Installation failed', ['transactionId' => $transactionId, 'error' => $messageText]);
|
||||
} elseif ($installResult['exitCode'] !== 0) {
|
||||
// Si hubo un exitCode distinto de 0, manejar como error desconocido
|
||||
$status = 'UNKNOWN_ERROR';
|
||||
$messageText = 'An unknown error occurred during the installation process.';
|
||||
$this->logger->error('Unknown installation error', ['transactionId' => $transactionId, 'exitCode' => $installResult['exitCode']]);
|
||||
} else {
|
||||
// Log: instalación completada con éxito
|
||||
$messageText = $installResult['output']['message'];
|
||||
$this->logger->info('Installation completed successfully', ['transactionId' => $transactionId]);
|
||||
}
|
||||
|
||||
// Preparar los datos para el webhook según el resultado
|
||||
$webhookData = [
|
||||
'ogCoreId' => $transactionId,
|
||||
'status' => $status,
|
||||
'code' => ($exitCode === 0) ? 200 : $exitCode, // Cambiar a 200 si es éxito
|
||||
'message' => $messageText ,
|
||||
];
|
||||
|
||||
$this->logger->info('Installation completed with details', ['installResult' => $installResult]);
|
||||
$this->logger->info('Webhook data to be sent: ', ['webhookData' => $webhookData]);
|
||||
|
||||
// Obtener la URL del webhook desde el archivo .env
|
||||
$webhookUrl = "https://172.17.8.90:8443/og-lives/install/webhook";
|
||||
|
||||
// Log: enviando datos al webhook
|
||||
$this->logger->info('Sending data to webhook', ['webhookUrl' => $webhookUrl, 'webhookData' => $webhookData]);
|
||||
|
||||
// Llamar al webhook para notificar el resultado
|
||||
$this->notifyWebhook($webhookUrl, $webhookData);
|
||||
$this->logger->info('Notify webhook con exito');
|
||||
// Log: notificación al webhook finalizada
|
||||
$this->logger->info('Webhook notification sent', ['transactionId' => $transactionId]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
// Log: error en la instalación
|
||||
$this->logger->error('Failed to complete ogLive installation', ['transactionId' => $transactionId, 'exception' => $e->getMessage()]);
|
||||
|
||||
// Manejar errores y enviar notificación de fallo al webhook
|
||||
$webhookData = [
|
||||
'ogCoreId' => $transactionId,
|
||||
'status' => 'failure',
|
||||
'code' => 500,
|
||||
'message' => $e->getMessage()
|
||||
];
|
||||
|
||||
$webhookUrl = "https://172.17.8.90:8443/og-lives/install/webhook";
|
||||
$this->notifyWebhook($webhookUrl, $webhookData);
|
||||
$this->logger->info('Notify webhook terminado con errores');
|
||||
// Log: notificación de error enviada al webhook
|
||||
$this->logger->info('Failure notification sent to webhook', ['transactionId' => $transactionId]);
|
||||
}
|
||||
|
||||
// Log: proceso de instalación terminado
|
||||
$this->logger->info('Installation process ended', ['transactionId' => $transactionId]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enviar el resultado al webhook
|
||||
*/
|
||||
private function notifyWebhook(string $webhookUrl, array $webhookData): void
|
||||
{
|
||||
try {
|
||||
$this->logger->info('Enter notify webhook');
|
||||
$this->logger->info('Data to be sent', ['webhookData' => $webhookData]);
|
||||
$this->httpClient->request('POST', $webhookUrl, [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'body' => json_encode(['webhookData' => $webhookData]),
|
||||
]);
|
||||
|
||||
// Log: éxito al enviar la notificación
|
||||
$this->logger->info('Webhook data sent successfully', ['webhookUrl' => $webhookUrl, 'webhookData' => $webhookData]);
|
||||
} catch (Exception $e) {
|
||||
// Log: error al enviar al webhook
|
||||
$this->logger->error('Error sending webhook notification', ['webhookUrl' => $webhookUrl, 'exception' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue