Skip to content

Commit

Permalink
finish logic and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
vsian committed Oct 10, 2024
1 parent 5dcb400 commit 8c9163e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
65 changes: 65 additions & 0 deletions docs/references/http_api_reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2741,6 +2741,71 @@ The response includes a JSON object like the following:
## Admin show node variable
**GET** `/admin/variables/{variable_name}`
Retrieves the value of a global variable in admin mode.
### Request
- Method: GET
- URL: `/admin/variables/{variable_name}`
- Headers: `accept: application/json`
#### Request example
```shell
curl --request GET \
--url http://localhost:23820/admin/variables/{variable_name} \
--header 'accept: application/json'
```
#### Request parameters
- `variable_name`: (*Path parameter*)
The name of the variable.
### Response
<Tabs
defaultValue="s200"
values={[
{label: 'Status code 200', value: 's200'},
{label: 'Status code 500', value: 's500'},
]}>
<TabItem value="s200">
The response includes a JSON object like the following:
```shell
{
"error_code":0,
"server_role":"admin"
}
```
- `"error_code"`: `integer`
`0`: The operation succeeds.
</TabItem>
<TabItem value="s500">
The response includes a JSON object like the following:
```shell
{
"error_code" : 3027,
"error_message":"variable does not exist : role."
}
```
- `"error_code"`: `integer`
A non-zero value indicates a specific error condition.
- `"error_message"`: `string`
When `error_code` is non-zero, `"error_message"` provides additional details about the error.
</TabItem>
</Tabs>
---
## Admin show current node
Expand Down
8 changes: 7 additions & 1 deletion src/network/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3686,7 +3686,7 @@ class AdminShowNodeVariableHandler final : public HttpRequestHandler {
auto infinity = Infinity::RemoteConnect();
DeferFn defer_fn([&]() { infinity->RemoteDisconnect(); });

auto variable_name = request->getPathVariable("variable_name");
String variable_name = request->getPathVariable("variable_name");
auto result = infinity->AdminShowVariable(variable_name);

HTTPStatus http_status;
Expand All @@ -3695,6 +3695,12 @@ class AdminShowNodeVariableHandler final : public HttpRequestHandler {
if (result.IsOk()) {
json_response["error_code"] = 0;
DataBlock *data_block = result.result_table_->GetDataBlockById(0).get();
if (data_block->row_count() == 0) {
json_response["error_code"] = ErrorCode::kNoSuchSystemVar;
json_response["error_message"] = fmt::format("variable does not exist : {}.", variable_name);
http_status = HTTPStatus::CODE_500;
return ResponseFactory::createResponse(http_status, json_response.dump());
}
Value value = data_block->GetValue(0, 0);
const String &variable_value = value.ToString();
json_response[variable_name] = variable_value;
Expand Down

0 comments on commit 8c9163e

Please sign in to comment.