def send_heart_beat(automat_host): """Send heartbeat.""" heart_rate = config.get('heart_rate', 30) logger.debug(f'contacting {automat_host}') automat_heart_beat_url = f'{automat_host}/heartbeat' plater_address = config.get('PLATER_SERVICE_ADDRESS') if not plater_address: logger.error( 'PLATER_SERVICE_ADDRESS environment variable not set. Please set ' 'this variable to the address of the host PLATER is running on.' ) raise ValueError( 'PLATER_SERVICE_ADDRESS cannot be None when joining automat ' 'cluster.' ) payload = { 'host': plater_address, 'tag': PLATER_TITLE, 'port': config.get('WEB_PORT', 8080) } while True: try: resp = httpx.post( automat_heart_beat_url, json=payload, timeout=0.5, ) logger.debug( 'heartbeat to %s returned %d', automat_host, resp.status_code, ) except Exception as err: logger.error(f'[X] Error contacting automat server {err}') time.sleep(heart_rate)
def construct_open_api_schema(app, trapi_version, prefix=""): plater_title = config.get('PLATER_TITLE', 'Plater API') plater_version = os.environ.get('PLATER_VERSION', '1.0.0') if app.openapi_schema: return app.openapi_schema open_api_schema = get_openapi( title=plater_title, version=plater_version, description='', routes=app.routes, ) open_api_extended_file_path = config.get_resource_path( f'../openapi-config.yaml') with open(open_api_extended_file_path) as open_api_file: open_api_extended_spec = yaml.load(open_api_file, Loader=yaml.SafeLoader) x_translator_extension = open_api_extended_spec.get("x-translator") contact_config = open_api_extended_spec.get("contact") terms_of_service = open_api_extended_spec.get("termsOfService") servers_conf = open_api_extended_spec.get("servers") tags = open_api_extended_spec.get("tags") title_override = (open_api_extended_spec.get("title") or plater_title) + f' (trapi v-{trapi_version})' description = open_api_extended_spec.get("description") if tags: open_api_schema['tags'] = tags if x_translator_extension: # if x_translator_team is defined amends schema with x_translator extension open_api_schema["info"]["x-translator"] = x_translator_extension open_api_schema["info"]["x-translator"][ "biolink-version"] = config.get("BL_VERSION", "1.5.0") if contact_config: open_api_schema["info"]["contact"] = contact_config if terms_of_service: open_api_schema["info"]["termsOfService"] = terms_of_service if description: open_api_schema["info"]["description"] = description if title_override: open_api_schema["info"]["title"] = title_override if servers_conf: for cnf in servers_conf: if prefix and 'url' in cnf: cnf['url'] = cnf['url'] + prefix open_api_schema["servers"] = servers_conf open_api_schema["info"]["x-trapi"] = {"version": trapi_version} return open_api_schema
def __init__(self, host, port, auth): self.driver = Neo4jHTTPDriver(host=host, port=port, auth=auth) self.schema = None self.summary = None self.meta_kg = None self.bl_version = config.get('BL_VERSION', '1.5.0') self.bl_url = f'https://raw.githubusercontent.com/biolink/biolink-model/{self.bl_version}/biolink-model.yaml' self.toolkit = Toolkit(self.bl_url)
def __init__(self, bl_url=config.get('bl_url')): self.bl_url = bl_url
def get_bl_helper(): """Get Biolink helper.""" return BLHelper(config.get('BL_HOST', 'https://bl-lookup-sri.renci.org'))
def get_graph_interface(): """Get graph interface.""" return GraphInterface( config.get('NEO4J_HOST'), config.get('NEO4J_HTTP_PORT'), (config.get('NEO4J_USERNAME'), config.get('NEO4J_PASSWORD')))
"""Plater heartbeat.""" import argparse import time import httpx from PLATER.services.config import config from PLATER.services.util.logutil import LoggingUtil logger = LoggingUtil.init_logging( __name__, config.get('logging_level'), config.get('logging_format'), ) PLATER_TITLE = config.get("PLATER_TITLE", "Plater API") def send_heart_beat(automat_host): """Send heartbeat.""" heart_rate = config.get('heart_rate', 30) logger.debug(f'contacting {automat_host}') automat_heart_beat_url = f'{automat_host}/heartbeat' plater_address = config.get('PLATER_SERVICE_ADDRESS') if not plater_address: logger.error( 'PLATER_SERVICE_ADDRESS environment variable not set. Please set ' 'this variable to the address of the host PLATER is running on.' ) raise ValueError( 'PLATER_SERVICE_ADDRESS cannot be None when joining automat '
import base64 import traceback import httpx from PLATER.services.config import config from PLATER.services.util.logutil import LoggingUtil from bmt import Toolkit logger = LoggingUtil.init_logging(__name__, config.get('logging_level'), config.get('logging_format')) class Neo4jHTTPDriver: def __init__(self, host: str, port: int, auth: tuple, scheme: str = 'http'): self._host = host self._neo4j_transaction_endpoint = "/db/data/transaction/commit" self._scheme = scheme self._full_transaction_path = f"{self._scheme}://{self._host}:{port}{self._neo4j_transaction_endpoint}" self._port = port self._supports_apoc = None self._header = { 'Accept': 'application/json; charset=UTF-8', 'Content-Type': 'application/json', 'Authorization':
"""FastAPI app.""" import os from fastapi import FastAPI from fastapi.openapi.utils import get_openapi from starlette.middleware.cors import CORSMiddleware from PLATER.services.config import config from PLATER.services.util.logutil import LoggingUtil from PLATER.services.app_trapi_1_0 import APP_TRAPI_1_0 from PLATER.services.app_trapi_1_1 import APP_TRAPI_1_1 from PLATER.services.util.api_utils import construct_open_api_schema TITLE = config.get('PLATER_TITLE', 'Plater API') VERSION = os.environ.get('PLATER_VERSION', '1.0.1') logger = LoggingUtil.init_logging( __name__, config.get('logging_level'), config.get('logging_format'), ) APP = FastAPI() # Mount 1.1 app at /1.1 APP.mount('/1.1', APP_TRAPI_1_1, 'Trapi 1.1') # Mount default 1.0 app at / APP.mount('/', APP_TRAPI_1_0, 'Trapi 1.0') # Add all routes of each app for open api generation at /openapi.json # This will create an aggregate openapi spec. APP.include_router(APP_TRAPI_1_1.router, prefix='/1.1') APP.include_router(APP_TRAPI_1_0.router)
import base64 import traceback import httpx from PLATER.services.config import config from PLATER.services.util.logutil import LoggingUtil from bmt import Toolkit from PLATER.services.util.attribute_mapping import get_attribute_bl_info logger = LoggingUtil.init_logging(__name__, config.get('logging_level'), config.get('logging_format') ) class Neo4jHTTPDriver: def __init__(self, host: str, port: int, auth: tuple, scheme: str = 'http'): self._host = host self._neo4j_transaction_endpoint = "/db/data/transaction/commit" self._scheme = scheme self._full_transaction_path = f"{self._scheme}://{self._host}:{port}{self._neo4j_transaction_endpoint}" self._port = port self._supports_apoc = None self._header = { 'Accept': 'application/json; charset=UTF-8', 'Content-Type': 'application/json', 'Authorization': 'Basic %s' % base64.b64encode(f"{auth[0]}:{auth[1]}".encode('utf-8')).decode('utf-8') } # ping and raise error if neo4j doesn't respond. logger.debug('PINGING NEO4J')