refs #952. First revision status endpoint ogAgent
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
parent
ba65454c38
commit
0ac01b8c4a
|
@ -25,7 +25,6 @@ class OgAdmClientController extends AbstractController
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
#[Route('/opengnsys/rest/ogAdmClient/InclusionCliente', methods: ['POST'])]
|
||||
public function processClient(Request $request): JsonResponse
|
||||
{
|
||||
|
@ -54,11 +53,9 @@ class OgAdmClientController extends AbstractController
|
|||
|
||||
$partitionEntity->setClient($clientEntity);
|
||||
$partitionEntity->setDiskNumber($cfg['disk']);
|
||||
//$partitionEntity->setPartitionCode($cfg['codpar']);
|
||||
$partitionEntity->setPartitionNumber($cfg['par']);
|
||||
$partitionEntity->setSize($cfg['tam']);
|
||||
$partitionEntity->setMemoryUsage($cfg['uso']);
|
||||
//$partitionEntity->setFilesystem($cfg['idsistemafichero']);
|
||||
$this->entityManager->persist($partitionEntity);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,60 @@
|
|||
|
||||
namespace App\Controller\OgAgent;
|
||||
|
||||
class StatusAction
|
||||
{
|
||||
use App\Entity\Client;
|
||||
use App\Model\OgLiveStatus;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
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;
|
||||
|
||||
#[AsController]
|
||||
class StatusAction extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient
|
||||
)
|
||||
{
|
||||
$httpClient = HttpClient::create([
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Client $client): JsonResponse
|
||||
{
|
||||
if (!$client->getIp()) {
|
||||
throw new ValidatorException('IP is required');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/ogAdmClient/status');
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
$client->setAgentJobId($data['job_id']);
|
||||
$this->entityManager->persist($data);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(data: $data, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,43 @@
|
|||
|
||||
namespace App\Controller\OgAgent\Webhook;
|
||||
|
||||
class GetStatusAction
|
||||
{
|
||||
use App\Controller\OgBoot\AbstractOgBootController;
|
||||
use App\Entity\OgLive;
|
||||
use App\Model\OgLiveStatus;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\Routing\Annotation\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;
|
||||
|
||||
#[AsController]
|
||||
class GetStatusAction extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/clients/status/webhook', name: 'status', methods: ['POST'])]
|
||||
public function installWebhook(Request $request): JsonResponse
|
||||
{
|
||||
$data = json_decode($request->getContent(), true);
|
||||
|
||||
if (!is_array($data)) {
|
||||
return new JsonResponse(['error' => 'Invalid JSON data'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new JsonResponse(data: $data, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue