api_v1_apps - OmniCloudOrg/OmniOrchestrator GitHub Wiki
Path: src/api/v1/apps.rs
Application management module for handling CRUD operations on applications.
This module provides a REST API for managing applications, including:
- Listing applications
- Creating new applications
- Updating existing applications
- Getting application details and statistics
- Starting and stopping applications
- Scaling applications
- Deleting applications
- Releasing new versions of applications
- struct Application
- struct ScaleRequest
- struct AppStats
- struct CreateAppRequest
- struct UpdateAppRequest
- async fn list_apps
- async fn get_app_with_instances
- async fn count_apps
- async fn get_app
- async fn create_app
- async fn update_app
- async fn get_app_stats
- async fn start_app
- async fn stop_app
- async fn scale_app
- async fn delete_app
- async fn release
pub struct Application {
/// Unique identifier for the application
id: String,
/// Name of the application
name: String,
/// Owner of the application
owner: String,
/// Number of running instances
instances: i64,
/// Memory allocation in MB
memory: i64,
/// Current status of the application
status: String,
/// Creation timestamp
created_at: chrono::DateTime<chrono::Utc>,
/// Last update timestamp
updated_at: chrono::DateTime<chrono::Utc>,
}
Represents an application in the system.
pub struct ScaleRequest {
/// Number of instances to scale to
instances: i32,
/// Memory allocation in MB to scale to
memory: i32,
}
Request data for scaling an application.
pub struct AppStats {
/// CPU usage as a percentage
cpu_usage: f64,
/// Memory usage in bytes
memory_usage: i64,
/// Disk usage in bytes
disk_usage: i64,
/// Average number of requests per second
requests_per_second: f64,
/// Average response time in milliseconds
response_time_ms: i64,
}
Statistics for an application's resource usage and performance.
pub struct CreateAppRequest {
/// Name of the application
name: String,
/// Memory allocation in MB
memory: i64,
/// Number of instances
instances: i64,
/// Organization ID that owns the application
org_id: i64,
}
Request data for creating a new application.
pub struct UpdateAppRequest {
/// New name for the application
name: String,
/// New memory allocation in MB
memory: i64,
/// New number of instances
instances: i64,
/// Organization ID that owns the application
org_id: i64,
}
Request data for updating an existing application.
pub async fn list_apps(
page: Option<i64>,
per_page: Option<i64>,
pool: &State<sqlx::Pool<MySql>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
List all applications with pagination support.
-
page
- Required page number for pagination -
per_page
- Required number of items per page -
pool
- Database connection pool
A JSON array of applications or an error if pagination parameters are missing
pub async fn get_app_with_instances(
pool: &State<sqlx::Pool<MySql>>,
app_id: i64
) -> Result<Json<AppWithInstances>, (Status, Json<Value>)> {
// ... function body
}
Get app with instances
pub async fn count_apps(pool: &State<sqlx::Pool<MySql>>) -> Json<i64> {
let count = db::app::count_apps(pool).await.unwrap();
Count the total number of applications.
pub async fn get_app(app_id: i64, pool: &State<sqlx::Pool<MySql>>) -> Option<Json<App>> {
let app_result = db::app::get_app_by_id(pool, app_id).await;
Get a specific application by ID.
-
app_id
- The ID of the application to retrieve -
pool
- Database connection pool
The application if found, or None if not found
pub async fn create_app(
app_request: Json<CreateAppRequest>,
pool: &State<sqlx::Pool<MySql>>,
) -> Json<App> {
// ... function body
}
Create a new application.
-
app_request
- JSON data containing application details -
pool
- Database connection pool
The newly created application
pub async fn update_app(
app_request: Json<UpdateAppRequest>,
pool: &State<sqlx::Pool<MySql>>,
app_id: i64,
) -> Json<App> {
// ... function body
}
Update an existing application.
-
app_request
- JSON data containing updated application details -
pool
- Database connection pool -
app_id
- The ID of the application to update
The updated application
pub async fn get_app_stats(app_id: String, pool: &State<sqlx::Pool<MySql>>) -> Json<AppStats> {
let app_stats = AppStats {
// ... function body
}
Get statistics for a specific application.
-
app_id
- The ID of the application to get statistics for -
pool
- Database connection pool
Statistics for the application
pub async fn start_app(app_id: String) -> Option<Json<Application>> {
todo!()
}
/// Stop a specific application.
///
/// # Arguments
///
/// * `app_id` - The ID of the application to stop
///
/// # Returns
///
/// The updated application if found, or None if not found
#[put("/apps/<app_id>/stop")]
pub async fn stop_app(app_id: String) -> Option<Json<Application>> {
// ... function body
}
Start a specific application.
-
app_id
- The ID of the application to start
The updated application if found, or None if not found
pub async fn stop_app(app_id: String) -> Option<Json<Application>> {
todo!()
}
/// Scale a specific application.
///
/// # Arguments
///
/// * `app_id` - The ID of the application to scale
/// * `scale` - JSON data containing scaling parameters
///
/// # Returns
///
/// The updated application if found, or None if not found
#[put("/apps/<app_id>/scale", format = "json", data = "<scale>")]
pub async fn scale_app(app_id: String, scale: Json<ScaleRequest>) -> Option<Json<Application>> {
// ... function body
}
Stop a specific application.
-
app_id
- The ID of the application to stop
The updated application if found, or None if not found
pub async fn scale_app(app_id: String, scale: Json<ScaleRequest>) -> Option<Json<Application>> {
todo!()
}
/// Delete a specific application.
///
/// # Arguments
///
/// * `app_id` - The ID of the application to delete
/// * `pool` - Database connection pool
///
/// # Returns
///
/// A JSON response indicating success or an error message
#[delete("/apps/<app_id>")]
pub async fn delete_app(
app_id: String,
pool: &State<sqlx::Pool<MySql>>,
) -> Result<Json<Value>, (rocket::http::Status, String)> {
// ... function body
}
Scale a specific application.
-
app_id
- The ID of the application to scale -
scale
- JSON data containing scaling parameters
The updated application if found, or None if not found
pub async fn delete_app(
app_id: String,
pool: &State<sqlx::Pool<MySql>>,
) -> Result<Json<Value>, (rocket::http::Status, String)> {
// ... function body
}
Delete a specific application.
-
app_id
- The ID of the application to delete -
pool
- Database connection pool
A JSON response indicating success or an error message
pub async fn release(
app_id: String,
release_version: String,
content_type: &ContentType,
data: Data<'_>,
) -> Result<Status, Status> {
// ... function body
}