Skip to content

Commit

Permalink
osrdyne: add process-compose driver
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Valais <[email protected]>
  • Loading branch information
leovalais committed Sep 9, 2024
1 parent 3eecd56 commit 23edcec
Show file tree
Hide file tree
Showing 11 changed files with 467 additions and 10 deletions.
11 changes: 11 additions & 0 deletions osrdyne/configuration_templates/process-compose-driver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
worker_driver:
type: ProcessComposeDriver
address: localhost
port: 8080 # process-compose sets it to 8080 by default, better change it...
process: core # the process name to scale

# Files to write the content of the osrdyne environment variables
comm_files:
worker_id: /tmp/worker_id # WORKER_ID
worker_key: /tmp/worker_key # WORKER_KEY
amqp_uri: /tmp/worker_amqp_uri # WORKER_AMQP_URI
37 changes: 37 additions & 0 deletions osrdyne/configuration_templates/process-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "0.5"
is_strict: true

environment:
- "CORE_EDITOAST_URL=http://localhost:8090"
- "JAVA_TOOL_OPTIONS=-javaagent:$HOME/opentelemetry-javaagent.jar" # edit this path
- "CORE_MONITOR_TYPE=opentelemetry"
- "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc"
- "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4317"
- "OTEL_METRICS_EXPORTER=none"
- "OTEL_LOGS_EXPORTER=none"

processes:
core:
# Disabled by default (started by osrdyne, only the templating matters).
# The osrdyne env variables are read from the files specified in the driver configuration.
command: |
(
export WORKER_ID=$(cat /tmp/worker_id);
export WORKER_KEY=$(cat /tmp/worker_key);
export WORKER_AMQP_URI="$(cat /tmp/worker_amqp_uri);"
java $$JAVA_OPTS -ea -jar build/libs/osrd-all.jar worker
)
working_dir: "$OSRD_PATH/core"
disabled: true
gateway:
command: cargo run
working_dir: "$OSRD_PATH/gateway"
editoast:
command: cargo run runserver
working_dir: "$OSRD_PATH/editoast"
front:
command: yarn start
working_dir: "$OSRD_PATH/front"
osrdyne:
command: cargo run
working_dir: "$OSRD_PATH/osrdyne"
6 changes: 5 additions & 1 deletion osrdyne/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::time::Duration;

use crate::drivers::{docker::DockerDriverOptions, kubernetes::KubernetesDriverOptions};
use crate::drivers::{
docker::DockerDriverOptions, kubernetes::KubernetesDriverOptions,
process_compose::PCDriverOptions,
};
use serde::{Deserialize, Serialize};

use figment::{
Expand All @@ -14,6 +17,7 @@ pub enum WorkerDriverConfig {
Noop,
DockerDriver(DockerDriverOptions),
KubernetesDriver(KubernetesDriverOptions),
ProcessComposeDriver(PCDriverOptions),
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
1 change: 1 addition & 0 deletions osrdyne/src/drivers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod docker;
pub mod kubernetes;
pub mod noop;
pub mod process_compose;
pub mod worker_driver;

const LABEL_MANAGED_BY: &str = "osrd/managed_by";
Expand Down
4 changes: 2 additions & 2 deletions osrdyne/src/drivers/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl DockerDriver {

impl WorkerDriver for DockerDriver {
fn get_or_create_worker_group(
&self,
&mut self,
worker_key: Key,
) -> Pin<Box<dyn Future<Output = Result<Uuid, DriverError>> + Send + '_>> {
Box::pin(async move {
Expand Down Expand Up @@ -140,7 +140,7 @@ impl WorkerDriver for DockerDriver {
}

fn destroy_worker_group(
&self,
&mut self,
worker_key: Key,
) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + '_>> {
Box::pin(async move {
Expand Down
4 changes: 2 additions & 2 deletions osrdyne/src/drivers/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl KubernetesDriver {

impl WorkerDriver for KubernetesDriver {
fn get_or_create_worker_group(
&self,
&mut self,
worker_key: Key,
) -> Pin<Box<dyn Future<Output = Result<Uuid, DriverError>> + Send + '_>> {
Box::pin(async move {
Expand Down Expand Up @@ -245,7 +245,7 @@ impl WorkerDriver for KubernetesDriver {
}

fn destroy_worker_group(
&self,
&mut self,
worker_key: Key,
) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + '_>> {
Box::pin(async move {
Expand Down
4 changes: 2 additions & 2 deletions osrdyne/src/drivers/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ impl NoopDriver {

impl WorkerDriver for NoopDriver {
fn get_or_create_worker_group(
&self,
&mut self,
_worker_key: Key,
) -> Pin<Box<dyn Future<Output = Result<Uuid, DriverError>> + Send + '_>> {
Box::pin(async move { Ok(self.fixed_pool_id) })
}

fn destroy_worker_group(
&self,
&mut self,
_worker_key: Key,
) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + '_>> {
Box::pin(async move { Ok(()) })
Expand Down
Loading

0 comments on commit 23edcec

Please sign in to comment.