Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
633724dc
Commit
633724dc
authored
May 27, 2013
by
James Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Timeouts implemented for riak stats operation. Removed failback mode
for fetching riak stats.
parent
5ec35fa3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
59 deletions
+22
-59
library/database/riak
+22
-59
No files found.
library/database/riak
View file @
633724dc
...
...
@@ -91,13 +91,6 @@ import json
import
time
def
is_number
(
s
):
try
:
float
(
s
)
return
True
except
ValueError
:
return
False
def
ring_check
():
rc
,
out
,
err
=
module
.
run_command
(
'riak-admin ringready 2> /dev/null'
)
if
rc
==
0
and
out
.
find
(
'TRUE All nodes agree on the ring'
)
!=
-
1
:
...
...
@@ -105,45 +98,6 @@ def ring_check():
else
:
return
False
def
status_to_json
():
# remove all unnecessary symbols and whitespace
stats
=
''
rc
,
out
,
err
=
module
.
run_command
(
"riak-admin status 2> /dev/null"
)
if
rc
==
0
:
raw_stats
=
out
else
:
module
.
fail_json
(
msg
=
"Could not properly gather stats"
)
for
line
in
raw_stats
.
splitlines
():
stats
+=
line
.
strip
()
+
'
\n
'
stats
=
stats
.
replace
(
'<<'
,
''
)
.
replace
(
'>>'
,
''
)
stats
=
stats
.
replace
(
'
\\
n'
,
''
)
.
replace
(
',
\n
'
,
','
)
stats
=
stats
.
replace
(
": '"
,
': '
)
.
replace
(
"'
\n
"
,
"
\n
"
)
stats
=
stats
.
replace
(
': "['
,
': ['
)
.
replace
(
']"
\n
'
,
"]
\n
"
)
stats
=
stats
.
replace
(
'"'
,
"'"
)
matchObj
=
re
.
compile
(
r"^(.*) : (.*)"
,
re
.
M
|
re
.
I
)
json_stats
=
'{'
for
match
in
matchObj
.
finditer
(
stats
):
key
,
value
=
match
.
groups
()
if
(
value
[
0
]
==
"'"
):
value
=
value
[
1
:
-
1
]
if
not
is_number
(
value
):
value
=
'"'
+
value
+
'"'
json_stats
+=
'"'
+
key
+
'":'
+
value
+
','
json_stats
=
json_stats
[
0
:
-
1
]
json_stats
+=
'}'
return
json_stats
def
main
():
ansible_facts
=
{}
...
...
@@ -153,8 +107,8 @@ def main():
config_dir
=
dict
(
default
=
'/etc/riak'
),
http_conn
=
dict
(
required
=
False
,
default
=
'127.0.0.1:8098'
),
target_node
=
dict
(
default
=
'riak@127.0.0.1'
,
required
=
False
),
wait_for_handoffs
=
dict
(
default
=
Fals
e
,
type
=
'bool'
),
wait_for_ring
=
dict
(
default
=
Fals
e
,
type
=
'bool'
),
wait_for_handoffs
=
dict
(
default
=
Non
e
,
type
=
'bool'
),
wait_for_ring
=
dict
(
default
=
Non
e
,
type
=
'bool'
),
wait_for_service
=
dict
(
required
=
False
,
default
=
None
,
choices
=
[
'kv'
])
)
...
...
@@ -187,24 +141,33 @@ def main():
else
:
module
.
fail_json
(
msg
=
'Could not determine Riak version'
)
# here we attempt to get stats from the http stats interface for 120 seconds.
timeout
=
time
.
time
()
+
120
while
True
:
if
time
.
time
()
>
timeout
:
module
.
fail_json
(
msg
=
'Timeout, could not fetch Riak stats.'
)
try
:
stats_raw
=
urllib2
.
urlopen
(
'http://
%
s/stats'
%
(
http_conn
),
None
,
5
)
.
read
()
break
except
urllib2
.
HTTPError
,
e
:
time
.
sleep
(
5
)
except
urllib2
.
URLError
,
e
:
time
.
sleep
(
5
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
'Could not fetch Riak stats:
%
s'
%
e
)
# here we attempt to load those stats,
try
:
stats_raw
=
urllib2
.
urlopen
(
'http://
%
s/stats'
%
(
http_conn
),
None
,
5
)
.
read
()
except
urllib2
.
HTTPError
,
e
:
stats_raw
=
status_to_json
()
except
urllib2
.
URLError
,
e
:
stats_raw
=
status_to_json
()
except
Exception
,
e
:
stats_raw
=
status_to_json
()
stats
=
json
.
loads
(
stats_raw
)
stats
=
json
.
loads
(
stats_raw
)
except
:
module
.
fail_json
(
msg
=
'Timeout, could not parse Riak stats.'
)
node_name
=
stats
[
'nodename'
]
nodes
=
stats
[
'ring_members'
]
ring_size
=
stats
[
'ring_creation_size'
]
result
=
{
'node_name'
:
node_name
,
'nodes'
:
nodes
,
'ring_size'
:
ring_size
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment