-
Notifications
You must be signed in to change notification settings - Fork 16
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
RESTClient: rewrite client.py to handle cluster & async #1204
Open
tehasdf
wants to merge
5
commits into
master
Choose a base branch
from
restclient-asyncclient-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The aim is: - a better subclass structure, which will allow useful subclassing in the future (in the future commit) for the async client - handle clustering right here - shorten the tracebacks :) To do this: - split HTTPClient into HTTPClientBase & HTTPClient. Now the Base has all kinds of utils, it's mostly ad-hoc because it was also ad-hoc before, and HTTPClient itself has only a .do_request A future async client would also implement .do_request - copy over all the clustering stuff from cloudify/cluster.py - rewrite the exception throwing :) Note that the .do_request and varius .get etc, now also take a `wrapper` argument, and if that is present, they wrap the response data in it. This will become very important soon!
Now the async client is more of a thing of its own. Similar to how you do CloudifyClient(), you can now also use AsyncCloudifyClient(), and that is going to be very similar to the usual client, except.. well, async. Not all endpoints are available yet. Some of them I couldn't easily translate :( And so, community_contacts, deployment_groups, and log_bundles, are just not available for now. Still pretty good.
For example, `wrapper = Deployment; wrapper(resp)` creates a Deployment object from a response. Similarly, now `wrapper = ListResponse.of(Deployment); wrapper(resp)` creates a list of deployments from a response.
In every client, replace this: ```python response = self.api.get(...) return Deployment(response) ``` with this: ```python return self.api.get(..., wrapper=Deployment) ``` Now there's a trick! Since we always just return the result of `self.api.x()`, all the specific client functions (BlueprintsClient.get, DeploymentsClient.get, etc. that's what I mean by "specific") don't really care whether they're sync or async. If self.api.get returns a future, we'll just return it from here directly. Very few endpoints were not really possible to be rewritten easily like that, so I've left TODO comments in there. Hopefully we can get back to them at some point.
Now the regular client just handles clustering.
tehasdf
added a commit
to cloudify-cosmo/cloudify-agent
that referenced
this pull request
Dec 13, 2022
cloudify-cosmo/cloudify-common#1204 removes the ClusterClient, and now just the regular CloudifyClient handles clusters
tehasdf
added a commit
to cloudify-cosmo/cloudify-manager
that referenced
this pull request
Dec 13, 2022
Prepare the mock client to work with cloudify-cosmo/cloudify-common#1204
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this, CloudifyClient handles clustering, so CloudifyClusterClient... stops existing.
Also, AsyncCloudifyClient (cloudify_async_client) becomes more of a thing. Now you can just create that client separately, and well, use it. It has (almost) all of the endpoints.