-
Notifications
You must be signed in to change notification settings - Fork 100
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
support range format in worker #325
Conversation
Please update the documentation.
04.03.2017 11:38 "Yukihiro Okada" <[email protected]> napisał(a):
… resolve #247 <#247>
------------------------------
Example.
- worker[01-02].example.com => [worker01.example.com,
worker02.example.com]
------------------------------
You can view, comment on, or merge this pull request online at:
#325
Commit Summary
- Add expand_host func
File Changes
- *M* prestoadmin/standalone/config.py
<https://github.com/prestodb/presto-admin/pull/325/files#diff-0> (21)
Patch Links:
- https://github.com/prestodb/presto-admin/pull/325.patch
- https://github.com/prestodb/presto-admin/pull/325.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#325>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHN_-6VZcU7mppTtRS6YJ95k5xKzOyIAks5riT8lgaJpZM4MTDIv>
.
|
Please also add unit tests.
04.03.2017 17:41 "Grzegorz Kokosiński" <[email protected]> napisał(a):
… Please update the documentation.
04.03.2017 11:38 "Yukihiro Okada" ***@***.***> napisał(a):
> resolve #247 <#247>
> ------------------------------
>
> Example.
>
> - worker[01-02].example.com => [worker01.example.com,
> worker02.example.com]
>
> ------------------------------
> You can view, comment on, or merge this pull request online at:
>
> #325
> Commit Summary
>
> - Add expand_host func
>
> File Changes
>
> - *M* prestoadmin/standalone/config.py
> <https://github.com/prestodb/presto-admin/pull/325/files#diff-0> (21)
>
> Patch Links:
>
> - https://github.com/prestodb/presto-admin/pull/325.patch
> - https://github.com/prestodb/presto-admin/pull/325.diff
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#325>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AHN_-6VZcU7mppTtRS6YJ95k5xKzOyIAks5riT8lgaJpZM4MTDIv>
> .
>
|
OK, I make a task-list. |
prestoadmin/standalone/config.py
Outdated
@@ -140,6 +143,24 @@ def validate_workers(workers): | |||
return workers | |||
|
|||
|
|||
def expand_host(host): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it private by prefixing method with _
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to _expand_host
prestoadmin/standalone/config.py
Outdated
@@ -116,6 +118,7 @@ def validate(conf): | |||
except KeyError: | |||
pass | |||
else: | |||
workers = [h for host in workers for h in expand_host(host)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if I don't want name expansion like that?
For example what if I have host names which are exactly like cdh5-1
and cdh5-2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function expand host when enclose with bracket.
"cdh5-[1-2].example.com" => expand
"cdh5-1.example.com" => not expand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. That sounds good as long [
and ]
are forbidden to be used in host names.
See https://en.wikipedia.org/wiki/Hostname.
The Internet standards (Requests for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.
so we are good here.
prestoadmin/standalone/config.py
Outdated
@@ -140,6 +143,24 @@ def validate_workers(workers): | |||
return workers | |||
|
|||
|
|||
def expand_host(host): | |||
m = re.match("(.*)\[(\d{1,})-(\d{1,})\](.*)", host) | |||
if m is not None and len(m.groups()) == 4: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to model it in more object-oriented manner. So it it would be possible to inject different expansions strategies.
@yuokada Please notice that with every commit you start a travis build. presto-admin travis build requires 7 executors for about 30 minutes. These executors are shared between all the prestodb projects |
@zpao Oh, sorry. I cancel some tests. |
@yuokada thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash the commits and add the docs.
Good job so far!
prestoadmin/standalone/config.py
Outdated
@@ -116,6 +118,7 @@ def validate(conf): | |||
except KeyError: | |||
pass | |||
else: | |||
workers = [h for host in workers for h in expand_host(host)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. That sounds good as long [
and ]
are forbidden to be used in host names.
See https://en.wikipedia.org/wiki/Hostname.
The Internet standards (Requests for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.
so we are good here.
tests/unit/test_expand.py
Outdated
self.assertEqual(expected, _expand_host(input_host)) | ||
|
||
|
||
if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this if
tests/unit/test_expand.py
Outdated
|
||
""" | ||
Tests the expand host func | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this doc
tests/unit/test_expand.py
Outdated
input_host = "worker0[1-2].example.com" | ||
expected = ["worker01.example.com", "worker02.example.com"] | ||
self.assertEqual(expected, _expand_host(input_host)) | ||
# self.assertEqualIgnoringOrder(expected, cmd_output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this line
I write a documents. Could you review it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments, looks good, once you address them I will merge your code
@cawallin @rschlussel you may may also want to take a look
prestoadmin/standalone/config.py
Outdated
@@ -140,6 +143,24 @@ def validate_workers(workers): | |||
return workers | |||
|
|||
|
|||
def _expand_host(host): | |||
m = re.match("(.*)\[(\d{1,})-(\d{1,})\](.*)", host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not use short names like m
please replace to m
to soemthing like match
and num_fnt
to number_format
(if understand it correctly)
prestoadmin/standalone/config.py
Outdated
host_list = [num_fmt.format(i) for i in range(int(start), int(end) + 1)] | ||
return ["{prefix}{num}{suffix}".format( | ||
prefix=prefix, num=i, suffix=suffix) | ||
for i in host_list] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would format this code as:
return ["{prefix}{num}{suffix}".format(prefix=prefix, num=i, suffix=suffix) for i in host_list]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that one line is too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... but in that case I would prefer to either extract method or variable, splitting line does not help IMO
prestoadmin/standalone/config.py
Outdated
else: | ||
return ["{prefix}{num}{suffix}".format( | ||
prefix=prefix, num=i, suffix=suffix) | ||
for i in range(int(start), int(end) + 1)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same with formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prestoadmin/standalone/config.py:155:121: E501 line too long (129 > 120 characters)
pep8 error occurred.
https://travis-ci.org/prestodb/presto-admin/jobs/209255743
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I format this code.
return ["{prefix}{num}{suffix}".format(prefix=prefix, num=i, suffix=suffix)
for i in range(int(start), int(end) + 1)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract a method then. When you take a look now (when you removed line splits) it is clear that code (the one with "...".format(...)
is repeated twice)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! A few minor things.
@@ -140,6 +143,24 @@ def validate_workers(workers): | |||
return workers | |||
|
|||
|
|||
def _expand_host(host): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should raise an error if the bottom of the range is greater than the top (e.g. worker[5-2]
. And also add a unit test for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I add a unittest: test_except_expand_host
.
@@ -93,6 +93,18 @@ username and port, a sample ``config.json`` would be: | |||
"workers": ["slave1","slave2","slave3","slave4","slave5"] | |||
} | |||
|
|||
.. NOTE:: the ``workers`` support range format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a note, make this its own paragraph with a bit more description.
e.g.
You can specify a range of workers by including the number range in brackets in the worker name. For example:
(and then keep your example)
|
||
"workers": ["worker[01-03]"] | ||
|
||
is same as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the same as
@yuokada There is a unit test failure on travis |
if match is not None and len(match.groups()) == 4: | ||
prefix, start, end, suffix = match.groups() | ||
if int(start) > int(end): | ||
raise ValueError("the range format must be ascending order") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rschlussel Is the error message is OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "the range must be in ascending order"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slight change in the error message, but otherwise looks good. Thanks!
if match is not None and len(match.groups()) == 4: | ||
prefix, start, end, suffix = match.groups() | ||
if int(start) > int(end): | ||
raise ValueError("the range format must be ascending order") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "the range must be in ascending order"
I made the minor change and merged. Thanks! |
resolve #247
Example.
worker[01-02].example.com
=>[worker01.example.com, worker02.example.com]
unittest
update document
git rebase
This change is