volcano-sdk 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/volcano/generated_transport.rb +10 -10
- data/lib/volcano/lock_auto_renewal.rb +3 -2
- data/lib/volcano/locks.rb +46 -62
- data/lib/volcano/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf20d0cdb7959be9f989d8b1f1e5f88b53a065a7b899b42f7c3a09af5d1327c6
|
|
4
|
+
data.tar.gz: 3350d3a721b2d25b67aaf0a76a8cab45cb1ca26c69d386c600789bb60589cfca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94a0671011cb9256c3bf768fe05fbea0e1d49fb8c3d29adb694cc5a01eb83e80fb0d978b4aa1c83919a3b38ca7cdd6069a7af5b41eaefa743622bdc745f68083
|
|
7
|
+
data.tar.gz: 756140f1665c4f360839a37da9ad15de033cf45373bee40a57b7b109d8d0830094af36974923841d538722869bd9f7fe987c7e3f50a55d5b5f9e657d6106d84f
|
data/README.md
CHANGED
|
@@ -671,6 +671,13 @@ client.locks.with_lock("deploy", ttl: 30) do |guard|
|
|
|
671
671
|
end
|
|
672
672
|
```
|
|
673
673
|
|
|
674
|
+
Acquisition accepts caller-owned UUID `token` and `request_id` values and retries
|
|
675
|
+
an ambiguous transport failure or HTTP 503 once with the same request and credential.
|
|
676
|
+
Retain those IDs to recover an uncertain acquisition. Other lock methods accept
|
|
677
|
+
`request_id`; block-scoped helpers forward initial IDs only to acquisition.
|
|
678
|
+
See the [lock guide](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/locks.md)
|
|
679
|
+
for examples and fencing requirements.
|
|
680
|
+
|
|
674
681
|
`locks.get` returns immutable lock availability, expiry, and fencing-token
|
|
675
682
|
state without acquiring the lock.
|
|
676
683
|
`locks.renew` returns a new immutable lease and leaves the previous value
|
|
@@ -47,57 +47,57 @@ module Volcano
|
|
|
47
47
|
@api_factory = api_factory || method(:build_apis)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def acquire_project_lock(authorization:, key:, ttl:, token:)
|
|
50
|
+
def acquire_project_lock(authorization:, key:, ttl:, token:, request_id: SecureRandom.uuid)
|
|
51
51
|
invoke do
|
|
52
52
|
apis = @api_factory.call(authorization)
|
|
53
53
|
body = Generated::ProjectLockLeaseRequest.new(ttl_seconds: ttl)
|
|
54
|
-
result = apis.locks.acquire_project_lock_with_http_info(key, token,
|
|
54
|
+
result = apis.locks.acquire_project_lock_with_http_info(key, token, request_id, body)
|
|
55
55
|
data, status, headers = result
|
|
56
56
|
response(data, status, headers)
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
def get_project_lock(authorization:, key:)
|
|
60
|
+
def get_project_lock(authorization:, key:, request_id: SecureRandom.uuid)
|
|
61
61
|
invoke do
|
|
62
62
|
apis = @api_factory.call(authorization)
|
|
63
63
|
data, status, headers = apis.locks.get_project_lock_with_http_info(
|
|
64
64
|
key,
|
|
65
|
-
|
|
65
|
+
request_id
|
|
66
66
|
)
|
|
67
67
|
response(data, status, headers)
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
def force_release_project_lock(authorization:, key:)
|
|
71
|
+
def force_release_project_lock(authorization:, key:, request_id: SecureRandom.uuid)
|
|
72
72
|
invoke do
|
|
73
73
|
apis = @api_factory.call(authorization)
|
|
74
74
|
data, status, headers = apis.locks.force_release_project_lock_with_http_info(
|
|
75
75
|
key,
|
|
76
|
-
|
|
76
|
+
request_id
|
|
77
77
|
)
|
|
78
78
|
response(data, status, headers)
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
def renew_project_lock(authorization:, key:, ttl:, token:)
|
|
82
|
+
def renew_project_lock(authorization:, key:, ttl:, token:, request_id: SecureRandom.uuid)
|
|
83
83
|
invoke do
|
|
84
84
|
apis = @api_factory.call(authorization)
|
|
85
85
|
body = Generated::ProjectLockLeaseRequest.new(ttl_seconds: ttl)
|
|
86
86
|
result = apis.locks.renew_project_lock_with_http_info(
|
|
87
|
-
key, token,
|
|
87
|
+
key, token, request_id, body
|
|
88
88
|
)
|
|
89
89
|
data, status, headers = result
|
|
90
90
|
response(data, status, headers)
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
def release_project_lock(authorization:, key:, token:)
|
|
94
|
+
def release_project_lock(authorization:, key:, token:, request_id: SecureRandom.uuid)
|
|
95
95
|
invoke do
|
|
96
96
|
apis = @api_factory.call(authorization)
|
|
97
97
|
data, status, headers = apis.locks.release_project_lock_with_http_info(
|
|
98
98
|
key,
|
|
99
99
|
token,
|
|
100
|
-
|
|
100
|
+
request_id
|
|
101
101
|
)
|
|
102
102
|
response(data, status, headers)
|
|
103
103
|
end
|
|
@@ -10,10 +10,11 @@ module Volcano
|
|
|
10
10
|
RENEWAL_REQUEST_BUDGET_SECONDS = 1.0
|
|
11
11
|
RENEWER_SHUTDOWN_TIMEOUT_SECONDS = 1.0
|
|
12
12
|
|
|
13
|
-
def with_lock(key, ttl:, &)
|
|
13
|
+
def with_lock(key, ttl:, token: nil, request_id: nil, &)
|
|
14
14
|
validate_ttl(ttl)
|
|
15
15
|
started_at = LockLeaseClock.capture
|
|
16
|
-
|
|
16
|
+
lease = acquire(key, ttl: ttl, token: token, request_id: request_id)
|
|
17
|
+
guard = LockGuard.new(lease, ttl: ttl, started_at: started_at)
|
|
17
18
|
owned_key = guard.lease.key
|
|
18
19
|
renewer = lock_renewer(owned_key, guard, ttl)
|
|
19
20
|
LockSession.new(self, owned_key, guard, renewer, method(:renewal_delay)).run(&)
|
data/lib/volcano/locks.rb
CHANGED
|
@@ -13,8 +13,8 @@ module Volcano
|
|
|
13
13
|
@transport = transport
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def get(key)
|
|
17
|
-
payload =
|
|
16
|
+
def get(key, request_id: nil)
|
|
17
|
+
payload = lock_request(:get_project_lock, 200, key: key, request_id: request_id)
|
|
18
18
|
LockState.new(
|
|
19
19
|
held: payload.fetch('held'),
|
|
20
20
|
expires_at: parse_time(payload['expires_at']),
|
|
@@ -22,84 +22,68 @@ module Volcano
|
|
|
22
22
|
)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def acquire(key, ttl:)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
)
|
|
25
|
+
def acquire(key, ttl:, token: nil, request_id: nil)
|
|
26
|
+
validate_ttl(ttl)
|
|
27
|
+
parameters = {
|
|
28
|
+
authorization: @client.service_token.dup.freeze, key: key.dup.freeze,
|
|
29
|
+
ttl: ttl, token: request_uuid(token, 'token'), request_id: request_uuid(request_id, 'request_id')
|
|
30
|
+
}.freeze
|
|
31
|
+
payload = acquire_payload(parameters)
|
|
32
|
+
build_lease(parameters[:key], parameters[:token], payload)
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
def renew(key, lease, ttl:)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
expires_at: parse_time(payload['expires_at']),
|
|
42
|
-
fencing_token: payload['fencing_token']
|
|
43
|
-
)
|
|
35
|
+
def renew(key, lease, ttl:, request_id: nil)
|
|
36
|
+
validate_ttl(ttl)
|
|
37
|
+
payload = lock_request(:renew_project_lock, 200, key: key, ttl: ttl,
|
|
38
|
+
token: lease.token, request_id: request_id)
|
|
39
|
+
build_lease(key, lease.token, payload)
|
|
44
40
|
end
|
|
45
41
|
|
|
46
|
-
def release(key, lease)
|
|
47
|
-
|
|
48
|
-
@transport.release_project_lock(
|
|
49
|
-
authorization: @client.service_token,
|
|
50
|
-
key: key,
|
|
51
|
-
token: lease.token
|
|
52
|
-
)
|
|
53
|
-
end
|
|
54
|
-
Transport.body(response, 204)
|
|
42
|
+
def release(key, lease, request_id: nil)
|
|
43
|
+
lock_request(:release_project_lock, 204, key: key, token: lease.token, request_id: request_id)
|
|
55
44
|
nil
|
|
56
45
|
end
|
|
57
46
|
|
|
58
|
-
def force_release(key)
|
|
59
|
-
|
|
47
|
+
def force_release(key, request_id: nil)
|
|
48
|
+
lock_request(:force_release_project_lock, 204, key: key, request_id: request_id)
|
|
60
49
|
nil
|
|
61
50
|
end
|
|
62
51
|
|
|
63
52
|
private
|
|
64
53
|
|
|
65
|
-
def
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
54
|
+
def acquire_payload(parameters)
|
|
55
|
+
perform_request(:acquire_project_lock, 201, parameters)
|
|
56
|
+
rescue Error::TransportError, Error::ServerError => e
|
|
57
|
+
raise unless e.status.nil? || e.status == 503
|
|
58
|
+
|
|
59
|
+
perform_request(:acquire_project_lock, 201, parameters)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def lock_request(operation, status, **parameters)
|
|
63
|
+
parameters[:authorization] = @client.service_token
|
|
64
|
+
parameters[:request_id] = request_uuid(parameters[:request_id], 'request_id')
|
|
65
|
+
perform_request(operation, status, parameters)
|
|
72
66
|
end
|
|
73
67
|
|
|
74
|
-
def
|
|
75
|
-
Transport.invoke
|
|
76
|
-
|
|
77
|
-
authorization: @client.service_token,
|
|
78
|
-
key: key
|
|
79
|
-
)
|
|
80
|
-
end
|
|
68
|
+
def perform_request(operation, status, parameters)
|
|
69
|
+
response = Transport.invoke { @transport.public_send(operation, **parameters) }
|
|
70
|
+
Transport.body(response, status)
|
|
81
71
|
end
|
|
82
72
|
|
|
83
|
-
def
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
)
|
|
91
|
-
end
|
|
73
|
+
def request_uuid(value, name)
|
|
74
|
+
return SecureRandom.uuid.freeze if value.nil?
|
|
75
|
+
|
|
76
|
+
valid = value.is_a?(String) && value.match?(/\A[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}\z/i)
|
|
77
|
+
raise ArgumentError, "#{name} must be a UUID string" unless valid
|
|
78
|
+
|
|
79
|
+
value.dup.freeze
|
|
92
80
|
end
|
|
93
81
|
|
|
94
|
-
def
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
ttl: ttl,
|
|
100
|
-
token: lease.token
|
|
101
|
-
)
|
|
102
|
-
end
|
|
82
|
+
def build_lease(key, token, payload)
|
|
83
|
+
LockLease.new(
|
|
84
|
+
key: key, token: token, expires_at: parse_time(payload['expires_at']),
|
|
85
|
+
fencing_token: payload['fencing_token']
|
|
86
|
+
)
|
|
103
87
|
end
|
|
104
88
|
|
|
105
89
|
def parse_time(value)
|
data/lib/volcano/version.rb
CHANGED