Skip to content

Feature/SK-1717 | Start combiner server if run as __main__ #982

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions config/settings-combiner.yaml.local.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ host: localhost
address: localhost
port: 12080
max_clients: 30
fqdn:
secure: false

cert_path: tmp/server.crt
key_path: tmp/server.key
Expand Down
2 changes: 2 additions & 0 deletions config/settings-combiner.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ name: combiner
host: combiner
port: 12080
max_clients: 30
fqdn:
secure: false

statestore:
# Available DB types are MongoDB, PostgreSQL, SQLite
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ services:
- MODELSTORAGE_CONFIG=/app/config/settings-combiner.yaml.template
- HOOK_SERVICE_HOST=hook:12081
- TMPDIR=/app/tmp
- FEDN_COMBINER_CONFIG=/app/config/settings-combiner.yaml.template
build:
context: .
args:
Expand All @@ -95,11 +96,9 @@ services:
working_dir: /app
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
entrypoint: ["sh", "-c"]
command:
- combiner
- start
- --init
- config/settings-combiner.yaml.template
- "/venv/bin/python /app/fedn/network/combiner/combiner.py"
ports:
- 12080:12080
healthcheck:
Expand Down
1 change: 1 addition & 0 deletions fedn/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"context": os.environ.get("FEDN_OBJECT_CONTEXT_BUCKET", "fedn-context"),
"prediction": os.environ.get("FEDN_OBJECT_PREDICTION_BUCKET", "fedn-prediction"),
}
FEDN_COMBINER_CONFIG = os.environ.get("FEDN_COMBINER_CONFIG", os.path.join(os.path.expanduser("~"), ".fedn", "combiner.yaml"))


def get_environment_config():
Expand Down
24 changes: 24 additions & 0 deletions fedn/network/combiner/combiner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import queue
import re
import signal
Expand All @@ -9,11 +10,13 @@
from enum import Enum
from typing import TypedDict

import yaml
from google.protobuf.json_format import MessageToDict

import fedn.network.grpc.fedn_pb2 as fedn
import fedn.network.grpc.fedn_pb2_grpc as rpc
from fedn.common.certificate.certificate import Certificate
from fedn.common.config import FEDN_COMBINER_CONFIG, get_modelstorage_config, get_network_config, get_statestore_config
from fedn.common.log_config import logger, set_log_level_from_string, set_log_stream
from fedn.network.combiner.modelservice import ModelService
from fedn.network.combiner.roundhandler import RoundConfig, RoundHandler
Expand Down Expand Up @@ -959,3 +962,24 @@ def run(self):
pass
self.server.stop()
self.server.stop()


if __name__ == "__main__":
if not os.path.exists(FEDN_COMBINER_CONFIG):
logger.error(f"Combiner config file {FEDN_COMBINER_CONFIG} does not exist.")
exit(1)

modelstorage_config = get_modelstorage_config()
statestore_config = get_statestore_config()
network_id = get_network_config()

with open(FEDN_COMBINER_CONFIG, "r") as file:
config = yaml.safe_load(file)

config = CombinerConfig(**config)

repository = Repository(modelstorage_config["storage_config"], storage_type=modelstorage_config["storage_type"], init_buckets=False)
db = DatabaseConnection(statestore_config, network_id)

server = Combiner(config, repository, db)
server.run()
Loading