Skip to content

Commit

Permalink
autodeploy: add force redeploy flag (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
justprosh committed Jul 27, 2021
1 parent 60c3744 commit cb2c8d9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
29 changes: 24 additions & 5 deletions crates/builtins-deployer/src/builtins_deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub struct BuiltinsDeployer {
call_service_out: Arc<Mutex<Vec<JValue>>>,
builtins_base_dir: PathBuf,
particle_ttl: Duration,
// if set to true, remove existing builtins before deploying
force_redeploy: bool,
}

fn assert_ok(result: Vec<JValue>, err_msg: &str) -> eyre::Result<()> {
Expand Down Expand Up @@ -182,6 +184,7 @@ impl BuiltinsDeployer {
node_api: AquamarineApi,
base_dir: PathBuf,
particle_ttl: Duration,
force_redeploy: bool,
) -> Self {
let call_in = Arc::new(Mutex::new(hashmap! {}));
let call_out = Arc::new(Mutex::new(vec![]));
Expand All @@ -197,6 +200,7 @@ impl BuiltinsDeployer {
call_service_out: call_out,
builtins_base_dir: base_dir,
particle_ttl,
force_redeploy,
}
}

Expand Down Expand Up @@ -359,20 +363,35 @@ impl BuiltinsDeployer {

pub fn deploy_builtin_services(&mut self) -> Result<()> {
let from_disk = self.list_builtins()?;
let local_services = self.get_service_blueprints()?;
let mut local_services = self.get_service_blueprints()?;

let mut to_create = vec![];
let mut to_start = vec![];

// if force_redeploy is set, then first remove all builtins
if self.force_redeploy {
for builtin in from_disk.iter() {
if local_services.contains_key(&builtin.name) {
self.remove_service(builtin.name.clone())?;
local_services.remove(&builtin.name);
}
}
}

for builtin in from_disk.iter() {
// check if builtin is already deployed
match local_services.get(&builtin.name) {
Some(id) if *id == builtin.blueprint_id => {
to_start.push(builtin);
}
Some(_) => {
// already deployed
// if blueprint_id has changed, then redeploy builtin
Some(bp_id) if *bp_id != builtin.blueprint_id => {
self.remove_service(builtin.name.clone())?;
to_create.push(builtin)
}
// already deployed with expected blueprint_id
Some(_) => {
to_start.push(builtin);
}
// isn't deployed yet
None => to_create.push(builtin),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/created-swarm/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ where
stepper,
builtins_dir,
Duration::from_millis(PARTICLE_TTL as u64),
false,
);

builtin_loader
Expand Down
4 changes: 4 additions & 0 deletions crates/server-config/src/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub struct NodeConfig {
#[serde(with = "humantime_serde")]
pub autodeploy_particle_ttl: Duration,

/// Affects builtins autodeploy. If set to true, then all builtins should be recreated and their state is cleaned up.
#[serde(default)]
pub force_builtins_redeploy: bool,

/// For TCP connections
#[serde(default = "default_tcp_port")]
pub tcp_port: u16,
Expand Down
3 changes: 2 additions & 1 deletion particle-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fn start_fluence(config: ResolvedConfig) -> eyre::Result<impl Stoppable> {

let startup_peer_id = to_peer_id(&config.builtins_key_pair.clone().into());
let autodeploy_particle_ttl = config.node_config.autodeploy_particle_ttl;
let force_builtins_redeploy = config.node_config.force_builtins_redeploy;
let listen_addrs = config.listen_config().multiaddrs;
let mut node = Node::new(config, startup_peer_id).wrap_err("error create node instance")?;
node.listen(listen_addrs).wrap_err("error on listen")?;
Expand All @@ -132,8 +133,8 @@ fn start_fluence(config: ResolvedConfig) -> eyre::Result<impl Stoppable> {
aquamarine_api,
builtins_dir,
autodeploy_particle_ttl,
force_builtins_redeploy,
);

// TODO: start deploy after AquamarineVMs are started
builtin_deployer
.deploy_builtin_services()
Expand Down

0 comments on commit cb2c8d9

Please sign in to comment.