此内容没有您所选择的语言版本。
8.5.2. Example Gear Placement Algorithms
Prerequisites:
The example gear placement algorithms in this section are provided as a reference to help with the development of your own custom algorithms. They are for use on brokers that have the gear placement plug-in installed and are intended for testing or development purposes.
After installing the gear placement plug-in, these examples are also installed on the broker host for convenience. Most of the following example algorithms are located in the
Gem_Location/lib/openshift/
directory, with any related example initializers and configuration files located in the Gem_Location/config/initializers/
and /etc/openshift/plugins.d/
directories, respectively. See Section 8.5.1, “Developing and Implementing a Custom Gear Placement Algorithm” for information on implementing custom algorithms in your environment.
Administrator Constraint Examples
The following are administrator constraint example algorithms for the gear placement plug-in.
Example 8.8. Return the First Node in the List
def self.select_best_fit_node_impl(server_infos, app_props, current_gears, comp_list, user_props, request_time) return server_infos.first end
def self.select_best_fit_node_impl(server_infos, app_props, current_gears, comp_list, user_props, request_time)
return server_infos.first
end
Example 8.9. Place PHP Applications on Specific Nodes
This example can also be found in the
Gem_Location/lib/openshift/gear_placement_plugin.rb.pin-php-to-host-example
file. However, to prevent scalable or highly-available applications from behaving unpredictably as a result of the server_infos
filters mentioned in Section 8.5.1, “Developing and Implementing a Custom Gear Placement Algorithm”, use the VALID_GEAR_SIZES_FOR_CARTRIDGE
parameter in the /etc/openshift/broker.conf
file in conjunction with profiles.
Example 8.10. Restrict a User's Applications to Slow Hosts
This example can also be found in the
Gem_Location/lib/openshift/gear_placement_plugin.rb.pin-user-to-host-example
file. However, this could prevent the user from scaling applications in some situations as a result of the server_infos
filters mentioned in Section 8.5.1, “Developing and Implementing a Custom Gear Placement Algorithm”.
Example 8.11. Ban a Specific Vendor's Cartridges
This example can also be found in the
Gem_Location/lib/openshift/gear_placement_plugin.rb.blacklisted-vendor-example
file.
Resource Usage Examples
The following are resource usage example algorithms for the gear placement plug-in.
Example 8.12. Place a Gear on the Node with the Most Free Memory
This example can also be found in the
Gem_Location/lib/openshift/gear_placement_plugin.rb.free-memory-example
file.
Example 8.13. Sort Nodes by Gear Usage (Round Robin)
def self.select_best_fit_node_impl(server_infos, app_props, current_gears, comp_list, user_props, request_time) return server_infos.sort_by {|x| x.node_consumed_capacity.to_f}.first end
def self.select_best_fit_node_impl(server_infos, app_props, current_gears, comp_list, user_props, request_time)
return server_infos.sort_by {|x| x.node_consumed_capacity.to_f}.first
end
This example can also be found in the
Gem_Location/lib/openshift/gear_placement_plugin.rb.round-robin-example
file. The nodes in each profile fill evenly, unless complications arise, for example due to scaled applications, gears being deleted unevenly, or MCollective fact updates trailing behind. Implementing true round robin requires writing out a state file owned by this algorithm and using that for scheduling the placement rotation.