Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Support for txn in HTTP API #148

Open
iandyh opened this issue May 2, 2017 · 15 comments · May be fixed by #225
Open

Support for txn in HTTP API #148

iandyh opened this issue May 2, 2017 · 15 comments · May be fixed by #225
Assignees

Comments

@iandyh
Copy link
Contributor

iandyh commented May 2, 2017

https://www.consul.io/api/txn.html

Any play for implementing this? Thanks.

@iandyh
Copy link
Contributor Author

iandyh commented May 10, 2017

ping @cablehead

@cablehead
Copy link
Collaborator

Pull requests gratefully accepted.

@beardedeagle
Copy link

@cablehead are you planning to work on this anytime in the near future? If not I may take a look at implementing it.

@iandyh
Copy link
Contributor Author

iandyh commented Aug 9, 2017

@beardedeagle Hi. I have a branch currently supports txn but does not support tornado and other async client yets. I am planning to add the support next week.

@cablehead
Copy link
Collaborator

I've deleted my previous comment, as I misread the conversation above.

Hi there. I won't have time to work on this in the near future (I've just recently become a parent, and I'm slowly adjusting!). @iandyh is it possible to create a PR for your branch? If it looks OK we can look to get it merge. @beardedeagle it'd be awesome if you had time to work on it to, particularly in order to support async clients as well.

@beardedeagle
Copy link

@iandyh That would be immediately be helpful to me since I am not using any async clients, but if you get it pr'd in I can look at helping to get those implemented.

@iandyh
Copy link
Contributor Author

iandyh commented Aug 10, 2017

@beardedeagle @cablehead Let me work on it on Friday with async support if it's straightforward.

@beardedeagle
Copy link

beardedeagle commented Aug 14, 2017

@iandyh were you able to make any headway on that? I pulled your changes locally and have started to tinker.

@iandyh
Copy link
Contributor Author

iandyh commented Aug 15, 2017 via email

abn pushed a commit to abn/python-consul that referenced this issue Aug 22, 2017
Add support for Transaction HTTP API.

Reference: https://www.consul.io/api/txn.html
Relates-to: python-consul#148
@abn
Copy link
Collaborator

abn commented Aug 22, 2017

I have merged initial work into master via #166. However, note that there is further work to be done here so leaving this issue open for now, might create more atomic issues later.

@abn abn self-assigned this Aug 22, 2017
abn added a commit that referenced this issue Aug 22, 2017
abn added a commit that referenced this issue Aug 22, 2017
@iandyh
Copy link
Contributor Author

iandyh commented Aug 22, 2017

@abn Just out of curiosity, what atomic issues you are referring to?

@abn
Copy link
Collaborator

abn commented Aug 22, 2017

@iandyh I just mean I might create more github issues with smaller chunks of further work required to expand on the feature.

@paltryeffort
Copy link

Hi, I tried to use txn like this:

curl --insecure --header "X-Consul-Token: abc123" \
--request PUT \
-H "Content-Type: application/json" \
-d '[{ "KV": {"Verb": "get-tree","Key": "service"} }]' \
https://consulhost:8501/v1/txn

This works fine.

My code does not:

import platform
print("python ", platform.python_version())
import consul
print("consul ", consul.__version__)
import urllib3
urllib3.disable_warnings()

payload = [{ "KV": { "Verb": "get-tree", "Key": "service" } }]

c = consul.Consul(host="consulhost",port="8501",token="abc123",scheme='https',verify=False)

result = c.txn.put(payload)
print(result)

However "Results" is always an empty list:

python  3.6.2
consul  0.7.2-dev
{'Results': [], 'Errors': None, 'Index': 0, 'LastContact': 0, 'KnownLeader': True}

What am I doing wrong?

@abn
Copy link
Collaborator

abn commented Aug 26, 2017

@paltryeffort I have tried to reproduce this but failed, havent tried with a token yet though. Here is what I did.

  1. Start consul instance via docker.
docker run --rm -it -p 8500:8500 consul
  1. Execute the following script.
import json

from consul.std import Consul


if __name__ == '__main__':
    c = Consul()
    c.txn.put(payload=[
        {
            "KV": {
                "Verb": "check-not-exists",
                "Key": "foo"
            }
        },
        {
            "KV": {
                "Verb": "set",
                "Key": "foo/bar",
                "Value": ""
            }
        },
        {
            "KV": {
                "Verb": "set",
                "Key": "foo/baz",
                "Value": ""
            }
        }
    ])
    r = c.txn.put(payload=[
        {
            "KV": {
                "Verb": "get-tree",
                "Key": "foo"
            }
        }
    ])
    print(json.dumps(r, indent=2))
    c.txn.put(payload=[
        {
            "KV": {
                "Verb": "delete-tree",
                "Key": "foo"
            }
        }
    ])

This produce the following output.

{
  "Index": 0, 
  "Errors": null, 
  "Results": [
    {
      "KV": {
        "LockIndex": 0, 
        "ModifyIndex": 99, 
        "Value": null, 
        "Flags": 0, 
        "Key": "foo/bar", 
        "CreateIndex": 99
      }
    }, 
    {
      "KV": {
        "LockIndex": 0, 
        "ModifyIndex": 99, 
        "Value": null, 
        "Flags": 0, 
        "Key": "foo/baz", 
        "CreateIndex": 99
      }
    }
  ], 
  "KnownLeader": true, 
  "LastContact": 0
}

@amuhametov amuhametov linked a pull request Aug 2, 2018 that will close this issue
@amuhametov
Copy link

@abn you have no token required with docker image. That is the reason why your test has passed.
If able, backport this pr to 0.7.2 (0.7.3?) as this version is included into EPEL repo for CentOS 7.

mbrulatout referenced this issue in criteo/py-consul Aug 28, 2023
Add support for Transaction HTTP API.

Reference: https://www.consul.io/api/txn.html
Relates-to: #148
mbrulatout referenced this issue in criteo/py-consul Aug 28, 2023
mbrulatout referenced this issue in criteo/py-consul Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants