> On 九月 27, 2016, 5:28 p.m., Jiang Yan Xu wrote: > > src/common/resources.cpp, lines 587-617 > > <https://reviews.apache.org/r/51999/diff/5/?file=1510283#file1510283line587> > > > > Is the following cleaner? (I added the logic to validate resources in > > the result vector instead of implicit conversion) > > > > ``` > > Try<vector<Resource>> resources = fromJSONString(text, defaultRole); > > > > // Parsing as a simple string if parsing as a JSON string fails. > > if (resources.isError()) { > > resources = fromSimpleString(text, defaultRole); > > } > > > > if (resources.isError()) { > > return Error(resources.error()); > > } > > > > Resources result; > > > > foreach (const Resource& resource, resoruces) { > > // If invalid, propgate error instead of skipping the resource. > > Option<Error> error = Resources::validate(resource); > > > > if (error.isSome()) { > > return error.get(); > > } > > > > result += resource; > > } > > > > Option<Error> error = internal::validateCommandLineResources(result); > > if (error.isSome()) { > > return error.get(); > > } > > > > return result; > > ```
1) Can we kill the validation? Seems we already done the validation in each sub function. ``` // If invalid, propgate error instead of skipping the resource. Option<Error> error = Resources::validate(resource); ``` 2) Using `result.add(resource)` instead. - Guangya ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/51999/#review150494 ----------------------------------------------------------- On 九月 26, 2016, 8:58 p.m., Anindya Sinha wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/51999/ > ----------------------------------------------------------- > > (Updated 九月 26, 2016, 8:58 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 > >
