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

Method fromJSON

src/v1/resources.cpp:766–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764
765
766Try<vector<Resource>> Resources::fromJSON(
767 const JSON::Array& resourcesJSON,
768 const string& defaultRole)
769{
770 // Convert the JSON Array into a protobuf message and use
771 // that to construct a vector of Resource object.
772 Try<RepeatedPtrField<Resource>> resourcesProtobuf =
773 protobuf::parse<RepeatedPtrField<Resource>>(resourcesJSON);
774
775 if (resourcesProtobuf.isError()) {
776 return Error(
777 "Some JSON resources were not formatted properly: " +
778 resourcesProtobuf.error());
779 }
780
781 vector<Resource> result;
782
783 foreach (Resource& resource, resourcesProtobuf.get()) {
784 // Set the default role if none was specified.
785 //
786 // NOTE: We rely on the fact that the result of this function is
787 // converted to the "post-reservation-refinement" format.
788 if (!resource.has_role() && resource.reservations_size() == 0) {
789 resource.set_role(defaultRole);
790 }
791
792 // We add the Resource object even if it is empty or invalid.
793 result.push_back(resource);
794 }
795
796 return result;
797}
798
799
800Try<vector<Resource>> Resources::fromSimpleString(

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected