Class: GoodData::Process
- Inherits:
-
Rest::Resource
- Object
- Rest::Object
- Rest::Resource
- GoodData::Process
- Defined in:
- lib/gooddata/models/process.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #raw_data, #json, #to_hash)
readonly
Returns the value of attribute data.
Attributes inherited from Rest::Object
Class Method Summary collapse
- .[](id, options = {}) ⇒ Object
- .all ⇒ Object
-
.deploy(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
Deploy a new process or redeploy existing one.
- .deploy_brick(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
- .deploy_from_appstore(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
- .upload_package(path, files_to_exclude, opts = { :client => GoodData.connection }) ⇒ Object
- .with_deploy(dir, options = {}, &block) ⇒ Object
Instance Method Summary collapse
- #create_notification_rule(opts = {}) ⇒ Object
- #create_schedule(cron, executable, options = {}) ⇒ Object
- #delete ⇒ Object
-
#deploy(path, options = {}) ⇒ Object
Redeploy existing process.
-
#download ⇒ IO
Downloads the process from S3 in a zipped form.
- #executables ⇒ Object
- #execute(executable, options = {}) ⇒ Object
- #executions_link ⇒ Object
- #graphs ⇒ Object
-
#initialize(data) ⇒ Process
constructor
A new instance of Process.
- #link ⇒ Object (also: #uri)
- #links ⇒ Object
- #name ⇒ Object
- #notification_rules ⇒ Object
- #obj_id ⇒ Object (also: #process_id)
- #path ⇒ Object
- #process ⇒ Object
- #schedules ⇒ Object
- #start_execution(executable, options = {}) ⇒ Object
- #type ⇒ Object
Methods inherited from Rest::Object
client, default_client, #saved?
Methods included from Mixin::DataPropertyReader
Methods included from Mixin::DataPropertyWriter
Methods included from Mixin::MetaPropertyReader
Methods included from Mixin::MetaPropertyWriter
Methods included from Mixin::MetaGetter
Methods included from Mixin::RootKeyGetter
Methods included from Mixin::ContentGetter
Constructor Details
#initialize(data) ⇒ Process
Returns a new instance of Process.
251 252 253 |
# File 'lib/gooddata/models/process.rb', line 251 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly) Also known as: raw_data, json, to_hash
Returns the value of attribute data.
20 21 22 |
# File 'lib/gooddata/models/process.rb', line 20 def data @data end |
Class Method Details
.[](id, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gooddata/models/process.rb', line 27 def [](id, = {}) project = [:project] c = [:client] || (project && project.client) if id == :all && project uri = "/gdc/projects/#{project.pid}/dataload/processes" data = c.get(uri) data['processes']['items'].map do |process_data| c.create(Process, process_data, project: project) end elsif id == :all uri = "/gdc/account/profile/#{c.user.obj_id}/dataload/processes" data = c.get(uri) pids = data['processes']['items'].map { |process_data| process_data['process']['links']['self'].match(%r{/gdc/projects/(\w*)/})[1] }.uniq projects_lookup = pids.pmap { |pid| c.projects(pid) }.reduce({}) do |a, e| a[e.pid] = e a end data['processes']['items'].map do |process_data| pid = process_data['process']['links']['self'].match(%r{/gdc/projects/(\w*)/})[1] c.create(Process, process_data, project: projects_lookup[pid]) end else uri = "/gdc/projects/#{project.pid}/dataload/processes/#{id}" c.create(Process, c.get(uri), project: project) end end |
.deploy(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
Deploy a new process or redeploy existing one.
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 |
# File 'lib/gooddata/models/process.rb', line 93 def deploy(path, = { :client => GoodData.client, :project => GoodData.project }) return deploy_brick(path, ) if path.to_s.start_with?(APP_STORE_URL) return deploy_from_appstore(path.to_s, ) if (path.to_s =~ %r{\${.*}:(.*)\/(.*):\/}) == 0 # rubocop:disable Style/NumericPredicate client, project = GoodData.get_client_and_project() path = Pathname(path) || fail('Path is not specified') files_to_exclude = [:files_to_exclude].nil? ? [] : [:files_to_exclude].map { |pname| Pathname(pname) } process_id = [:process_id] type = [:type] || 'GRAPH' deploy_name = [:name] fail ArgumentError, 'options[:name] can not be nil or empty!' if deploy_name.nil? || deploy_name.empty? verbose = [:verbose] || false puts HighLine.color("Deploying #{path}", HighLine::BOLD) if verbose deployed_path = Process.upload_package(path, files_to_exclude, client: client, project: project) data = { :process => { :name => deploy_name, :path => "/uploads/#{File.basename(deployed_path)}", :type => type } } res = if process_id.nil? client.post("/gdc/projects/#{project.pid}/dataload/processes", data) else client.put("/gdc/projects/#{project.pid}/dataload/processes/#{process_id}", data) end process = client.create(Process, res, project: project) puts HighLine.color("Deploy DONE #{path}", HighLine::GREEN) if verbose process end |
.deploy_brick(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gooddata/models/process.rb', line 131 def deploy_brick(path, = { :client => GoodData.client, :project => GoodData.project }) client, project = GoodData.get_client_and_project() brick_uri_parts = URI(path).path.split('/') ref = brick_uri_parts[4] brick_name = brick_uri_parts.last brick_path = brick_uri_parts[5..-1].join('/') Dir.mktmpdir do |dir| Dir.chdir(dir) do `git clone #{APP_STORE_URL}` end Dir.chdir(File.join(dir, 'app_store')) do if ref `git checkout #{ref}` fail 'Wrong branch or tag specified!' if $CHILD_STATUS.to_i.nonzero? end opts = { :client => client, :project => project, :name => brick_name, :type => 'RUBY' } full_brick_path = File.join(dir, 'app_store', brick_path) unless File.exist?(full_brick_path) fail "Invalid brick name specified - '#{brick_name}'" end return deploy(full_brick_path, opts) end end end |
.deploy_from_appstore(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/gooddata/models/process.rb', line 169 def deploy_from_appstore(path, = { :client => GoodData.client, :project => GoodData.project }) client, project = GoodData.get_client_and_project() deploy_name = [:name] fail ArgumentError, 'options[:name] can not be nil or empty!' if deploy_name.nil? || deploy_name.empty? verbose = [:verbose] || false puts HighLine.color("Deploying #{path}", HighLine::BOLD) if verbose process_id = [:process_id] data = { process: { name: deploy_name, path: path, type: 'RUBY' } } res = if process_id.nil? client.post("/gdc/projects/#{project.pid}/dataload/processes", data) else client.put("/gdc/projects/#{project.pid}/dataload/processes/#{process_id}", data) end if res.keys.first == 'asyncTask' res = JSON.parse(client.poll_on_code(res['asyncTask']['links']['poll'], .merge(process: false))) end process = client.create(Process, res, project: project) puts HighLine.color("Deploy DONE #{path}", HighLine::GREEN) if verbose process end |
.upload_package(path, files_to_exclude, opts = { :client => GoodData.connection }) ⇒ Object
80 81 82 83 |
# File 'lib/gooddata/models/process.rb', line 80 def upload_package(path, files_to_exclude, opts = { :client => GoodData.connection }) GoodData.get_client_and_project(opts) zip_and_upload(path, files_to_exclude, opts) end |
.with_deploy(dir, options = {}, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gooddata/models/process.rb', line 60 def with_deploy(dir, = {}, &block) _client, project = GoodData.get_client_and_project() GoodData.with_project(project) do params = [:params].nil? ? [] : [[:params]] if block begin res = GoodData::Process.deploy(dir, .merge(:files_to_exclude => params)) block.call(res) rescue => e puts e.inspect ensure res.delete if res end else GoodData::Process.deploy(dir, .merge(:files_to_exclude => params)) end end end |
Instance Method Details
#create_notification_rule(opts = {}) ⇒ Object
362 363 364 |
# File 'lib/gooddata/models/process.rb', line 362 def create_notification_rule(opts = {}) NotificationRule.create(opts.merge(project: project, process: self, client: client)) end |
#create_schedule(cron, executable, options = {}) ⇒ Object
328 329 330 |
# File 'lib/gooddata/models/process.rb', line 328 def create_schedule(cron, executable, = {}) project.create_schedule(process_id, cron, executable, .merge(client: client, project: project)) end |
#delete ⇒ Object
255 256 257 |
# File 'lib/gooddata/models/process.rb', line 255 def delete client.delete(uri) end |
#deploy(path, options = {}) ⇒ Object
Redeploy existing process.
267 268 269 |
# File 'lib/gooddata/models/process.rb', line 267 def deploy(path, = {}) Process.deploy(path, { client: client, process_id: process_id, :project => project, :name => name, :type => type }.merge()) end |
#download ⇒ IO
Downloads the process from S3 in a zipped form.
274 275 276 277 278 |
# File 'lib/gooddata/models/process.rb', line 274 def download link = links['source'] client.connection.refresh_token client.get(link, process: false) { |_, _, result| RestClient.get(result.to_hash['location'].first) } end |
#executables ⇒ Object
316 317 318 |
# File 'lib/gooddata/models/process.rb', line 316 def executables process['executables'] end |
#execute(executable, options = {}) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/gooddata/models/process.rb', line 332 def execute(executable, = {}) result = start_execution(executable, ) begin client.poll_on_code(result['executionTask']['links']['poll'], ) rescue RestClient::RequestFailed => e raise(e) ensure result = client.get(result['executionTask']['links']['detail']) if result['executionDetail']['status'] == 'ERROR' fail "Runing process failed. You can look at a log here #{result['executionDetail']['logFileName']}" end end client.create(GoodData::ExecutionDetail, result, client: client, project: project) end |
#executions_link ⇒ Object
308 309 310 |
# File 'lib/gooddata/models/process.rb', line 308 def executions_link links['executions'] end |
#graphs ⇒ Object
312 313 314 |
# File 'lib/gooddata/models/process.rb', line 312 def graphs process['graphs'] end |
#link ⇒ Object Also known as: uri
296 297 298 |
# File 'lib/gooddata/models/process.rb', line 296 def link links['self'] end |
#links ⇒ Object
292 293 294 |
# File 'lib/gooddata/models/process.rb', line 292 def links process['links'] end |
#name ⇒ Object
284 285 286 |
# File 'lib/gooddata/models/process.rb', line 284 def name process['name'] end |
#notification_rules ⇒ Object
358 359 360 |
# File 'lib/gooddata/models/process.rb', line 358 def notification_rules NotificationRule.all(project: project, process: self, client: client) end |
#obj_id ⇒ Object Also known as: process_id
302 303 304 |
# File 'lib/gooddata/models/process.rb', line 302 def obj_id uri.split('/').last end |
#path ⇒ Object
320 321 322 |
# File 'lib/gooddata/models/process.rb', line 320 def path process['path'] end |
#process ⇒ Object
280 281 282 |
# File 'lib/gooddata/models/process.rb', line 280 def process data['process'] end |
#schedules ⇒ Object
324 325 326 |
# File 'lib/gooddata/models/process.rb', line 324 def schedules project.schedules.select { |schedule| schedule.process_id == obj_id } end |
#start_execution(executable, options = {}) ⇒ Object
347 348 349 350 351 352 353 354 355 356 |
# File 'lib/gooddata/models/process.rb', line 347 def start_execution(executable, = {}) params = [:params] || {} hidden_params = [:hidden_params] || {} client.post(executions_link, :execution => { :graph => executable.to_s, :params => GoodData::Helpers.encode_public_params(params), :hiddenParams => GoodData::Helpers.encode_hidden_params(hidden_params) }) end |
#type ⇒ Object
288 289 290 |
# File 'lib/gooddata/models/process.rb', line 288 def type process['type'].downcase.to_sym end |