api_v1_apps - OmniCloudOrg/OmniOrchestrator GitHub Wiki

apps (src/api/v1)

Path: src/api/v1/apps.rs

Module Documentation

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

Table of Contents

Public Items

struct Application

Definition

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>,
}

Documentation

Represents an application in the system.

struct ScaleRequest

Definition

pub struct ScaleRequest {
    /// Number of instances to scale to
    instances: i32,
    /// Memory allocation in MB to scale to
    memory: i32,
}

Documentation

Request data for scaling an application.

struct AppStats

Definition

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,
}

Documentation

Statistics for an application's resource usage and performance.

struct CreateAppRequest

Definition

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,
}

Documentation

Request data for creating a new application.

struct UpdateAppRequest

Definition

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,
}

Documentation

Request data for updating an existing application.

async fn list_apps

Definition

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
}

Documentation

List all applications with pagination support.

Arguments
  • page - Required page number for pagination
  • per_page - Required number of items per page
  • pool - Database connection pool
Returns

A JSON array of applications or an error if pagination parameters are missing

async fn get_app_with_instances

Definition

pub async fn get_app_with_instances(
    pool: &State<sqlx::Pool<MySql>>, 
    app_id: i64
) -> Result<Json<AppWithInstances>, (Status, Json<Value>)> {
    // ... function body
}

Documentation

Get app with instances

async fn count_apps

Definition

pub async fn count_apps(pool: &State<sqlx::Pool<MySql>>) -> Json<i64> {
    let count = db::app::count_apps(pool).await.unwrap();

Documentation

Count the total number of applications.

async fn get_app

Definition

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;

Documentation

Get a specific application by ID.

Arguments
  • app_id - The ID of the application to retrieve
  • pool - Database connection pool
Returns

The application if found, or None if not found

async fn create_app

Definition

pub async fn create_app(
    app_request: Json<CreateAppRequest>,
    pool: &State<sqlx::Pool<MySql>>,
) -> Json<App> {
    // ... function body
}

Documentation

Create a new application.

Arguments
  • app_request - JSON data containing application details
  • pool - Database connection pool
Returns

The newly created application

async fn update_app

Definition

pub async fn update_app(
    app_request: Json<UpdateAppRequest>,
    pool: &State<sqlx::Pool<MySql>>,
    app_id: i64,
) -> Json<App> {
    // ... function body
}

Documentation

Update an existing application.

Arguments
  • app_request - JSON data containing updated application details
  • pool - Database connection pool
  • app_id - The ID of the application to update
Returns

The updated application

async fn get_app_stats

Definition

pub async fn get_app_stats(app_id: String, pool: &State<sqlx::Pool<MySql>>) -> Json<AppStats> {
    let app_stats = AppStats {
    // ... function body
}

Documentation

Get statistics for a specific application.

Arguments
  • app_id - The ID of the application to get statistics for
  • pool - Database connection pool
Returns

Statistics for the application

async fn start_app

Definition

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
}

Documentation

Start a specific application.

Arguments
  • app_id - The ID of the application to start
Returns

The updated application if found, or None if not found

async fn stop_app

Definition

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
}

Documentation

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

async fn scale_app

Definition

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
}

Documentation

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

async fn delete_app

Definition

pub async fn delete_app(
    app_id: String,
    pool: &State<sqlx::Pool<MySql>>,
) -> Result<Json<Value>, (rocket::http::Status, String)> {
    // ... function body
}

Documentation

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

async fn release

Definition

pub async fn release(
    app_id: String,
    release_version: String,
    content_type: &ContentType,
    data: Data<'_>,
) -> Result<Status, Status> {
    // ... function body
}
⚠️ **GitHub.com Fallback** ⚠️