Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --listen-http rather than --listen-sidecar #574

Merged
merged 1 commit into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions components/director/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions components/director/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use super::task::{Task, ExecContext, ExecParams};
static MINIMUM_LOOP_TIME_MS: i64 = 200;
static LOGKEY: &'static str = "CTRL";
pub const FIRST_GOSSIP_PORT: u16 = 9000;
pub const FIRST_SIDECAR_PORT: u16 = 8000;
pub const FIRST_HTTP_PORT: u16 = 8000;

pub struct Controller {
pub config: Config,
Expand All @@ -51,11 +51,11 @@ impl Controller {

/// iterate through the config ServiceDefs and create `Task`
/// instances. A Controller contains "all the tasks", so
/// it calculate gossip_port + sidecar_port #s accordingly.
/// it calculate gossip_port + http_port #s accordingly.
pub fn create_children(&mut self) -> Result<()> {
let mut children = Vec::new();
let mut next_gossip_port = FIRST_GOSSIP_PORT;
let mut next_sidecar_port = FIRST_SIDECAR_PORT;
let mut next_http_port = FIRST_HTTP_PORT;

let default_ip = try!(ip());
let listen_ip = try!(Ipv4Addr::from_str(&default_ip));
Expand All @@ -66,7 +66,7 @@ impl Controller {
for sd in &self.config.service_defs {
let exec_ctx = self.exec_ctx.clone();
let exec_params = ExecParams::new(SocketAddrV4::new(listen_ip, next_gossip_port),
SocketAddrV4::new(listen_ip, next_sidecar_port),
SocketAddrV4::new(listen_ip, next_http_port),
initial_peer);

// after the first iteration, each child will connect to the previous
Expand All @@ -76,9 +76,9 @@ impl Controller {
children.push(dc);

// this will have to be more intelligent if we
// let users define gossip/sidecar ports
// let users define gossip/http ports
next_gossip_port += 1;
next_sidecar_port += 1;
next_http_port += 1;
}
self.children = Some(children);
Ok(())
Expand Down Expand Up @@ -260,7 +260,7 @@ mod tests {
"foo",
"--listen-peer",
format!("{}:9000", test_ip).as_str(),
"--listen-sidecar",
"--listen-http",
format!("{}:8000", test_ip).as_str(),
"--group",
"somegroup",
Expand All @@ -279,7 +279,7 @@ mod tests {
"--listen-peer",
// did we increment the port?
format!("{}:9001", test_ip).as_str(),
"--listen-sidecar",
"--listen-http",
// did we increment the port?
format!("{}:8001", test_ip).as_str(),
"--group",
Expand All @@ -301,7 +301,7 @@ mod tests {
"--listen-peer",
// did we increment the port?
format!("{}:9002", test_ip).as_str(),
"--listen-sidecar",
"--listen-http",
// did we increment the port?
format!("{}:8002", test_ip).as_str(),
"--group",
Expand Down
16 changes: 8 additions & 8 deletions components/director/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//!
//! - `Controller`
//! - A controller "has" and supervises many Tasks (children)
//! - calculates gossip and sidecar port #'s for all children before starting.
//! - calculates gossip and http port #'s for all children before starting.
//! - runs in a tight loop to see if children are down and start/restarts them.
//! - catches OS signals
//!
Expand All @@ -35,7 +35,7 @@
//! - Config values for a `Task` that the `Controller` calculates during
//! startup. `ExecParams` currently includes:
//! - gossip_listen
//! - sidecar_listen
//! - http_listen
//! - Option<peer_ip_port>
//!
//! - `ServiceDef`
Expand Down Expand Up @@ -123,39 +123,39 @@
//! - Each subsequent task that is created uses the previous tasks IP:port as
//! a value for --peer.
//! - Gossip port numbers are assigned starting with FIRST_GOSSIP_PORT (9000)
//! - Sidecar port numbers are assigned starting with FIRST_SIDECAR_PORT (8000)
//! - HTTP port numbers are assigned starting with FIRST_HTTP_PORT (8000)
//! - If the hab-sup that's running the director is assigned ports other than
//! the defaults (9634, 9631), there is a possibility that they could conflict
//! with the automatically assigned port numbers of the child tasks.
//! - The diagram below shows a hab-sup process running the director with it's
//! default IP + port (changeable by the user). Each task that's started is
//! assigned a new consecutive gossip + sidecar IP.
//! assigned a new consecutive gossip + http IP.
//!
//! ┌────────────────────────────┐
//! │ hab-sup (Director) │
//! ┌─▶│ Gossip = 9634 │ * default ports
//! │ │ Sidecar = 9631 │
//! │ │ HTTP = 9631
//! │ └────────────────────────────┘
//! │
//! Peer │
//! │ ┌────────────────────────────┐
//! │ │Task 0 │
//! └──│FIRST_GOSSIP_PORT (9000) │◀─┐
//! │FIRST_SIDECAR_PORT (8000) │ │
//! │FIRST_HTTP_PORT (8000) │ │
//! └────────────────────────────┘ │
//! │
//! │ Peer
//! ┌────────────────────────────┐ │
//! │Task 1 │ │
//! ┌─▶│FIRST_GOSSIP_PORT+1 (9001) │──┘
//! │ │FIRST_SIDECAR_PORT+1 (8001) │
//! │ │FIRST_HTTP_PORT+1 (8001)
//! │ └────────────────────────────┘
//! │
//! Peer │
//! │ ┌────────────────────────────┐
//! │ │Task 2 │
//! └──│FIRST_GOSSIP_PORT+2 (9002) │
//! │FIRST_SIDECAR_PORT+2 (8002) │
//! │FIRST_HTTP_PORT+2 (8002)
//! └────────────────────────────┘
//!

Expand Down
30 changes: 15 additions & 15 deletions components/director/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Task {
args.insert(1, self.service_def.ident.to_string());
args.push("--listen-peer".to_string());
args.push(self.exec_params.gossip_listen.to_string());
args.push("--listen-sidecar".to_string());
args.push("--listen-http".to_string());
args.push(self.exec_params.sidecar_listen.to_string());
args.push("--group".to_string());
args.push(self.service_def.service_group.group.clone());
Expand Down Expand Up @@ -187,28 +187,28 @@ impl Task {
);

let mut child = try!(Command::new(&self.exec_ctx.sup_path)
.args(&args)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn());
.args(&args)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn());
self.pid = Some(child.id());

outputln!("Started {} [gossip {}, http API: {}, peer: {}, pid: {}]",
&self.service_def.to_string(),
&self.exec_params.gossip_listen,
&self.exec_params.sidecar_listen,
&self.exec_params
.initial_peer
.as_ref()
.map_or("None".to_string(), |v| v.to_string()),
.initial_peer
.as_ref()
.map_or("None".to_string(), |v| v.to_string()),
&child.id());

try!(self.transition_to_started());
let name = self.service_def.to_string();
try!(thread::Builder::new()
.name(String::from(name.clone()))
.spawn(move || -> Result<()> { child_reader(&mut child, name) }));
.name(String::from(name.clone()))
.spawn(move || -> Result<()> { child_reader(&mut child, name) }));
debug!("Spawned child reader");

} else {
Expand Down Expand Up @@ -449,7 +449,7 @@ mod tests {
Task::new(exec_ctx, exec_params, sd)
}

/// parse args, inject listen-peer and listen-sidecar, no peer
/// parse args, inject listen-peer and listen-http, no peer
#[test]
fn cmd_args_parsing_no_peer() {
let dc = get_test_dc();
Expand All @@ -462,15 +462,15 @@ mod tests {
"-foo=bar",
"--listen-peer",
"127.0.0.1:9000",
"--listen-sidecar",
"--listen-http",
"127.0.0.1:8000",
"--group",
"somegroup",
"--org",
"someorg"]);
}

/// parse args, inject listen-peer, listen-sidecar, peer
/// parse args, inject listen-peer, listen-http, peer
#[test]
fn cmd_args_parsing_peer() {
let mut dc = get_test_dc();
Expand All @@ -486,7 +486,7 @@ mod tests {
"-foo=bar",
"--listen-peer",
"127.0.0.1:9000",
"--listen-sidecar",
"--listen-http",
"127.0.0.1:8000",
"--group",
"somegroup",
Expand Down
20 changes: 10 additions & 10 deletions components/sup/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ pub struct Config {
expire_days: Option<u16>,
gossip_listen_ip: String,
gossip_listen_port: u16,
sidecar_listen_ip: String,
sidecar_listen_port: u16,
http_listen_ip: String,
http_listen_port: u16,
userkey: Option<String>,
servicekey: Option<String>,
infile: Option<String>,
Expand Down Expand Up @@ -292,21 +292,21 @@ impl Config {
self
}

pub fn sidecar_listen_ip(&self) -> &str {
&self.sidecar_listen_ip
pub fn http_listen_ip(&self) -> &str {
&self.http_listen_ip
}

pub fn set_sidecar_listen_ip(&mut self, ip: String) -> &mut Config {
self.sidecar_listen_ip = ip;
pub fn set_http_listen_ip(&mut self, ip: String) -> &mut Config {
self.http_listen_ip = ip;
self
}

pub fn sidecar_listen_port(&self) -> u16 {
self.sidecar_listen_port
pub fn http_listen_port(&self) -> u16 {
self.http_listen_port
}

pub fn set_sidecar_listen_port(&mut self, port: u16) -> &mut Config {
self.sidecar_listen_port = port;
pub fn set_http_listen_port(&mut self, port: u16) -> &mut Config {
self.http_listen_port = port;
self
}

Expand Down
Loading