Class: Zillabyte::API::Flows

Inherits:
Base
  • Object
show all
Defined in:
lib/zillabyte/api/flows.rb

Direct Known Subclasses

Apps, Components

Instance Method Summary collapse

Methods inherited from Base

#initialize, #request

Methods included from Helpers

#app, #ask, #command, #create_git_remote, #display, #error, #extract_app_from_git_config, #extract_app_in_dir, #format_with_bang, #friendly_dir, #get_flow_ui_link, #get_info, #get_rich_info, #git, #handle_downloading_manifest, #has_git?, #longest, #read_multiline, #truncate_message, #version_okay?, #with_tty

Constructor Details

This class inherits a constructor from Zillabyte::API::Base

Instance Method Details

#create_delete(id, options = {}) ⇒ Object

POST /flows/id/delete



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/zillabyte/api/flows.rb', line 162

def create_delete(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :post,
    :path     => "/flows/#{id}/delete",
    :body     => options.to_json
  )

  res.body

end

#create_kill(id, options = {}) ⇒ Object

POST /flows/id/kill



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zillabyte/api/flows.rb', line 17

def create_kill(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :post,
    :path     => "/flows/#{id}/kill",
    :body     => options.to_json
  )

  res.body

end

#create_pause(id, options = {}) ⇒ Object

POST /flows/id/pause



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/zillabyte/api/flows.rb', line 90

def create_pause(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :post,
    :path     => "/flows/#{id}/pause",
    :body     => options.to_json
  )

  res.body

end

#create_resume(id, options = {}) ⇒ Object

POST /flows/id/kill



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/zillabyte/api/flows.rb', line 126

def create_resume(id, options = {})

  options = {
    # TODO
  }.merge(options)
  res = @api.request(
    :expects  => 200,
    :method   => :post,
    :path     => "/flows/#{id}/resume",
    :body     => options.to_json
  )

  res.body

end

#create_scale(id, options = {}) ⇒ Object

POST /flows/id/scale



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/zillabyte/api/flows.rb', line 53

def create_scale(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :post,
    :path     => "/flows/#{id}/scale",
    :body     => options.to_json
  )

  res.body

end

#delete(id, options = {}) ⇒ Object

DELETE /flows/id



6
7
8
9
10
11
12
13
14
# File 'lib/zillabyte/api/flows.rb', line 6

def delete(id, options ={})
  res = @api.request(
    :expects  => 200,
    :method   => :delete,
    :path     => "/flows/#{id}",
    :body     => options.to_json
  )
  res.body
end

#get_meta(id, options = {}) ⇒ Object

GET /flows/id/config



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/zillabyte/api/flows.rb', line 199

def get_meta(id, options = {})

  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/flows/#{id}/config",
    :body     => options.to_json
  )

  res.body

end

#poll_delete(id, options = {}) ⇒ Object

GET /flows/id/delete



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/zillabyte/api/flows.rb', line 180

def poll_delete(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/flows/#{id}/delete",
    :body     => options.to_json
  )

  res.body

end

#poll_kill(id, options = {}) ⇒ Object

GET /flows/id/kill



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/zillabyte/api/flows.rb', line 35

def poll_kill(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/flows/#{id}/kill",
    :body     => options.to_json
  )

  res.body

end

#poll_pause(id, options = {}) ⇒ Object

GET /flows/id/pause



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/zillabyte/api/flows.rb', line 108

def poll_pause(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/flows/#{id}/pause",
    :body     => options.to_json
  )

  res.body

end

#poll_resume(id, options = {}) ⇒ Object

GET /flows/id/kill



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/zillabyte/api/flows.rb', line 143

def poll_resume(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/flows/#{id}/resume",
    :body     => options.to_json
  )

  res.body

end

#poll_scale(id, options = {}) ⇒ Object

GET /flows/id/scale



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/zillabyte/api/flows.rb', line 71

def poll_scale(id, options = {})

  options = {
    # TODO
  }.merge(options)

  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/flows/#{id}/scale",
    :body     => options.to_json
  )

  res.body

end

#pull_to_directory(id, dir, session = nil, options = {}) ⇒ Object

GET /flows/id/download



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/zillabyte/api/flows.rb', line 213

def pull_to_directory(id, dir, session = nil, options = {})
  require("zillabyte/common/tar")
  require("stringio")
  # Get the resource. note query params
  type = options[:output_type]
  session.display "downloading ##{id}" if session && type.nil?
  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/flows/#{id}/download",
    :body     => options.to_json
  )

  hash = res.body
  if hash['status'] == 'error'
    error hash['error_message']
  else
    if(hash['tar'])
      session.display "unpacking to #{friendly_dir(dir)}" if type.nil?
      require("base64")
      tar = StringIO.new(Base64.decode64(hash['tar']))
      hash.delete('tar')
      Zillabyte::Common::Tar.untar(tar, dir)
    #If you get an uri instead of the tar, then download the file directly from s3
    elsif(hash['uri'])
      require("net/http")
      session.display "downloading ##{id} to #{friendly_dir(dir)}" if type.nil?
      uri = URI(hash['uri'])
      try_again = 1
      while(try_again)
        Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
          request = Net::HTTP::Get.new(uri.request_uri)
          response = http.request(request)
          if response.code.to_i >= 300
            try_again = 1
            break
          end
          tar = StringIO.new(response.body)
          Zillabyte::Common::Tar.untar(tar, dir)
          try_again = nil
        end
      end
      hash.delete('uri')
    end
  end
  
  hash
  
end

#push_directory(dir, hash, session = nil, options = {}) ⇒ Object

POST /apps OR /components



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/zillabyte/api/flows.rb', line 265

def push_directory(dir, hash, session = nil, options = {})
  require("zillabyte/common/tar")
  type = options[:output_type]
  flow_type = hash["flow_type"]

  # Tar up everything... 
  hash['ignore_files'] ||= []
  hash['ignore_files'] << "info_to_ruby.in"
  hash['ignore_files'] << "vEnv"
  hash['ignore_files'] << "vendor"

  top_dir = hash['top_dir'] || "."
  ignore_files = hash['ignore_files'] || []
  session.display("packaging directory... ", false) if session && type.nil?
  tar = Zillabyte::Common::Tar.tar(top_dir, ignore_files)
  session.display("done") if session && type.nil?

  hash.delete('pwd')

  options = {
    :name => hash['name'],
    :meta => hash,
    # :tar => Base64.encode64(tar.read)
  }.merge(options)

  session.display("uploading #{tar.size} bytes... ", false) if session && type.nil?
  res = @api.request(
    :expects  => 200,
    :method   => :post,
    :path     => "/#{flow_type}s",
    :body     => options.to_json
  )


  if(res.body['uri'])
    require("net/http")

    uri = URI(res.body['uri'])
    try_again = 1
    while(try_again)
      Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
        request = Net::HTTP::Put.new(uri.request_uri)
        request.body_stream = tar
        request['Content-Length'] = request.body_stream.size
        request['Content-Type'] = ''
        response = http.request(request)
        if response.code.to_i >= 300
          try_again = 1
          break
        end
        try_again = nil
      end
    end
    res.body.delete('uri')
  end
  session.display("done")if session && type.nil?
  res.body

end