Skip to content

Commit 96aa190

Browse files
committed
api cleanup; contenprovider wip
1 parent b813d28 commit 96aa190

7 files changed

Lines changed: 127 additions & 161 deletions

File tree

docker-compose.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ services:
1111
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
1212
command: postgres -c config_file=/etc/postgresql.conf -c hba_file=/etc/pg_hba.conf
1313
volumes:
14-
# - ~/data/OKMaps/${COMPOSE_PROJECT_NAME}/postgresql/data:/var/lib/postgresql/data
1514
- db_data:/var/lib/postgresql/data
16-
- ./server/workers/pg_hba.conf:/etc/pg_hba.conf
17-
- ./server/workers/postgresql.conf:/etc/postgresql.conf
15+
- ./pg_hba.conf:/etc/pg_hba.conf
16+
- ./postgresql.conf:/etc/postgresql.conf
1817
networks:
1918
- headstart
2019

@@ -35,8 +34,7 @@ services:
3534
command: ["redis-server", "/etc/redis/redis.conf", "--bind", "${REDIS_HOST}", "--appendonly", "yes", "--port", "${REDIS_PORT}"]
3635
volumes:
3736
- 'redis:/var/lib/redis/data'
38-
- ./server/workers/redis.conf:/etc/redis/redis.conf
39-
- ./server/workers/certs:/etc/certs
37+
- ./redis.conf:/etc/redis/redis.conf
4038
ports:
4139
- "127.0.0.1:${REDIS_PORT}:6379"
4240
restart: always
@@ -57,6 +55,8 @@ services:
5755
DATABASES: "${DATABASES}"
5856
FLASK_ENV: "${FLASK_ENV}"
5957
command: ["gunicorn", "--workers", "10", "--threads", "2", "-b", "0.0.0.0:${API_PORT}", "app:app", "--timeout", "300"]
58+
volumes:
59+
- ./api_cache:/var/api_cache
6060
depends_on:
6161
- redis
6262
networks:
@@ -81,8 +81,6 @@ services:
8181

8282
triple:
8383
image: triple:${SERVICE_VERSION}
84-
env_file:
85-
- server/workers/triple/triple.env
8684
environment:
8785
SERVICE_VERSION: "${SERVICE_VERSION}"
8886
REDIS_HOST: "${REDIS_HOST}"
@@ -105,8 +103,6 @@ services:
105103

106104
gsheets:
107105
image: gsheets:${SERVICE_VERSION}
108-
env_file:
109-
- server/workers/gsheets/gsheets.env
110106
environment:
111107
SERVICE_VERSION: "${SERVICE_VERSION}"
112108
REDIS_HOST: "${REDIS_HOST}"
@@ -122,15 +118,19 @@ services:
122118

123119
dataprocessing:
124120
image: dataprocessing:${SERVICE_VERSION}
125-
env_file:
126-
- server/workers/dataprocessing/dataprocessing.env
127121
environment:
128122
SERVICE_VERSION: "${SERVICE_VERSION}"
129123
REDIS_HOST: "${REDIS_HOST}"
130124
REDIS_PORT: "${REDIS_PORT}"
131125
REDIS_DB: "${REDIS_DB}"
132126
REDIS_PASSWORD: "${REDIS_PASSWORD}"
133127
LOGLEVEL: "${LOGLEVEL}"
128+
LOGFILE: "${LOGFILE}"
129+
RENV_VERSION: 0.14.0-5
130+
CRAN_REPOS: https://cran.wu.ac.at
131+
LC_ALL: "en_US.UTF-8"
132+
LANG: "en_US.UTF-8"
133+
RENV_PATHS_CACHE: /renv/cache
134134
restart: always
135135
volumes:
136136
- /opt/local/renv/cache:/renv/cache
@@ -174,13 +174,12 @@ services:
174174
REDIS_DB: "${REDIS_DB}"
175175
REDIS_PASSWORD: "${REDIS_PASSWORD}"
176176
LOGLEVEL: "${LOGLEVEL}"
177-
LOGFILE: "/var/log/headstart/headstart.log"
177+
LOGFILE: "${LOGFILE}"
178178
RENV_VERSION: 0.14.0-5
179179
CRAN_REPOS: https://cran.wu.ac.at
180180
LC_ALL: "en_US.UTF-8"
181181
LANG: "en_US.UTF-8"
182182
RENV_PATHS_CACHE: /renv/cache
183-
PYTHONIOENCODING: "utf-8"
184183
restart: always
185184
volumes:
186185
- /opt/local/renv/cache:/renv/cache
@@ -199,13 +198,12 @@ services:
199198
REDIS_DB: "${REDIS_DB}"
200199
REDIS_PASSWORD: "${REDIS_PASSWORD}"
201200
LOGLEVEL: "${LOGLEVEL}"
202-
LOGFILE: "/var/log/headstart/headstart.log"
201+
LOGFILE: "${LOGFILE}"
203202
RENV_VERSION: 0.14.0-5
204203
CRAN_REPOS: https://cran.wu.ac.at
205204
LC_ALL: "en_US.UTF-8"
206205
LANG: "en_US.UTF-8"
207206
RENV_PATHS_CACHE: /renv/cache
208-
PYTHONIOENCODING: "utf-8"
209207
restart: always
210208
volumes:
211209
- /opt/local/renv/cache:/renv/cache
@@ -219,6 +217,8 @@ volumes:
219217
redis:
220218
db_data:
221219
driver: local
220+
api_cache:
221+
driver: local
222222

