Class: Publisher::IIS

Inherits:
Object
  • Object
show all
Defined in:
lib/depengine/publisher/iis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#http_read_timeoutObject

Returns the value of attribute http_read_timeout.



3
4
5
# File 'lib/depengine/publisher/iis.rb', line 3

def http_read_timeout
  @http_read_timeout
end

#protocolObject

Returns the value of attribute protocol.



3
4
5
# File 'lib/depengine/publisher/iis.rb', line 3

def protocol
  @protocol
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/depengine/publisher/iis.rb', line 3

def url
  @url
end

Instance Method Details

#appcmd(value) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/depengine/publisher/iis.rb', line 40

def appcmd(value)
  Helper.validates_presence_of @url, "IIS URL not set"
  Helper.validates_presence_of @protocol, "Protocol not set"

  begin
    uri    = URI(@protocol + '://' + @url)
    Net::HTTP.start(uri.host, uri.port) do |http|
      http.read_timeout = http_read_timeout
      request = Net::HTTP::Post.new uri.request_uri
      request.set_form_data('value' => value)
      request.content_type = 'application/x-www-form-urlencoded;charset=utf-8'
      http.request request do |response|
        response.read_body do |chunk|
          $log.writer.info "#{chunk}"
        end
      end
    end
  rescue Exception => e
    $log.writer.error "Error: while connecting to IIS Server"
    $log.writer.error "Request was: #{uri.to_s}"
    $log.writer.error e.message
    exit 1
  end
end

#build(tag, env, version, value, application_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/depengine/publisher/iis.rb', line 5

def build(tag, env, version, value, application_name)
  Helper.validates_presence_of @url, "IIS URL not set"
  Helper.validates_presence_of @protocol, "Protocol not set"
  iis_error = false

  begin
    uri = URI(@protocol + '://' + @url)
    Net::HTTP.start(uri.host, uri.port) do |http|
      http.read_timeout = http_read_timeout
      request = Net::HTTP::Post.new uri.request_uri
      request.set_form_data('tag' => tag, 'env' => env, 'version' => version, 'value' => value, 'application_name' => application_name)
      request.content_type = 'application/x-www-form-urlencoded;charset=utf-8'
      http.request request do |response|
        response.read_body do |chunk|
          if chunk.include?("### Error while executing")
            $log.writer.error "Error executing build on IIS"
            iis_error = true
          end
          $log.writer.info "#{chunk}"
        end
      end
    end
  rescue Exception => e
    $log.writer.error "Error: while connecting to IIS Server"
    $log.writer.error "Request was: #{uri.to_s}"
    $log.writer.error e.message
    exit 1
  end

  if iis_error
    exit 1
  end

end

#deploy(version, iis_application_name, env) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/depengine/publisher/iis.rb', line 65

def deploy(version, iis_application_name, env)
  Helper.validates_presence_of @url, "IIS URL not set"
  Helper.validates_presence_of @protocol, "Protocol not set"
  iis_error = false

  begin
    uri    = URI(@protocol + '://' + @url)
    Net::HTTP.start(uri.host, uri.port) do |http|
      http.read_timeout = http_read_timeout
      request = Net::HTTP::Post.new uri.request_uri
      request.set_form_data('version' => version, 'application_name' => iis_application_name, 'env' => env)
      request.content_type = 'application/x-www-form-urlencoded;charset=utf-8'
      http.request request do |response|
        response.read_body do |chunk|
          if chunk.include?("### Error while executing")
            $log.writer.error "Error executing deploy on IIS"
            iis_error = true
          end
          $log.writer.info "#{chunk}"
        end
      end
    end
  rescue Exception => e
    $log.writer.error "Error: while connecting to IIS Server"
    $log.writer.error "Request was: #{uri.to_s}"
    $log.writer.error e.message
    exit 1
  end

  if iis_error
    exit 1
  end

end