use crate::auth::PasswordAuthenticator;
use crate::batch::BatchManager;
use crate::config::Config;
use crate::graph_service::GraphService;
use crate::query::executor::expression::functions::FunctionRegistry;
use crate::session::GraphSessionManager;
use crate::storage::{
StorageClient, StorageOperationContextOps, StorageSchemaContextOps, StorageSyncContextOps,
};
use linkrs_api::api_core::{QueryApi, SchemaApi, TransactionApi};
use linkrs_transaction::TransactionManager;
use parking_lot::RwLock;
use std::sync::Arc;
pub struct HttpServer<
S: StorageClient
+ StorageSchemaContextOps
+ StorageSyncContextOps
+ StorageOperationContextOps
+ Clone
+ 'static,
> {
graph_service: Arc<GraphService<S>>,
query_api: QueryApi<S>,
txn_manager: Arc<TransactionManager>,
txn_api: TransactionApi,
schema_api: SchemaApi<S>,
auth_service: PasswordAuthenticator,
batch_manager: Arc<BatchManager<S>>,
storage: Arc<RwLock<S>>,
config: Arc<RwLock<Config>>,
config_path: Option<std::path::PathBuf>,
function_registry: Arc<RwLock<FunctionRegistry>>,
rebuild_tasks: super::handlers::rebuild::RebuildTaskRegistry,
}
impl<
S: StorageClient
+ StorageSchemaContextOps
+ StorageSyncContextOps
+ StorageOperationContextOps
+ Clone
+ 'static,
> HttpServer<S>
{
pub fn new(
graph_service: Arc<GraphService<S>>,
storage: Arc<RwLock<S>>,
txn_manager: Arc<TransactionManager>,
config: &Config,
config_path: Option<std::path::PathBuf>,
) -> Self {
let stats_manager = graph_service.get_stats_manager().clone();
Self {
graph_service: graph_service.clone(),
query_api: QueryApi::new(storage.clone(), stats_manager)
.with_password_history_depth(config.server.security.password_policy.history_size),
txn_manager: txn_manager.clone(),
txn_api: TransactionApi::new(txn_manager),
schema_api: SchemaApi::new(storage.clone()),
auth_service: PasswordAuthenticator::new_default(config.server.auth.clone()),
batch_manager: Arc::new(BatchManager::new(storage.clone())),
storage: storage.clone(),
config: Arc::new(RwLock::new(config.clone())),
config_path,
function_registry: Arc::new(RwLock::new(FunctionRegistry::new())),
rebuild_tasks: super::handlers::rebuild::RebuildTaskRegistry::default(),
}
}
pub fn get_graph_service(&self) -> Arc<GraphService<S>> {
self.graph_service.clone()
}
pub fn get_session_manager(&self) -> &GraphSessionManager {
self.graph_service.get_session_manager()
}
pub fn get_query_api(&self) -> &QueryApi<S> {
&self.query_api
}
pub fn get_txn_manager(&self) -> Arc<TransactionManager> {
self.txn_manager.clone()
}
pub fn get_txn_api(&self) -> &TransactionApi {
&self.txn_api
}
pub fn get_schema_api(&self) -> &SchemaApi<S> {
&self.schema_api
}
pub fn get_auth_service(&self) -> &PasswordAuthenticator {
&self.auth_service
}
pub fn get_batch_manager(&self) -> Arc<BatchManager<S>> {
self.batch_manager.clone()
}
pub fn get_stats_manager(&self) -> &Arc<linkrs_metrics::StatsManager> {
self.graph_service.get_stats_manager()
}
pub fn get_storage(&self) -> Arc<RwLock<S>> {
self.storage.clone()
}
pub fn get_config(&self) -> parking_lot::RwLockReadGuard<'_, Config> {
self.config.read()
}
pub fn get_config_path(&self) -> Option<std::path::PathBuf> {
self.config_path.clone()
}
pub(crate) fn config_store(&self) -> Arc<RwLock<Config>> {
Arc::clone(&self.config)
}
pub fn migration_config(&self) -> linkrs_migration::MigrationConfig {
let guard = self.config.read();
let settings = &guard.common.migration;
let data_dir = guard.common.database.storage_path.as_str();
linkrs_migration::MigrationConfig {
batch_size: settings.batch_size,
lock_ttl_secs: 300,
checkpoint_dir: settings.resolved_checkpoint_dir(data_dir),
lock_path: settings.resolved_lock_path(data_dir),
min_free_bytes: settings.min_free_bytes,
drain_timeout_ms: settings.drain_timeout_ms,
backup_dir: settings.resolved_backup_dir(data_dir),
}
}
pub fn get_function_registry(&self) -> Arc<RwLock<FunctionRegistry>> {
self.function_registry.clone()
}
pub fn rebuild_tasks(&self) -> super::handlers::rebuild::RebuildTaskRegistry {
self.rebuild_tasks.clone()
}
}