Module: Deployment::Methods::Helper

Defined in:
lib/depengine/dsl/helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validates_not_empty(attribute, message = nil) ⇒ Object

Raises:

  • (ArgumentError)


143
144
145
# File 'lib/depengine/dsl/helper.rb', line 143

def validates_not_empty(attribute, message=nil)
  raise ArgumentError, message || "Parameter is empty", caller if attribute.nil?
end

.validates_presence_of(attribute, message = nil) ⇒ Object

Raises:

  • (ArgumentError)


138
139
140
# File 'lib/depengine/dsl/helper.rb', line 138

def validates_presence_of(attribute, message=nil)
  raise ArgumentError, message || "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(options={})
  asserter = ::Asserter::Url.new
  asserter.check_protocol  = options[:check_protocol] ||  @cdb['check_protocol'] || "http"
  asserter.check_host  = options[:check_host] || @cdb['check_host']
  asserter.check_port  = options[:check_port] || @cdb['check_port'] || '80'
  asserter.check_uri  = options[:check_uri] || @cdb['check_uri'] || '/'
  asserter.check_response_string  = options[:check_response_string] || @cdb['check_response_string'] || 'html'

  asserter.assert_url_response_of(options)
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(options={})
  options = @cdb.merge($recipe_config).merge(options)
  options[:status] ||= 'success'
  options[:message] ||= ''

  mail_options = {
    :from => options[:deploy_email_from] || @cdb['deploy_email_from'],
    :to => options[:deploy_email_to] || @cdb['deploy_email_to'],
    :subject => "#{options[:env]} #{options[:job_name]} #{options[:module_name]} #{options[:application_name]} #{options[:version]} #{options[:status]}",
    :body => "Env: #{options[:env]}\nJob: #{options[:job_name]}\nModule: #{options[:module_name]}\nApplication: #{options[:application_name]}\nVersion: #{options[:version].to_json}\n#{options[:status]}.\n\n---\nx#{options[:message]}"
  }
  sendmail(mail_options)
end

#report_to_cdbObject

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(options)
  Helper.validates_presence_of options[:from],    "Mail-FROM not set"
  Helper.validates_presence_of options[:to],      "Mail-TO not set"
  Helper.validates_presence_of options[:subject], "No mail subject set"
  Helper.validates_presence_of options[:body],    "No mail body set"

  helper = ::Helper::Mail.new
  helper.smtp_host = @cdb['smtp_host'] if @cdb and @cdb['smtp_host']
  helper.sendmail(options)
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(options={})
  publisher = ::Publisher::Tomcat.new
  publisher.servers  = options[:servers] || @cdb['servers']
  publisher.runners = options[:runners] || @cdb['runners'] || publisher.servers
  publisher.initd_script  = options[:initd_script] || @cdb['initd_script']
  publisher.application_name  = options[:application_name] ||  $recipe_config[:application_name] || @cdb['application_name']
  publisher.catalina_home  = options[:catalina_home] || @cdb['catalina_home']
  publisher.tomcat_context  = options[:tomcat_context] || @cdb['tomcat_context']
  publisher.logfilename  = options[:logfilename] || @cdb['logfilename']
  publisher.check_host  = options[:check_host] || @cdb['check_host']
  publisher.worker  = self
  publisher.deploy(options)
end