mesos-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jiang Yan Xu <...@jxu.me>
Subject Re: Review Request 51999: Refactor parsing of resources.
Date Wed, 05 Oct 2016 17:23:09 GMT


> On Sept. 27, 2016, 10:28 a.m., Jiang Yan Xu wrote:
> > include/mesos/resources.hpp, line 199
> > <https://reviews.apache.org/r/51999/diff/5/?file=1510281#file1510281line199>
> >
> >     s/JSON::Array& resourcesJSON/std::string text/
> >     
> >     Looking the current and potential call-sites, it doesn't look like we ever directly
call this method with a `JSON::Array` not parsed from text.
> >     
> >     Considering this, I think it would be more consistent to have the following
three methods which take the same argument list.
> >     
> >     ```
> >     static Try<Resources> parse(
> >         const std::string& text,
> >         const std::string& defaultRole = "*");
> >     
> >     static Try<std::vector<Resource>> fromJSONString(
> >         const std::string& text,
> >         const std::string& defaultRole = "*");
> >     
> >     static Try<vector<Resource>> fromSimpleString(
> >         const std::string& text,
> >         const std::string& defaultRole = "*")
> >     ```
> 
> Anindya Sinha wrote:
>     For JSON handling, we do the following in sequence:
>     (1) `JSON::parse<JSON::Array>()` converts input string to JSON array. 
>     (2) `protobuf::parse<RepeatedPtrField<Resource>>(resourcesJSON)` converts
the JSON array to protobuf.
>     
>     If we call both of these in `fromJSONString()`, then in `Resources::parse()`, we
would not be able to deduce which of the above 2 functions failed. This is needed since if
it failed in (1), it means we parse assuming text; whereas if it failed in (2), that is an
error since protobuf conversion failed for the JSON (we should not assume it is text).
>     
>     So, I think this should work:
>     In `Resources::parse()`:
>     - Convert to JSON array (`JSON::parse<JSON::Array>()`).
>     - If `JSON::parse<JSON::Array>()` succeeds, process JSON array in `fromJSONString()`.
Any failure here is an error condition.
>     - If `JSON::parse<JSON::Array>()` fails, assume it is text and process in `fromSimpleString()`.

OK, makes sense. Some of my other comments were based on the assumption of this method taking
a string. I see that Guangya has already made comments about renaming it to `fromJSONArray()`.
I'll add some additional comments.


> On Sept. 27, 2016, 10:28 a.m., Jiang Yan Xu wrote:
> > src/tests/resources_tests.cpp, lines 630-657
> > <https://reviews.apache.org/r/51999/diff/5/?file=1510284#file1510284line630>
> >
> >     With out refactor, the result of `Resources::parse()` doesn't change right?
> 
> Jiang Yan Xu wrote:
>     s/out/our/
> 
> Anindya Sinha wrote:
>     Im original code: If a resource in text format is encountered with value of 0, it
is dropped; but in JSON, it flags an error. This patch makes the behavior same, ie. just drop
if a `Resource` has a value of 0. Hence, this test would fail for value of 0. So I modified
this test to test for negative values which is obviously an Error.

OK, I don't think parse should return Error for empty values either.


- Jiang Yan


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/51999/#review150494
-----------------------------------------------------------


On Oct. 3, 2016, 4:46 p.m., Anindya Sinha wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/51999/
> -----------------------------------------------------------
> 
> (Updated Oct. 3, 2016, 4:46 p.m.)
> 
> 
> Review request for mesos and Jiang Yan Xu.
> 
> 
> Bugs: MESOS-6062
>     https://issues.apache.org/jira/browse/MESOS-6062
> 
> 
> Repository: mesos
> 
> 
> Description
> -------
> 
> Refactored `Resources::parse()` into 2 separate static functions:
> 1. Resources::fromJSONString() to parse JSON representation of
>    resources.
> 2. Resources::fromSimpleString() to parse text representation of
>    resources.
> 
> Since these 2 new functions return a `Try<vector<Resource>>`, the
> existing `Resources::parse()` implicitly converts that to a
> `Resources` object. This refactor is done to retrieve all resources
> (include empty resources) required for auto detection of root
> and MOUNT disks.
> 
> 
> Diffs
> -----
> 
>   include/mesos/resources.hpp 3ef8cacee529addc745b4aeb6398d7606c61b749 
>   include/mesos/v1/resources.hpp ef56b4960b103a3efd916fab64796aa334ba44c6 
>   src/common/resources.cpp 0774ff0669e831494d5b12b88e19dfa0a4a3f757 
>   src/tests/resources_tests.cpp 3e493007d6d1d8194d07035aaa1cde28dedf2b5a 
>   src/v1/resources.cpp 62a644ebbd13cfc0862bd118ba16c43e0f6aaf90 
> 
> Diff: https://reviews.apache.org/r/51999/diff/
> 
> 
> Testing
> -------
> 
> All tests passed.
> 
> 
> Thanks,
> 
> Anindya Sinha
> 
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message