Class: GoodData::Process
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #raw_data, #json, #to_hash)
readonly
Returns the value of attribute data.
Attributes inherited from Rest::Object
#client, #project
Class Method Summary
collapse
-
.[](id, options = { :client => GoodData.connection }) ⇒ 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_component(data, options = { client: GoodData.client, project: GoodData.project }) ⇒ Object
-
.deploy_from_appstore(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
-
.deploy_simple_process(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
client, default_client, #saved?
#data_property_reader
#data_property_writer
#metadata_property_reader
#metadata_property_writer
#meta
#root_key
#content
Constructor Details
#initialize(data) ⇒ Process
Returns a new instance of Process.
256
257
258
|
# File 'lib/gooddata/models/process.rb', line 256
def initialize(data)
@data = data
end
|
Instance Attribute Details
#data ⇒ Object
Also known as:
raw_data, json, to_hash
Returns the value of attribute data.
19
20
21
|
# File 'lib/gooddata/models/process.rb', line 19
def data
@data
end
|
Class Method Details
.[](id, options = { :client => GoodData.connection }) ⇒ Object
26
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 26
def [](id, options = { :client => GoodData.connection })
project = options[:project]
client = options[:client] || (project && project.client)
fail 'Client has to be specified in options' unless client
if id == :all && project
uri = "/gdc/projects/#{project.pid}/dataload/processes"
data = client.get(uri)
data['processes']['items'].map do |process_data|
client.create(Process, process_data, project: project)
end
elsif id == :all
uri = "/gdc/account/profile/#{client.user.obj_id}/dataload/processes"
data = client.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| client.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]
client.create(Process, process_data, project: projects_lookup[pid])
end
else
uri = "/gdc/projects/#{project.pid}/dataload/processes/#{id}"
client.create(Process, client.get(uri), project: project)
end
end
|
56
57
58
|
# File 'lib/gooddata/models/process.rb', line 56
def all
Process[:all]
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
|
# File 'lib/gooddata/models/process.rb', line 93
def deploy(path, options = { client: GoodData.client, project: GoodData.project })
if path.is_a?(Hash) && path[:component]
deploy_component path, options
elsif path.to_s.start_with?(APP_STORE_URL)
deploy_brick path, options
elsif path.to_s =~ %r{\${.*}:(.*)\/(.*):\/}
deploy_from_appstore path.to_s, options
else
deploy_simple_process path, options
end
end
|
.deploy_brick(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
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
168
|
# File 'lib/gooddata/models/process.rb', line 134
def deploy_brick(path, options = { :client => GoodData.client, :project => GoodData.project })
client, project = GoodData.get_client_and_project(options)
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)
fail "Invalid brick name specified - '#{brick_name}'" unless File.exist?(full_brick_path)
return deploy(full_brick_path, opts)
end
end
end
|
.deploy_component(data, options = { client: GoodData.client, project: GoodData.project }) ⇒ Object
189
190
191
192
193
194
195
196
|
# File 'lib/gooddata/models/process.rb', line 189
def deploy_component(data, options = { client: GoodData.client, project: GoodData.project })
client, project = GoodData.get_client_and_project(options)
data = { process: data } unless data[:process]
data[:process] = GoodData::Helpers.symbolize_keys(data[:process]).select { |k| %i[type name component dataSources].include? k }
data[:process][:component] = GoodData::Helpers.symbolize_keys(data[:process][:component]).select { |k| %i[name version configLocation config].include? k }
save(data, options)
end
|
.deploy_from_appstore(path, options = { :client => GoodData.client, :project => GoodData.project }) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/gooddata/models/process.rb', line 170
def deploy_from_appstore(path, options = { :client => GoodData.client, :project => GoodData.project })
deploy_name = options[:name] || "Process of #{path}"
verbose = options[:verbose] || false
GoodData.logger.info("Deploying #{path}") if verbose
data_sources = options[:data_sources] || []
data = {
process: {
name: deploy_name,
path: path,
dataSources: data_sources,
type: 'RUBY'
}
}
save(data, options)
end
|
.deploy_simple_process(path, options = { client: GoodData.client, project: GoodData.project }) ⇒ Object
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
|
# File 'lib/gooddata/models/process.rb', line 105
def deploy_simple_process(path, options = { client: GoodData.client, project: GoodData.project })
client, project = GoodData.get_client_and_project(options)
fail 'Path is not specified' unless path
path = Pathname(path) || fail('Path is not a valid pathname')
files_to_exclude = options[:files_to_exclude].nil? ? [] : options[:files_to_exclude].map { |pname| Pathname(pname) }
type = options[:type] || 'GRAPH'
deploy_name = options[:name] || "Process of #{path} script"
fail ArgumentError, 'options[:name] can not be nil or empty!' if deploy_name.nil? || deploy_name.empty?
verbose = options[:verbose] || false
GoodData.logger.info("Deploying #{path}") if verbose
deployed_path = Process.upload_package(path, files_to_exclude, client: client, project: project)
data_sources = options[:data_sources] || []
data = {
:process => {
:name => deploy_name,
:path => "/uploads/#{File.basename(deployed_path)}",
:type => type,
:dataSources => data_sources
}
}
save(data, options)
end
|
.upload_package(path, files_to_exclude, opts = { :client => GoodData.connection }) ⇒ Object
.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, options = {}, &block)
_client, project = GoodData.get_client_and_project(options)
GoodData.with_project(project) do
params = options[:params].nil? ? [] : [options[:params]]
if block
begin
res = GoodData::Process.deploy(dir, options.merge(:files_to_exclude => params))
block.call(res)
rescue StandardError => e
GoodData.logger.error(e.inspect)
ensure
res.delete if res
end
else
GoodData::Process.deploy(dir, options.merge(:files_to_exclude => params))
end
end
end
|
Instance Method Details
#add_v2_component? ⇒ Bool
Determines whether the process is an ADDv2 component.
339
340
341
|
# File 'lib/gooddata/models/process.rb', line 339
def add_v2_component?
process['component'] && process['component']['name'] == 'gdc-data-distribution'
end
|
#component ⇒ Object
329
330
331
|
# File 'lib/gooddata/models/process.rb', line 329
def component
process['component']
end
|
#create_manual_schedule(options = {}) ⇒ Object
347
348
349
|
# File 'lib/gooddata/models/process.rb', line 347
def create_manual_schedule(options = {})
create_schedule(nil, nil, options)
end
|
#create_notification_rule(opts = {}) ⇒ Object
383
384
385
|
# File 'lib/gooddata/models/process.rb', line 383
def create_notification_rule(opts = {})
NotificationRule.create(opts.merge(project: project, process: self, client: client))
end
|
#create_schedule(cron, executable, options = {}) ⇒ Object
351
352
353
|
# File 'lib/gooddata/models/process.rb', line 351
def create_schedule(cron, executable, options = {})
project.create_schedule(process_id, cron, executable, options.merge(client: client, project: project))
end
|
#data_sources ⇒ Object
333
334
335
|
# File 'lib/gooddata/models/process.rb', line 333
def data_sources
process['dataSources']
end
|
260
261
262
|
# File 'lib/gooddata/models/process.rb', line 260
def delete
client.delete(uri)
end
|
#deploy(path, options = {}) ⇒ Object
Redeploy existing process.
272
273
274
|
# File 'lib/gooddata/models/process.rb', line 272
def deploy(path, options = {})
Process.deploy(path, { client: client, process_id: process_id, :project => project, :name => name, :type => type, :data_sources => data_sources }.merge(options))
end
|
#download ⇒ IO
Downloads the process from S3 in a zipped form.
279
280
281
282
283
|
# File 'lib/gooddata/models/process.rb', line 279
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
321
322
323
|
# File 'lib/gooddata/models/process.rb', line 321
def executables
process['executables']
end
|
#execute(executable, options = {}) ⇒ Object
355
356
357
358
359
360
361
362
363
364
365
366
|
# File 'lib/gooddata/models/process.rb', line 355
def execute(executable, options = {})
result = start_execution(executable, options)
begin
client.poll_on_code(result['executionTask']['links']['poll'], options)
rescue RestClient::RequestFailed => e
raise(e)
ensure
result = client.get(result['executionTask']['links']['detail'])
fail "Runing process failed. You can look at a log here #{result['executionDetail']['logFileName']}" if result['executionDetail']['status'] == 'ERROR'
end
client.create(GoodData::ExecutionDetail, result, client: client, project: project)
end
|
#executions_link ⇒ Object
313
314
315
|
# File 'lib/gooddata/models/process.rb', line 313
def executions_link
links['executions']
end
|
317
318
319
|
# File 'lib/gooddata/models/process.rb', line 317
def graphs
process['graphs']
end
|
#link ⇒ Object
Also known as:
uri
301
302
303
|
# File 'lib/gooddata/models/process.rb', line 301
def link
links['self']
end
|
297
298
299
|
# File 'lib/gooddata/models/process.rb', line 297
def links
process['links']
end
|
289
290
291
|
# File 'lib/gooddata/models/process.rb', line 289
def name
process['name']
end
|
#notification_rules ⇒ Object
379
380
381
|
# File 'lib/gooddata/models/process.rb', line 379
def notification_rules
NotificationRule.all(project: project, process: self, client: client)
end
|
#obj_id ⇒ Object
Also known as:
process_id
307
308
309
|
# File 'lib/gooddata/models/process.rb', line 307
def obj_id
uri.split('/').last
end
|
325
326
327
|
# File 'lib/gooddata/models/process.rb', line 325
def path
process['path']
end
|
285
286
287
|
# File 'lib/gooddata/models/process.rb', line 285
def process
data['process']
end
|
#schedules ⇒ Object
343
344
345
|
# File 'lib/gooddata/models/process.rb', line 343
def schedules
project.schedules.select { |schedule| schedule.process_id == obj_id }
end
|
#start_execution(executable, options = {}) ⇒ Object
368
369
370
371
372
373
374
375
376
377
|
# File 'lib/gooddata/models/process.rb', line 368
def start_execution(executable, options = {})
params = options[:params] || {}
hidden_params = options[: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
|
293
294
295
|
# File 'lib/gooddata/models/process.rb', line 293
def type
process['type'].downcase.to_sym
end
|