Move allocator header and proto to own package. This is the second part of moving allocator to own package: 1. Move the non-versioned allocator.proto and allocator.hpp; 2. Move namespace of `Allocator` base class; 3. Fix allocation-module.md; 4. Call out allocator api change in docs/upgrades.md.
Review: https://reviews.apache.org/r/49118/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/170ac150 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/170ac150 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/170ac150 Branch: refs/heads/master Commit: 170ac150edd12ddbe06de1b35b827767e0d82c55 Parents: c335bfc Author: Zhitao Li <zhitaoli...@gmail.com> Authored: Sun Jun 26 20:52:30 2016 -0700 Committer: Vinod Kone <vinodk...@gmail.com> Committed: Sun Jun 26 20:52:30 2016 -0700 ---------------------------------------------------------------------- CHANGELOG | 3 + docs/allocation-module.md | 8 +- docs/upgrades.md | 5 + include/mesos/allocator/allocator.hpp | 394 ++++++++++++++++++ include/mesos/allocator/allocator.proto | 51 +++ include/mesos/maintenance/maintenance.proto | 4 +- include/mesos/master/allocator.hpp | 395 ------------------- include/mesos/master/allocator.proto | 51 --- include/mesos/module/allocator.hpp | 12 +- src/CMakeLists.txt | 2 +- src/Makefile.am | 18 +- src/examples/test_allocator_module.cpp | 4 +- src/local/local.cpp | 4 +- src/local/local.hpp | 4 +- src/master/allocator/allocator.cpp | 4 +- src/master/allocator/mesos/allocator.hpp | 25 +- src/master/allocator/mesos/hierarchical.cpp | 2 +- src/master/allocator/mesos/hierarchical.hpp | 7 +- src/master/http.cpp | 9 +- src/master/main.cpp | 4 +- src/master/master.cpp | 12 +- src/master/master.hpp | 6 +- src/tests/allocator.hpp | 14 +- src/tests/cluster.cpp | 6 +- src/tests/cluster.hpp | 6 +- src/tests/fault_tolerance_tests.cpp | 2 +- src/tests/hierarchical_allocator_tests.cpp | 4 +- src/tests/master_allocator_tests.cpp | 4 +- src/tests/master_authorization_tests.cpp | 2 +- src/tests/master_maintenance_tests.cpp | 4 +- src/tests/master_slave_reconciliation_tests.cpp | 2 +- src/tests/master_tests.cpp | 2 +- src/tests/mesos.cpp | 2 +- src/tests/mesos.hpp | 2 +- src/tests/rate_limiting_tests.cpp | 2 +- src/tests/reservation_tests.cpp | 2 +- 36 files changed, 546 insertions(+), 532 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/CHANGELOG ---------------------------------------------------------------------- diff --git a/CHANGELOG b/CHANGELOG index c987d19..7a44422 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -168,6 +168,9 @@ Additional API Changes: * [MESOS-5680] - We should not 'chown -R' on persistent volumes every time container tries to use it. + * [MESOS-5642] - Namespace and header file of `Allocator` has been moved to + be consistent with other packages. + 3rd Party Upgrades: * [MESOS-4805] - Upgraded vendored ry-http-parser-1c3624a to nodejs/http-parser 2.6.1. * [MESOS-4678] - Upgraded vendored protobuf 2.5.0 to 2.6.1. http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/docs/allocation-module.md ---------------------------------------------------------------------- diff --git a/docs/allocation-module.md b/docs/allocation-module.md index 6cb1392..81f9d0c 100644 --- a/docs/allocation-module.md +++ b/docs/allocation-module.md @@ -9,14 +9,14 @@ The logic that the Mesos master uses to determine which frameworks to make resou To use a custom allocator in Mesos, one must: -- [Implement](#writing-a-custom-allocator) the `Allocator` interface as defined in `mesos/master/allocator.hpp`, +- [Implement](#writing-a-custom-allocator) the `Allocator` interface as defined in `mesos/allocator/allocator.hpp`, - [Wrap](#wiring-up-a-custom-allocator) the allocator implementation in a module and load it in the Mesos master. <a name="writing-a-custom-allocator"></a> ## Writing a custom allocator -Allocator modules are implemented in C++, the same language in which Mesos is written. They must subclass the `Allocator` interface defined in `mesos/master/allocator.hpp`. However, your implementation can be a C++ proxy, which delegates calls to an actual allocator written in a language of your choice. +Allocator modules are implemented in C++, the same language in which Mesos is written. They must subclass the `Allocator` interface defined in `mesos/allocator/allocator.hpp`. However, your implementation can be a C++ proxy, which delegates calls to an actual allocator written in a language of your choice. The default allocator is `HierarchicalDRFAllocatorProcess`, which lives in `$MESOS_HOME/src/master/allocator/mesos/hierarchical.hpp`. Like most Mesos components, it is actor-based, which means all interface methods are non-blocking and return immediately after putting the corresponding action into the actor's queue. If you would like to design your custom allocator in a similar manner, subclass `MesosAllocatorProcess` from `$MESOS_HOME/src/master/allocator/mesos/allocator.hpp` and wrap your actor-based allocator in `MesosAllocator`. This dispatches calls to the underlying actor and controls its lifetime. You can refer to `HierarchicalDRFAllocatorProcess` as a starting place if you choose to write your own actor-based allocation module. @@ -37,14 +37,14 @@ Once a custom allocator has been written, the next step is to override the built An allocator module is a factory function and a module description, as defined in `mesos/module/allocator.hpp`. Assuming the allocation logic is implemented by the `ExternalAllocator` class declared in `external_allocator.hpp`, the following snippet describes the implementation of an allocator module named `ExternalAllocatorModule`: ~~~{.cpp} -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/module/allocator.hpp> #include <stout/try.hpp> #include "external_allocator.hpp" using namespace mesos; -using mesos::master::allocator::Allocator; +using mesos::allocator::Allocator; using mesos::internal::master::allocator::HierarchicalDRFAllocator; static Allocator* createExternalAllocator(const Parameters& parameters) http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/docs/upgrades.md ---------------------------------------------------------------------- diff --git a/docs/upgrades.md b/docs/upgrades.md index be3bd27..079e04f 100644 --- a/docs/upgrades.md +++ b/docs/upgrades.md @@ -72,6 +72,7 @@ We categorize the changes as follows: </td> <td style="word-wrap: break-word; overflow-wrap: break-word;"><!--Module API--> <li>C <a href="#1-0-x-authorizer">Authorizer</a></li> + <li>C <a href="#1-0-x-allocator">Allocator</a></li> </td> <td style="word-wrap: break-word; overflow-wrap: break-word;"><!--Endpoints--> <li>C <a href="#1-0-x-status-code">HTTP return codes</a></li> @@ -262,6 +263,10 @@ We categorize the changes as follows: * Authorization-based HTTP endpoint filtering enables operators to restrict which parts of the cluster state a user is authorized to see. Consider for example the `/state` master endpoint: an operator can now authorize users to only see a subset of the running frameworks, tasks, or executors. * The ``subject` and `object` fields in the authorization::Request protobuf message have been changed to be optional. If these fields are not set, the request should only be allowed for ACLs with `ANY` semantics. NOTE: This is a semantic change for authorizer modules. +<a name="1-0-x-allocator"></a> + +* Namespace and header file of `Allocator` has been moved to be consistent with other packages. + <a name="1-0-x-endpoint-authorization"></a> * Mesos 1.0 introduces authorization support for several HTTP endpoints. Note that some of these endpoints are used by the web UI, and thus using the web UI in a cluster with authorization enabled will require that ACLs be set appropriately. Please refer to the [authorization documentation](authorization.md) for details. http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/include/mesos/allocator/allocator.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/allocator/allocator.hpp b/include/mesos/allocator/allocator.hpp new file mode 100644 index 0000000..98025bc --- /dev/null +++ b/include/mesos/allocator/allocator.hpp @@ -0,0 +1,394 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef __MESOS_ALLOCATOR_ALLOCATOR_HPP__ +#define __MESOS_ALLOCATOR_ALLOCATOR_HPP__ + +#include <string> +#include <vector> + +// ONLY USEFUL AFTER RUNNING PROTOC. +#include <mesos/allocator/allocator.pb.h> + +#include <mesos/maintenance/maintenance.hpp> + +#include <mesos/quota/quota.hpp> + +#include <mesos/resources.hpp> + +#include <process/future.hpp> + +#include <stout/duration.hpp> +#include <stout/hashmap.hpp> +#include <stout/hashset.hpp> +#include <stout/lambda.hpp> +#include <stout/option.hpp> +#include <stout/try.hpp> + +namespace mesos { +namespace allocator { + +/** + * Basic model of an allocator: resources are allocated to a framework + * in the form of offers. A framework can refuse some resources in + * offers and run tasks in others. Allocated resources can have offer + * operations applied to them in order for frameworks to alter the + * resource metadata (e.g. creating persistent volumes). Resources can + * be recovered from a framework when tasks finish/fail (or are lost + * due to an agent failure) or when an offer is rescinded. + * + * This is the public API for resource allocators. + */ +class Allocator +{ +public: + /** + * Attempts either to create a built-in DRF allocator or to load an + * allocator instance from a module using the given name. If `Try` + * does not report an error, the wrapped `Allocator*` is not null. + * + * @param name Name of the allocator. + */ + static Try<Allocator*> create(const std::string& name); + + Allocator() {} + + virtual ~Allocator() {} + + /** + * Initializes the allocator when the master starts up. Any errors in + * initialization should fail fast and result in an ABORT. The master expects + * the allocator to be successfully initialized if this call returns. + * + * @param allocationInterval The allocate interval for the allocator, it + * determines how often the allocator should perform the batch + * allocation. An allocator may also perform allocation based on events + * (a framework is added and so on), this depends on the implementation. + * @param offerCallback A callback the allocator uses to send allocations + * to the frameworks. + * @param inverseOfferCallback A callback the allocator uses to send reclaim + * allocations from the frameworks. + * @param weights Configured per-role weights. Any roles that do not + * appear in this map will be assigned the default weight of 1. + */ + virtual void initialize( + const Duration& allocationInterval, + const lambda::function< + void(const FrameworkID&, + const hashmap<SlaveID, Resources>&)>& offerCallback, + const lambda::function< + void(const FrameworkID&, + const hashmap<SlaveID, UnavailableResources>&)>& + inverseOfferCallback, + const hashmap<std::string, double>& weights) = 0; + + /** + * Informs the allocator of the recovered state from the master. + * + * Because it is hard to define recovery for a running allocator, this + * method should be called after `initialize()`, but before actual + * allocation starts (i.e. `addSlave()` is called). + * + * TODO(alexr): Consider extending the signature with expected + * frameworks count once it is available upon the master failover. + * + * @param quotas A (possibly empty) collection of quotas, keyed by + * their role, known to the master. + */ + virtual void recover( + const int expectedAgentCount, + const hashmap<std::string, Quota>& quotas) = 0; + + /** + * Adds a framework to the Mesos cluster. The allocator is invoked when + * a new framework joins the Mesos cluster and is entitled to participate + * in resource sharing. + * + * @param used Resources used by this framework. The allocator should + * account for these resources when updating the allocation of this + * framework. + */ + virtual void addFramework( + const FrameworkID& frameworkId, + const FrameworkInfo& frameworkInfo, + const hashmap<SlaveID, Resources>& used) = 0; + + /** + * Removes a framework from the Mesos cluster. It is up to an allocator to + * decide what to do with framework's resources. For example, they may be + * released and added back to the shared pool of resources. + */ + virtual void removeFramework( + const FrameworkID& frameworkId) = 0; + + /** + * Activates a framework in the Mesos cluster. + * Offers are only sent to active frameworks. + */ + virtual void activateFramework( + const FrameworkID& frameworkId) = 0; + + /** + * Deactivates a framework in the Mesos cluster. + * Resource offers are not sent to deactivated frameworks. + */ + virtual void deactivateFramework( + const FrameworkID& frameworkId) = 0; + + /** + * Updates capabilities of a framework in the Mesos cluster. + * + * This will be invoked when a framework is re-added. As some of the + * framework's capabilities may be updated when re-added, this API should + * update the capabilities of the newly added framework to Mesos cluster to + * reflect the latest framework info. Please refer to the design document here + * https://cwiki.apache.org/confluence/display/MESOS/Design+doc:+Updating+Framework+Info // NOLINT + * for more details related to framework update. + */ + virtual void updateFramework( + const FrameworkID& frameworkId, + const FrameworkInfo& frameworkInfo) = 0; + + /** + * Adds or re-adds an agent to the Mesos cluster. It is invoked when a + * new agent joins the cluster or in case of agent recovery. + * + * @param slaveId ID of the agent to be added or re-added. + * @param slaveInfo Detailed info of the agent. The slaveInfo resources + * correspond directly to the static --resources flag value on the agent. + * @param total The `total` resources are passed explicitly because it + * includes resources that are dynamically "checkpointed" on the agent + * (e.g. persistent volumes, dynamic reservations, etc). + * @param used Resources that are allocated on the current agent. + */ + virtual void addSlave( + const SlaveID& slaveId, + const SlaveInfo& slaveInfo, + const Option<Unavailability>& unavailability, + const Resources& total, + const hashmap<FrameworkID, Resources>& used) = 0; + + /** + * Removes an agent from the Mesos cluster. All resources belonging to this + * agent should be released by the allocator. + */ + virtual void removeSlave( + const SlaveID& slaveId) = 0; + + /** + * Updates an agent. + * + * Updates the latest oversubscribed resources for an agent. + * TODO(vinod): Instead of just oversubscribed resources have this + * method take total resources. We can then reuse this method to + * update Agent's total resources in the future. + * + * @param oversubscribed The new oversubscribed resources estimate from + * the agent. The oversubscribed resources include the total amount + * of oversubscribed resources that are allocated and available. + */ + virtual void updateSlave( + const SlaveID& slave, + const Resources& oversubscribed) = 0; + + /** + * Activates an agent. This is invoked when an agent reregisters. Offers + * are only sent for activated agents. + */ + virtual void activateSlave( + const SlaveID& slaveId) = 0; + + /** + * Deactivates an agent. + * + * This is triggered if an agent disconnects from the master. The allocator + * should treat all offers from the deactivated agent as rescinded. (There + * is no separate call to the allocator to handle this). Resources aren't + * "recovered" when an agent deactivates because the resources are lost. + */ + virtual void deactivateSlave( + const SlaveID& slaveId) = 0; + + /** + * Updates the list of trusted agents. + * + * This is invoked when the master starts up with the --whitelist flag. + * + * @param whitelist A set of agents that are allowed to contribute + * their resources to the resource pool. + */ + virtual void updateWhitelist( + const Option<hashset<std::string>>& whitelist) = 0; + + /** + * Requests resources for a framework. + * + * A framework may request resources via this call. It is up to the allocator + * how to react to this request. For example, a request may be ignored, or + * may influence internal priorities the allocator may keep for frameworks. + */ + virtual void requestResources( + const FrameworkID& frameworkId, + const std::vector<Request>& requests) = 0; + + /** + * Updates allocation by applying offer operations. + * + * This call is mainly intended to support persistence-related features + * (dynamic reservation and persistent volumes). The allocator may react + * differently for certain offer operations. The allocator should use this + * call to update bookkeeping information related to the framework. + */ + virtual void updateAllocation( + const FrameworkID& frameworkId, + const SlaveID& slaveId, + const std::vector<Offer::Operation>& operations) = 0; + + /** + * Updates available resources on an agent based on a sequence of offer + * operations. Operations may include reserve, unreserve, create or destroy. + * + * @param slaveId ID of the agent. + * @param operations The offer operations to apply to this agent's resources. + */ + virtual process::Future<Nothing> updateAvailable( + const SlaveID& slaveId, + const std::vector<Offer::Operation>& operations) = 0; + + /** + * Updates unavailability for an agent. + * + * We currently support storing the next unavailability, if there is one, + * per agent. If `unavailability` is not set then there is no known upcoming + * unavailability. This might require the implementation of the function to + * remove any inverse offers that are outstanding. + */ + virtual void updateUnavailability( + const SlaveID& slaveId, + const Option<Unavailability>& unavailability) = 0; + + /** + * Updates inverse offer. + * + * Informs the allocator that the inverse offer has been responded to or + * revoked. + * + * @param unavailableResources The `unavailableResources` can be used by the + * allocator to distinguish between different inverse offers sent to the + * same framework for the same slave. + * @param status If `status` is not set then the inverse offer was not + * responded to, possibly because the offer timed out or was rescinded. + * This might require the implementation of the function to remove any + * inverse offers that are outstanding. + * @param filters A filter attached to the inverse offer can be used by the + * framework to control when it wants to be contacted again with the + * inverse offer. The "filters" for InverseOffers are identical to the + * existing mechanism for re-offering Offers to frameworks. + */ + virtual void updateInverseOffer( + const SlaveID& slaveId, + const FrameworkID& frameworkId, + const Option<UnavailableResources>& unavailableResources, + const Option<InverseOfferStatus>& status, + const Option<Filters>& filters = None()) = 0; + + /** + * Retrieves the status of all inverse offers maintained by the allocator. + */ + virtual process::Future< + hashmap<SlaveID, + hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>> + getInverseOfferStatuses() = 0; + + /** + * Recovers resources. + * + * Used to update the set of available resources for a specific agent. This + * method is invoked to inform the allocator about allocated resources that + * have been refused or are no longer in use. + */ + virtual void recoverResources( + const FrameworkID& frameworkId, + const SlaveID& slaveId, + const Resources& resources, + const Option<Filters>& filters) = 0; + + /** + * Suppresses offers. + * + * Informs the allocator to stop sending offers to the framework. + */ + virtual void suppressOffers( + const FrameworkID& frameworkId) = 0; + + /** + * Revives offers for a framework. This is invoked by a framework when + * it wishes to receive filtered resources or offers immediately. + */ + virtual void reviveOffers( + const FrameworkID& frameworkId) = 0; + + /** + * Informs the allocator to set quota for the given role. + * + * It is up to the allocator implementation how to satisfy quota. An + * implementation may employ different strategies for roles with or + * without quota. Hence an empty (or zero) quota is not necessarily the + * same as an absence of quota. Logically, this method implies that the + * given role should be transitioned to the group of roles with quota + * set. An allocator implementation may assert quota for the given role + * is not set prior to the call and react accordingly if this assumption + * is violated (i.e. fail). + * + * TODO(alexr): Consider returning a future which an allocator can fail + * in order to report failure. + * + * TODO(alexr): Consider adding an `updateQuota()` method which allows + * updating existing quota. + */ + virtual void setQuota( + const std::string& role, + const Quota& quota) = 0; + + /** + * Informs the allocator to remove quota for the given role. + * + * An allocator implementation may employ different strategies for roles + * with or without quota. Hence an empty (or zero) quota is not necessarily + * the same as an absence of quota. Logically, this method implies that the + * given role should be transitioned to the group of roles without quota + * set (absence of quota). An allocator implementation may assert quota + * for the given role is set prior to the call and react accordingly if + * this assumption is violated (i.e. fail). + * + * TODO(alexr): Consider returning a future which an allocator can fail in + * order to report failure. + */ + virtual void removeQuota( + const std::string& role) = 0; + + /** + * Updates the weight of each provided role. + * Subsequent allocation calculations will use these updated weights. + */ + virtual void updateWeights( + const std::vector<WeightInfo>& weightInfos) = 0; +}; + +} // namespace allocator { +} // namespace mesos { + +#endif // __MESOS_MASTER_ALLOCATOR_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/include/mesos/allocator/allocator.proto ---------------------------------------------------------------------- diff --git a/include/mesos/allocator/allocator.proto b/include/mesos/allocator/allocator.proto new file mode 100644 index 0000000..df7e6db --- /dev/null +++ b/include/mesos/allocator/allocator.proto @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import "mesos/mesos.proto"; + +package mesos.allocator; + + +/** + * Describes the status of an inverse offer. + * + * This is a protobuf so as to be able to share the status to inverse offers + * through endpoints such as the maintenance status endpoint. + */ +message InverseOfferStatus { + enum Status { + // We have not received a response yet. This is the default state before + // receiving a response. + UNKNOWN = 1; + // The framework is ok with the inverse offer. This means it will not + // violate any SLAs and will attempt to evacuate any tasks running on the + // agent. If the tasks are not evacuated by the framework, the operator can + // manually shut down the slave knowing that the framework will not have + // violated its SLAs. + ACCEPT = 2; + // The framework wants to block the maintenance operation from happening. An + // example would be that it can not meet its SLA by losing resources. + DECLINE = 3; + } + + required Status status = 1; + required FrameworkID framework_id = 2; + + // Time, since the epoch, when this status was last updated. + required TimeInfo timestamp = 3; + + // TODO(jmlvanre): Capture decline message. +} http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/include/mesos/maintenance/maintenance.proto ---------------------------------------------------------------------- diff --git a/include/mesos/maintenance/maintenance.proto b/include/mesos/maintenance/maintenance.proto index 458b427..4afae5c 100644 --- a/include/mesos/maintenance/maintenance.proto +++ b/include/mesos/maintenance/maintenance.proto @@ -15,7 +15,7 @@ // limitations under the License. import "mesos/mesos.proto"; -import "mesos/master/allocator.proto"; +import "mesos/allocator/allocator.proto"; package mesos.maintenance; @@ -76,7 +76,7 @@ message ClusterStatus { // A list of the most recent responses to inverse offers from frameworks // running on this draining machine. - repeated master.InverseOfferStatus statuses = 2; + repeated allocator.InverseOfferStatus statuses = 2; } repeated DrainingMachine draining_machines = 1; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/include/mesos/master/allocator.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/master/allocator.hpp b/include/mesos/master/allocator.hpp deleted file mode 100644 index a4743c5..0000000 --- a/include/mesos/master/allocator.hpp +++ /dev/null @@ -1,395 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef __MESOS_MASTER_ALLOCATOR_HPP__ -#define __MESOS_MASTER_ALLOCATOR_HPP__ - -#include <string> -#include <vector> - -// ONLY USEFUL AFTER RUNNING PROTOC. -#include <mesos/master/allocator.pb.h> - -#include <mesos/maintenance/maintenance.hpp> - -#include <mesos/quota/quota.hpp> - -#include <mesos/resources.hpp> - -#include <process/future.hpp> - -#include <stout/duration.hpp> -#include <stout/hashmap.hpp> -#include <stout/hashset.hpp> -#include <stout/lambda.hpp> -#include <stout/option.hpp> -#include <stout/try.hpp> - -namespace mesos { -namespace master { -namespace allocator { - -/** - * Basic model of an allocator: resources are allocated to a framework - * in the form of offers. A framework can refuse some resources in - * offers and run tasks in others. Allocated resources can have offer - * operations applied to them in order for frameworks to alter the - * resource metadata (e.g. creating persistent volumes). Resources can - * be recovered from a framework when tasks finish/fail (or are lost - * due to an agent failure) or when an offer is rescinded. - * - * This is the public API for resource allocators. - */ -class Allocator -{ -public: - /** - * Attempts either to create a built-in DRF allocator or to load an - * allocator instance from a module using the given name. If `Try` - * does not report an error, the wrapped `Allocator*` is not null. - * - * @param name Name of the allocator. - */ - static Try<Allocator*> create(const std::string& name); - - Allocator() {} - - virtual ~Allocator() {} - - /** - * Initializes the allocator when the master starts up. Any errors in - * initialization should fail fast and result in an ABORT. The master expects - * the allocator to be successfully initialized if this call returns. - * - * @param allocationInterval The allocate interval for the allocator, it - * determines how often the allocator should perform the batch - * allocation. An allocator may also perform allocation based on events - * (a framework is added and so on), this depends on the implementation. - * @param offerCallback A callback the allocator uses to send allocations - * to the frameworks. - * @param inverseOfferCallback A callback the allocator uses to send reclaim - * allocations from the frameworks. - * @param weights Configured per-role weights. Any roles that do not - * appear in this map will be assigned the default weight of 1. - */ - virtual void initialize( - const Duration& allocationInterval, - const lambda::function< - void(const FrameworkID&, - const hashmap<SlaveID, Resources>&)>& offerCallback, - const lambda::function< - void(const FrameworkID&, - const hashmap<SlaveID, UnavailableResources>&)>& - inverseOfferCallback, - const hashmap<std::string, double>& weights) = 0; - - /** - * Informs the allocator of the recovered state from the master. - * - * Because it is hard to define recovery for a running allocator, this - * method should be called after `initialize()`, but before actual - * allocation starts (i.e. `addSlave()` is called). - * - * TODO(alexr): Consider extending the signature with expected - * frameworks count once it is available upon the master failover. - * - * @param quotas A (possibly empty) collection of quotas, keyed by - * their role, known to the master. - */ - virtual void recover( - const int expectedAgentCount, - const hashmap<std::string, Quota>& quotas) = 0; - - /** - * Adds a framework to the Mesos cluster. The allocator is invoked when - * a new framework joins the Mesos cluster and is entitled to participate - * in resource sharing. - * - * @param used Resources used by this framework. The allocator should - * account for these resources when updating the allocation of this - * framework. - */ - virtual void addFramework( - const FrameworkID& frameworkId, - const FrameworkInfo& frameworkInfo, - const hashmap<SlaveID, Resources>& used) = 0; - - /** - * Removes a framework from the Mesos cluster. It is up to an allocator to - * decide what to do with framework's resources. For example, they may be - * released and added back to the shared pool of resources. - */ - virtual void removeFramework( - const FrameworkID& frameworkId) = 0; - - /** - * Activates a framework in the Mesos cluster. - * Offers are only sent to active frameworks. - */ - virtual void activateFramework( - const FrameworkID& frameworkId) = 0; - - /** - * Deactivates a framework in the Mesos cluster. - * Resource offers are not sent to deactivated frameworks. - */ - virtual void deactivateFramework( - const FrameworkID& frameworkId) = 0; - - /** - * Updates capabilities of a framework in the Mesos cluster. - * - * This will be invoked when a framework is re-added. As some of the - * framework's capabilities may be updated when re-added, this API should - * update the capabilities of the newly added framework to Mesos cluster to - * reflect the latest framework info. Please refer to the design document here - * https://cwiki.apache.org/confluence/display/MESOS/Design+doc:+Updating+Framework+Info // NOLINT - * for more details related to framework update. - */ - virtual void updateFramework( - const FrameworkID& frameworkId, - const FrameworkInfo& frameworkInfo) = 0; - - /** - * Adds or re-adds an agent to the Mesos cluster. It is invoked when a - * new agent joins the cluster or in case of agent recovery. - * - * @param slaveId ID of the agent to be added or re-added. - * @param slaveInfo Detailed info of the agent. The slaveInfo resources - * correspond directly to the static --resources flag value on the agent. - * @param total The `total` resources are passed explicitly because it - * includes resources that are dynamically "checkpointed" on the agent - * (e.g. persistent volumes, dynamic reservations, etc). - * @param used Resources that are allocated on the current agent. - */ - virtual void addSlave( - const SlaveID& slaveId, - const SlaveInfo& slaveInfo, - const Option<Unavailability>& unavailability, - const Resources& total, - const hashmap<FrameworkID, Resources>& used) = 0; - - /** - * Removes an agent from the Mesos cluster. All resources belonging to this - * agent should be released by the allocator. - */ - virtual void removeSlave( - const SlaveID& slaveId) = 0; - - /** - * Updates an agent. - * - * Updates the latest oversubscribed resources for an agent. - * TODO(vinod): Instead of just oversubscribed resources have this - * method take total resources. We can then reuse this method to - * update Agent's total resources in the future. - * - * @param oversubscribed The new oversubscribed resources estimate from - * the agent. The oversubscribed resources include the total amount - * of oversubscribed resources that are allocated and available. - */ - virtual void updateSlave( - const SlaveID& slave, - const Resources& oversubscribed) = 0; - - /** - * Activates an agent. This is invoked when an agent reregisters. Offers - * are only sent for activated agents. - */ - virtual void activateSlave( - const SlaveID& slaveId) = 0; - - /** - * Deactivates an agent. - * - * This is triggered if an agent disconnects from the master. The allocator - * should treat all offers from the deactivated agent as rescinded. (There - * is no separate call to the allocator to handle this). Resources aren't - * "recovered" when an agent deactivates because the resources are lost. - */ - virtual void deactivateSlave( - const SlaveID& slaveId) = 0; - - /** - * Updates the list of trusted agents. - * - * This is invoked when the master starts up with the --whitelist flag. - * - * @param whitelist A set of agents that are allowed to contribute - * their resources to the resource pool. - */ - virtual void updateWhitelist( - const Option<hashset<std::string>>& whitelist) = 0; - - /** - * Requests resources for a framework. - * - * A framework may request resources via this call. It is up to the allocator - * how to react to this request. For example, a request may be ignored, or - * may influence internal priorities the allocator may keep for frameworks. - */ - virtual void requestResources( - const FrameworkID& frameworkId, - const std::vector<Request>& requests) = 0; - - /** - * Updates allocation by applying offer operations. - * - * This call is mainly intended to support persistence-related features - * (dynamic reservation and persistent volumes). The allocator may react - * differently for certain offer operations. The allocator should use this - * call to update bookkeeping information related to the framework. - */ - virtual void updateAllocation( - const FrameworkID& frameworkId, - const SlaveID& slaveId, - const std::vector<Offer::Operation>& operations) = 0; - - /** - * Updates available resources on an agent based on a sequence of offer - * operations. Operations may include reserve, unreserve, create or destroy. - * - * @param slaveId ID of the agent. - * @param operations The offer operations to apply to this agent's resources. - */ - virtual process::Future<Nothing> updateAvailable( - const SlaveID& slaveId, - const std::vector<Offer::Operation>& operations) = 0; - - /** - * Updates unavailability for an agent. - * - * We currently support storing the next unavailability, if there is one, - * per agent. If `unavailability` is not set then there is no known upcoming - * unavailability. This might require the implementation of the function to - * remove any inverse offers that are outstanding. - */ - virtual void updateUnavailability( - const SlaveID& slaveId, - const Option<Unavailability>& unavailability) = 0; - - /** - * Updates inverse offer. - * - * Informs the allocator that the inverse offer has been responded to or - * revoked. - * - * @param unavailableResources The `unavailableResources` can be used by the - * allocator to distinguish between different inverse offers sent to the - * same framework for the same slave. - * @param status If `status` is not set then the inverse offer was not - * responded to, possibly because the offer timed out or was rescinded. - * This might require the implementation of the function to remove any - * inverse offers that are outstanding. - * @param filters A filter attached to the inverse offer can be used by the - * framework to control when it wants to be contacted again with the - * inverse offer. The "filters" for InverseOffers are identical to the - * existing mechanism for re-offering Offers to frameworks. - */ - virtual void updateInverseOffer( - const SlaveID& slaveId, - const FrameworkID& frameworkId, - const Option<UnavailableResources>& unavailableResources, - const Option<InverseOfferStatus>& status, - const Option<Filters>& filters = None()) = 0; - - /** - * Retrieves the status of all inverse offers maintained by the allocator. - */ - virtual process::Future< - hashmap<SlaveID, hashmap<FrameworkID, mesos::master::InverseOfferStatus>>> - getInverseOfferStatuses() = 0; - - /** - * Recovers resources. - * - * Used to update the set of available resources for a specific agent. This - * method is invoked to inform the allocator about allocated resources that - * have been refused or are no longer in use. - */ - virtual void recoverResources( - const FrameworkID& frameworkId, - const SlaveID& slaveId, - const Resources& resources, - const Option<Filters>& filters) = 0; - - /** - * Suppresses offers. - * - * Informs the allocator to stop sending offers to the framework. - */ - virtual void suppressOffers( - const FrameworkID& frameworkId) = 0; - - /** - * Revives offers for a framework. This is invoked by a framework when - * it wishes to receive filtered resources or offers immediately. - */ - virtual void reviveOffers( - const FrameworkID& frameworkId) = 0; - - /** - * Informs the allocator to set quota for the given role. - * - * It is up to the allocator implementation how to satisfy quota. An - * implementation may employ different strategies for roles with or - * without quota. Hence an empty (or zero) quota is not necessarily the - * same as an absence of quota. Logically, this method implies that the - * given role should be transitioned to the group of roles with quota - * set. An allocator implementation may assert quota for the given role - * is not set prior to the call and react accordingly if this assumption - * is violated (i.e. fail). - * - * TODO(alexr): Consider returning a future which an allocator can fail - * in order to report failure. - * - * TODO(alexr): Consider adding an `updateQuota()` method which allows - * updating existing quota. - */ - virtual void setQuota( - const std::string& role, - const Quota& quota) = 0; - - /** - * Informs the allocator to remove quota for the given role. - * - * An allocator implementation may employ different strategies for roles - * with or without quota. Hence an empty (or zero) quota is not necessarily - * the same as an absence of quota. Logically, this method implies that the - * given role should be transitioned to the group of roles without quota - * set (absence of quota). An allocator implementation may assert quota - * for the given role is set prior to the call and react accordingly if - * this assumption is violated (i.e. fail). - * - * TODO(alexr): Consider returning a future which an allocator can fail in - * order to report failure. - */ - virtual void removeQuota( - const std::string& role) = 0; - - /** - * Updates the weight of each provided role. - * Subsequent allocation calculations will use these updated weights. - */ - virtual void updateWeights( - const std::vector<WeightInfo>& weightInfos) = 0; -}; - -} // namespace allocator { -} // namespace master { -} // namespace mesos { - -#endif // __MESOS_MASTER_ALLOCATOR_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/include/mesos/master/allocator.proto ---------------------------------------------------------------------- diff --git a/include/mesos/master/allocator.proto b/include/mesos/master/allocator.proto deleted file mode 100644 index 8252abf..0000000 --- a/include/mesos/master/allocator.proto +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import "mesos/mesos.proto"; - -package mesos.master; - - -/** - * Describes the status of an inverse offer. - * - * This is a protobuf so as to be able to share the status to inverse offers - * through endpoints such as the maintenance status endpoint. - */ -message InverseOfferStatus { - enum Status { - // We have not received a response yet. This is the default state before - // receiving a response. - UNKNOWN = 1; - // The framework is ok with the inverse offer. This means it will not - // violate any SLAs and will attempt to evacuate any tasks running on the - // agent. If the tasks are not evacuated by the framework, the operator can - // manually shut down the slave knowing that the framework will not have - // violated its SLAs. - ACCEPT = 2; - // The framework wants to block the maintenance operation from happening. An - // example would be that it can not meet its SLA by losing resources. - DECLINE = 3; - } - - required Status status = 1; - required FrameworkID framework_id = 2; - - // Time, since the epoch, when this status was last updated. - required TimeInfo timestamp = 3; - - // TODO(jmlvanre): Capture decline message. -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/include/mesos/module/allocator.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/module/allocator.hpp b/include/mesos/module/allocator.hpp index 5e65e69..048ebca 100644 --- a/include/mesos/module/allocator.hpp +++ b/include/mesos/module/allocator.hpp @@ -20,20 +20,20 @@ #include <mesos/mesos.hpp> #include <mesos/module.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> namespace mesos { namespace modules { template <> -inline const char* kind<mesos::master::allocator::Allocator>() +inline const char* kind<mesos::allocator::Allocator>() { return "Allocator"; } template <> -struct Module<mesos::master::allocator::Allocator> : ModuleBase +struct Module<mesos::allocator::Allocator> : ModuleBase { Module( const char* _moduleApiVersion, @@ -42,19 +42,19 @@ struct Module<mesos::master::allocator::Allocator> : ModuleBase const char* _authorEmail, const char* _description, bool (*_compatible)(), - mesos::master::allocator::Allocator* + mesos::allocator::Allocator* (*_create)(const Parameters& parameters)) : ModuleBase( _moduleApiVersion, _mesosVersion, - mesos::modules::kind<mesos::master::allocator::Allocator>(), + mesos::modules::kind<mesos::allocator::Allocator>(), _authorName, _authorEmail, _description, _compatible), create(_create) {} - mesos::master::allocator::Allocator* (*create)(const Parameters& parameters); + mesos::allocator::Allocator* (*create)(const Parameters& parameters); }; } // namespace modules { http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 872a102..97cc96d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,7 @@ include(MesosProtobuf) # Build the protobuf structs. PROTOC_TO_INCLUDE_DIR(ACLS mesos/authorizer/acls) PROTOC_TO_INCLUDE_DIR(AGENT mesos/agent/agent) -PROTOC_TO_INCLUDE_DIR(ALLOCATOR mesos/master/allocator) +PROTOC_TO_INCLUDE_DIR(ALLOCATOR mesos/allocator/allocator) PROTOC_TO_INCLUDE_DIR(APPC_SPEC mesos/appc/spec) PROTOC_TO_INCLUDE_DIR(AUTHENTICATION mesos/authentication/authentication) PROTOC_TO_INCLUDE_DIR(AUTHORIZATION mesos/authorizer/authorizer) http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index e52f47e..86c39fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -207,7 +207,7 @@ MESOS_CPPFLAGS += -DHAS_AUTHENTICATION=1 ACLS_PROTO = $(top_srcdir)/include/mesos/authorizer/acls.proto AGENT_PROTO = $(top_srcdir)/include/mesos/agent/agent.proto -ALLOCATOR_PROTO = $(top_srcdir)/include/mesos/master/allocator.proto +ALLOCATOR_PROTO = $(top_srcdir)/include/mesos/allocator/allocator.proto APPC_SPEC_PROTO = $(top_srcdir)/include/mesos/appc/spec.proto AUTHENTICATION_PROTO = $(top_srcdir)/include/mesos/authentication/authentication.proto AUTHORIZATION_PROTO = $(top_srcdir)/include/mesos/authorizer/authorizer.proto @@ -242,6 +242,8 @@ CXX_PROTOS = \ ../include/mesos/mesos.pb.h \ ../include/mesos/agent/agent.pb.cc \ ../include/mesos/agent/agent.pb.h \ + ../include/mesos/allocator/allocator.pb.cc \ + ../include/mesos/allocator/allocator.pb.h \ ../include/mesos/appc/spec.pb.cc \ ../include/mesos/appc/spec.pb.h \ ../include/mesos/authentication/authentication.pb.cc \ @@ -264,8 +266,6 @@ CXX_PROTOS = \ ../include/mesos/fetcher/fetcher.pb.h \ ../include/mesos/maintenance/maintenance.pb.cc \ ../include/mesos/maintenance/maintenance.pb.h \ - ../include/mesos/master/allocator.pb.cc \ - ../include/mesos/master/allocator.pb.h \ ../include/mesos/master/master.pb.cc \ ../include/mesos/master/master.pb.h \ ../include/mesos/module/module.pb.cc \ @@ -464,6 +464,15 @@ nodist_pkginclude_HEADERS = \ ../include/mesos/version.hpp \ ../include/mesos/mesos.pb.h +allocatordir = $(pkgincludedir)/allocator + +allocator_HEADERS = \ + $(top_srcdir)/include/mesos/allocator/allocator.hpp \ + $(top_srcdir)/include/mesos/allocator/allocator.proto + +nodist_allocator_HEADERS = \ + ../include/mesos/allocator/allocator.pb.h + appcdir = $(pkgincludedir)/appc appc_HEADERS = \ @@ -556,15 +565,12 @@ nodist_maintenance_HEADERS = \ masterdir = $(pkgincludedir)/master master_HEADERS = \ - $(top_srcdir)/include/mesos/master/allocator.hpp \ - $(top_srcdir)/include/mesos/master/allocator.proto \ $(top_srcdir)/include/mesos/master/contender.hpp \ $(top_srcdir)/include/mesos/master/detector.hpp \ $(top_srcdir)/include/mesos/master/master.hpp \ $(top_srcdir)/include/mesos/master/master.proto nodist_master_HEADERS = \ - ../include/mesos/master/allocator.pb.h \ ../include/mesos/master/master.pb.h moduledir = $(pkgincludedir)/module http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/examples/test_allocator_module.cpp ---------------------------------------------------------------------- diff --git a/src/examples/test_allocator_module.cpp b/src/examples/test_allocator_module.cpp index bc28eb4..f591415 100644 --- a/src/examples/test_allocator_module.cpp +++ b/src/examples/test_allocator_module.cpp @@ -17,7 +17,7 @@ #include <mesos/mesos.hpp> #include <mesos/module.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/module/allocator.hpp> @@ -29,7 +29,7 @@ using namespace mesos; -using mesos::master::allocator::Allocator; +using mesos::allocator::Allocator; using mesos::internal::master::allocator::HierarchicalDRFAllocator; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/local/local.cpp ---------------------------------------------------------------------- diff --git a/src/local/local.cpp b/src/local/local.cpp index b40ca7c..a543aef 100644 --- a/src/local/local.cpp +++ b/src/local/local.cpp @@ -23,7 +23,7 @@ #include <mesos/authorizer/authorizer.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/module/anonymous.hpp> #include <mesos/module/authorizer.hpp> @@ -80,7 +80,7 @@ using namespace mesos::internal::log; using mesos::log::Log; -using mesos::master::allocator::Allocator; +using mesos::allocator::Allocator; using mesos::master::contender::MasterContender; using mesos::master::contender::StandaloneMasterContender; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/local/local.hpp ---------------------------------------------------------------------- diff --git a/src/local/local.hpp b/src/local/local.hpp index 0c86f97..16999a0 100644 --- a/src/local/local.hpp +++ b/src/local/local.hpp @@ -17,7 +17,7 @@ #ifndef __MESOS_LOCAL_HPP__ #define __MESOS_LOCAL_HPP__ -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <process/process.hpp> @@ -38,7 +38,7 @@ namespace local { // Launch a local cluster with the given flags. process::PID<master::Master> launch( const Flags& flags, - mesos::master::allocator::Allocator* _allocator = nullptr); + mesos::allocator::Allocator* _allocator = nullptr); void shutdown(); http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/allocator/allocator.cpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/allocator.cpp b/src/master/allocator/allocator.cpp index 8e76a3a..e3dd737 100644 --- a/src/master/allocator/allocator.cpp +++ b/src/master/allocator/allocator.cpp @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/module/allocator.hpp> @@ -29,7 +29,6 @@ using std::string; using mesos::internal::master::allocator::HierarchicalDRFAllocator; namespace mesos { -namespace master { namespace allocator { Try<Allocator*> Allocator::create(const string& name) @@ -46,5 +45,4 @@ Try<Allocator*> Allocator::create(const string& name) } } // namespace allocator { -} // namespace master { } // namespace mesos { http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/allocator/mesos/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp index 64bce0f..f096d2b 100644 --- a/src/master/allocator/mesos/allocator.hpp +++ b/src/master/allocator/mesos/allocator.hpp @@ -17,7 +17,7 @@ #ifndef __MASTER_ALLOCATOR_MESOS_ALLOCATOR_HPP__ #define __MASTER_ALLOCATOR_MESOS_ALLOCATOR_HPP__ -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <process/dispatch.hpp> #include <process/future.hpp> @@ -38,11 +38,11 @@ class MesosAllocatorProcess; // lifetime. We ensure the template parameter AllocatorProcess // implements MesosAllocatorProcess by storing a pointer to it. template <typename AllocatorProcess> -class MesosAllocator : public mesos::master::allocator::Allocator +class MesosAllocator : public mesos::allocator::Allocator { public: // Factory to allow for typed tests. - static Try<mesos::master::allocator::Allocator*> create(); + static Try<mesos::allocator::Allocator*> create(); ~MesosAllocator(); @@ -123,11 +123,12 @@ public: const SlaveID& slaveId, const FrameworkID& frameworkId, const Option<UnavailableResources>& unavailableResources, - const Option<mesos::master::InverseOfferStatus>& status, + const Option<mesos::allocator::InverseOfferStatus>& status, const Option<Filters>& filters); process::Future< - hashmap<SlaveID, hashmap<FrameworkID, mesos::master::InverseOfferStatus>>> + hashmap<SlaveID, + hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>> getInverseOfferStatuses(); void recoverResources( @@ -250,11 +251,12 @@ public: const SlaveID& slaveId, const FrameworkID& frameworkId, const Option<UnavailableResources>& unavailableResources, - const Option<mesos::master::InverseOfferStatus>& status, + const Option<mesos::allocator::InverseOfferStatus>& status, const Option<Filters>& filters = None()) = 0; virtual process::Future< - hashmap<SlaveID, hashmap<FrameworkID, mesos::master::InverseOfferStatus>>> + hashmap<SlaveID, + hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>> getInverseOfferStatuses() = 0; virtual void recoverResources( @@ -282,10 +284,10 @@ public: template <typename AllocatorProcess> -Try<mesos::master::allocator::Allocator*> +Try<mesos::allocator::Allocator*> MesosAllocator<AllocatorProcess>::create() { - mesos::master::allocator::Allocator* allocator = + mesos::allocator::Allocator* allocator = new MesosAllocator<AllocatorProcess>(); return CHECK_NOTNULL(allocator); } @@ -539,7 +541,7 @@ inline void MesosAllocator<AllocatorProcess>::updateInverseOffer( const SlaveID& slaveId, const FrameworkID& frameworkId, const Option<UnavailableResources>& unavailableResources, - const Option<mesos::master::InverseOfferStatus>& status, + const Option<mesos::allocator::InverseOfferStatus>& status, const Option<Filters>& filters) { return process::dispatch( @@ -555,7 +557,8 @@ inline void MesosAllocator<AllocatorProcess>::updateInverseOffer( template <typename AllocatorProcess> inline process::Future< - hashmap<SlaveID, hashmap<FrameworkID, mesos::master::InverseOfferStatus>>> + hashmap<SlaveID, + hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>> MesosAllocator<AllocatorProcess>::getInverseOfferStatuses() { return process::dispatch( http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/allocator/mesos/hierarchical.cpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp index 5b2331b..c363934 100644 --- a/src/master/allocator/mesos/hierarchical.cpp +++ b/src/master/allocator/mesos/hierarchical.cpp @@ -35,7 +35,7 @@ using std::string; using std::vector; -using mesos::master::InverseOfferStatus; +using mesos::allocator::InverseOfferStatus; using process::Failure; using process::Future; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/allocator/mesos/hierarchical.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp index c9cb1e1..98a1f69 100644 --- a/src/master/allocator/mesos/hierarchical.hpp +++ b/src/master/allocator/mesos/hierarchical.hpp @@ -168,11 +168,12 @@ public: const SlaveID& slaveId, const FrameworkID& frameworkId, const Option<UnavailableResources>& unavailableResources, - const Option<mesos::master::InverseOfferStatus>& status, + const Option<mesos::allocator::InverseOfferStatus>& status, const Option<Filters>& filters); process::Future< - hashmap<SlaveID, hashmap<FrameworkID, mesos::master::InverseOfferStatus>>> + hashmap<SlaveID, + hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>> getInverseOfferStatuses(); void recoverResources( @@ -359,7 +360,7 @@ protected: // allocator will send out new inverse offers and re-collect the // information. This is similar to all the outstanding offers from an old // master being invalidated, and new offers being sent out. - hashmap<FrameworkID, mesos::master::InverseOfferStatus> statuses; + hashmap<FrameworkID, mesos::allocator::InverseOfferStatus> statuses; // Represents the "unit of accounting" for maintenance. When a // `FrameworkID` is present in the hashset it means an inverse offer has http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index ad3f723..d55aa05 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -3420,10 +3420,9 @@ Future<mesos::maintenance::ClusterStatus> return master->allocator->getInverseOfferStatuses() .then(defer( master->self(), - [=]( - hashmap< - SlaveID, - hashmap<FrameworkID, mesos::master::InverseOfferStatus>> result) + [=](hashmap< + SlaveID, + hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>> result) -> Future<mesos::maintenance::ClusterStatus> { // Unwrap the master's machine information into two arrays of machines. // The data is coming from the allocator and therefore could be stale. @@ -3444,7 +3443,7 @@ Future<mesos::maintenance::ClusterStatus> foreach (const SlaveID& slave, machine.slaves) { if (result.contains(slave)) { foreachvalue ( - const mesos::master::InverseOfferStatus& status, + const mesos::allocator::InverseOfferStatus& status, result[slave]) { drainingMachine->add_statuses()->CopyFrom(status); } http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/main.cpp ---------------------------------------------------------------------- diff --git a/src/master/main.cpp b/src/master/main.cpp index 01c8276..84f3b07 100644 --- a/src/master/main.cpp +++ b/src/master/main.cpp @@ -26,7 +26,7 @@ #include <mesos/authorizer/authorizer.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/master/contender.hpp> #include <mesos/master/detector.hpp> @@ -88,7 +88,7 @@ using mesos::Parameters; using mesos::log::Log; -using mesos::master::allocator::Allocator; +using mesos::allocator::Allocator; using mesos::master::contender::MasterContender; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index d89c049..907233b 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -33,7 +33,7 @@ #include <mesos/authorizer/authorizer.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/master/contender.hpp> #include <mesos/master/detector.hpp> @@ -124,7 +124,7 @@ namespace master { namespace authentication = process::http::authentication; -using mesos::master::allocator::Allocator; +using mesos::allocator::Allocator; using mesos::master::contender::MasterContender; @@ -4025,8 +4025,8 @@ void Master::acceptInverseOffers( CHECK(inverseOffer->has_slave_id()); slaveId = inverseOffer->slave_id(); - mesos::master::InverseOfferStatus status; - status.set_status(mesos::master::InverseOfferStatus::ACCEPT); + mesos::allocator::InverseOfferStatus status; + status.set_status(mesos::allocator::InverseOfferStatus::ACCEPT); status.mutable_framework_id()->CopyFrom(inverseOffer->framework_id()); status.mutable_timestamp()->CopyFrom(protobuf::getCurrentTime()); @@ -4115,8 +4115,8 @@ void Master::declineInverseOffers( // longer valid. InverseOffer* inverseOffer = getInverseOffer(offerId); if (inverseOffer != nullptr) { // If this is an inverse offer. - mesos::master::InverseOfferStatus status; - status.set_status(mesos::master::InverseOfferStatus::DECLINE); + mesos::allocator::InverseOfferStatus status; + status.set_status(mesos::allocator::InverseOfferStatus::DECLINE); status.mutable_framework_id()->CopyFrom(inverseOffer->framework_id()); status.mutable_timestamp()->CopyFrom(protobuf::getCurrentTime()); http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index e983d1b..648f1a2 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -32,7 +32,7 @@ #include <mesos/maintenance/maintenance.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/master/contender.hpp> #include <mesos/master/detector.hpp> #include <mesos/master/master.hpp> @@ -392,7 +392,7 @@ struct HttpConnection class Master : public ProtobufProcess<Master> { public: - Master(mesos::master::allocator::Allocator* allocator, + Master(mesos::allocator::Allocator* allocator, Registrar* registrar, Files* files, mesos::master::contender::MasterContender* contender, @@ -1471,7 +1471,7 @@ private: Option<MasterInfo> leader; // Current leading master. - mesos::master::allocator::Allocator* allocator; + mesos::allocator::Allocator* allocator; WhitelistWatcher* whitelistWatcher; Registrar* registrar; Files* files; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/tests/allocator.hpp b/src/tests/allocator.hpp index 4081193..bc2d89e 100644 --- a/src/tests/allocator.hpp +++ b/src/tests/allocator.hpp @@ -19,7 +19,7 @@ #include <gmock/gmock.h> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <process/future.hpp> #include <process/gmock.hpp> @@ -203,17 +203,17 @@ ACTION_P(InvokeUpdateWeights, allocator) template <typename T = master::allocator::HierarchicalDRFAllocator> -mesos::master::allocator::Allocator* createAllocator() +mesos::allocator::Allocator* createAllocator() { // T represents the allocator type. It can be a default built-in // allocator, or one provided by an allocator module. - Try<mesos::master::allocator::Allocator*> instance = T::create(); + Try<mesos::allocator::Allocator*> instance = T::create(); CHECK_SOME(instance); return CHECK_NOTNULL(instance.get()); } template <typename T = master::allocator::HierarchicalDRFAllocator> -class TestAllocator : public mesos::master::allocator::Allocator +class TestAllocator : public mesos::allocator::Allocator { public: // Actual allocation is done by an instance of real allocator, @@ -433,13 +433,13 @@ public: const SlaveID&, const FrameworkID&, const Option<UnavailableResources>&, - const Option<mesos::master::InverseOfferStatus>&, + const Option<mesos::allocator::InverseOfferStatus>&, const Option<Filters>&)); MOCK_METHOD0(getInverseOfferStatuses, process::Future< hashmap<SlaveID, hashmap< FrameworkID, - mesos::master::InverseOfferStatus>>>()); + mesos::allocator::InverseOfferStatus>>>()); MOCK_METHOD4(recoverResources, void( const FrameworkID&, @@ -463,7 +463,7 @@ public: MOCK_METHOD1(updateWeights, void( const std::vector<WeightInfo>&)); - process::Owned<mesos::master::allocator::Allocator> real; + process::Owned<mesos::allocator::Allocator> real; }; } // namespace tests { http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/cluster.cpp ---------------------------------------------------------------------- diff --git a/src/tests/cluster.cpp b/src/tests/cluster.cpp index f25b887..e1be275 100644 --- a/src/tests/cluster.cpp +++ b/src/tests/cluster.cpp @@ -24,7 +24,7 @@ #include <mesos/log/log.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/slave/resource_estimator.hpp> @@ -104,7 +104,7 @@ namespace cluster { Try<process::Owned<Master>> Master::start( const master::Flags& flags, const Option<zookeeper::URL>& zookeeperUrl, - const Option<mesos::master::allocator::Allocator*>& allocator, + const Option<mesos::allocator::Allocator*>& allocator, const Option<Authorizer*>& authorizer, const Option<std::shared_ptr<process::RateLimiter>>& slaveRemovalLimiter) { @@ -113,7 +113,7 @@ Try<process::Owned<Master>> Master::start( // If the allocator is not provided, create a default one. if (allocator.isNone()) { - Try<mesos::master::allocator::Allocator*> _allocator = + Try<mesos::allocator::Allocator*> _allocator = master::allocator::HierarchicalDRFAllocator::create(); if (_allocator.isError()) { http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/cluster.hpp ---------------------------------------------------------------------- diff --git a/src/tests/cluster.hpp b/src/tests/cluster.hpp index 3b37f96..55dbaae 100644 --- a/src/tests/cluster.hpp +++ b/src/tests/cluster.hpp @@ -26,7 +26,7 @@ #include <mesos/log/log.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/master/contender.hpp> #include <mesos/master/detector.hpp> @@ -82,7 +82,7 @@ public: static Try<process::Owned<Master>> start( const master::Flags& flags = master::Flags(), const Option<zookeeper::URL>& zookeeperUrl = None(), - const Option<mesos::master::allocator::Allocator*>& allocator = None(), + const Option<mesos::allocator::Allocator*>& allocator = None(), const Option<Authorizer*>& authorizer = None(), const Option<std::shared_ptr<process::RateLimiter>>& slaveRemovalLimiter = None()); @@ -112,7 +112,7 @@ private: Files files; // Dependencies that are created by the factory method. - process::Owned<mesos::master::allocator::Allocator> allocator; + process::Owned<mesos::allocator::Allocator> allocator; process::Owned<Authorizer> authorizer; process::Owned<mesos::master::contender::MasterContender> contender; process::Owned<mesos::master::detector::MasterDetector> detector; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/fault_tolerance_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/fault_tolerance_tests.cpp b/src/tests/fault_tolerance_tests.cpp index 5109b83..57b1503 100644 --- a/src/tests/fault_tolerance_tests.cpp +++ b/src/tests/fault_tolerance_tests.cpp @@ -25,7 +25,7 @@ #include <mesos/authentication/authentication.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/scheduler/scheduler.hpp> http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/hierarchical_allocator_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp index 6de0702..eb11ff6 100644 --- a/src/tests/hierarchical_allocator_tests.cpp +++ b/src/tests/hierarchical_allocator_tests.cpp @@ -22,7 +22,7 @@ #include <gmock/gmock.h> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <process/clock.hpp> #include <process/future.hpp> @@ -55,7 +55,7 @@ using mesos::internal::master::allocator::HierarchicalDRFAllocator; using mesos::internal::protobuf::createLabel; -using mesos::master::allocator::Allocator; +using mesos::allocator::Allocator; using process::Clock; using process::Future; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/master_allocator_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_allocator_tests.cpp b/src/tests/master_allocator_tests.cpp index 0425266..7910f55 100644 --- a/src/tests/master_allocator_tests.cpp +++ b/src/tests/master_allocator_tests.cpp @@ -23,7 +23,7 @@ #include <mesos/executor.hpp> #include <mesos/scheduler.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/module/allocator.hpp> @@ -52,7 +52,7 @@ using google::protobuf::RepeatedPtrField; -using mesos::master::allocator::Allocator; +using mesos::allocator::Allocator; using mesos::internal::master::allocator::HierarchicalDRFAllocator; using mesos::internal::master::Master; http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/master_authorization_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_authorization_tests.cpp b/src/tests/master_authorization_tests.cpp index 9ae6b9d..1cda523 100644 --- a/src/tests/master_authorization_tests.cpp +++ b/src/tests/master_authorization_tests.cpp @@ -24,7 +24,7 @@ #include <mesos/authorizer/authorizer.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/module/authorizer.hpp> http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/master_maintenance_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_maintenance_tests.cpp b/src/tests/master_maintenance_tests.cpp index b104385..2d4b45f 100644 --- a/src/tests/master_maintenance_tests.cpp +++ b/src/tests/master_maintenance_tests.cpp @@ -1300,7 +1300,7 @@ TEST_F(MasterMaintenanceTest, InverseOffers) ASSERT_EQ(1, statuses.get().draining_machines(0).statuses().size()); ASSERT_EQ( - mesos::master::InverseOfferStatus::DECLINE, + mesos::allocator::InverseOfferStatus::DECLINE, statuses.get().draining_machines(0).statuses(0).status()); ASSERT_EQ( @@ -1363,7 +1363,7 @@ TEST_F(MasterMaintenanceTest, InverseOffers) ASSERT_EQ(1, statuses.get().draining_machines(0).statuses().size()); ASSERT_EQ( - mesos::master::InverseOfferStatus::ACCEPT, + mesos::allocator::InverseOfferStatus::ACCEPT, statuses.get().draining_machines(0).statuses(0).status()); ASSERT_EQ( http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/master_slave_reconciliation_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_slave_reconciliation_tests.cpp b/src/tests/master_slave_reconciliation_tests.cpp index f67bfd2..fc02ca6 100644 --- a/src/tests/master_slave_reconciliation_tests.cpp +++ b/src/tests/master_slave_reconciliation_tests.cpp @@ -22,7 +22,7 @@ #include <mesos/mesos.hpp> #include <mesos/scheduler.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <process/future.hpp> #include <process/gmock.hpp> http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/master_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp index ce9c192..ddbab7a 100644 --- a/src/tests/master_tests.cpp +++ b/src/tests/master_tests.cpp @@ -25,7 +25,7 @@ #include <mesos/executor.hpp> #include <mesos/scheduler.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/scheduler/scheduler.hpp> http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/mesos.cpp ---------------------------------------------------------------------- diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp index 6918343..a433e5b 100644 --- a/src/tests/mesos.cpp +++ b/src/tests/mesos.cpp @@ -252,7 +252,7 @@ Try<Owned<cluster::Master>> MesosTest::StartMaster( Try<Owned<cluster::Master>> MesosTest::StartMaster( - mesos::master::allocator::Allocator* allocator, + mesos::allocator::Allocator* allocator, const Option<master::Flags>& flags) { return cluster::Master::start( http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/mesos.hpp ---------------------------------------------------------------------- diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp index bcd060e..3173bf9 100644 --- a/src/tests/mesos.hpp +++ b/src/tests/mesos.hpp @@ -127,7 +127,7 @@ protected: // Starts a master with the specified allocator process and flags. virtual Try<process::Owned<cluster::Master>> StartMaster( - mesos::master::allocator::Allocator* allocator, + mesos::allocator::Allocator* allocator, const Option<master::Flags>& flags = None()); // Starts a master with the specified authorizer and flags. http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/rate_limiting_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/rate_limiting_tests.cpp b/src/tests/rate_limiting_tests.cpp index 5d68ac1..6167415 100644 --- a/src/tests/rate_limiting_tests.cpp +++ b/src/tests/rate_limiting_tests.cpp @@ -16,7 +16,7 @@ #include <gmock/gmock.h> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <mesos/scheduler/scheduler.hpp> http://git-wip-us.apache.org/repos/asf/mesos/blob/170ac150/src/tests/reservation_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/reservation_tests.cpp b/src/tests/reservation_tests.cpp index 2cc352d..d7e90bc 100644 --- a/src/tests/reservation_tests.cpp +++ b/src/tests/reservation_tests.cpp @@ -25,7 +25,7 @@ #include <mesos/executor.hpp> #include <mesos/scheduler.hpp> -#include <mesos/master/allocator.hpp> +#include <mesos/allocator/allocator.hpp> #include <process/clock.hpp> #include <process/future.hpp>