Improvements in ogBoot API
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
81da6b7a34
commit
b0efe07977
|
@ -38,6 +38,7 @@ resources:
|
||||||
class: ApiPlatform\Metadata\Post
|
class: ApiPlatform\Metadata\Post
|
||||||
method: POST
|
method: POST
|
||||||
input: false
|
input: false
|
||||||
|
output: false
|
||||||
uriTemplate: /clients/{uuid}/agent/status
|
uriTemplate: /clients/{uuid}/agent/status
|
||||||
controller: App\Controller\OgAgent\StatusAction
|
controller: App\Controller\OgAgent\StatusAction
|
||||||
|
|
||||||
|
|
|
@ -43,21 +43,21 @@ class StatusAction extends AbstractController
|
||||||
throw new ValidatorException('IP is required');
|
throw new ValidatorException('IP is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($client->getStatus() === ClientStatus::OG_LIVE) {
|
if ($client->getStatus() === ClientStatus::OG_LIVE || $client->getStatus() === ClientStatus::OFF) {
|
||||||
$this->getOgLiveStatus($client);
|
$response = $this->getOgLiveStatus($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($client->getStatus() === ClientStatus::LINUX) {
|
if ($client->getStatus() === ClientStatus::LINUX) {
|
||||||
$this->getSOStatus($client);
|
$response = $this->getSOStatus($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonResponse(
|
return new JsonResponse(
|
||||||
data: ['status' => $client->getStatus()],
|
data: ['status' => $response],
|
||||||
status: Response::HTTP_OK
|
status: $response === Response::HTTP_OK ? Response::HTTP_OK : Response::HTTP_INTERNAL_SERVER_ERROR
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOgLiveStatus (Client $client): JsonResponse
|
public function getOgLiveStatus (Client $client): JsonResponse|int
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [
|
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [
|
||||||
|
@ -75,10 +75,7 @@ class StatusAction extends AbstractController
|
||||||
} catch (TransportExceptionInterface $e) {
|
} catch (TransportExceptionInterface $e) {
|
||||||
$client->setStatus(ClientStatus::OFF);
|
$client->setStatus(ClientStatus::OFF);
|
||||||
|
|
||||||
return new JsonResponse(
|
return Response::HTTP_INTERNAL_SERVER_ERROR;
|
||||||
data: ['error' => $e->getMessage()],
|
|
||||||
status: Response::HTTP_INTERNAL_SERVER_ERROR
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
$data = json_decode($response->getContent(), true);
|
||||||
|
@ -90,10 +87,10 @@ class StatusAction extends AbstractController
|
||||||
$this->entityManager->persist($client);
|
$this->entityManager->persist($client);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
return new JsonResponse(status: Response::HTTP_OK);
|
return Response::HTTP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSOStatus (Client $client): JsonResponse
|
public function getSOStatus (Client $client): JsonResponse|int
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/status', [
|
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/status', [
|
||||||
|
@ -111,10 +108,7 @@ class StatusAction extends AbstractController
|
||||||
} catch (TransportExceptionInterface $e) {
|
} catch (TransportExceptionInterface $e) {
|
||||||
$client->setStatus(ClientStatus::OFF);
|
$client->setStatus(ClientStatus::OFF);
|
||||||
|
|
||||||
return new JsonResponse(
|
return Response::HTTP_INTERNAL_SERVER_ERROR;
|
||||||
data: ['error' => $e->getMessage()],
|
|
||||||
status: Response::HTTP_INTERNAL_SERVER_ERROR
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
$data = json_decode($response->getContent(), true);
|
||||||
|
@ -126,6 +120,6 @@ class StatusAction extends AbstractController
|
||||||
$this->entityManager->persist($client);
|
$this->entityManager->persist($client);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
return new JsonResponse(status: Response::HTTP_OK);
|
return Response::HTTP_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,6 +19,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class SyncAction extends AbstractOgBootController
|
class SyncAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
|
const string OG_BOOT_DIRECTORY = '/opt/opengnsys/ogboot/tftpboot//';
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
* @throws ServerExceptionInterface
|
* @throws ServerExceptionInterface
|
||||||
|
@ -53,7 +54,7 @@ class SyncAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
private function extracted(OgLive|null $ogLiveEntity, mixed $ogLive): void
|
private function extracted(OgLive|null $ogLiveEntity, mixed $ogLive): void
|
||||||
{
|
{
|
||||||
$ogLiveEntity->setName($ogLive['directory']);
|
$ogLiveEntity->setName(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory']));
|
||||||
$ogLiveEntity->setInstalled(true);
|
$ogLiveEntity->setInstalled(true);
|
||||||
$ogLiveEntity->setArchitecture($ogLive['architecture']);
|
$ogLiveEntity->setArchitecture($ogLive['architecture']);
|
||||||
$ogLiveEntity->setDistribution($ogLive['distribution']);
|
$ogLiveEntity->setDistribution($ogLive['distribution']);
|
||||||
|
|
Loading…
Reference in New Issue