-
Notifications
You must be signed in to change notification settings - Fork 3
Remove refinery-config #266
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8253c0c
Initial config addition
anmarhindi 1dee431
adjust services
anmarhindi 8f349d7
edits
anmarhindi 626656c
Adjust config route
anmarhindi 12ec0f5
remove check_config_service
anmarhindi a04fde3
move implementation
anmarhindi b82c6e6
Change order of config
anmarhindi 1368d06
Access values directly
anmarhindi 8b06114
adjust fastapi
anmarhindi 14ba267
Add new routes for config
anmarhindi ec5f005
edit
anmarhindi fcef6c0
edit
anmarhindi 9bc0677
add direct default route for base_config
anmarhindi ab63c34
Fix: outdated lines
anmarhindi e54a113
Fix: unnecessary async
anmarhindi 4f0a715
Remove unused service
anmarhindi 9ccc21d
Moves change config to misc routing
anmarhindi 23b48f7
Merge remote-tracking branch 'origin/dev' into config
JWittmeyer 0b9393b
remove org createino endpoint for os version
JWittmeyer de0af28
Removes unused config parts
JWittmeyer 8610e3c
remove unused notify services
JWittmeyer fd94ddc
Removes auto notify on startup
JWittmeyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,4 +143,6 @@ project_export* | |
tmp/* | ||
!tmp/.gitkeep | ||
|
||
logs/* | ||
logs/* | ||
|
||
current_config.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
from controller.misc import config_service | ||
from starlette.endpoints import HTTPEndpoint | ||
from starlette.responses import JSONResponse | ||
from starlette import status | ||
from fastapi import Request | ||
|
||
from config_handler import ( | ||
full_config_json, | ||
) | ||
|
||
class IsManagedRest(HTTPEndpoint): | ||
def get(self, request) -> JSONResponse: | ||
is_managed = config_service.get_config_value("is_managed") | ||
return JSONResponse(is_managed, status_code=status.HTTP_200_OK) | ||
|
||
class IsDemoRest(HTTPEndpoint): | ||
def get(self, request) -> JSONResponse: | ||
is_managed = config_service.get_config_value("is_demo") | ||
return JSONResponse(is_managed, status_code=status.HTTP_200_OK) | ||
class FullConfigRest(HTTPEndpoint): | ||
def get(self, request: Request) -> JSONResponse: | ||
return full_config_json() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"s3_region": null, | ||
"KERN_S3_ENDPOINT": null, | ||
"spacy_downloads": [ | ||
"en_core_web_sm", | ||
"de_core_news_sm" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from typing import Dict, Any, Optional, Union | ||
import os | ||
import json | ||
from notify_handler import notify_others_about_change_thread | ||
from fastapi import responses, status | ||
|
||
__config = None | ||
|
||
BASE_CONFIG_PATH = "base_config.json" | ||
CURRENT_CONFIG_PATH = "/config/current_config.json" | ||
|
||
SERVICES_TO_NOTIFY = { | ||
"TOKENIZER": "http://refinery-tokenizer:80", | ||
} | ||
|
||
|
||
def get_config_value( | ||
key: str, subkey: Optional[str] = None | ||
) -> Union[str, Dict[str, str]]: | ||
if key not in __config: | ||
raise ValueError(f"Key {key} coudn't be found in config") | ||
value = __config[key] | ||
|
||
if not subkey: | ||
return value | ||
|
||
if isinstance(value, dict) and subkey in value: | ||
return value[subkey] | ||
else: | ||
raise ValueError(f"Subkey {subkey} coudn't be found in config[{key}]") | ||
|
||
|
||
def __read_and_change_base_config(): | ||
print("reading base config file", flush=True) | ||
global __config | ||
f = open(BASE_CONFIG_PATH) | ||
__config = json.load(f) | ||
__config["s3_region"] = os.getenv("S3_REGION", "eu-west-1") | ||
__save_current_config() | ||
|
||
|
||
def change_config(changes: Dict[str, Any]) -> bool: | ||
global __config | ||
something_changed = False | ||
for key in changes: | ||
if key == "KERN_S3_ENDPOINT": | ||
continue | ||
if key in __config: | ||
if isinstance(changes[key], dict): | ||
for subkey in changes[key]: | ||
if subkey in __config[key]: | ||
__config[key][subkey] = changes[key][subkey] | ||
something_changed = True | ||
else: | ||
__config[key] = changes[key] | ||
something_changed = True | ||
if something_changed: | ||
__save_current_config() | ||
else: | ||
print("nothing was changed with input", changes, flush=True) | ||
return something_changed | ||
|
||
|
||
def __save_current_config() -> None: | ||
print("saving config file", flush=True) | ||
with open(CURRENT_CONFIG_PATH, "w") as f: | ||
json.dump(__config, f, indent=4) | ||
|
||
|
||
def init_config() -> None: | ||
if not os.path.exists(CURRENT_CONFIG_PATH): | ||
__read_and_change_base_config() | ||
else: | ||
__load_and_remove_outdated_config_keys() | ||
# this one is to be set on every start to ensure its up to date | ||
print("setting s3 endpoint", flush=True) | ||
__config["KERN_S3_ENDPOINT"] = os.getenv("KERN_S3_ENDPOINT") | ||
|
||
|
||
def __load_and_remove_outdated_config_keys(): | ||
if not os.path.exists(CURRENT_CONFIG_PATH): | ||
return | ||
|
||
global __config | ||
with open(CURRENT_CONFIG_PATH) as f: | ||
__config = json.load(f) | ||
|
||
with open(BASE_CONFIG_PATH) as f: | ||
base_config = json.load(f) | ||
|
||
to_remove = [key for key in __config if key not in base_config] | ||
|
||
if len(to_remove) > 0: | ||
print("removing outdated config keys", to_remove, flush=True) | ||
for key in to_remove: | ||
del __config[key] | ||
__save_current_config() | ||
|
||
|
||
def get_config() -> Dict[str, Any]: | ||
global __config | ||
return __config | ||
|
||
|
||
def change_json(config_data) -> responses.PlainTextResponse: | ||
try: | ||
has_changed = change_config(config_data) | ||
|
||
if has_changed: | ||
notify_others_about_change_thread(SERVICES_TO_NOTIFY) | ||
|
||
return responses.PlainTextResponse( | ||
f"Did update: {has_changed}", status_code=status.HTTP_200_OK | ||
) | ||
|
||
except Exception as e: | ||
return responses.PlainTextResponse( | ||
f"Error: {str(e)}", status_code=status.HTTP_500_INTERNAL_SERVER_ERROR | ||
) | ||
|
||
|
||
def full_config_json() -> responses.JSONResponse: | ||
return responses.JSONResponse(status_code=status.HTTP_200_OK, content=get_config()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.