schemas_v1_api_apps - OmniCloudOrg/OmniOrchestrator GitHub Wiki
Path: src/schemas/v1/api/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
- async fn list_instances
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(
platform_id: i64,
page: Option<i64>,
per_page: Option<i64>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
List all applications with pagination support.
-
platform_id
- Platform identifier -
page
- Required page number for pagination -
per_page
- Required number of items per page -
db_manager
- Database manager for accessing platform-specific pools
A JSON array of applications or an error if pagination parameters are missing
pub async fn get_app_with_instances(
db_manager: &State<Arc<DatabaseManager>>,
platform_id: i64,
app_id: i64
) -> Result<Json<AppWithInstances>, (Status, Json<Value>)> {
// ... function body
}
Get app with instances
pub async fn count_apps(
platform_id: i64,
db_manager: &State<Arc<DatabaseManager>>
) -> Result<Json<i64>, (Status, Json<Value>)> {
// ... function body
}
Count the total number of applications.
pub async fn get_app(
platform_id: i64,
app_id: i64,
db_manager: &State<Arc<DatabaseManager>>
) -> Result<Json<App>, (Status, Json<Value>)> {
// ... function body
}
Get a specific application by ID.
-
platform_id
- Platform identifier -
app_id
- The ID of the application to retrieve -
db_manager
- Database manager for accessing platform-specific pools
The application if found, or None if not found
pub async fn create_app(
platform_id: i64,
app_request: Json<CreateAppRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<App>, (Status, Json<Value>)> {
// ... function body
}
Create a new application.
-
platform_id
- Platform identifier -
app_request
- JSON data containing application details -
db_manager
- Database manager for accessing platform-specific pools
The newly created application
pub async fn update_app(
platform_id: i64,
app_request: Json<UpdateAppRequest>,
db_manager: &State<Arc<DatabaseManager>>,
app_id: i64,
) -> Result<Json<App>, (Status, Json<Value>)> {
// ... function body
}
Update an existing application.
-
platform_id
- Platform identifier -
app_request
- JSON data containing updated application details -
db_manager
- Database manager for accessing platform-specific pools -
app_id
- The ID of the application to update
The updated application
pub async fn get_app_stats(
platform_id: i64,
app_id: String,
db_manager: &State<Arc<DatabaseManager>>
) -> Result<Json<AppStats>, (Status, Json<Value>)> {
// ... function body
}
Get statistics for a specific application.
-
platform_id
- Platform identifier -
app_id
- The ID of the application to get statistics for -
db_manager
- Database manager for accessing platform-specific pools
Statistics for the application
pub async fn start_app(
platform_id: i64,
app_id: String,
db_manager: &State<Arc<DatabaseManager>>
) -> Result<Json<Application>, (Status, Json<Value>)> {
// ... function body
}
Start a specific application.
-
platform_id
- Platform identifier -
app_id
- The ID of the application to start -
db_manager
- Database manager for accessing platform-specific pools
The updated application if found, or None if not found
pub async fn stop_app(
platform_id: i64,
app_id: String,
db_manager: &State<Arc<DatabaseManager>>
) -> Result<Json<Application>, (Status, Json<Value>)> {
// ... function body
}
Stop a specific application.
-
platform_id
- Platform identifier -
app_id
- The ID of the application to stop -
db_manager
- Database manager for accessing platform-specific pools
The updated application if found, or None if not found
pub async fn scale_app(
platform_id: i64,
app_id: String,
scale: Json<ScaleRequest>,
db_manager: &State<Arc<DatabaseManager>>
) -> Result<Json<Application>, (Status, Json<Value>)> {
// ... function body
}
Scale a specific application.
-
platform_id
- Platform identifier -
app_id
- The ID of the application to scale -
scale
- JSON data containing scaling parameters -
db_manager
- Database manager for accessing platform-specific pools
The updated application if found, or None if not found
pub async fn delete_app(
platform_id: i64,
app_id: String,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
Delete a specific application.
-
platform_id
- Platform identifier -
app_id
- The ID of the application to delete -
db_manager
- Database manager for accessing platform-specific pools
A JSON response indicating success or an error message
pub async fn release(
platform_id: i64,
app_id: String,
release_version: String,
content_type: &ContentType,
data: Data<'_>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Status, Status> {
// ... function body
}
pub async fn list_instances(
platform_id: i64,
app_id: i64,
page: Option<i64>,
per_page: Option<i64>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}