MCPcopy Create free account
hub / github.com/apache/mesos / fromJSON

Method fromJSON

src/common/resources.cpp:739–772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737
738
739Try<vector<Resource>> Resources::fromJSON(
740 const JSON::Array& resourcesJSON,
741 const string& defaultRole)
742{
743 // Convert the JSON Array into a protobuf message and use
744 // that to construct a vector of Resource object.
745 Try<RepeatedPtrField<Resource>> resourcesProtobuf =
746 protobuf::parse<RepeatedPtrField<Resource>>(resourcesJSON);
747
748 if (resourcesProtobuf.isError()) {
749 return Error(
750 "Some JSON resources were not formatted properly: " +
751 resourcesProtobuf.error());
752 }
753
754 vector<Resource> result;
755
756 foreach (Resource& resource, resourcesProtobuf.get()) {
757 // Set the default role if none was specified.
758 //
759 // NOTE: We rely on the fact that the result of this function is
760 // converted to the "post-reservation-refinement" format.
761 if (!resource.has_role() && resource.reservations_size() == 0) {
762 resource.set_role(defaultRole);
763 }
764
765 upgradeResource(&resource);
766
767 // We add the Resource object even if it is empty or invalid.
768 result.push_back(resource);
769 }
770
771 return result;
772}
773
774
775Try<vector<Resource>> Resources::fromSimpleString(

Callers

nothing calls this directly

Calls 6

upgradeResourceFunction · 0.85
foreachFunction · 0.70
errorMethod · 0.65
ErrorFunction · 0.50
isErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected