Skip to content

Commit 39beffa

Browse files
committed
Ping proxy work now !
1 parent da5f5b0 commit 39beffa

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

src/controller/definitions/epsilon_instance.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ impl EpsilonInstance {
5050
let status = self
5151
.status
5252
.as_ref()
53-
.ok_or(EpsilonError::RetrieveStatusError)?.clone();
53+
.ok_or(EpsilonError::RetrieveStatusError)?
54+
.clone();
5455

5556
Ok(InstanceJson {
5657
name: self.get_name(),
@@ -82,13 +83,21 @@ impl EpsilonInstance {
8283
}
8384

8485
pub async fn get_info(&self) -> Result<StatusResponse, EpsilonError> {
85-
let address = self
86+
let status = self
8687
.status
8788
.as_ref()
88-
.and_then(|status| status.ip.as_ref())
8989
.ok_or(EpsilonError::RetrieveStatusError)?;
9090

91-
let config = ConnectionConfig::build(address);
91+
let address = status
92+
.ip
93+
.as_ref()
94+
.ok_or(EpsilonError::RetrieveIpAddressError)?;
95+
96+
let port = status.t.get_entry_port();
97+
98+
let mut config = ConnectionConfig::build(address);
99+
config = config.with_port(port as u16);
100+
92101
let duration = Duration::from_millis(150);
93102

94103
let status_result: Result<StatusResponse, EpsilonError> = timeout(duration, async move {
@@ -158,5 +167,5 @@ pub struct InstanceJson {
158167
pub slots: i32,
159168
pub online_count: i32,
160169

161-
pub ip: Option<String>
170+
pub ip: Option<String>,
162171
}

src/controller/epsilon_controller.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl EpsilonController {
134134
..Default::default()
135135
},
136136
]),
137-
ports: Some(instance_type.get_associated_ports()),
137+
ports: Some(instance_type.get_container_ports()),
138138
resources: Some(instance_resource.kube_resources()),
139139
readiness_probe: Some(Probe {
140140
initial_delay_seconds: Some(5),
@@ -176,7 +176,9 @@ impl EpsilonController {
176176

177177
let state = if is_starting
178178
|| !instance_status.is_some()
179-
|| (is_running && !is_ready && instance_status.as_ref().unwrap().state != EpsilonState::Running)
179+
|| (is_running
180+
&& !is_ready
181+
&& instance_status.as_ref().unwrap().state != EpsilonState::Running)
180182
{
181183
EpsilonState::Starting
182184
} else if is_running && is_ready {
@@ -215,7 +217,8 @@ impl EpsilonController {
215217
status.state = state;
216218

217219
if state == EpsilonState::Running {
218-
status.online = epsilon_instance.get_online_count().await.unwrap_or(0);
220+
status.online =
221+
epsilon_instance.get_online_count().await.unwrap_or(0);
219222
}
220223

221224
status

src/epsilon/epsilon_error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub enum EpsilonError {
2626
#[error("Retrieve status error")]
2727
RetrieveStatusError,
2828

29+
#[error("Retrieve Ip address error")]
30+
RetrieveIpAddressError,
31+
2932
#[error("Queue not found error {0}")]
3033
QueueNotFoundError(String),
3134

src/epsilon/server/instances/common/instance_type.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ pub enum InstanceType {
1212
}
1313

1414
impl InstanceType {
15-
pub fn get_associated_ports(&self) -> Vec<ContainerPort> {
15+
pub fn get_container_ports(&self) -> Vec<ContainerPort> {
1616
match self {
1717
InstanceType::Server => vec![ContainerPort {
18-
container_port: 25565,
18+
container_port: self.get_entry_port(),
1919
name: Some(String::from("server")),
2020
protocol: Some(String::from("TCP")),
2121
..Default::default()
2222
}],
2323
InstanceType::Proxy => vec![
2424
ContainerPort {
25-
container_port: 25577,
25+
container_port: self.get_entry_port(),
2626
name: Some(String::from("proxy")),
2727
protocol: Some(String::from("TCP")),
2828
..Default::default()
@@ -36,19 +36,11 @@ impl InstanceType {
3636
],
3737
}
3838
}
39-
}
40-
41-
impl FromStr for InstanceType {
42-
type Err = io::Error;
4339

44-
fn from_str(input: &str) -> Result<InstanceType, Self::Err> {
45-
match input.to_lowercase().as_str() {
46-
"server" => Ok(InstanceType::Server),
47-
"proxy" => Ok(InstanceType::Proxy),
48-
_ => Err(io::Error::new(
49-
io::ErrorKind::InvalidInput,
50-
format!("Invalid instance type, {}", input),
51-
)),
40+
pub fn get_entry_port(&self) -> i32 {
41+
match self {
42+
InstanceType::Server => 25565,
43+
InstanceType::Proxy => 25577,
5244
}
5345
}
5446
}

0 commit comments

Comments
 (0)