Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Created two DSLs to help set the MPM Info #3

Merged
merged 1 commit into from

2 participants

Franklin Webber Sean OMeara
Franklin Webber
  • MPMModelDSL which lets you setup the model for criteria. Currently we are only checking the criteria of the httpd version but that could be changed.

  • MPMConfigParameterDSL which lets you specify configuration parameters for a criteria. This is currently the httpd version and the model being employed.

Franklin Webber burtlo Created two DSLs to help set the MPMInfo
* MPMModelDSL which lets you setup the model for criteria. Currently we are only checking the criteria of the httpd version but that could be changed.

* MPMConfigParameterDSL which lets you specify configuration parameters for a criteria. This is currently the httpd version and the model being employed.
a43e896
Sean OMeara someara merged commit cdc8e54 into from
Sean OMeara
Owner

somuchwin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 17, 2014
  1. Franklin Webber

    Created two DSLs to help set the MPMInfo

    burtlo authored
    * MPMModelDSL which lets you setup the model for criteria. Currently we are only checking the criteria of the httpd version but that could be changed.
    
    * MPMConfigParameterDSL which lets you specify configuration parameters for a criteria. This is currently the httpd version and the model being employed.
This page is out of date. Refresh to see the latest.
58 libraries/mpm_config_parameter_dsl.rb
View
@@ -0,0 +1,58 @@
+module Httpd
+ module Service
+ module Helpers
+ module MPMConfigParameterDSL
+ #
+ # Given a key, which is a hash of criteria (i.e. httpd_version,
+ # mpm_model, parameter), this method will return for you the
+ # configuration parameter value. `Nil` is returned if no preset value
+ # for the parameter exists
+ #
+ # @example Searching for the 'maxclients' value for httpd version 2.2
+ # when using the 'prefork' mpm model
+ #
+ # MPMConfigInfo.find(:parameter => :maxclients, :httpd_version => '2.2', :mpm_model => 'prefork')
+ #
+ def find(key)
+ found_key = configuration.keys.find { |lock| key.merge(lock) == key }
+ configuration[found_key]
+ end
+
+ #
+ # Define the configuration parameter value for any criteria: mpm_model,
+ # httpd_version, etc.
+ #
+ # @example define parameters for httpd version 2.4 when using the mpm
+ # 'event' model.
+ #
+ # config :for => { :httpd_version => '2.4', :mpm_model => 'event' },
+ # :are => {
+ # :minspareservers => '5',
+ # :maxspareservers => '10'
+ # }
+ # When defining the criteria you can specify as little or as much
+ # criteria you need. Not specifying the field means that field allows
+ # any value.
+ #
+ # @example Setting the the maxclients for all versions of httpd that are
+ # using
+ #
+ # @note the order that these configs are defined are important. The first
+ # one to match will return that value. So that ensure the more specific
+ # settings are defined first and the more general ones defined later.
+ #
+ def config(options)
+ options[:are].each do |parameter, value|
+ key = options[:for].merge(:parameter => parameter)
+
+ configuration[key] = value
+ end
+ end
+
+ def configuration
+ @configuration ||= {}
+ end
+ end
+ end
+ end
+end
40 libraries/mpm_model_dsl.rb
View
@@ -0,0 +1,40 @@
+module Httpd
+ module Service
+ module Helpers
+ module MPMModelDSL
+ #
+ # Given key, which is a hash of criteria, (i.e. httpd_version), this
+ # method will return for you the mpm model value. `Nil` is returned if
+ # no mpm model matches the criteria.
+ #
+ # @example Searching for the mpm model to use for httpd version 2.4
+ #
+ # MPMModelInfo.find(:httpd_version => '2.4')
+ #
+ def find(key)
+ found_key = mpm_models_list.keys.find { |lock| key.merge(lock) == key }
+ mpm_models_list[found_key]
+ end
+
+ #
+ # Define the mpm model to use for a specified criteria.
+ #
+ # @example use the 'worker' mpm model when the httpd version is '2.2'
+ #
+ # use :model => 'worker', :for => { :httpd_version => '2.2' }
+ #
+ #
+ def use(options)
+ model_name = options[:model]
+ key = options[:for]
+
+ mpm_models_list[key] = model_name
+ end
+
+ def mpm_models_list
+ @mpm_models_list ||= {}
+ end
+ end
+ end
+ end
+end
20 libraries/service_default_mpm_for.rb
View
@@ -1,20 +1,18 @@
+require_relative 'mpm_model_dsl'
+
module Httpd
module Service
module Helpers
- ## MPM section
def default_mpm_for(version)
- MPMinfo.mpm_version_map[version]
- rescue NoMethodError
- nil
+ MPMModelInfo.find :httpd_version => version
end
- class MPMinfo
- def self.mpm_version_map
- @version_map ||= {
- '2.2' => 'worker',
- '2.4' => 'event'
- }
- end
+ class MPMModelInfo
+ extend MPMModelDSL
+
+ use :model => 'worker', :for => { :httpd_version => '2.2' }
+
+ use :model => 'event', :for => { :httpd_version => '2.4' }
end
end
end
185 libraries/service_default_value_for.rb
View
@@ -1,102 +1,107 @@
+require_relative 'mpm_config_parameter_dsl'
+
module Httpd
module Service
module Helpers
## MPM section
def default_value_for(version, mpm, parameter)
- MPMinfo.mpm_info[version][mpm][parameter]
- rescue NoMethodError
- nil
+ MPMConfigInfo.find :httpd_version => version, :mpm_model => mpm, :parameter => parameter
end
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html
# http://httpd.apache.org/docs/2.4/mod/mpm_common.html
- class MPMinfo
- def self.mpm_info
- @mpm_info ||= {
- '2.2' => {
- 'prefork' => {
- :startservers => '5',
- :minspareservers => '5',
- :maxspareservers => '10',
- :maxclients => '150',
- :maxrequestsperchild => '0',
- :minsparethreads => nil,
- :maxsparethreads => nil,
- :threadlimit => nil,
- :threadsperchild => nil,
- :maxrequestworkers => nil,
- :maxconnectionsperchild => nil
- },
- 'worker' => {
- :startservers => '2',
- :minspareservers => nil,
- :maxspareservers => nil,
- :maxclients => '150',
- :maxrequestsperchild => '0',
- :minsparethreads => '25',
- :maxsparethreads => '75',
- :threadlimit => '64',
- :threadsperchild => '25',
- :maxrequestworkers => nil,
- :maxconnectionsperchild => nil
- },
- 'event' => {
- :startservers => '2',
- :minspareservers => nil,
- :maxspareservers => nil,
- :maxclients => '150',
- :maxrequestsperchild => '0',
- :minsparethreads => '25',
- :maxsparethreads => '75',
- :threadlimit => '64',
- :threadsperchild => '25',
- :maxrequestworkers => nil,
- :maxconnectionsperchild => nil
- }
- },
- '2.4' => {
- 'prefork' => {
- :startservers => '5',
- :minspareservers => '5',
- :maxspareservers => '10',
- :maxclients => nil,
- :maxrequestsperchild => nil,
- :minsparethreads => nil,
- :maxsparethreads => nil,
- :threadlimit => nil,
- :threadsperchild => nil,
- :maxrequestworkers => '150',
- :maxconnectionsperchild => '0'
- },
- 'worker' => {
- :startservers => '2',
- :minspareservers => nil,
- :maxspareservers => nil,
- :maxclients => nil,
- :maxrequestsperchild => nil,
- :minsparethreads => '25',
- :maxsparethreads => '75',
- :threadlimit => '64',
- :threadsperchild => '25',
- :maxrequestworkers => '150',
- :maxconnectionsperchild => '0'
- },
- 'event' => {
- :startservers => '2',
- :minspareservers => nil,
- :maxspareservers => nil,
- :maxclients => nil,
- :maxrequestsperchild => nil,
- :minsparethreads => '25',
- :maxsparethreads => '75',
- :threadlimit => '64',
- :threadsperchild => '25',
- :maxrequestworkers => '150',
- :maxconnectionsperchild => '0'
- }
- }
- }
- end
+ class MPMConfigInfo
+ extend MPMConfigParameterDSL
+
+ config :for => { :httpd_version => '2.2', :mpm_model => 'prefork' },
+ :are => {
+ :startservers => '5',
+ :minspareservers => '5',
+ :maxspareservers => '10',
+ :maxclients => '150',
+ :maxrequestsperchild => '0',
+ :minsparethreads => nil,
+ :maxsparethreads => nil,
+ :threadlimit => nil,
+ :threadsperchild => nil,
+ :maxrequestworkers => nil,
+ :maxconnectionsperchild => nil
+ }
+
+ config :for => { :httpd_version => '2.2', :mpm_model => 'worker' },
+ :are => {
+ :startservers => '2',
+ :minspareservers => nil,
+ :maxspareservers => nil,
+ :maxclients => '150',
+ :maxrequestsperchild => '0',
+ :minsparethreads => '25',
+ :maxsparethreads => '75',
+ :threadlimit => '64',
+ :threadsperchild => '25',
+ :maxrequestworkers => nil,
+ :maxconnectionsperchild => nil
+ }
+
+ config :for => { :httpd_version => '2.2', :mpm_model => 'event' },
+ :are => {
+ :startservers => '2',
+ :minspareservers => nil,
+ :maxspareservers => nil,
+ :maxclients => '150',
+ :maxrequestsperchild => '0',
+ :minsparethreads => '25',
+ :maxsparethreads => '75',
+ :threadlimit => '64',
+ :threadsperchild => '25',
+ :maxrequestworkers => nil,
+ :maxconnectionsperchild => nil
+ }
+
+ config :for => { :httpd_version => '2.4', :mpm_model => 'prefork' },
+ :are => {
+ :startservers => '5',
+ :minspareservers => '5',
+ :maxspareservers => '10',
+ :maxclients => nil,
+ :maxrequestsperchild => nil,
+ :minsparethreads => nil,
+ :maxsparethreads => nil,
+ :threadlimit => nil,
+ :threadsperchild => nil,
+ :maxrequestworkers => '150',
+ :maxconnectionsperchild => '0'
+ }
+
+ config :for => { :httpd_version => '2.4', :mpm_model => 'worker' },
+ :are => {
+ :startservers => '2',
+ :minspareservers => nil,
+ :maxspareservers => nil,
+ :maxclients => nil,
+ :maxrequestsperchild => nil,
+ :minsparethreads => '25',
+ :maxsparethreads => '75',
+ :threadlimit => '64',
+ :threadsperchild => '25',
+ :maxrequestworkers => '150',
+ :maxconnectionsperchild => '0'
+ }
+
+ config :for => { :httpd_version => '2.4', :mpm_model => 'event' },
+ :are => {
+ :startservers => '2',
+ :minspareservers => nil,
+ :maxspareservers => nil,
+ :maxclients => nil,
+ :maxrequestsperchild => nil,
+ :minsparethreads => '25',
+ :maxsparethreads => '75',
+ :threadlimit => '64',
+ :threadsperchild => '25',
+ :maxrequestworkers => '150',
+ :maxconnectionsperchild => '0'
+ }
end
end
end
Something went wrong with that request. Please try again.