Skip to content

Commit

Permalink
fix jupyter configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Dec 12, 2024
1 parent e63be5f commit 6864adc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions wedpr-builder/conf/config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ wedpr_api_token = ""
deploy_ip = ["127.0.0.1:1"]
# the server start port
server_start_port = "19000"
jupyter_external_ip = ""

# configuration for mpc
[agency.mpc]
Expand Down Expand Up @@ -269,6 +270,7 @@ wedpr_api_token = ""
deploy_ip = ["127.0.0.1:1"]
# the server start port
server_start_port = "29000"
jupyter_external_ip = ""

# configuration for mpc
[agency.mpc]
Expand Down
13 changes: 12 additions & 1 deletion wedpr-builder/wedpr_builder/config/wedpr_deploy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,11 @@ def __init__(
self,
entry_point: str,
start_port: int,
jupyter_external_ip: str,
max_jupyter_count: int = 10):
self.entryPoint = entry_point
self.jupyterStartPort = start_port
self.jupyterExternalIp = jupyter_external_ip
self.maxJupyterCount = max_jupyter_count

def __repr__(self):
Expand All @@ -356,6 +358,8 @@ def __repr__(self):
def as_dict(self):
result = {}
result.update({"\"entryPoint\"": f"\"{self.entryPoint}\""})
result.update(
{"\"jupyterExternalIp\"": f"\"{self.jupyterExternalIp}\""})
result.update({"\"jupyterStartPort\"": f"{self.jupyterStartPort}"})
result.update({"\"maxJupyterCount\"": f"{self.maxJupyterCount}"})
return result
Expand All @@ -377,6 +381,9 @@ def __init__(self, config, env_config: EnvConfig,
self.agency = agency
self.tpl_config_file_path = tpl_config_file_path
self.config_file_list = config_file_list
# the jupyter external ip
self.jupyter_external_ip = utilities.get_item_value(
self.config, "jupyter_external_ip", None, False, config_section)
self.deploy_ip_list = utilities.get_item_value(
self.config, "deploy_ip", [], must_exist, config_section)
self.server_start_port = int(utilities.get_item_value(
Expand Down Expand Up @@ -454,14 +461,18 @@ def to_properties(self, deploy_ip, node_index: int) -> {}:
# reserver 100 ports for jupyter use
jupyter_start_port = server_start_port + 100
default_jupyter_max_num = 20
jupyter_external_ip = self.jupyter_external_ip
if jupyter_external_ip is None or len(jupyter_external_ip) == 0:
jupyter_external_ip = deploy_ip
if self.service_type == constant.ServiceInfo.wedpr_jupyter_worker_service:
begin_port = jupyter_start_port + default_jupyter_max_num * node_index
end_port = begin_port + default_jupyter_max_num
exposed_port_list = f"{exposed_port_list} -p {begin_port}-{end_port}:{begin_port}-{end_port}"
entry_point = f"http://{deploy_ip}:{server_start_port}"
entry_point = f"{jupyter_external_ip}:{server_start_port}"
# add the SingleJupyterInfo
self.jupyter_infos.jupyters.append(SingleJupyterInfo(
entry_point=entry_point,
jupyter_external_ip=jupyter_external_ip,
start_port=begin_port))
if self.service_type == constant.ServiceInfo.wedpr_mpc_service:
spdz_listen_port = server_start_port + 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,34 @@
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

@Data
public class JupyterHostSetting {
private static final Logger logger = LoggerFactory.getLogger(JupyterHostSetting.class);

@Data
public static class SingleHostSetting {
// the client entryPoint
private String jupyterExternalIp;
// the entry point of the host
private String entryPoint;
// the limitation
private Integer maxJupyterCount = JupyterConfig.getMaxJupyterPerHost();
// the startPort
private Integer jupyterStartPort = JupyterConfig.getDefaultJupyterStartPort();

public String getJupyterExternalIp() {
if (StringUtils.isBlank(jupyterExternalIp)) {
if (StringUtils.isBlank(entryPoint)) {
return entryPoint;
}
return entryPoint.split(":")[0];
}
return jupyterExternalIp;
}
}

private List<SingleHostSetting> hostSettings = new ArrayList<>();
Expand Down Expand Up @@ -75,6 +87,8 @@ public JupyterInfoDO allocateJupyter(String userName, String agency) throws Exce
allocatedHost.toString());

JupyterSetting jupyterSetting = new JupyterSetting(userName, listenPort);
// set the host ip
jupyterSetting.setHostIp(allocatedHost.getJupyterExternalIp());
// insert the information
JupyterInfoDO allocatedJupyter = new JupyterInfoDO();
allocatedJupyter.setAgency(agency);
Expand All @@ -98,7 +112,7 @@ public String serialize() throws Exception {
}

public static JupyterHostSetting deserialize(String data) throws Exception {
if (StringUtils.isEmpty(data)) {
if (StringUtils.isBlank(data)) {
return null;
}
return ObjectMapperFactory.getObjectMapper().readValue(data, JupyterHostSetting.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class JupyterSetting {
private String listenIp = JupyterConfig.getDefaultJupyterListenIp();
private Integer listenPort;
private String noteBookPath;
private String hostIp;

public JupyterSetting() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ protected void generateJupyterAccessUrl() {
if (this.jupyterSetting == null) {
return;
}
String accessHost = (this.getAccessEntry().split(":")[0]);
String accessHost = (this.jupyterSetting.getHostIp());
if (StringUtils.isBlank(accessHost)) {
accessHost = this.accessEntry.split(":")[0];
}
this.jupyterAccessUrl =
Common.getUrl(
String.format(
Expand Down

0 comments on commit 6864adc

Please sign in to comment.