223223
networks:
224224
headstart:

server/workers/api/src/apis/base.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,57 @@ def post(self):
8585
base_ns.logger.error(e)
8686
abort(500, "Problem encountered, check logs.")
8787

88+
def get_or_create_contentprovider_lookup():
89+
try:
90+
k = str(uuid.uuid4())
91+
d = {"id": k, "params": {},
92+
"endpoint": "contentproviders"}
93+
base_ns.logger.debug(d)
94+
redis_store.rpush("base", json.dumps(d))
95+
result = get_key(redis_store, k)
96+
df = pd.DataFrame(json.loads(result))
97+
df.set_index("internal_name", inplace=True)
98+
cp_dict = df.name.to_dict()
99+
return cp_dict
100+
except Exception as e:
101+
base_ns.logger.error(e)
102+
103+
contentprovider_lookup = get_or_create_contentprovider_lookup()
104+
base_ns.logger.debug(len(contentprovider_lookup))
105+
106+
@base_ns.route('contentprovider')
107+
class ContentProvider(Resource):
108+
@base_ns.doc(responses={200: 'OK',
109+
400: 'Invalid search parameters'})
110+
@base_ns.produces(["application/json"])
111+
def post(self):
112+
"""
113+
params: can be empty
114+
content_provider: BASE internal name, e.g. "fthsaugsburg"
115+
116+
returns: json
117+
{"contentprovider_short": "fthsaugsburg",
118+
"contentprovider_long": "OPUS - Publikationsserver der Hochschule Augsburg"}
119+
"""
120+
params = request.get_json()
121+
if not params:
122+
result = contentprovider_lookup
123+
else:
124+
result = contentprovider_lookup.get(params["repo"])
125+
try:
126+
headers = {}
127+
headers["Content-Type"] = "application/json"
128+
return make_response(result,
129+
200,
130+
headers)
131+
except Exception as e:
132+
base_ns.logger.error(e)
133+
abort(500, "Problem encountered, check logs.")
134+
88135

89136

90137
@base_ns.route('/service_version')
91138
class ServiceVersion(Resource):
92139
def get(self):
93140
result = {"service_version": os.getenv("SERVICE_VERSION")}
94-
return make_response(result, 200, {"Content-Type": "application/json"})
141+
return make_response(result, 200, {"Content-Type": "application/json"})

server/workers/api/src/app.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import sys
3-
from flask import Flask, redirect, url_for
3+
from flask import Flask
44
from flask_restx import Api
55
from flask_cors import CORS
66
from werkzeug.middleware.proxy_fix import ProxyFix
7+
import logging
78

89
from apis.triple import triple_ns
910
from apis.gsheets import gsheets_ns
@@ -12,19 +13,45 @@
1213
from apis.openaire import openaire_ns
1314
from apis.create_vis import vis_ns
1415

15-
from utils.monkeypatches import ReverseProxied, __schema__, specs_url, _register_apidoc
16-
import logging
1716

17+
class ReverseProxied(object):
18+
'''Wrap the application in this middleware and configure the
19+
front-end server to add these headers, to let you quietly bind
20+
this to a URL other than / and to an HTTP scheme that is
21+
different than what is used locally.
22+
23+
location /myprefix {
24+
proxy_pass http://192.168.0.1:5001;
25+
proxy_set_header Host $host;
26+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27+
proxy_set_header X-Scheme $scheme;
28+
proxy_set_header X-Script-Name /myprefix;
29+
}
30+
31+
:param app: the WSGI application
32+
'''
33+
def __init__(self, app):
34+
self.app = app
35+
36+
def __call__(self, environ, start_response):
37+
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
38+
if script_name:
39+
environ['SCRIPT_NAME'] = script_name
40+
path_info = environ['PATH_INFO']
41+
if path_info.startswith(script_name):
42+
environ['PATH_INFO'] = path_info[len(script_name):]
43+
44+
scheme = environ.get('HTTP_X_SCHEME', '')
45+
if scheme:
46+
environ['wsgi.url_scheme'] = scheme
47+
return self.app(environ, start_response)
1848

1949
def api_patches(app):
20-
Api._register_apidoc = _register_apidoc
21-
Api.__schema__ = __schema__
22-
Api.specs_url = specs_url
2350

2451
api_fixed = Api(
2552
app,
2653
title="Head Start API",
27-
description="Head Start API demo",
54+
description="Head Start API",
2855
version="0.1",
2956
prefix='/api',
3057
doc="/docs")

server/workers/api/src/utils/__init__.py

Whitespace-only changes.

server/workers/api/src/utils/monkeypatches.py

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)