Skip to content

Commit

Permalink
feat(orchestrator): create zombie.json in base_dir (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepoviola authored Jul 16, 2024
1 parent 72be0de commit f628bb4
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 20 deletions.
1 change: 1 addition & 0 deletions crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ uuid = { workspace = true }
regex = { workspace = true }
glob-match = { workspace = true }
async-trait = { workspace = true }
serde = { workspace = true, features = ["derive"] }

# Zombienet deps
configuration = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/orchestrator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum OrchestratorError {
ProviderError(#[from] ProviderError),
#[error("FileSystem error")]
FileSystemError(#[from] FileSystemError),
#[error("Serialization error")]
SerializationError(#[from] serde_json::Error),
#[error(transparent)]
SpawnerError(#[from] anyhow::Error),
}
15 changes: 11 additions & 4 deletions crates/orchestrator/src/generators/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use provider::{
types::{GenerateFileCommand, GenerateFilesOptions, TransferedFile},
DynNamespace, ProviderError,
};
use serde::Serialize;
use serde_json::json;
use support::{constants::THIS_IS_A_BUG, fs::FileSystem, replacer::apply_replacements};
use tokio::process::Command;
Expand All @@ -22,7 +23,7 @@ use crate::{
};

// TODO: (javier) move to state
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub enum Context {
Relay,
Para,
Expand All @@ -39,7 +40,7 @@ enum KeyType {
Grandpa,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub enum CommandInContext {
Local(String),
Remote(String),
Expand All @@ -61,7 +62,7 @@ pub struct ParaGenesisConfig<T: AsRef<Path>> {
pub(crate) as_parachain: bool,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct ChainSpec {
// Name of the spec file, most of the times could be the same as the chain_name. (e.g rococo-local)
chain_spec_name: String,
Expand Down Expand Up @@ -774,10 +775,13 @@ fn get_runtime_config_pointer(chain_spec_json: &serde_json::Value) -> Result<Str

// Merge `patch_section` with `overrides`.
fn merge(patch_section: &mut serde_json::Value, overrides: &serde_json::Value) {
trace!("patch: {:?}", patch_section);
trace!("overrides: {:?}", overrides);
if let (Some(genesis_obj), Some(overrides_obj)) =
(patch_section.as_object_mut(), overrides.as_object())
{
for overrides_key in overrides_obj.keys() {
trace!("overrides_key: {:?}", overrides_key);
// we only want to override keys present in the genesis object
if let Some(genesis_value) = genesis_obj.get_mut(overrides_key) {
match (&genesis_value, overrides_obj.get(overrides_key)) {
Expand All @@ -789,9 +793,12 @@ fn merge(patch_section: &mut serde_json::Value, overrides: &serde_json::Value) {
},
// override if genesis value not an object
(_, Some(overrides_value)) => {
trace!("overriding: {:?} / {:?}", genesis_value, overrides_value);
*genesis_value = overrides_value.clone();
},
_ => {},
_ => {
trace!("not match!");
},
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/orchestrator/src/generators/para_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ use provider::{
types::{GenerateFileCommand, GenerateFilesOptions, TransferedFile},
DynNamespace,
};
use serde::Serialize;
use support::fs::FileSystem;
use uuid::Uuid;

use super::errors::GeneratorError;
use crate::ScopedFilesystem;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub(crate) enum ParaArtifactType {
Wasm,
State,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub(crate) enum ParaArtifactBuildOption {
Path(String),
Command(String),
}

/// Parachain artifact (could be either the genesis state or genesis wasm)
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct ParaArtifact {
artifact_type: ParaArtifactType,
build_option: ParaArtifactBuildOption,
Expand Down
7 changes: 6 additions & 1 deletion crates/orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,13 @@ where
Parachain::register(register_para_options, &scoped_fs).await?;
}

// - write zombie.json state file (we should defined in a way we can load later)
// - write zombie.json state file
let mut zombie_json = serde_json::to_value(&network)?;
zombie_json["local_base_dir"] = serde_json::value::Value::String(base_dir.to_string());

scoped_fs
.write("zombie.json", serde_json::to_string_pretty(&zombie_json)?)
.await?;
Ok(network)
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/orchestrator/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use configuration::{
ParachainConfig, ParachainConfigBuilder, RegistrationStrategy,
};
use provider::{types::TransferedFile, DynNamespace, ProviderError};
use serde::Serialize;
use support::fs::FileSystem;

use self::{node::NetworkNode, parachain::Parachain, relaychain::Relaychain};
Expand All @@ -25,12 +26,16 @@ use crate::{
ScopedFilesystem, ZombieRole,
};

#[derive(Serialize)]
pub struct Network<T: FileSystem> {
#[serde(skip)]
ns: DynNamespace,
#[serde(skip)]
filesystem: T,
relay: Relaychain,
initial_spec: NetworkSpec,
parachains: HashMap<u32, Parachain>,
#[serde(skip)]
nodes_by_name: HashMap<String, NetworkNode>,
}

Expand Down
5 changes: 4 additions & 1 deletion crates/orchestrator/src/network/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use glob_match::glob_match;
use prom_metrics_parser::MetricMap;
use provider::DynNode;
use regex::Regex;
use serde::Serialize;
use subxt::{backend::rpc::RpcClient, OnlineClient};
use support::net::wait_ws_ready;
use thiserror::Error;
Expand All @@ -21,15 +22,17 @@ pub enum NetworkNodeError {
MetricNotFound(String),
}

#[derive(Clone)]
#[derive(Clone, Serialize)]
pub struct NetworkNode {
#[serde(skip)]
pub(crate) inner: DynNode,
// TODO: do we need the full spec here?
// Maybe a reduce set of values.
pub(crate) spec: NodeSpec,
pub(crate) name: String,
pub(crate) ws_uri: String,
pub(crate) prometheus_uri: String,
#[serde(skip)]
metrics_cache: Arc<RwLock<MetricMap>>,
}

Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/network/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
};

use provider::types::TransferedFile;
use serde::Serialize;
use subxt::{dynamic::Value, tx::TxStatus, OnlineClient, SubstrateConfig};
use subxt_signer::{sr25519::Keypair, SecretUri};
use support::{constants::THIS_IS_A_BUG, fs::FileSystem};
Expand All @@ -17,7 +18,7 @@ use crate::{
ScopedFilesystem,
};

#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct Parachain {
pub(crate) chain: Option<String>,
pub(crate) para_id: u32,
Expand Down
4 changes: 3 additions & 1 deletion crates/orchestrator/src/network/relaychain.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::path::PathBuf;

use serde::Serialize;

use super::node::NetworkNode;

#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct Relaychain {
pub(crate) chain: String,
pub(crate) chain_id: String,
Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/network_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
use configuration::{GlobalSettings, HrmpChannelConfig, NetworkConfig};
use futures::future::try_join_all;
use provider::{DynNamespace, ProviderError, ProviderNamespace};
use serde::Serialize;
use support::{constants::THIS_IS_A_BUG, fs::FileSystem};
use tracing::debug;

Expand All @@ -17,7 +18,7 @@ pub mod relaychain;

use self::{node::NodeSpec, parachain::ParachainSpec, relaychain::RelaychainSpec};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct NetworkSpec {
/// Relaychain configuration.
pub(crate) relaychain: RelaychainSpec,
Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/network_spec/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use configuration::shared::{
};
use multiaddr::Multiaddr;
use provider::types::Port;
use serde::{Deserialize, Serialize};
use support::constants::THIS_IS_A_BUG;

use crate::{
Expand Down Expand Up @@ -44,7 +45,7 @@ impl_from_for_add_node_opts!(AddNodeOptions);
impl_from_for_add_node_opts!(AddCollatorOptions);

/// A node configuration, with fine-grained configuration options.
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct NodeSpec {
// Node name (should be unique or an index will be appended).
pub(crate) name: String,
Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/network_spec/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use configuration::{
ParachainConfig, RegistrationStrategy,
};
use provider::DynNamespace;
use serde::Serialize;
use support::{fs::FileSystem, replacer::apply_replacements};
use tracing::debug;

Expand All @@ -20,7 +21,7 @@ use crate::{
ScopedFilesystem,
};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct ParachainSpec {
// `name` of the parachain (used in some corner cases)
// name: Option<Chain>,
Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/network_spec/relaychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use configuration::{
},
RelaychainConfig,
};
use serde::Serialize;
use support::replacer::apply_replacements;

use super::node::NodeSpec;
Expand All @@ -17,7 +18,7 @@ use crate::{
};

/// A relaychain configuration spec
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct RelaychainSpec {
/// Chain to use (e.g. rococo-local).
pub(crate) chain: Chain,
Expand Down
12 changes: 8 additions & 4 deletions crates/orchestrator/src/shared/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use configuration::shared::{
resources::Resources,
types::{Arg, AssetLocation, Command, Image, Port},
};
use serde::{Deserialize, Serialize};

pub type Accounts = HashMap<String, NodeAccount>;

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NodeAccount {
pub address: String,
pub public_key: String,
Expand All @@ -27,14 +28,17 @@ impl NodeAccount {
}
}

#[derive(Debug, Clone, Default, PartialEq)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct NodeAccounts {
pub(crate) seed: String,
pub(crate) accounts: Accounts,
}

#[derive(Clone, Default, Debug)]
pub struct ParkedPort(pub(crate) Port, pub(crate) Arc<RwLock<Option<TcpListener>>>);
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub struct ParkedPort(
pub(crate) Port,
#[serde(skip)] pub(crate) Arc<RwLock<Option<TcpListener>>>,
);

impl ParkedPort {
pub(crate) fn new(port: u16, listener: TcpListener) -> ParkedPort {
Expand Down
3 changes: 2 additions & 1 deletion crates/provider/src/shared/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use configuration::{shared::resources::Resources, types::AssetLocation};
use serde::Serialize;

pub type Port = u16;

Expand Down Expand Up @@ -321,7 +322,7 @@ impl RunScriptOptions {
}

// TODO(team): I think we can rename it to FileMap?
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct TransferedFile {
pub local_path: PathBuf,
pub remote_path: PathBuf,
Expand Down

0 comments on commit f628bb4

Please sign in to comment.