Class: Zillabyte::API::Flows
Direct Known Subclasses
Class Method Summary collapse
-
.get_rich_meta_info_from_script(dir, session = nil, options = {}) ⇒ Object
IMPORTANT#################################################### # get_rich_meta_info_from_script only works with zillabyte apps:push now! The pipe "info_to_ruby.in" is # hardcoded as the meta info passing pipe, so if 2 processes are trying to access it simultaneously there might # be problems since it gets created/destroyed within this script (attempting to create a fifo that already # exists or deleting a fifo that still has information in it may occur).
Instance Method Summary collapse
-
#create_delete(id, options = {}) ⇒ Object
POST /flows/id/delete.
-
#create_kill(id, options = {}) ⇒ Object
POST /flows/id/kill.
-
#delete(id, options = {}) ⇒ Object
DELETE /flows/id.
-
#poll_delete(id, options = {}) ⇒ Object
GET /flows/id/delete.
-
#poll_kill(id, options = {}) ⇒ Object
GET /flows/id/kill.
-
#pull_to_directory(id, dir, session = nil, options = {}) ⇒ Object
GET /flows/id/download.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Zillabyte::API::Base
Class Method Details
.get_rich_meta_info_from_script(dir, session = nil, options = {}) ⇒ Object
IMPORTANT#################################################### # get_rich_meta_info_from_script only works with zillabyte apps:push now! The pipe "info_to_ruby.in" is # hardcoded as the meta info passing pipe, so if 2 processes are trying to access it simultaneously there might # be problems since it gets created/destroyed within this script (attempting to create a fifo that already # exists or deleting a fifo that still has information in it may occur). # # IMPORTANT####################################################
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/zillabyte/api/flows.rb', line 145 def self.(dir, session = nil, = {}) hash = Zillabyte::CLI::Config.get_config_info(dir, session, ) if hash.nil? return {"status" => "error", "error" => "invalid_directory", "error_message" => "The specified directory (#{dir}) does not appear to contain a valid Zillabyte configuration file."} end type = [:output_type] full_script = File.join(dir, hash['script']) command = nil info_file = "#{dir}/#{SecureRandom.uuid}" arg = "--info --file #{info_file}" case hash["language"] when "ruby" command = "cd \"#{dir}\"; unset BUNDLE_GEMFILE; ZILLABYTE_HARNESS=1 bundle exec ruby \"#{full_script}\" #{arg}" command = "cd \"#{dir}\"; unset BUNDLE_GEMFILE; ZILLABYTE_HARNESS=1 bundle exec ruby \"#{full_script}\" #{arg}" when "python" if(File.directory?("#{dir}/vEnv")) command = "cd \"#{dir}\"; PYTHONPATH=~/zb1/multilang/python/Zillabyte #{dir}/vEnv/bin/python \"#{full_script}\" #{arg}" else command = "cd \"#{dir}\"; PYTHONPATH=~/zb1/multilang/python/Zillabyte python \"#{full_script}\" #{arg}" end when "js" #command = "#{Zillabyte::API::CASPERJS_BIN} #{Zillabyte::API::API_CLIENT_JS} \"#{full_script}\" --info" command = "cd \"#{dir}\"; NODE_PATH=~/zb1/multilang/js/src/lib #{Zillabyte::API::NODEJS_BIN} \"#{full_script}\" #{arg}" else session.error "unsupported language: #{hash["language"]}" if session return nil end results = Zillabyte::Command::Flows.get_info(command, info_file, dir, ) begin = JSON.parse(results.split("\n").first.strip) # Throws error if invalid json rescue Exception => e session.error("the underlying app did not return a valid result. command: #{command} error: #{e.}", type) if session exit end # Merge with the new info return hash.merge() end |
Instance Method Details
#create_delete(id, options = {}) ⇒ Object
POST /flows/id/delete
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/zillabyte/api/flows.rb', line 54 def create_delete(id, = {}) = { # TODO }.merge() res = @api.request( :expects => 200, :method => :post, :path => "/flows/#{id}/delete", :body => .to_json ) res.body end |
#create_kill(id, options = {}) ⇒ Object
POST /flows/id/kill
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/zillabyte/api/flows.rb', line 18 def create_kill(id, = {}) = { # TODO }.merge() res = @api.request( :expects => 200, :method => :post, :path => "/flows/#{id}/kill", :body => .to_json ) res.body end |
#delete(id, options = {}) ⇒ Object
DELETE /flows/id
7 8 9 10 11 12 13 14 15 |
# File 'lib/zillabyte/api/flows.rb', line 7 def delete(id, ={}) res = @api.request( :expects => 200, :method => :delete, :path => "/flows/#{id}", :body => .to_json ) res.body end |
#poll_delete(id, options = {}) ⇒ Object
GET /flows/id/delete
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/zillabyte/api/flows.rb', line 72 def poll_delete(id, = {}) = { # TODO }.merge() res = @api.request( :expects => 200, :method => :get, :path => "/flows/#{id}/delete", :body => .to_json ) res.body end |
#poll_kill(id, options = {}) ⇒ Object
GET /flows/id/kill
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zillabyte/api/flows.rb', line 36 def poll_kill(id, = {}) = { # TODO }.merge() res = @api.request( :expects => 200, :method => :get, :path => "/flows/#{id}/kill", :body => .to_json ) res.body end |
#pull_to_directory(id, dir, session = nil, options = {}) ⇒ Object
GET /flows/id/download
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/zillabyte/api/flows.rb', line 90 def pull_to_directory(id, dir, session = nil, = {}) # Get the resource. note query params type = [:output_type] session.display "downloading ##{id}" if session && type.nil? res = @api.request( :expects => 200, :method => :get, :path => "/flows/#{id}/download", :body => .to_json ) hash = res.body if hash['status'] == 'error' error hash['error_message'] else if(hash['tar']) session.display "unpacking to #{dir}" if type.nil? 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']) session.display "downloading ##{id} to #{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 |