aboutsummaryrefslogtreecommitdiff
path: root/src/consul_actor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/consul_actor.rs')
-rw-r--r--src/consul_actor.rs39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/consul_actor.rs b/src/consul_actor.rs
index 241a643..de5e216 100644
--- a/src/consul_actor.rs
+++ b/src/consul_actor.rs
@@ -35,29 +35,38 @@ fn retry_to_time(retries: u32, max_time: Duration) -> Duration {
return Duration::from_secs(cmp::min(max_time.as_secs(), 1.2f64.powf(retries as f64) as u64))
}
-fn from_catalog_to_open_ports(catalog: &consul::CatalogNode) -> messages::PublicExposedPorts {
- let mut op = messages::PublicExposedPorts {
- tcp_ports: Vec::new(),
- udp_ports: Vec::new()
- };
+fn to_parameters(catalog: &consul::CatalogNode) -> Vec<DiplonatConsul> {
+ let mut r = Vec::new();
for (_, service_info) in &catalog.Services {
for tag in &service_info.Tags {
let diplo_conf: error::Result<DiplonatConsul> = from_str(tag);
match diplo_conf {
- Ok(conf) => {
- let DiplonatConsul::diplonat(c) = conf;
- for parameter in &c {
- match parameter {
- DiplonatParameter::tcp_port(p) => op.tcp_ports.extend(p),
- DiplonatParameter::udp_port(p) => op.udp_ports.extend(p),
- }
- }
- }
+ Ok(conf) => r.push(conf),
Err(e) => debug!("Failed to parse entry {}. {}", tag, e),
};
}
}
+
+ return r;
+}
+
+fn to_open_ports(params: &Vec<DiplonatConsul>) -> messages::PublicExposedPorts {
+ let mut op = messages::PublicExposedPorts {
+ tcp_ports: Vec::new(),
+ udp_ports: Vec::new()
+ };
+
+ for conf in params {
+ let DiplonatConsul::diplonat(c) = conf;
+ for parameter in c {
+ match parameter {
+ DiplonatParameter::tcp_port(p) => op.tcp_ports.extend(p),
+ DiplonatParameter::udp_port(p) => op.udp_ports.extend(p),
+ };
+ }
+ }
+
return op;
}
@@ -91,7 +100,7 @@ impl ConsulActor {
}
};
self.retries = 0;
- info!("{:#?}", from_catalog_to_open_ports(&catalog));
+ info!("{:#?}", to_open_ports(&to_parameters(&catalog)));
}
}
}