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

Commits on Dec 13, 2022

  1. Rewrite CloudifyClient & HTTPClient

    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!
    tehasdf committed Dec 13, 2022
    Configuration menu
    Copy the full SHA
    315a7b6 View commit details
    Browse the repository at this point in the history
  2. Rewrite the async client too

    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.
    tehasdf committed Dec 13, 2022
    Configuration menu
    Copy the full SHA
    7e80c3f View commit details
    Browse the repository at this point in the history
  3. Shorthand for constructing ListResponses

    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.
    tehasdf committed Dec 13, 2022
    Configuration menu
    Copy the full SHA
    a65adac View commit details
    Browse the repository at this point in the history
  4. Use wrappers & returns in all clients

    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.
    tehasdf committed Dec 13, 2022
    Configuration menu
    Copy the full SHA
    10b5671 View commit details
    Browse the repository at this point in the history
  5. Remove now-unused cluster stuff

    Now the regular client just handles clustering.
    tehasdf committed Dec 13, 2022
    Configuration menu
    Copy the full SHA
    605289a View commit details
    Browse the repository at this point in the history