robotrt-cli 0.1.0-beta.2

RobotRT modular robotics runtime and middleware components.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fs;
use std::path::{Path, PathBuf};

use introspection_core::StatusSnapshot;
use obs_core::{MetricsAggregator, export_otel_json_value, export_prometheus_text};
use replay_core::FileReplaySession;

use crate::constants::{DEFAULT_BAG_PATH, DEFAULT_STATUS_REPORT_PATH};
use crate::helpers::{has_flag, option_value, parse_u64_option};
use crate::gateway::STATUS_SERVICE_NAME;

mod commands {
    mod diff_replay;
    mod fleet_profile;
    mod snapshot_console;

    pub(super) fn ops_snapshot(args: &[String]) -> Result<(), String> {
        snapshot_console::ops_snapshot(args)
    }

    pub(super) fn ops_console(args: &[String]) -> Result<(), String> {
        snapshot_console::ops_console(args)
    }

    pub(super) fn ops_diff(args: &[String]) -> Result<(), String> {
        diff_replay::ops_diff(args)
    }

    pub(super) fn ops_replay(args: &[String]) -> Result<(), String> {
        diff_replay::ops_replay(args)
    }

    pub(super) fn ops_fleet(args: &[String]) -> Result<(), String> {
        fleet_profile::ops_fleet(args)
    }

    pub(super) fn ops_profile(args: &[String]) -> Result<(), String> {
        fleet_profile::ops_profile(args)
    }
}

mod helpers {
    use super::*;

    mod console;
    mod diff;
    mod fleet_analysis;
    mod profile;
    mod source;

    pub(super) use console::*;
    pub(super) use diff::*;
    pub(super) use fleet_analysis::*;
    pub(super) use profile::*;
    pub(super) use source::*;
}

mod policy;

use self::helpers::*;
use self::policy::{AlertPolicy, parse_alert_policy, parse_profile_template};

const OPS_SNAPSHOT_API_VERSION: &str = "robotrt.ops.snapshot.v1";
const OPS_CONSOLE_API_VERSION: &str = "robotrt.ops.console.v1";
const OPS_DIFF_API_VERSION: &str = "robotrt.ops.diff.v1";
const OPS_REPLAY_API_VERSION: &str = "robotrt.ops.replay.v1";
const OPS_FLEET_API_VERSION: &str = "robotrt.ops.fleet.v1";
const OPS_PROFILE_API_VERSION: &str = "robotrt.ops.profile.v1";
const DEFAULT_OPS_CONSOLE_PATH: &str = "artifacts/ops/console.html";

type OpsSource = super::snapshot_shared::SnapshotSource;

#[derive(Clone)]
struct OpsAlert {
    severity: String,
    component: String,
    message: String,
}

#[derive(Clone, Default)]
struct FleetTotals {
    instances: usize,
    nodes: usize,
    topics: usize,
    services: usize,
    actions: usize,
    missions: usize,
    plugins_loaded: usize,
    alerts: usize,
    healthy_instances: usize,
    degraded_instances: usize,
    unhealthy_instances: usize,
    local_reliable_subscribers: usize,
    local_reliable_acked_subscribers: usize,
    remote_reliable_subscribers: usize,
    remote_reliable_acked_subscribers: usize,
}

pub fn ops_snapshot(args: &[String]) -> Result<(), String> {
    commands::ops_snapshot(args)
}

pub fn ops_console(args: &[String]) -> Result<(), String> {
    commands::ops_console(args)
}

pub fn ops_diff(args: &[String]) -> Result<(), String> {
    commands::ops_diff(args)
}

pub fn ops_replay(args: &[String]) -> Result<(), String> {
    commands::ops_replay(args)
}

pub fn ops_fleet(args: &[String]) -> Result<(), String> {
    commands::ops_fleet(args)
}

pub fn ops_profile(args: &[String]) -> Result<(), String> {
    commands::ops_profile(args)
}