-
Notifications
You must be signed in to change notification settings - Fork 26
Client WebApp API #44
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
b2ee515
152347c
1105823
455cdf9
54ef4cf
28bf8d7
53cd5be
8f37d10
9efdcb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import sys | ||
|
||
if sys.version_info >= (3,0): | ||
import urllib.parse | ||
dku_quote_fn = urllib.parse.quote | ||
else: | ||
import urllib | ||
dku_quote_fn = urllib.quote | ||
|
||
class DSSWebApp(object): | ||
""" | ||
A handle to manage a webapp | ||
""" | ||
def __init__(self, client, project_key, webapp_id, definition): | ||
"""Do not call directly, use :meth:`dataikuapi.dss.project.DSSProject.get_webapps`""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
self.client = client | ||
self.project_key = project_key | ||
self.webapp_id = webapp_id | ||
self.definition = definition | ||
|
||
""" | ||
Update an existing webapp | ||
|
||
:returns: a webapp state excerpt | ||
:rtype: :class:`dataikuapi.dss.webapp.DSSWebAppSaveResponse` | ||
""" | ||
def update(self): | ||
apichery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
response = self.client._perform_json("PUT", "/projects/%s/webapps/%s" % (self.project_key, self.webapp_id), body=self.definition) | ||
return DSSWebAppSaveResponse(self.client, self.project_key, self.webapp_id, response) | ||
apichery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
""" | ||
Stop a webapp | ||
""" | ||
def stop_backend(self): | ||
self.client._perform_empty("PUT", "/projects/%s/webapps/%s/stop-backend" % (self.project_key, self.webapp_id)) | ||
return | ||
|
||
""" | ||
Restart a webapp | ||
""" | ||
def restart_backend(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this corresponds to what the API really does, the fact that there is a "restart" method but no "start" method could be confusing. Not sure what the best to do is here. Maybe call the method |
||
self.client._perform_empty("PUT", "/projects/%s/webapps/%s/restart-backend" % (self.project_key, self.webapp_id)) | ||
apichery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
|
||
|
||
class DSSWebAppSaveResponse(object): | ||
""" | ||
Response for the update method on a WebApp | ||
""" | ||
def __init__(self, client, project_key, webapp_id, definition): | ||
apichery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Do not call directly, use :meth:`dataikuapi.dss.webapp.DSSWebApp.update`""" | ||
self.client = client | ||
self.project_key = project_key | ||
self.webapp_id = webapp_id | ||
self.definition = definition | ||
|
||
|
||
class DSSWebAppHead(object): | ||
apichery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
A handle to manage a WebApp head | ||
""" | ||
def __init__(self, client, project_key, webapp_id, definition): | ||
"""Do not call directly, use :meth:`dataikuapi.dss.project.DSSProject.get_webapps`""" | ||
self.client = client | ||
self.project_key = project_key | ||
self.webapp_id = webapp_id | ||
self.definition = definition |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from time import sleep | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this test class as it cannot be run automatically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talk with @Basharsh96 first :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a copy of the test and I'll add it later to the tests in the CI pipeline I'm working on. Thank you, you can safely remove it 😊 |
||
from dataikuapi.dssclient import DSSClient | ||
from dataikuapi.dss.project import DSSProject | ||
from nose.tools import ok_ | ||
from nose.tools import eq_ | ||
|
||
host="http://localhost:8083" | ||
apiKey="CMZBjFkUgcDh08S3awoPyVIweBelxPjy" | ||
testProjectKey="WEBAPPS" | ||
testWebAppPythonId="VCMN2ra" | ||
|
||
def remove_key(d, key): | ||
r = dict(d) | ||
del r[key] | ||
return r | ||
|
||
class webapp_api_tests(object): | ||
|
||
def setUp(self): | ||
self.client = DSSClient(host, apiKey) | ||
self.project = DSSProject(self.client, testProjectKey) | ||
|
||
def list_webapps_test(self): | ||
webapps = self.project.list_webapps(); | ||
ok_(len(webapps) > 0) | ||
|
||
|
||
def get_python_webapp_test(self): | ||
webapp = self.project.get_webapp(testWebAppPythonId) | ||
ok_(webapp is not None) | ||
|
||
def update_python_webapp_test(self): | ||
webapp_pre = self.project.get_webapp(testWebAppPythonId) | ||
webapp_pre.update() | ||
webapp_post = self.project.get_webapp(testWebAppPythonId) | ||
eq_(webapp_pre.project_key, webapp_post.project_key) | ||
eq_(webapp_pre.webapp_id, webapp_post.webapp_id) | ||
eq_(remove_key(webapp_pre.definition, "versionTag"), remove_key(webapp_post.definition, "versionTag")) | ||
eq_(webapp_pre.definition["versionTag"]["versionNumber"]+1,webapp_post.definition["versionTag"]["versionNumber"]) | ||
|
||
def restart_backend_test(self): | ||
""" | ||
WARNING: you should manually stop the backend before this test | ||
""" | ||
filtered_webapps = [w for w in self.project.list_webapps() if w.webapp_id == testWebAppPythonId] | ||
webapp = self.project.get_webapp(testWebAppPythonId) | ||
ok_(not filtered_webapps[0].definition["backendRunning"],"The backend should be stopped before the test") | ||
webapp.restart_backend() | ||
apichery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sleep(2) | ||
filtered_webapps = [w for w in self.project.list_webapps() if w.webapp_id == testWebAppPythonId] | ||
ok_(filtered_webapps[0].definition["backendRunning"]) | ||
|
||
def stop_backend_test(self): | ||
""" | ||
WARNING: you should manually start the backend before this test | ||
""" | ||
filtered_webapps = [w for w in self.project.list_webapps() if w.webapp_id == testWebAppPythonId] | ||
webapp = self.project.get_webapp(testWebAppPythonId) | ||
ok_(filtered_webapps[0].definition["backendRunning"],"The backend should be started before the test") | ||
webapp.stop_backend() | ||
sleep(2) | ||
filtered_webapps = [w for w in self.project.list_webapps() if w.webapp_id == testWebAppPythonId] | ||
ok_(not filtered_webapps[0].definition["backendRunning"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adopt the newer standard of returning either listitem or object. See list_scenarios for an up-to-date example. This allows basic listing with a single API call instead of N+1
Provide properties on the core things in the DSSWebAppListItem