-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds a new 'Inject' protocol for injecting rumors without being a member * Adds a new config_file and config_file_list, for tracking configuration files shared by gossip * Writes out any files for our service group, and runs a new file_updated hook when they are updated * Changes the hook display output to use the hook name as the preamble * If the file is named 'gossip.toml', we wire it through to the service configuration, re-ender our hooks, and execute the reconfigure hook.
- Loading branch information
Showing
15 changed files
with
773 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright:: Copyright (c) 2015-2016 Chef Software, Inc. | ||
// | ||
// The terms of the Evaluation Agreement (Bldr) between Chef Software Inc. and the party accessing | ||
// this file ("Licensee") apply to Licensee's use of the Software until such time that the Software | ||
// is made available under an open source license such as the Apache 2.0 License. | ||
|
||
use std::path::Path; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
use config::Config; | ||
use config_file::{ConfigFile, ServiceGroup}; | ||
use error::BldrResult; | ||
use gossip::client::Client; | ||
use gossip::rumor::{Rumor, RumorList}; | ||
|
||
static LOGKEY: &'static str = "IJ"; | ||
|
||
pub fn inject(config: &Config) -> BldrResult<()> { | ||
let sg = try!(ServiceGroup::from(&config.service_group())); | ||
let vn = *config.version_number(); | ||
let cf = try!(ConfigFile::from_file(sg, Path::new(&config.file_path()), vn)); | ||
let mut rumor_list = RumorList::new(); | ||
let rumor = Rumor::config_file(cf); | ||
rumor_list.add_rumor(rumor); | ||
initial_peers(config.gossip_peer(), &rumor_list); | ||
Ok(()) | ||
} | ||
|
||
pub fn initial_peers(peer_listeners: &[String], rumor_list: &RumorList) -> BldrResult<()> { | ||
let fail_after = 10; | ||
let mut count = 0; | ||
|
||
if peer_listeners.len() > 0 { | ||
while count < fail_after { | ||
if try_peers(peer_listeners, rumor_list) { | ||
return Ok(()); | ||
} else { | ||
count = count + 1; | ||
outputln!("Could not connect to any initial peers; attempt {} of {}.", | ||
count, | ||
fail_after); | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn try_peers(peer_listeners: &[String], rumor_list: &RumorList) -> bool { | ||
let mut initialized = false; | ||
for to in peer_listeners { | ||
outputln!("Joining gossip peer at {}", to); | ||
let mut c = match Client::new(&to[..]) { | ||
Ok(c) => c, | ||
Err(e) => { | ||
debug!("Error creating gossip client - {:?}", e); | ||
outputln!("Failed to create a gossip client for {}", to); | ||
continue; | ||
} | ||
}; | ||
|
||
match c.inject(rumor_list.clone()) { | ||
Ok(_) => outputln!("Rumors injected at {}", to), | ||
Err(e) => { | ||
outputln!("Failed to ping {:?}: {:?}", to, e); | ||
continue; | ||
} | ||
} | ||
initialized = true; | ||
} | ||
initialized | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ pub mod start; | |
pub mod key; | ||
pub mod upload; | ||
pub mod configure; | ||
pub mod inject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
6c37bef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delivery Status: