summaryrefslogtreecommitdiff
path: root/opendc/api/v2/traces
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-23 18:08:28 +0200
committerGeorgios Andreadis <info@gandreadis.com>2020-06-23 18:08:28 +0200
commit565ede0dc50c3b2df09c066ea3a28a4901cce547 (patch)
treee81a1bbed43d2eaf7e2be0bc61007963f807b62d /opendc/api/v2/traces
parent6f41be7d9c244b67bfa5ff72f1e90d18fa45b590 (diff)
Add DB handlers and rename to v2
Diffstat (limited to 'opendc/api/v2/traces')
-rw-r--r--opendc/api/v2/traces/__init__.py0
-rw-r--r--opendc/api/v2/traces/endpoint.py18
-rw-r--r--opendc/api/v2/traces/traceId/__init__.py0
-rw-r--r--opendc/api/v2/traces/traceId/endpoint.py34
-rw-r--r--opendc/api/v2/traces/traceId/jobs/__init__.py0
-rw-r--r--opendc/api/v2/traces/traceId/jobs/endpoint.py37
6 files changed, 89 insertions, 0 deletions
diff --git a/opendc/api/v2/traces/__init__.py b/opendc/api/v2/traces/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/opendc/api/v2/traces/__init__.py
diff --git a/opendc/api/v2/traces/endpoint.py b/opendc/api/v2/traces/endpoint.py
new file mode 100644
index 00000000..78930b0f
--- /dev/null
+++ b/opendc/api/v2/traces/endpoint.py
@@ -0,0 +1,18 @@
+from opendc.models.trace import Trace
+from opendc.util.rest import Response
+
+
+def GET(request):
+ """Get all available Traces."""
+
+ # Get the Traces
+
+ traces = Trace.query()
+
+ # Return the Traces
+
+ return Response(
+ 200,
+ 'Successfully retrieved Traces',
+ [x.to_JSON() for x in traces]
+ )
diff --git a/opendc/api/v2/traces/traceId/__init__.py b/opendc/api/v2/traces/traceId/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/opendc/api/v2/traces/traceId/__init__.py
diff --git a/opendc/api/v2/traces/traceId/endpoint.py b/opendc/api/v2/traces/traceId/endpoint.py
new file mode 100644
index 00000000..50993c41
--- /dev/null
+++ b/opendc/api/v2/traces/traceId/endpoint.py
@@ -0,0 +1,34 @@
+from opendc.models.trace import Trace
+from opendc.util import exceptions
+from opendc.util.rest import Response
+
+
+def GET(request):
+ """Get this Trace."""
+
+ # Make sure required parameters are there
+
+ try:
+ request.check_required_parameters(
+ path={
+ 'traceId': 'int'
+ }
+ )
+
+ except exceptions.ParameterError as e:
+ return Response(400, e.message)
+
+ # Instantiate a Trace and make sure it exists
+
+ trace = Trace.from_primary_key((request.params_path['traceId'],))
+
+ if not trace.exists():
+ return Response(404, '{} not found.'.format(trace))
+
+ # Return this Trace
+
+ return Response(
+ 200,
+ 'Successfully retrieved {}.'.format(trace),
+ trace.to_JSON()
+ )
diff --git a/opendc/api/v2/traces/traceId/jobs/__init__.py b/opendc/api/v2/traces/traceId/jobs/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/opendc/api/v2/traces/traceId/jobs/__init__.py
diff --git a/opendc/api/v2/traces/traceId/jobs/endpoint.py b/opendc/api/v2/traces/traceId/jobs/endpoint.py
new file mode 100644
index 00000000..bd2c6eb0
--- /dev/null
+++ b/opendc/api/v2/traces/traceId/jobs/endpoint.py
@@ -0,0 +1,37 @@
+from opendc.models.job import Job
+from opendc.models.trace import Trace
+from opendc.util import exceptions
+from opendc.util.rest import Response
+
+
+def GET(request):
+ """Get this Trace's Jobs."""
+
+ # Make sure required parameters are there
+
+ try:
+ request.check_required_parameters(
+ path={
+ 'traceId': 'int'
+ }
+ )
+
+ except exceptions.ParameterError as e:
+ return Response(400, e.message)
+
+ # Instantiate a Trace and make sure it exists
+
+ trace = Trace.from_primary_key((request.params_path['traceId'],))
+
+ if not trace.exists():
+ return Response(404, '{} not found.'.format(trace))
+
+ # Get and return the Jobs
+
+ jobs = Job.query('trace_id', request.params_path['traceId'])
+
+ return Response(
+ 200,
+ 'Successfully retrieved Jobs for {}.'.format(trace),
+ [x.to_JSON() for x in jobs]
+ )