Skip to content

Commit

Permalink
add some config defaults and a tool to validate properties file
Browse files Browse the repository at this point in the history
Signed-off-by: sagewe <wbwmat@gmail.com>
  • Loading branch information
sagewe committed Dec 8, 2023
1 parent be7d3bb commit 8c7826d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions python/eggroll/config/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def main():
import argparse
import configparser
import omegaconf

from .config import Config

arguments = argparse.ArgumentParser()
arguments.add_argument("-c", "--config", type=str, required=True)
args = arguments.parse_args()

config = Config()
config.load_default()
c = configparser.ConfigParser()
c.read(args.config)
for k, v in c.items("eggroll"):
try:
if v == "":
omegaconf.OmegaConf.select(config.config, k)
else:
config.config = omegaconf.OmegaConf.merge(
config.config, omegaconf.OmegaConf.from_dotlist([f"{k}={v}"])
)
except omegaconf.errors.ConfigKeyError:
print(f"Error: {k} is not set, please add it to eggroll/config/defaults")


if __name__ == "__main__":
main()
39 changes: 39 additions & 0 deletions python/eggroll/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
class DefaultConfig:
@dataclass
class EggrollConfig:
@dataclass
class DashboardConfig:
@dataclass
class ServerConfig:
port: int = 8083

server: ServerConfig = ServerConfig()

@dataclass
class TransferConfig:
@dataclass
Expand Down Expand Up @@ -36,6 +44,18 @@ class JdbcConfig:

@dataclass
class NodemanagerConfig:
@dataclass
class GpuConfig:
@dataclass
class NumConfig:
shell: str = MISSING

num: NumConfig = NumConfig()

@dataclass
class NetConfig:
device: str = MISSING

@dataclass
class ContainersConfig:
@dataclass
Expand All @@ -47,6 +67,8 @@ class DataConfig:
host: str = MISSING
port: int = MISSING
containers: ContainersConfig = ContainersConfig()
net: NetConfig = NetConfig()
gpu: GpuConfig = GpuConfig()

@dataclass
class ProcessConfig:
Expand Down Expand Up @@ -350,12 +372,28 @@ class ServerConfig:

@dataclass
class SecurityConfig:
@dataclass
class EncryptConfig:
public_key: str = MISSING
private_key: str = MISSING
enable: bool = False

@dataclass
class SessionConfig:
@dataclass
class ExpiredConfig:
time: int = 30

expired: ExpiredConfig = ExpiredConfig()

@dataclass
class LoginConfig:
username: str = MISSING
password: str = MISSING

login: LoginConfig = LoginConfig()
session: SessionConfig = SessionConfig()
encrypt: EncryptConfig = EncryptConfig()

@dataclass
class ContainerConfig:
Expand Down Expand Up @@ -604,5 +642,6 @@ class RootConfig:
home: str = MISSING
gc: GCConfig = GCConfig()
transfer: TransferConfig = TransferConfig()
dashboard: DashboardConfig = DashboardConfig()

eggroll: EggrollConfig = EggrollConfig()

0 comments on commit 8c7826d

Please sign in to comment.