Module: Deployment::Methods::Helper
- Defined in:
- lib/depengine/dsl/helper.rb
Class Method Summary collapse
- .validates_not_empty(attribute, message = nil) ⇒ Object
- .validates_presence_of(attribute, message = nil) ⇒ Object
Instance Method Summary collapse
-
#assert_url_response_of(options = {}) ⇒ Object
Checks if a given url returns 200 and a body that matches a given regexp.
-
#date_unique(format = "%Y-%m-%d_%s") ⇒ Object
Returns an time-dependant string that can be used in pseudo-unique release versions and the such.
-
#report_by_mail(options = {}) ⇒ Object
Sends an email to report a deployment to a given recepiant.
-
#report_to_cdb ⇒ Object
Reports a deployment to its cdb.
-
#samba_mount(remote_path, local_path) ⇒ Object
Mounts a SMB share.
-
#samba_umount(local_path) ⇒ Object
Unmounts a previously mounted SMB share.
-
#sendmail(options) ⇒ Object
Sends an email.
-
#tomcat_deploy(options = {}) ⇒ Object
Deploys a tomcat based application to a set of app servers.
Class Method Details
.validates_not_empty(attribute, message = nil) ⇒ Object
143 144 145 |
# File 'lib/depengine/dsl/helper.rb', line 143 def validates_not_empty(attribute, =nil) raise ArgumentError, || "Parameter is empty", caller if attribute.nil? end |
.validates_presence_of(attribute, message = nil) ⇒ Object
138 139 140 |
# File 'lib/depengine/dsl/helper.rb', line 138 def validates_presence_of(attribute, =nil) raise ArgumentError, || "Missing parameter", caller if attribute.nil? end |
Instance Method Details
#assert_url_response_of(options = {}) ⇒ Object
Checks if a given url returns 200 and a body that matches a given regexp.
Parameters:
-
options
- a hash with needed configuration options-
:check_protocol
- “http” or “https” or maybe something else… -
:check_host
- the host to contact -
:check_port
- the port to connect to -
:check_uri
- the recipiants address -
:check_response_string
- the string or regexp to check
-
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/depengine/dsl/helper.rb', line 45 def assert_url_response_of(={}) asserter = ::Asserter::Url.new asserter.check_protocol = [:check_protocol] || @cdb['check_protocol'] || "http" asserter.check_host = [:check_host] || @cdb['check_host'] asserter.check_port = [:check_port] || @cdb['check_port'] || '80' asserter.check_uri = [:check_uri] || @cdb['check_uri'] || '/' asserter.check_response_string = [:check_response_string] || @cdb['check_response_string'] || 'html' asserter.assert_url_response_of() end |
#date_unique(format = "%Y-%m-%d_%s") ⇒ Object
Returns an time-dependant string that can be used in pseudo-unique release versions and the such.
The object will be cached for later reference, so multiple uses of this method in a recipe will result in the same string.
Parameters:
-
format
- the strftime format that is to be used to generate the unique string. Defaults to “%Y-%m-%d_%s”.
13 14 15 |
# File 'lib/depengine/dsl/helper.rb', line 13 def date_unique(format="%Y-%m-%d_%s") @date_unique ||= Time.now.strftime(format) end |
#report_by_mail(options = {}) ⇒ Object
Sends an email to report a deployment to a given recepiant.
Parameters:
-
options
- a hash with needed configuration options for the email. All parameters are optional.-
:application_name
- which application has been deployed -
:module_name
- which module of the application has been deployed -
:status
- the resulting status of the deployment -
:message
- a additional message to send in the mail, commonly used to specify any non positive status. -
:deploy_email_from
- the senders address -
:deploy_email_to
- the recipiants address
-
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/depengine/dsl/helper.rb', line 74 def report_by_mail(={}) = @cdb.merge($recipe_config).merge() [:status] ||= 'success' [:message] ||= '' = { :from => [:deploy_email_from] || @cdb['deploy_email_from'], :to => [:deploy_email_to] || @cdb['deploy_email_to'], :subject => "#{[:env]} #{[:job_name]} #{[:module_name]} #{[:application_name]} #{[:version]} #{[:status]}", :body => "Env: #{[:env]}\nJob: #{[:job_name]}\nModule: #{[:module_name]}\nApplication: #{[:application_name]}\nVersion: #{[:version].to_json}\n#{[:status]}.\n\n---\nx#{[:message]}" } sendmail() end |
#report_to_cdb ⇒ Object
Reports a deployment to its cdb.
57 58 59 60 61 62 |
# File 'lib/depengine/dsl/helper.rb', line 57 def report_to_cdb() reporter = ::Reporter::Cdb.new reporter.version = @version.to_json reporter.worker = self reporter.set_version() end |
#samba_mount(remote_path, local_path) ⇒ Object
Mounts a SMB share.
Parameters:
-
remote_path
- the path to the remote share (e.g.“smb://somehost/someshare”) -
:local_path
- the local path in which the share will be mounted
121 122 123 124 125 126 |
# File 'lib/depengine/dsl/helper.rb', line 121 def samba_mount (remote_path, local_path) smb = ::Helper::Smb.new smb.remote_path = remote_path smb.local_path = local_path smb.samba_mount() end |
#samba_umount(local_path) ⇒ Object
Unmounts a previously mounted SMB share.
Parameters:
-
:local_path
- the local path in which the share is mounted
132 133 134 135 136 |
# File 'lib/depengine/dsl/helper.rb', line 132 def samba_umount (local_path) smb = ::Helper::Smb.new smb.local_path = local_path smb.samba_umount() end |
#sendmail(options) ⇒ Object
Sends an email.
Parameters:
-
options
- a hash with needed configuration options for the email.-
:body
- the actual text to send -
:subject
- the subject line of the email -
:from
- the senders address -
:to
- the recipiants address
-
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/depengine/dsl/helper.rb', line 25 def sendmail() Helper.validates_presence_of [:from], "Mail-FROM not set" Helper.validates_presence_of [:to], "Mail-TO not set" Helper.validates_presence_of [:subject], "No mail subject set" Helper.validates_presence_of [:body], "No mail body set" helper = ::Helper::Mail.new helper.smtp_host = @cdb['smtp_host'] if @cdb and @cdb['smtp_host'] helper.sendmail() end |
#tomcat_deploy(options = {}) ⇒ Object
Deploys a tomcat based application to a set of app servers.
The tomcats are restarted in this process.
Parameters:
-
options
- a hash with needed configuration options.-
:servers
- an enumerable list of the app servers -
:runners
- a subset of:servers
which are currently active. Is equal to:servers
if not set -
:initd_script
- the path to the init script of the appserver. Used to stop/start. -
:application_name
- the name of the current application -
:catalina_home
- the path in which the app servers webapps/ directory is -
:tomcat_context
- the tomcat context to deploy in -
:logfilename
- the name of the logfile. Will be automatically prefixed with #catalina_home/logs/ -
:check_host
- an options hash to pass to#assert_url_response_of
to check the status of the app
-
All parameters can also be spcified via CDB.
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/depengine/dsl/helper.rb', line 102 def tomcat_deploy(={}) publisher = ::Publisher::Tomcat.new publisher.servers = [:servers] || @cdb['servers'] publisher.runners = [:runners] || @cdb['runners'] || publisher.servers publisher.initd_script = [:initd_script] || @cdb['initd_script'] publisher.application_name = [:application_name] || $recipe_config[:application_name] || @cdb['application_name'] publisher.catalina_home = [:catalina_home] || @cdb['catalina_home'] publisher.tomcat_context = [:tomcat_context] || @cdb['tomcat_context'] publisher.logfilename = [:logfilename] || @cdb['logfilename'] publisher.check_host = [:check_host] || @cdb['check_host'] publisher.worker = self publisher.deploy() end |