Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial server skeleton #9

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ default-members = ["server"]
[workspace.package]
edition = "2021"
license = "Apache-2.0"
version = "0.0.1"
version = "0.1.0"
authors = [
"Alexander Brassel <[email protected]>",
"Abhi Agarwal <[email protected]>",
"R. Tyler Croy <[email protected]>",
]
publish = false

[workspace.dependencies]
chrono = { version = "0.4.38", features = ["serde"] }
Expand All @@ -19,4 +25,5 @@ serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
tracing = { version = "^0.1.40" }
tracing-subscriber = { version = "^0.3.18", features = ["env-filter"] }
utoipa = { version = "4.2.3", features = ["openapi_extensions"] }
uuid = { version = "^1.8", features = ["serde", "v4"] }
9 changes: 5 additions & 4 deletions models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[package]
name = "unitycatalog-models"
version = "0.1.0"
description = "Generated structs for Unity Catalog models"

edition.workspace = true
authors.workspace = true
license.workspace = true

publish = false
version.workspace = true
publish.workspace = true

[dependencies]
strum = { version = "0.26", features = ["derive"] }

chrono = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
utoipa = { workspace = true }
uuid = { workspace = true }
chrono = { workspace = true }
27 changes: 26 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
[package]
name = "unitycatalog-server"
description = "Unity catalog server, implemented in rust"

edition.workspace = true
authors.workspace = true
license.workspace = true
version.workspace = true
publish = false
publish.workspace = true

[dependencies]
anyhow = "^1.0.86"
axum = "^0.7.5"
object_store = { version = "^0.10.1", features = ["serde"] }
thiserror = "1.0.61"
toml_edit = { version = "0.22.14", features = ["serde"] }

unitycatalog-models = { path = "../models" }

chrono = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
reqwest = { workspace = true }
utoipa = { workspace = true, features = ["axum_extras"] }
uuid = { workspace = true }

[features]
aws = ["object_store/aws"]
azure = ["object_store/azure"]
gcp = ["object_store/gcp"]
29 changes: 27 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
fn main() {
println!("Hello, world!");
#![allow(unused)]

use crate::routes::all_routes;
use crate::state::AppState;
use anyhow::Result;
use axum::Router;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

mod routes;
mod state;

#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "unitycatalog=debug,tower_http=debug".into()),
)
.with(tracing_subscriber::fmt::layer())
.try_init()?;

let state = AppState {};

let listener = tokio::net::TcpListener::bind("127.0.0.1:8000").await?;
let app = Router::new().nest("/api/2.1/unity-catalog/", all_routes(state));
axum::serve(listener, app).await?;
Ok(())
}
97 changes: 97 additions & 0 deletions server/src/routes/catalogs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use axum::{
extract::{Path, Query, State},
response::IntoResponse,
routing::{get, Router},
Json,
};

use unitycatalog_models::models::{
CatalogInfo, CreateCatalog, ListCatalogsResponse, UpdateCatalog,
};

use crate::state::AppState;

use super::PaginationParams;

pub fn router(state: AppState) -> Router {
Router::new()
.route("/", get(get_catalogs).post(post_catalog))
.route(
"/:name",
get(get_catalog).patch(get_catalog).delete(delete_catalog),
)
.with_state(state)
}

#[utoipa::path(
post,
path = "/",
operation_id = "listCatalogs",
responses(
(status = 200, description = "The catalog list was successfully retrieved.")
)
)]
async fn get_catalogs(
State(state): State<AppState>,
Query(pagination): Query<PaginationParams>,
) -> Json<ListCatalogsResponse> {
todo!()
}

#[utoipa::path(
post,
path = "/",
operation_id = "createCatalog",
responses(
(status = 200, description = "The new catalog was successfully created.", body = CatalogInfo)
)
)]
async fn post_catalog(
State(state): State<AppState>,
Json(body): Json<CreateCatalog>,
) -> Json<CatalogInfo> {
todo!()
}

