From 4a69b4467f24dac269d1bfad75097a3365f1af76 Mon Sep 17 00:00:00 2001
From: Daniel K Lyons <dlyons@nrao.edu>
Date: Tue, 1 Sep 2020 16:39:31 -0600
Subject: [PATCH] Remove Cornice. Not using it is more efficient than using it.

---
 services/workflow/setup.py                 |  1 -
 services/workflow/src/workflow/__init__.py |  7 +++--
 services/workflow/src/workflow/workflow.py | 32 ++++++++++++++++------
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/services/workflow/setup.py b/services/workflow/setup.py
index fc677861a..ee3172b1a 100644
--- a/services/workflow/setup.py
+++ b/services/workflow/setup.py
@@ -37,7 +37,6 @@ def find_version(*file_paths):
 
 
 requires = [
-    'cornice',
     'pycapo',
     'pyramid',
     'pyramid_beaker',
diff --git a/services/workflow/src/workflow/__init__.py b/services/workflow/src/workflow/__init__.py
index 587758fdf..4a8734bb7 100644
--- a/services/workflow/src/workflow/__init__.py
+++ b/services/workflow/src/workflow/__init__.py
@@ -13,11 +13,14 @@ def main(global_config, **settings):
 
     with Configurator(settings=settings) as config:
         session_factory = session_factory_from_settings(settings)
-        config.include('cornice')
         config.set_session_factory(session_factory)
         config.add_renderer('jsonp', JSONP(param_name='callback'))
 
-        config.include('pyramid_beaker')
+        config.add_route('workflows', '/workflows')
+        config.add_route('workflow', '/workflows/{id}')
+        config.add_route('submit_workflow', '/workflows/{id}/submit')
+        config.add_route('workflow_files', '/workflows/{id}/files')
 
+        config.include('pyramid_beaker')
         config.scan('workflow.workflow')
         return config.make_wsgi_app()
diff --git a/services/workflow/src/workflow/workflow.py b/services/workflow/src/workflow/workflow.py
index 4ebc22599..6bd15db9b 100644
--- a/services/workflow/src/workflow/workflow.py
+++ b/services/workflow/src/workflow/workflow.py
@@ -1,22 +1,36 @@
-from cornice.resource import resource
+from pyramid.view import view_config, view_defaults
 
+WORKFLOWS = [{'id': 1, 'name': 'foo', 'files': [{'id': 1, 'name': 'first file'}]}]
 
-WORKFLOWS = [{'id': 1, 'name': 'foo'}]
 
-
-@resource(collection_path="/workflows", path="/workflows/{id}")
-class Workflow:
-    def __init__(self, request, context=None):
+@view_defaults(route_name='workflows', renderer='json')
+class Workflows:
+    def __init__(self, request):
         self.request = request
 
-    def collection_get(self):
+    @view_config(request_method='GET')
+    def list_workflows(self):
         return WORKFLOWS
 
-    def collection_post(self):
+    @view_config(request_method='POST')
+    def create_workflow(self):
         WORKFLOWS.append(self.request.json_body)
         return True
 
-    def get(self):
+    @view_config(request_method='GET', route_name='workflow')
+    def get_workflow(self):
         return WORKFLOWS[int(self.request.matchdict['id'])]
 
+    @view_config(request_method='POST', route_name='submit_workflow')
+    def submit_workflow(self):
+        # submit the workflow for processing
+        print(f"Submitting workflow {self.request.matchdict['id']}")
+
+    @view_config(request_method='POST', route_name='workflow_files')
+    def add_file(self):
+        # add a file to this workflow request
+        print('Adding a file')
 
+    @view_config(request_method='GET', route_name='workflow_files')
+    def get_files(self):
+        return WORKFLOWS[int(self.request.matchdict['id'])]['files']
-- 
GitLab