| 1929 | |
| 1930 | |
| 1931 | Future<Response> Master::Http::_reserve( |
| 1932 | const SlaveID& slaveId, |
| 1933 | const RepeatedPtrField<Resource>& source, |
| 1934 | const RepeatedPtrField<Resource>& resources, |
| 1935 | const Option<Principal>& principal) const |
| 1936 | { |
| 1937 | Slave* slave = master->slaves.registered.get(slaveId); |
| 1938 | if (slave == nullptr) { |
| 1939 | return BadRequest("No agent found with specified ID"); |
| 1940 | } |
| 1941 | |
| 1942 | // Create an operation. |
| 1943 | Offer::Operation operation; |
| 1944 | operation.set_type(Offer::Operation::RESERVE); |
| 1945 | operation.mutable_reserve()->mutable_source()->CopyFrom(source); |
| 1946 | operation.mutable_reserve()->mutable_resources()->CopyFrom(resources); |
| 1947 | |
| 1948 | Option<Error> error = validateAndUpgradeResources(&operation); |
| 1949 | if (error.isSome()) { |
| 1950 | return BadRequest(error->message); |
| 1951 | } |
| 1952 | |
| 1953 | error = validation::operation::validate( |
| 1954 | operation.reserve(), principal, slave->capabilities); |
| 1955 | |
| 1956 | if (error.isSome()) { |
| 1957 | return BadRequest( |
| 1958 | "Invalid RESERVE operation on agent " + stringify(*slave) + ": " + |
| 1959 | error->message); |
| 1960 | } |
| 1961 | |
| 1962 | return master->authorize( |
| 1963 | principal, ActionObject::reserve(operation.reserve())) |
| 1964 | .then(defer(master->self(), [=](bool authorized) -> Future<Response> { |
| 1965 | if (!authorized) { |
| 1966 | return Forbidden(); |
| 1967 | } |
| 1968 | |
| 1969 | return _operation(slaveId, operation); |
| 1970 | })); |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | Future<Response> Master::Http::reserveResources( |
nothing calls this directly
no test coverage detected