Skip to content
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

for wsgi testing #1

Open
wants to merge 8 commits 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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,22 @@ These never shared with the client via the protocol.

* At no time should the same test file contents change. It is better to create a new file with a new name.
We want to allow the client system to pre-cache and pre-processing the test data given the URI or filename (e.g. place in a pyTorch dataset).


# WSGI

Running with WSGI requires a configfile (python) to specify the bind port for the service AND the worker processes count:

```
import multiprocessing

bind = "0.0.0.0:5000"
workers = 1 #multiprocessing.cpu_count() * 2 + 1
```

Run wsgi in the PIPENV environment providing the config file for WSGI and the location of the test and results directories:

```
LOG_NAME=`date +"%m-%d-%Y.%H.%M"`
pipenv run gunicorn -c gunicorn.config.py 'sail_on.wsgi:create_app(data_directory="/home/robertsone/TESTS", results_directory="/home/robertsone/RESULTS")' >> "${LOG_NAME}_unicorn_0.txt" 2>&1
```
2 changes: 1 addition & 1 deletion sail_on/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(
class RoundError(ServerError):
"""Error indicating problem with rounds."""

error_code = 502
error_code = 400

def __init__(
self, reason: str, msg: str, stack_trace: str = "stack trace unavailable"
Expand Down
9 changes: 3 additions & 6 deletions sail_on/api/file_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def dataset_request(self, session_id: str, test_id: str, round_id: int) -> FileR

if round_id is not None:
# Check for removing leftover files from restarting tests within a session
if round_id == 0 and test_info:
if int(round_id) == 0 and test_info:
test_session_path = os.path.join(self.results_folder, f"{str(session_id)}.{str(test_id)}.json")
if os.path.exists(test_session_path):
os.remove(test_session_path)
Expand Down Expand Up @@ -551,11 +551,8 @@ def dataset_request(self, session_id: str, test_id: str, round_id: int) -> FileR
traceback.format_stack(),
)
if round_pos >= len(lines):
raise RoundError(
"round_id_invalid",
f"Round id {str(round_id)} is out of scope for test id {test_id}. Check the metadata round_size.",
traceback.format_stack(),
)
return None

text = ('\n'.join(lines[round_pos:round_pos + int(metadata["round_size"])]) + "\n").encode('utf-8')
temp_file_path.write(text)
temp_file_path.seek(0)
Expand Down
3 changes: 3 additions & 0 deletions sail_on/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ def dataset_request() -> Response:
except Exception as e:
raise ServerError(str(type(e)), str(e), traceback.format_exc())

if file_name is None:
return {"session_id": session_id, "msg": "end of test"}, 204

# returns the file
try:
logging.info(f"Returning dataset_uris at file path: {file_name}")
Expand Down
15 changes: 8 additions & 7 deletions sail_on/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

class Args:

results_directory = '/home/robertsone/RESULTS'
data_directory = '/home/robertsone/TESTS'
log_file = f'{os.getpid()}_wsgi.log'
log_level = logging.INFO
url = '0.0.0.0:5003'
def __init__(*args,**kwargs):
self.results_directory = kwargs['results_directory'] if 'results_directory' in kwargs else './RESULTS'
self.data_directory = kwargs['data_directory'] if 'data_directory' in kwargs else './TEST'
self.log_file = f'{os.getpid()}_wsgi.log'
self.log_level = logging.INFO
self.url = kwargs.get('url','0.0.0.0:5003')

def set_up(args):
set_provider(
Expand All @@ -26,7 +27,7 @@ def set_up(args):
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
logging.info(f"Api server starting with provider set to FileProvider")

def create_app():
set_up(Args())
def create_app(**kwargs):
set_up(Args(**kwargs))
return app

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
test_suite="tests",
tests_require=test_requirements,
url="https://gitlab.kitware.com/darpa-sail-on/sail-on",
version="0.0.2",
version="0.2.1",
zip_safe=False,
entry_points={
"console_scripts": [
Expand Down
10 changes: 10 additions & 0 deletions tests/data/OND/image_classification/OND.1.1.1235_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"domain": "image_classification",
"protocol": "OND",
"known_classes": 3,
"max_novel_classes": 2,
"round_size": 2,
"threshold": 0.1,
"red_light": "n01484850_4515.JPEG",
"feedback_max_ids": 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file,detection,writer_id
n01484850_18013.JPEG, 1, 1
n01484850_24624.JPEG, 0, 2
n01484850_4515.JPEG, 1, 0
n01484850_45289.JPEG, 0, 2
10 changes: 10 additions & 0 deletions tests/data/OND/image_classification/OND.1.1.1236_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"domain": "image_classification",
"protocol": "OND",
"known_classes": 3,
"max_novel_classes": 2,
"round_size": 2,
"threshold": 0.1,
"red_light": "n01484850_4515.JPEG",
"feedback_max_ids": 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file,detection,writer_id
n01484850_18013.JPEG, 1, 1
n01484850_24624.JPEG, 0, 2
n01484850_4515.JPEG, 1, 0
n01484850_45289.JPEG, 0, 2