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

ref-enum-types #115

Merged
merged 5 commits into from
Jan 2, 2025
Merged
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
379 changes: 210 additions & 169 deletions Cargo.lock

Large diffs are not rendered by default.

42 changes: 3 additions & 39 deletions aquila/src/configuration/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::configuration::mode::Mode;
use dotenv::from_filename;
use log::{error, info};
use std::env;
use std::fmt::{Debug, Display};
use std::str::FromStr;

/// Struct for all relevant `Aquila` startup configurations
Expand All @@ -21,18 +20,12 @@ pub struct Config {
/// Options:
/// `static` (default)
/// `hybrid`
/// `dynamic`
pub mode: Mode,

/// URL to the Redis Server.
/// Default none
pub redis_url: String,

/// Interval for `Aquila` to ask `Sagittarius` about updated flows.
/// Unit: `Seconds`
/// Default: 3600 seconds => 1 hour
pub update_schedule_interval: u32,

/// Fallback file to load flows if gRPC & scheduling is disabled.
pub flow_fallback_path: String,

Expand All @@ -59,7 +52,6 @@ impl Config {
environment: Self::get_environment("ENVIRONMENT", Environment::Development),
mode: Self::get_mode("MODE", Mode::STATIC),
redis_url: Self::get_string("REDIS_URL", "redis://redis:6379"),
update_schedule_interval: Self::get_u32("UPDATE_SCHEDULE_INTERVAL", 3600),
flow_fallback_path: Self::get_string(
"FLOW_FALLBACK_PATH",
"configuration/configuration.json",
Expand All @@ -70,48 +62,20 @@ impl Config {
}

fn get_environment(key: &str, default: Environment) -> Environment {
let value = match env::var(key) {
Ok(result) => {
info!("Env. {} was found", key);
result
}
Err(_) => {
error!("Env. {} was not found", key);
return default;
}
};

Environment::from_str(&value)
Self::get_env_with_default(key, default)
}

fn get_mode(key: &str, default: Mode) -> Mode {
let value = match env::var(key) {
Ok(result) => {
info!("Env. {} was found", key);
result
}
Err(_) => {
error!("Env. {} was not found", key);
return default;
}
};

Mode::from_str(&value)
Self::get_env_with_default(key, default)
}

fn get_string(key: &str, default: &str) -> String {
Self::get_env_with_default(key, String::from(default))
}

fn get_u32(key: &str, default: u32) -> u32 {
Self::get_env_with_default(key, default)
}

pub fn get_env_with_default<T>(name: &str, default: T) -> T
where
T: FromStr,
T: Display,
T: Debug,
{
let env_variable = match env::var(name) {
Ok(result) => {
Expand All @@ -135,7 +99,7 @@ impl Config {
}
};

info!("Env. variable {} was set to the value: {:?}", name, result);
info!("Env. variable {} was set to the value", name);
result
}
}
19 changes: 12 additions & 7 deletions aquila/src/configuration/environment.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use std::str::FromStr;

pub enum Environment {
Development,
Staging,
Production,
}

impl Environment {
pub(crate) fn from_str(env: &str) -> Self {
match env.to_lowercase().as_str() {
"staging" => Environment::Staging,
"production" => Environment::Production,
_ => Environment::Development,
impl FromStr for Environment {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"staging" => Ok(Environment::Staging),
"production" => Ok(Environment::Production),
"development" => Ok(Environment::Development),
_ => Err(())
}
}
}
}
19 changes: 10 additions & 9 deletions aquila/src/configuration/mode.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use std::str::FromStr;

/// Aquila Startup-Mode
///
/// STATIC:
/// Aquila will start from configuration file
///
/// DYNAMIC:
/// Aquila will be updated by releases (via request scheduler)
///
/// HYBRID
/// Aquila will be updated by updates (via stream)
pub enum Mode {
STATIC,
DYNAMIC,
}

impl Mode {
pub(crate) fn from_str(string: &str) -> Mode {
match string.to_lowercase().as_str() {
"static" => Mode::STATIC,
"dynamic" => Mode::DYNAMIC,
_ => Mode::STATIC,
impl FromStr for Mode {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"static" => Ok(Mode::STATIC),
"dynamic" => Ok(Mode::DYNAMIC),
_ => Err(()),
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions aquila/src/server/action/action_server.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::pin::Pin;
use std::sync::Arc;
use crate::service::action_service::{ActionService, ActionServiceBase};
use async_trait::async_trait;
use futures::Stream;
use std::pin::Pin;
use std::sync::Arc;
use tokio::sync::Mutex;
use tonic::{Request, Response, Status, Streaming};
use tucana::aquila::action_transfer_service_server::ActionTransferService;
use tucana::aquila::{ActionExecuteRequest, ActionExecuteResponse, InformationRequest, InformationResponse};
use crate::service::action_service::{ActionService, ActionServiceBase};
use tucana::aquila::{
ActionExecuteRequest, ActionExecuteResponse, InformationRequest, InformationResponse,
};

pub struct ActionTransferServerBase {
action_service: Arc<Mutex<ActionServiceBase>>,
Expand All @@ -16,14 +18,20 @@ pub struct ActionTransferServerBase {
#[async_trait]
impl ActionTransferService for ActionTransferServerBase {
/// Transfers `Flows` redivided from the `Action` to `Sagittarius`
async fn transfer(&self, request: Request<Streaming<InformationRequest>>) -> Result<Response<InformationResponse>, Status> {
async fn transfer(
&self,
request: Request<Streaming<InformationRequest>>,
) -> Result<Response<InformationResponse>, Status> {
let mut service = self.action_service.lock().await;
service.transfer_action_flows(request).await
}

type ExecuteStream = Pin<Box<dyn Stream<Item=Result<ActionExecuteResponse, Status>> + Send>>;
type ExecuteStream = Pin<Box<dyn Stream<Item = Result<ActionExecuteResponse, Status>> + Send>>;

async fn execute(&self, _: Request<Streaming<ActionExecuteRequest>>) -> Result<Response<Self::ExecuteStream>, Status> {
async fn execute(
&self,
_: Request<Streaming<ActionExecuteRequest>>,
) -> Result<Response<Self::ExecuteStream>, Status> {
todo!()
}
}
}
42 changes: 42 additions & 0 deletions docs/content/dev/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Develop Aquila
---

# Develop Aquila

## Requirements

To contribute to Aquila's development, you need the following expertise and tools:

- **Advanced Rust Knowledge**: Proficient in Rust programming, including complex abstractions and performance optimizations.
- **Experience with gRPC**: Familiarity with building and consuming gRPC services.
- **Redis & RabbitMQ**: Understanding of setting up and using Redis and RabbitMQ for messaging and caching.

---

## Setting Up a Local Development Environment

Choose between a manual setup or using a pre-configured development container.

### Manual Setup

1. **Install Rust and Cargo**
Install the latest versions of Rust and its package manager, Cargo. Use [Rustup](https://rustup.rs/) for an easy installation.
2. **Set Up Local Redis and RabbitMQ Services**
- Install Redis and RabbitMQ on your local machine.
- Ensure both services are running and accessible.

### Using a Development Container

1. Set up a development container with all required dependencies pre-installed (details to be provided).
2. Ensure your container runtime (e.g., Docker) is installed and running.
3. Open the project in a compatible IDE like Visual Studio Code, and select the dev-container configuration to start development.

---

## Additional Notes

- Ensure all dependencies are compatible with the version of Aquila you are working on.
- Use the provided `.env` file as a reference for setting up your environment variables.

---
11 changes: 7 additions & 4 deletions docs/content/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ description: Find out how Aquila works
template: splash
---

import { Card, CardGrid } from '@astrojs/starlight/components';
import {Card, CardGrid} from '@astrojs/starlight/components';

<CardGrid stagger>
<Card title='<a href="setup/setup.md">Setup</a>' icon="document">
View the setup guide for aquila.
</Card>
<Card title='<a href="setup/setup.md">Setup</a>' icon="document">
View the setup guide for aquila.
</Card>
<Card title='<a href="dev/dev.md">Develop</a>' icon="rust">
Development for aquila.
</Card>
</CardGrid>
71 changes: 55 additions & 16 deletions docs/content/setup/setup.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
---
title: Setup
title: Aquila Setup Guide
---

# Environment Variables

| Name | Description | Default |
|----------------------------|------------------------------------------------------------------------------|---------|
| `SESSION_TOKEN` | Session token for authenticated communication between Aquila and Sagittarius | |
| `BACKEND_HOST` | Hostname of the running Sagittarius | |
| `BACKEND_PORT` | Port of the running Sagittarius instance | |
| `RABBITMQ_HOST` | Hostname of the running RabbitMQ instance | |
| `RABBITMQ_PORT` | Port of the running RabbitMQ instance | |
| `RABBITMQ_USER` | Username of the running RabbitMQ instance | |
| `RABBITMQ_PASSWORD` | Password of the running RabbitMQ instance | |
| `REDIS_URL` | URL for the running Redis instance | |
| `ENABLE_SCHEDULED_UPDATE` | If Aquila should retrieve flows from the Backend | true |
| `UPDATE_SCHEDULE_INTERVAL` | The given interval in that the flows will be retrieve | 180 |
| `ENABLE_GRPC_UPDATE` | If the backend should be permitted to send update/deletion request for flows | true |
# Aquila Setup Guide

Follow this guide to set up Aquila.

---

## Setup Options

### Using Docker

1. **Pull the Docker Image**
Pull the latest Docker image from `<image-registry-url>`.
2. **Configure Environment Variables**
Set up the necessary environment variables in a `.env` file (see [Environment Variables](#environment-variables)
section).
3. **Start the Application**
Run the Docker container using the appropriate command.

### Manual Installation

1. **Download the Latest Binary**
Download the latest Aquila binary from https://github.com/code0-tech/aquila/releases.
2. **Set Up Environment Variables**
Configure the `.env` file in the root folder with the required settings.
3. **Ensure Required Services Are Running**
- **Redis**: Ensure a Redis instance is reachable.
- **RabbitMQ**: Ensure a RabbitMQ instance is also reachable.
4. **Start the Application**
Execute the binary to start Aquila.

---

## Environment Variables

Below is a list of required environment variables for configuring Aquila:

| Name | Description | Default |
|----------------------|------------------------------------------------------------------------------------------------------------------------------------|---------|
| `MODE` | Specifies the application mode. `Static`: Startup using a flow file & `Dynamic`: Startup and continuously update from Sagittarius. | |
| `ENVIRONMENT` | Defines the application environment for logging and debugging (e.g., `development`, `production`). | |
| `REDIS_URL` | The URL of the Redis instance Aquila connects to. | |
| `BACKEND_URL` | The URL of the Sagittarius instance Aquila communicates with. | |
| `FLOW_FALLBACK_PATH` | Path to the flow file used for static configuration in `Static` mode. | |
| `SESSION_TOKEN` | A session token for authenticated communication between Aquila and Sagittarius. | |

---

### Notes

- Ensure that all required services (Redis, RabbitMQ, Sagittarius) are properly configured and accessible before
starting Aquila.
- If using Docker, remember to map necessary ports and volumes based on your deployment requirements.

---
Loading