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

Client WebApp API #44

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

MayeulRousselet
Copy link

Implementation of a WebApp API client + TU

Copy link
Contributor

@spicquenot spicquenot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactorize the WebApp classes for simplicity (see DSSWiki & DSSWikiSettings as example)

dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
tests/webapps_tests.py Outdated Show resolved Hide resolved
Copy link
Contributor

@spicquenot spicquenot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small reqs

dataikuapi/dss/webapp.py Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
Copy link
Contributor

@spicquenot spicquenot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not store the state within the webapp, otherwise, cannot refresh the state, even by calling get_state on the webapp object

dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
dataikuapi/dss/webapp.py Outdated Show resolved Hide resolved
Copy link
Contributor

@spicquenot spicquenot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better future handling

dataikuapi/dss/webapp.py Show resolved Hide resolved
Copy link
Contributor

@spicquenot spicquenot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good, if you want you can add a new function in DSSWebAppBackendState get_future that returns a DSSFuture with the jobId stored in DSSWebAppBackendState so the loading state of the webapp backend can be handle more easily

@cstenac cstenac changed the base branch from release/6.0 to master July 3, 2020 06:56
@FChataigner FChataigner added this to the 9.0 milestone Feb 2, 2021
@apichery apichery modified the milestones: 9.0, 9.0.2 Apr 9, 2021
Copy link
Contributor

@FChataigner FChataigner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,82 @@
from time import sleep
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this test class as it cannot be run automatically

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talk with @Basharsh96 first :)

Choose a reason for hiding this comment

The 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 😊

Copy link
Member

@cstenac cstenac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API modernization

# Webapps
########################################################

def list_webapps(self):
Copy link
Member

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

A handle to manage a webapp
"""
def __init__(self, client, project_key, webapp_id):
"""Do not call directly, use :meth:`dataikuapi.dss.project.DSSProject.get_webapps`"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

"""
Stop a webapp
"""
self.client._perform_empty("PUT", "/projects/%s/webapps/%s/backend/actions/stop" % (self.project_key, self.webapp_id))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with @FChataigner whether it's a good thing that this does not return a future

:rtype: :class:`dataikuapi.dss.future.DSSFuture`
"""
future = self.client._perform_json("PUT", "/projects/%s/webapps/%s/backend/actions/restart" % (self.project_key, self.webapp_id))
return DSSFuture(self.client, future["jobId"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use DSSFuture.from_resp which properly handles the case where the future instantly succeeded or failed (here, it will do KeyError on jobId

"""
self.client._perform_empty("PUT", "/projects/%s/webapps/%s/backend/actions/stop" % (self.project_key, self.webapp_id))

def restart_backend(self):
Copy link
Member

Choose a reason for hiding this comment

The 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 start_or_restart_backend

self.webapp_id = webapp_id
self.state = state

def get_state(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a property

"""
return self.state

def is_running(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a property called "running"

self.webapp_id = webapp_id
self.definition = definition

def get_definition(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this would be webapp.get_definition().get_definition() :) Standard practice is to call this method get_raw

so it will be webapp.get_settings().get_raw()

"""
return self.definition

def set_definition(self, definition):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no set function on a "modern" settings object. It's modification in place.

@@ -0,0 +1,82 @@
from time import sleep
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talk with @Basharsh96 first :)

@mhoarau mhoarau marked this pull request as draft July 22, 2024 07:30
@mhoarau mhoarau removed this from the 9.0.2 milestone Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants