Skip to content

Commit

Permalink
[clickhouse-admin] Modify endpoints to avoid redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
karencfv committed Nov 7, 2024
1 parent eb8791c commit 9bc771b
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 87 deletions.
16 changes: 8 additions & 8 deletions clickhouse-admin/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub trait ClickhouseAdminKeeperApi {
/// configuration set via this endpoint.
#[endpoint {
method = PUT,
path = "/config",
path = "/gen-config-and-enable",
}]
async fn generate_config(
async fn generate_config_and_enable_svc(
rqctx: RequestContext<Self::Context>,
body: TypedBody<KeeperConfigurableSettings>,
) -> Result<HttpResponseCreated<KeeperConfig>, HttpError>;
Expand All @@ -45,7 +45,7 @@ pub trait ClickhouseAdminKeeperApi {
/// and logs for consistency and recovery.
#[endpoint {
method = GET,
path = "/keeper/lgif",
path = "/lgif",
}]
async fn lgif(
rqctx: RequestContext<Self::Context>,
Expand All @@ -55,7 +55,7 @@ pub trait ClickhouseAdminKeeperApi {
/// contains last committed cluster configuration.
#[endpoint {
method = GET,
path = "/keeper/raft-config",
path = "/raft-config",
}]
async fn raft_config(
rqctx: RequestContext<Self::Context>,
Expand All @@ -64,7 +64,7 @@ pub trait ClickhouseAdminKeeperApi {
/// Retrieve configuration information from a keeper node.
#[endpoint {
method = GET,
path = "/keeper/conf",
path = "/conf",
}]
async fn keeper_conf(
rqctx: RequestContext<Self::Context>,
Expand All @@ -73,7 +73,7 @@ pub trait ClickhouseAdminKeeperApi {
/// Retrieve cluster membership information from a keeper node.
#[endpoint {
method = GET,
path = "/keeper/cluster-membership",
path = "/cluster-membership",
}]
async fn keeper_cluster_membership(
rqctx: RequestContext<Self::Context>,
Expand All @@ -99,9 +99,9 @@ pub trait ClickhouseAdminServerApi {
/// directory and enable the SMF service.
#[endpoint {
method = PUT,
path = "/config"
path = "/gen-config-and-enable"
}]
async fn generate_config(
async fn generate_config_and_enable_svc(
rqctx: RequestContext<Self::Context>,
body: TypedBody<ServerConfigurableSettings>,
) -> Result<HttpResponseCreated<ReplicaConfig>, HttpError>;
Expand Down
4 changes: 2 additions & 2 deletions clickhouse-admin/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum ClickhouseAdminServerImpl {}
impl ClickhouseAdminServerApi for ClickhouseAdminServerImpl {
type Context = Arc<ServerContext>;

async fn generate_config(
async fn generate_config_and_enable_svc(
rqctx: RequestContext<Self::Context>,
body: TypedBody<ServerConfigurableSettings>,
) -> Result<HttpResponseCreated<ReplicaConfig>, HttpError> {
Expand Down Expand Up @@ -62,7 +62,7 @@ enum ClickhouseAdminKeeperImpl {}
impl ClickhouseAdminKeeperApi for ClickhouseAdminKeeperImpl {
type Context = Arc<ServerContext>;

async fn generate_config(
async fn generate_config_and_enable_svc(
rqctx: RequestContext<Self::Context>,
body: TypedBody<KeeperConfigurableSettings>,
) -> Result<HttpResponseCreated<KeeperConfig>, HttpError> {
Expand Down
40 changes: 24 additions & 16 deletions nexus/reconfigurator/execution/src/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,22 @@ pub(crate) async fn deploy_nodes(
let log = log.new(slog::o!("admin_url" => admin_url.clone()));
futs.push(Either::Left(async move {
let client = ClickhouseKeeperClient::new(&admin_url, log.clone());
client.generate_config(&config).await.map(|_| ()).map_err(|e| {
anyhow!(
concat!(
client
.generate_config_and_enable_svc(&config)
.await
.map(|_| ())
.map_err(|e| {
anyhow!(
concat!(
"failed to send config for clickhouse keeper ",
"with id {} to clickhouse-admin-keeper; admin_url = {}",
"error = {}"
),
config.settings.id,
admin_url,
e
)
})
config.settings.id,
admin_url,
e
)
})
}));
}
for config in server_configs {
Expand All @@ -118,18 +122,22 @@ pub(crate) async fn deploy_nodes(
let log = opctx.log.new(slog::o!("admin_url" => admin_url.clone()));
futs.push(Either::Right(async move {
let client = ClickhouseServerClient::new(&admin_url, log.clone());
client.generate_config(&config).await.map(|_| ()).map_err(|e| {
anyhow!(
concat!(
client
.generate_config_and_enable_svc(&config)
.await
.map(|_| ())
.map_err(|e| {
anyhow!(
concat!(
"failed to send config for clickhouse server ",
"with id {} to clickhouse-admin-server; admin_url = {}",
"error = {}"
),
config.settings.id,
admin_url,
e
)
})
config.settings.id,
admin_url,
e
)
})
}));
}

Expand Down
62 changes: 31 additions & 31 deletions openapi/clickhouse-admin-keeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,17 @@
"version": "0.0.1"
},
"paths": {
"/config": {
"put": {
"summary": "Generate a ClickHouse configuration file for a keeper node on a specified",
"description": "directory and enable the SMF service if not currently enabled.\n\nNote that we cannot start the keeper service until there is an initial configuration set via this endpoint.",
"operationId": "generate_config",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeeperConfigurableSettings"
}
}
},
"required": true
},
"/cluster-membership": {
"get": {
"summary": "Retrieve cluster membership information from a keeper node.",
"operationId": "keeper_cluster_membership",
"responses": {
"201": {
"description": "successful creation",
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeeperConfig"
"$ref": "#/components/schemas/ClickhouseKeeperClusterMembership"
}
}
}
Expand All @@ -45,17 +34,17 @@
}
}
},
"/keeper/cluster-membership": {
"/conf": {
"get": {
"summary": "Retrieve cluster membership information from a keeper node.",
"operationId": "keeper_cluster_membership",
"summary": "Retrieve configuration information from a keeper node.",
"operationId": "keeper_conf",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ClickhouseKeeperClusterMembership"
"$ref": "#/components/schemas/KeeperConf"
}
}
}
Expand All @@ -69,17 +58,28 @@
}
}
},
"/keeper/conf": {
"get": {
"summary": "Retrieve configuration information from a keeper node.",
"operationId": "keeper_conf",
"/gen-config-and-enable": {
"put": {
"summary": "Generate a ClickHouse configuration file for a keeper node on a specified",
"description": "directory and enable the SMF service if not currently enabled.\n\nNote that we cannot start the keeper service until there is an initial configuration set via this endpoint.",
"operationId": "generate_config_and_enable_svc",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeeperConfigurableSettings"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "successful operation",
"201": {
"description": "successful creation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeeperConf"
"$ref": "#/components/schemas/KeeperConfig"
}
}
}
Expand All @@ -93,7 +93,7 @@
}
}
},
"/keeper/lgif": {
"/lgif": {
"get": {
"summary": "Retrieve a logically grouped information file from a keeper node.",
"description": "This information is used internally by ZooKeeper to manage snapshots and logs for consistency and recovery.",
Expand All @@ -118,7 +118,7 @@
}
}
},
"/keeper/raft-config": {
"/raft-config": {
"get": {
"summary": "Retrieve information from ClickHouse virtual node /keeper/config which",
"description": "contains last committed cluster configuration.",
Expand Down
60 changes: 30 additions & 30 deletions openapi/clickhouse-admin-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,22 @@
"version": "0.0.1"
},
"paths": {
"/config": {
"put": {
"summary": "Generate a ClickHouse configuration file for a server node on a specified",
"description": "directory and enable the SMF service.",
"operationId": "generate_config",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ServerConfigurableSettings"
}
}
},
"required": true
},
"/distributed-ddl-queue": {
"get": {
"summary": "Contains information about distributed ddl queries (ON CLUSTER clause)",
"description": "that were executed on a cluster.",
"operationId": "distributed_ddl_queue",
"responses": {
"201": {
"description": "successful creation",
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ReplicaConfig"
"title": "Array_of_DistributedDdlQueue",
"type": "array",
"items": {
"$ref": "#/components/schemas/DistributedDdlQueue"
}
}
}
}
Expand All @@ -45,22 +39,28 @@
}
}
},
"/distributed-ddl-queue": {
"get": {
"summary": "Contains information about distributed ddl queries (ON CLUSTER clause)",
"description": "that were executed on a cluster.",
"operationId": "distributed_ddl_queue",
"/gen-config-and-enable": {
"put": {
"summary": "Generate a ClickHouse configuration file for a server node on a specified",
"description": "directory and enable the SMF service.",
"operationId": "generate_config_and_enable_svc",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ServerConfigurableSettings"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "successful operation",
"201": {
"description": "successful creation",
"content": {
"application/json": {
"schema": {
"title": "Array_of_DistributedDdlQueue",
"type": "array",
"items": {
"$ref": "#/components/schemas/DistributedDdlQueue"
}
"$ref": "#/components/schemas/ReplicaConfig"
}
}
}
Expand Down

0 comments on commit 9bc771b

Please sign in to comment.