#[utoipa::path(
post,
path = "/{name}",
operation_id = "getCatalog",
responses(
(status = 200, description = "The catalog was successfully retrieved.", body = CatalogInfo)
)
)]
async fn get_catalog(State(state): State<AppState>, Path(name): Path<String>) -> Json<CatalogInfo> {
todo!()
}

#[utoipa::path(
post,
path = "/{name}",
operation_id = "updateCatalog",
responses(
(status = 200, description = "The catalog was successfully updated.", body = CatalogInfo)
)
)]
async fn patch_catalog(
State(state): State<AppState>,
Path(name): Path<String>,
Json(body): Json<UpdateCatalog>,
) -> Json<CatalogInfo> {
todo!()
}

#[utoipa::path(
post,
path = "/{name}",
operation_id = "deleteCatalog",
responses(
(status = 200, description = "The catalog was successfully deleted.")
)
)]
async fn delete_catalog(
State(state): State<AppState>,
Path(name): Path<String>,
) -> impl IntoResponse {
todo!()
}
89 changes: 89 additions & 0 deletions server/src/routes/functions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use axum::{
extract::{Path, Query, State},
response::IntoResponse,
routing::{get, Router},
Json,
};

use serde::{Deserialize, Serialize};
use unitycatalog_models::models::{CreateFunction, FunctionInfo, ListFunctionsResponse};
use utoipa::IntoParams;

use crate::state::AppState;

use super::PaginationParams;

pub fn router(state: AppState) -> Router {
Router::new()
.route("/", get(get_functions).post(post_function))
.route("/:name", get(get_function).delete(delete_function))
.with_state(state)
}

#[derive(Debug, Clone, Deserialize, Serialize, IntoParams)]
pub struct ListFunctionParams {
catalog_name: String,
schema_name: String,
#[serde(flatten)]
pagination: PaginationParams,
}

#[utoipa::path(
post,
path = "/",
operation_id = "listFunctions",
responses(
(status = 200, description = "The function list was successfully retrieved.")
)
)]
async fn get_functions(
State(state): State<AppState>,
Query(pagination): Query<ListFunctionParams>,
) -> Json<ListFunctionsResponse> {
todo!()
}

#[utoipa::path(
post,
path = "/",
operation_id = "createFunction",
responses(
(status = 200, description = "The new function was successfully created.", body = FunctionInfo)
)
)]
async fn post_function(
State(state): State<AppState>,
Json(body): Json<CreateFunction>,
) -> Json<FunctionInfo> {
todo!()
}

#[utoipa::path(
post,
path = "/{name}",
operation_id = "getFunction",
responses(
(status = 200, description = "The function was successfully retrieved.", body = FunctionInfo)
)
)]
async fn get_function(
State(state): State<AppState>,
Path(name): Path<String>,
) -> Json<FunctionInfo> {
todo!()
}

#[utoipa::path(
post,
path = "/{name}",
operation_id = "deleteFunction",
responses(
(status = 200, description = "The function was successfully deleted.")
)
)]
async fn delete_function(
State(state): State<AppState>,
Path(name): Path<String>,
) -> impl IntoResponse {
todo!()
}
26 changes: 26 additions & 0 deletions server/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use axum::Router;
use serde::{Deserialize, Serialize};
use utoipa::IntoParams;

use crate::state::AppState;

mod functions;
mod catalogs;
mod schemas;
mod tables;
mod volumes;

#[derive(Debug, Clone, Deserialize, Serialize, IntoParams)]
pub struct PaginationParams {
pub page_token: String,
pub max_results: u32,
}

pub fn all_routes(state: AppState) -> Router {
Router::new()
.nest("/functions", functions::router(state.clone()))
.nest("/catalogs", catalogs::router(state.clone()))
.nest("/schemas", schemas::router(state.clone()))
.nest("/tables", tables::router(state.clone()))
.nest("/volumes", volumes::router(state.clone()))
}
Loading
Loading