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

support range format in worker #325

Closed
wants to merge 2 commits into from
Closed

support range format in worker #325

wants to merge 2 commits into from

Conversation

yuokada
Copy link
Contributor

@yuokada yuokada commented Mar 4, 2017

resolve #247


Example.

  • worker[01-02].example.com => [worker01.example.com, worker02.example.com]

  • unittest

  • update document

  • git rebase


This change is Reviewable

@kokosing
Copy link
Contributor

kokosing commented Mar 4, 2017 via email

@kokosing
Copy link
Contributor

kokosing commented Mar 4, 2017 via email

@yuokada yuokada changed the title support range format in worker [WIP] support range format in worker Mar 4, 2017
@yuokada
Copy link
Contributor Author

yuokada commented Mar 5, 2017

OK, I make a task-list.

@@ -140,6 +143,24 @@ def validate_workers(workers):
return workers


def expand_host(host):
Copy link
Contributor

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 _

Copy link
Contributor Author

@yuokada yuokada Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to _expand_host

@@ -116,6 +118,7 @@ def validate(conf):
except KeyError:
pass
else:
workers = [h for host in workers for h in expand_host(host)]
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

@@ -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:
Copy link
Contributor

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.

@kokosing
Copy link
Contributor

kokosing commented Mar 7, 2017

@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

@yuokada
Copy link
Contributor Author

yuokada commented Mar 7, 2017

@zpao Oh, sorry. I cancel some tests.

@kokosing
Copy link
Contributor

kokosing commented Mar 7, 2017

@yuokada thanks

kokosing
kokosing previously approved these changes Mar 8, 2017
Copy link
Contributor

@kokosing kokosing left a 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!

@@ -116,6 +118,7 @@ def validate(conf):
except KeyError:
pass
else:
workers = [h for host in workers for h in expand_host(host)]
Copy link
Contributor

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.

self.assertEqual(expected, _expand_host(input_host))


if __name__ == "__main__":
Copy link
Contributor

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 the expand host func
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this doc

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this line

@kokosing kokosing dismissed their stale review March 8, 2017 08:06

missing docs

@yuokada
Copy link
Contributor Author

yuokada commented Mar 8, 2017

I write a documents. Could you review it?

@yuokada yuokada changed the title [WIP] support range format in worker support range format in worker Mar 8, 2017
@yuokada
Copy link
Contributor Author

yuokada commented Mar 8, 2017

The document is like this.


2017-03-09 00 45 24

Copy link
Contributor

@kokosing kokosing left a 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

@@ -140,6 +143,24 @@ def validate_workers(workers):
return workers


def _expand_host(host):
m = re.match("(.*)\[(\d{1,})-(\d{1,})\](.*)", host)
Copy link
Contributor

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)

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]
Copy link
Contributor

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]

Copy link
Contributor Author

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.

Copy link
Contributor

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

else:
return ["{prefix}{num}{suffix}".format(
prefix=prefix, num=i, suffix=suffix)
for i in range(int(start), int(end) + 1)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same with formatting

Copy link
Contributor Author

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

Copy link
Contributor Author

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)]

Copy link
Contributor

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)

Copy link
Member

@rschlussel-zz rschlussel-zz left a 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):
Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the same as

@kokosing
Copy link
Contributor

@yuokada There is a unit test failure on travis

@yuokada
Copy link
Contributor Author

yuokada commented Mar 10, 2017

Update doc.

2017-03-10 18 09 55

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")
Copy link
Contributor Author

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?

Copy link
Member

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"

Copy link
Member

@rschlussel-zz rschlussel-zz left a 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")
Copy link
Member

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"

@rschlussel-zz
Copy link
Member

I made the minor change and merged. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to specify a range or * for hosts in config.json
3 participants