> On Sept. 12, 2017, 1:07 p.m., Dmytro Grinenko wrote:
> > ambari-common/src/main/python/resource_management/libraries/functions/stack_select.py
> > Lines 125 (patched)
> > <https://reviews.apache.org/r/62226/diff/2/?file=1819598#file1819598line125>
> >
> > According to code below, this function would be called
> > "get_supported_packages" each time in for cycle and would do/return the
> > same. Can we optimize this?
>
> Jonathan Hurley wrote:
> Yes, I thought about the fact it's called a lot. The problem is that
> caching the result wouldn't work since we don't know when to clear the cache.
> How would you recommend that we optimize this?
No need to cache it in the script-life cycle, it is enough only for
function-call lifetime, as i dont see any change, which may cause output change
per function call.
so it could be like:
def is_package_supported(package, pkgs=None):
if not pkgs:
pkgs = get_supported_packages()
..........
def get_packages():
...
pkgs = get_supported_packages()
for .........:
if not is_package_supported(package, pkgs)
.........
> On Sept. 12, 2017, 1:07 p.m., Dmytro Grinenko wrote:
> > ambari-common/src/main/python/resource_management/libraries/functions/stack_select.py
> > Lines 145 (patched)
> > <https://reviews.apache.org/r/62226/diff/2/?file=1819598#file1819598line145>
> >
> > while map function is present in python, using generators is more
> > prefferable
>
> Jonathan Hurley wrote:
> I've never used generators before - the syntax looks a bit cumbersome for
> what's needed here. Can you provide an example of what a generator to trim a
> string would look like?
return (s.strip() for s in stdout.splitlines()) # this would return gerator,
which supports iterative interface
pros:
- actuall method execution would be issues only when you will call iterator,
each result would return via "yield" (code would run only once)
cons:
- this would be not list, so no index accessing and only one cycle
return [s.strip() for s in stdout.splitlines()] # this would return list
- this will return list
- Dmytro
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62226/#review185174
-----------------------------------------------------------
On Sept. 11, 2017, 7:43 p.m., Jonathan Hurley wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/62226/
> -----------------------------------------------------------
>
> (Updated Sept. 11, 2017, 7:43 p.m.)
>
>
> Review request for Ambari, Dmytro Grinenko, Dmitro Lisnichenko, and Nate Cole.
>
>
> Bugs: AMBARI-21931
> https://issues.apache.org/jira/browse/AMBARI-21931
>
>
> Repository: ambari
>
>
> Description
> -------
>
> There are several "INVALID" types listed in the stack_packages.json file.
> These were placeholders that need to be updated with the packages exposed by
> the stack-select tool.
>
> {code}
> ...
> "HDFS_CLIENT": {
> "STACK-SELECT-PACKAGE": "hadoop-client",
> "INSTALL": [
> "hadoop-client"
> ],
> "PATCH": [
> "INVALID"
> ],
> "STANDARD": [
> "hadoop-client"
> ]
> },
> ...
> {code}
>
>
> Diffs
> -----
>
>
> ambari-common/src/main/python/resource_management/libraries/functions/stack_select.py
> eac1bef13c
>
> ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_packages.json
> 704fb54293
> ambari-server/src/test/python/TestStackSelect.py 3d4e5b6a43
> ambari-server/src/test/python/stacks/utils/RMFTestCase.py 0341092b69
>
>
> Diff: https://reviews.apache.org/r/62226/diff/2/
>
>
> Testing
> -------
>
> ----------------------------------------------------------------------
> Total run:1191
> Total errors:0
> Total failures:0
> OK
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 58.379 s
> [INFO] Finished at: 2017-09-11T16:25:26-04:00
> [INFO] Final Memory: 21M/619M
> [INFO]
> ------------------------------------------------------------------------
>
>
> Thanks,
>
> Jonathan Hurley
>
>