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

RESTClient: rewrite client.py to handle cluster & async #1204

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tehasdf
Copy link
Contributor

@tehasdf tehasdf commented Dec 13, 2022

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant