Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SVLT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ALMF
SVLT
Commits
9c735683
Commit
9c735683
authored
7 months ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Added and tested exception handling for unlisted accessor ID
parent
b33a5047
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
model_server/base/api.py
+13
-5
13 additions, 5 deletions
model_server/base/api.py
model_server/base/session.py
+2
-0
2 additions, 0 deletions
model_server/base/session.py
tests/base/test_api.py
+5
-1
5 additions, 1 deletion
tests/base/test_api.py
with
20 additions
and
6 deletions
model_server/base/api.py
+
13
−
5
View file @
9c735683
...
...
@@ -3,7 +3,7 @@ from typing import Union
from
fastapi
import
FastAPI
,
HTTPException
from
.accessors
import
generate_file_accessor
from
.session
import
session
,
InvalidPathError
from
.session
import
session
,
AccessorIdError
,
InvalidPathError
app
=
FastAPI
(
debug
=
True
)
...
...
@@ -64,9 +64,19 @@ def list_active_models():
def
list_accessors
():
return
session
.
list_accessors
()
def
_session_accessor
(
func
,
acc_id
):
try
:
return
func
(
acc_id
)
except
AccessorIdError
as
e
:
raise
HTTPException
(
404
,
f
'
Did not find accessor with ID
{
acc_id
}
'
)
@app.get
(
'
/accessors/{accessor_id}
'
)
def
get_accessor
(
accessor_id
:
str
):
return
session
.
get_accessor_info
(
accessor_id
)
return
_session_accessor
(
session
.
get_accessor_info
,
accessor_id
)
@app.get
(
'
/accessors/delete/{accessor_id}
'
)
def
delete_accessor
(
accessor_id
:
str
):
return
_session_accessor
(
session
.
del_accessor
,
accessor_id
)
@app.put
(
'
/accessors/read_from_file
'
)
def
read_accessor_from_file
(
filename
:
str
,
accessor_id
:
Union
[
str
,
None
]
=
None
):
...
...
@@ -76,7 +86,5 @@ def read_accessor_from_file(filename: str, accessor_id: Union[str, None] = None)
acc
=
generate_file_accessor
(
fp
)
return
session
.
add_accessor
(
acc
,
accessor_id
=
accessor_id
)
@app.get
(
'
/accessors/delete/{accessor_id}
'
)
def
delete_accessor
(
accessor_id
:
str
):
return
session
.
del_accessor
(
accessor_id
)
This diff is collapsed.
Click to expand it.
model_server/base/session.py
+
2
−
0
View file @
9c735683
...
...
@@ -125,6 +125,8 @@ class _Session(object):
"""
Get information about a single accessor
"""
if
acc_id
not
in
self
.
accessors
.
keys
():
raise
AccessorIdError
(
f
'
No accessor with ID
{
acc_id
}
is registered
'
)
return
self
.
list_accessors
()[
acc_id
]
@staticmethod
...
...
This diff is collapsed.
Click to expand it.
tests/base/test_api.py
+
5
−
1
View file @
9c735683
...
...
@@ -206,4 +206,8 @@ class TestApiFromAutomatedClient(TestServerTestCase):
# delete and check that its 'loaded' state changes
self
.
assertTrue
(
self
.
_get
(
f
'
accessors/
{
acc_id
}
'
).
json
()[
'
loaded
'
])
self
.
assertEqual
(
self
.
_get
(
f
'
accessors/delete/
{
acc_id
}
'
).
json
(),
acc_id
)
self
.
assertFalse
(
self
.
_get
(
f
'
accessors/
{
acc_id
}
'
).
json
()[
'
loaded
'
])
\ No newline at end of file
self
.
assertFalse
(
self
.
_get
(
f
'
accessors/
{
acc_id
}
'
).
json
()[
'
loaded
'
])
# and try a non-existent accessor ID
resp_wrong_acc
=
self
.
_get
(
'
accessors/auto_123456
'
)
self
.
assertEqual
(
resp_wrong_acc
.
status_code
,
404
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment