-
Language:
English
-
Language:
English
8.5. Installing and Configuring the Gear Placement Plug-in
Procedure 8.15. To Install and Configure the Gear Placement Plug-in:
- Install the gear placement plug-in on each broker host:
# yum install rubygem-openshift-origin-gear-placement
This installs a gem with a Rails engine containing theGearPlacementPlugin
class. - On each broker host, copy the
/etc/openshift/plugins.d/openshift-origin-gear-placement.conf.example
file to/etc/openshift/plugins.d/openshift-origin-gear-placement.conf
:#
cp /etc/openshift/plugins.d/openshift-origin-gear-placement.conf.example /etc/openshift/plugins.d/openshift-origin-gear-placement.conf
As long as this configuration file with a.conf
extension exists, the broker automatically loads a gem matching the file name, and the gem can use the file to configure itself. - Restart the broker service:
# service openshift-broker restart
If you make further modifications to the configuration file of the gear placement plug-in, you must restart the broker service again after making your final changes. - The default implementation of the plug-in simply logs the plug-in inputs and delegates the actual gear placement to the default algorithm. You can verify that the plug-in is correctly installed and configured with the default implementation by creating an application and checking the
/var/log/openshift/broker/production.log
file.Example 8.7. Checking Broker Logs for Default Gear Placement Plug-in Activity
2014-10-17 12:53:18.476 [INFO ] Parameters: {"cartridges"=>["php-5.4"], "scale"=>true, "name"=>"mytestapp", "domain_id"=>"demo"} (pid:14508) 2014-10-17 12:53:24.715 [INFO ] Using gear placement plugin to choose node. (pid:14508) 2014-10-17 12:53:24.715 [INFO ] selecting from nodes: node2.example.com, node1.example.com (pid:14508) 2014-10-17 12:53:24.718 [INFO ] server_infos: [#<NodeProperties:0x00000007675438 @district_available_capacity=5994, @district_id="5441e3896892df06a4000001", @name="node2.example.com", @node_consumed_capacity=3.3333333333333335, @region_id=nil, @zone_id=nil>, #<NodeProperties:0x00000006e302a0 @district_available_capacity=5994, @district_id="5441e3896892df06a4000001", @name="node1.example.com", @node_consumed_capacity=6.666666666666667, @region_id=nil, @zone_id=nil>] (pid:14508) 2014-10-17 12:53:24.719 [INFO ] app_props: #<ApplicationProperties:0x000000078b97a8 @id="54446b0e6892dff4b5000001", @name="mytestapp", @web_cartridge="php-5.4"> (pid:14508) 2014-10-17 12:53:24.720 [INFO ] current_gears: [] (pid:14508) 2014-10-17 12:53:24.721 [INFO ] comp_list: [#<ComponentProperties:0x000000076a8b08 @cartridge_name="haproxy-1.4", @cartridge_vendor="redhat", @component_name="web_proxy", @version="1.4">, #<ComponentProperties:0x000000076a88d8 @cartridge_name="php-5.4", @cartridge_vendor="redhat", @component_name="php-5.4", @version="5.4">] (pid:14508) 2014-10-17 12:53:24.724 [INFO ] user_props: #<UserProperties:0x000000078b8f38 @capabilities= {"ha"=>false, "subaccounts"=>false, "gear_sizes"=>["small"], "max_domains"=>10, "max_gears"=>100, "max_teams"=>0, "view_global_teams"=>false, "max_storage_per_gear"=>0}, @consumed_gears=7, @id="5441e5f26892df39e9000001", @login="demo", @plan_id=nil, @plan_state=nil> (pid:14508) 2014-10-17 12:53:24.724 [INFO ] selected node: 'node2.example.com' (pid:14508)
8.5.1. Developing and Implementing a Custom Gear Placement Algorithm
# rpm -ql rubygem-openshift-origin-gear-placement
- Gem_Location/lib/openshift/gear_placement_plugin.rb
- This contains the
GearPlacementPlugin
class. Modify theself.select_best_fit_node_impl
method to customize the algorithm. - Gem_Location/config/initializers/openshift-origin-gear-placement.rb
- This is the plug-in initializer that loads any configuration settings, if relevant.
- /etc/openshift/plugins.d/openshift-origin-gear-placement.conf
- This is where any relevant configuration settings for the plug-in can be defined.
When you install the rubygem-openshift-origin-gear-placement RPM package, a gem with a Rails engine containing the GearPlacementPlugin
class is also installed. The only method you must modify is self.select_best_fit_node_impl
in the Gem_Location/lib/openshift/gear_placement_plugin.rb
file, because it is the method invoked by the OpenShift::ApplicationContainerProxy
class. Whenever a gear is created, the ApplicationContainerProxy.select_best_fit_node
method is invoked, and if the gear placement plug-in is installed, that method invokes the plug-in.
self.select_best_fit_node_impl
method signature, there are multiple data structures available for use in the algorithm:
GearPlacementPlugin.select_best_fit_node_impl(server_infos, app_props, current_gears, comp_list, user_props, request_time)
server_infos
; it cannot be a node outside of this list. The Gem_Location/lib/openshift/
directory contains several example algorithms for reference, which are also described in Section 8.5.2, “Example Gear Placement Algorithms”.
Table 8.2. Input Data Structures
Data Structure | Description | Properties |
---|---|---|
server_infos | Array of server information: objects of class NodeProperties. | :name, :node_consumed_capacity, :district_id, :district_available_capacity, :region_id, :zone_id |
app_props | Properties of the application to which the gear is being added: objects of class ApplicationProperties. | :id, :name, :web_cartridge |
current_gears | Array of existing gears in the application: objects of class GearProperties. | :id, :name, :server, :district, :cartridges, :region, :zone |
comp_list | Array of components that will be present on the new gear: objects of class ComponentProperties. | :cartridge_name, :component_name, :version, :cartridge_vendor |
user_props | Properties of the user: object of class UserProperties. | :id, :login, :consumed_gears, :capabilities, :plan_id, :plan_state |
request_time | The time that the request was sent to the plug-in: Time on the OpenShift Broker host. | Time.now |
/var/log/openshift/broker/production.log
file in Section 8.5, “Installing and Configuring the Gear Placement Plug-in” for examples of these inputs.
server_infos
entries provided to the algorithm are already filtered for compatibility with the gear request. They can be filtered by:
- Specified profile.
- Specified region.
- Full, deactivated, or undistricted nodes.
- Nodes without a region and zone, if regions and zones are in use.
- Zones being used in a high-availability application, depending on the configuration.
- Nodes being used in a scaled application. If this would return zero nodes, then only one is returned.
- Availability of UID and other specified constraints when a gear is being moved.
server_infos
list presented to the algorithm to only contain one node when the developer might expect there to be plenty of other nodes from which to choose. The intent of the plug-in currently is not to enable complete flexibility of node choice, but rather to enforce custom constraints or to load balance based on preferred parameters.
Optionally, you can implement configuration settings with the plug-in. To do so, you must:
- Load them in the plug-in initializer in the
Gem_Location/config/initializers/openshift-origin-gear-placement.rb
file, and - Add and define the settings in the
/etc/openshift/plugins.d/openshift-origin-gear-placement.conf
file.
Gem_Location/config/initializers/openshift-origin-gear-placement.rb
file are loaded using the following syntax:
config.gear_placement = { :confkey1 => conf.get("CONFKEY1", "value1"), :confkey2 => conf.get("CONFKEY2", "value2"), :confkey3 => conf.get("CONFKEY3", "value3") }
Gem_Location/config/initializers/
directory contains several example initializers for use with their respective example algorithms described in Section 8.5.2, “Example Gear Placement Algorithms”.
Any changes to the Gem_Location/lib/openshift/gear_placement_plugin.rb
, Gem_Location/config/initializers/openshift-origin-gear-placement.rb
, or /etc/openshift/plugins.d/openshift-origin-gear-placement.conf
files must be done equally across all broker hosts in your environment. After making the desired changes to any of these files, the broker service must be restarted to load the changes:
# service openshift-broker restart
/var/log/openshift/broker/production.log
file for the expected logs.