> On 九月 28, 2016, 10:37 p.m., Jiang Yan Xu wrote: > > src/common/resources.cpp, lines 587-618 > > <https://reviews.apache.org/r/51879/diff/6/?file=1510293#file1510293line587> > > > > No need for the helpers. Just the following is sufficient. > > > > ``` > > Resource resource; > > resource.set_name(name); > > resource.set_role(role); > > > > // Return a Resource with missing value. > > if (_value.isNone()) { > > return resource; > > } > > > > Value _value = result.get(); > > > > if (_value.type() == Value::SCALAR) { > > resource.set_type(Value::SCALAR); > > resource.mutable_scalar()->CopyFrom(_value.scalar()); > > } else if (_value.type() == Value::RANGES) { > > resource.set_type(Value::RANGES); > > resource.mutable_ranges()->CopyFrom(_value.ranges()); > > } else if (_value.type() == Value::SET) { > > resource.set_type(Value::SET); > > resource.mutable_set()->CopyFrom(_value.set()); > > } else { > > return Error( > > "Bad type for resource " + name + " value " + value + > > " type " + Value::Type_Name(_value.type())); > > } > > ```
Seems we still need the `type` for resource when `_value.isNone()`, so the logic could be: ``` Resource resource; resource.set_name(name); resource.set_role(role); // Return a Resource with missing value. if (_value.isNone()) { Try<Value::Type> _type = Resources::valueType(name); if (_type.isError()) { return Error(_type.error()); } resource.set_type(_type.get()); return resource; } Value _value = result.get(); if (_value.type() == Value::SCALAR) { resource.set_type(Value::SCALAR); resource.mutable_scalar()->CopyFrom(_value.scalar()); } else if (_value.type() == Value::RANGES) { resource.set_type(Value::RANGES); resource.mutable_ranges()->CopyFrom(_value.ranges()); } else if (_value.type() == Value::SET) { resource.set_type(Value::SET); resource.mutable_set()->CopyFrom(_value.set()); } else { return Error( "Bad type for resource " + name + " value " + value + " type " + Value::Type_Name(_value.type())); } ``` - Guangya ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/51879/#review150615 ----------------------------------------------------------- On 十月 3, 2016, 11:46 p.m., Anindya Sinha wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/51879/ > ----------------------------------------------------------- > > (Updated 十月 3, 2016, 11: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 > ------- > > When static resources indicate resources with a positive size, we use > that for the resources on the agent. However, --resources can include > resources with no size, which indicates that mesos agent determine the > size of those resources from the agent and uses that information. For > disk resources, this is not allowed for PATH disks since PATH disks > can be carved into smaller chunks and we cannot assume that the whole > physical disk is available to the PATH disk. > > With this change, JSON or textual representation for disk resources > that specify scalar value of 0 would not result in an error, but those > resources will not be accounted for until a valid size is determined > for such resources. A scalar value of -1 in JSON or textual formats > still results in an invalid resource. > > > Diffs > ----- > > include/mesos/resources.hpp 3ef8cacee529addc745b4aeb6398d7606c61b749 > include/mesos/v1/resources.hpp ef56b4960b103a3efd916fab64796aa334ba44c6 > src/common/resources.cpp 0774ff0669e831494d5b12b88e19dfa0a4a3f757 > src/slave/containerizer/containerizer.cpp > d46882baa904fd439bffb23c324828b777228f1c > src/slave/containerizer/mesos/isolators/gpu/allocator.hpp > b2eabfebef99ccebef427d144bb816adc0175ecf > src/slave/containerizer/mesos/isolators/gpu/allocator.cpp > 2e722691475c84afae14009014ea70cc0fdd0e65 > src/v1/resources.cpp 62a644ebbd13cfc0862bd118ba16c43e0f6aaf90 > > Diff: https://reviews.apache.org/r/51879/diff/ > > > Testing > ------- > > Tests passed. > > > Thanks, > > Anindya Sinha > >