Skip to content

Commit c485664

Browse files
author
Tomas Korcak
committed
Merge pull request #276 from fluke777/master
Couple of small fixes with client. Enabled tests for ruby processes, fixed empty report failure, added data deletion helper
2 parents 9424520 + 894bd1f commit c485664

12 files changed

Lines changed: 126 additions & 49 deletions

File tree

lib/gooddata/models/empty_result.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,27 @@ def ==(other)
3131
def diff(otherDataResult)
3232
['empty']
3333
end
34+
35+
def [](index, options = {})
36+
to_table[index]
37+
end
38+
39+
alias_method :row, :[]
40+
41+
def empty?
42+
true
43+
end
44+
45+
def column(index)
46+
table[index]
47+
end
48+
49+
def include_row?(row = nil)
50+
false
51+
end
52+
53+
def include_column?(row = nil)
54+
false
55+
end
3456
end
3557
end

lib/gooddata/models/metadata/report.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,15 @@ def execute
8989
result = client.post '/gdc/xtab2/executor3', 'report_req' => { 'report' => uri }
9090
data_result_uri = result['execResult']['dataResult']
9191

92-
result = client.get data_result_uri
93-
while result['taskState'] && result['taskState']['status'] == 'WAIT'
94-
sleep 10
95-
result = client.get data_result_uri
92+
result = client.poll_on_response(data_result_uri) do |body|
93+
body && body['taskState'] && body['taskState']['status'] == 'WAIT'
94+
end
95+
96+
if result.empty?
97+
client.create(EmptyResult, result)
98+
else
99+
client.create(ReportDataResult, result)
96100
end
97-
ReportDataResult.new(client.get data_result_uri)
98101
end
99102

100103
def exportable?

lib/gooddata/models/metadata/report_definition.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,15 @@ def data_result(result, options = { :client => GoodData.connection })
162162
fail ArgumentError, 'No :client specified' if client.nil?
163163

164164
data_result_uri = result['execResult']['dataResult']
165-
result = client.get data_result_uri
166-
167-
while result && result['taskState'] && result['taskState']['status'] == 'WAIT'
168-
sleep 10
169-
result = client.get data_result_uri
165+
result = client.poll_on_response(data_result_uri) do |body|
166+
body && body['taskState'] && body['taskState']['status'] == 'WAIT'
170167
end
171168

172-
return nil unless result
173-
174-
client.create(ReportDataResult, client.get(data_result_uri))
169+
if result.empty?
170+
client.create(EmptyResult, result)
171+
else
172+
client.create(ReportDataResult, result)
173+
end
175174
end
176175

177176
def create(options = { :client => GoodData.connection, :project => GoodData.project })

lib/gooddata/models/process.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def upload_package(path, files_to_exclude, opts = { :client => GoodData.connecti
7676
fail ArgumentError, 'Wrong :project specified' if project.nil?
7777

7878
if !path.directory? && (path.extname == '.grf' || path.extname == '.rb')
79-
79+
puts 'Creating package for upload'
8080
Tempfile.open('deploy-graph-archive') do |temp|
8181
Zip::OutputStream.open(temp.path) do |zio|
8282
FileUtils.cd(path.parent) do
@@ -240,11 +240,11 @@ def execute(executable, options = {})
240240
params = options[:params] || {}
241241
hidden_params = options[:hidden_params] || {}
242242
result = client.post(executions_link,
243-
:execution => {
244-
:graph => executable.to_s,
245-
:params => params,
246-
:hiddenParams => hidden_params
247-
})
243+
:execution => {
244+
:graph => executable.to_s,
245+
:params => params,
246+
:hiddenParams => hidden_params
247+
})
248248
begin
249249
client.poll_on_code(result['executionTask']['links']['poll'])
250250
rescue RestClient::RequestFailed => e

lib/gooddata/models/project.rb

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ def delete
271271
client.delete(uri)
272272
end
273273

274+
# Helper for getting rid of all data in the project
275+
#
276+
# @option options [Boolean] :force has to be added otherwise the operation is not performed
277+
# @return [Array] Result of executing MAQLs
278+
def delete_all_data(options = {})
279+
return false unless options[:force]
280+
datasets.pmap do |dataset|
281+
execute_maql("SYNCHRONIZE {#{dataset.identifier}}")
282+
end
283+
end
284+
274285
# Deletes dashboards for project
275286
def delete_dashboards
276287
Dashboard.all.map { |data| Dashboard[data['link']] }.each { |d| d.delete }
@@ -284,17 +295,29 @@ def deploy_process(path, options = {})
284295
# for some examples and explanations
285296
#
286297
# @param dml [String] DML expression
298+
# @return [Hash] Result of executing DML
287299
def execute_dml(dml)
288300
uri = "/gdc/md/#{pid}/dml/manage"
289-
result = GoodData.post(uri,
290-
manage: {
291-
maql: dml
292-
})
301+
result = client.post(uri, manage: { maql: dml })
293302
polling_uri = result['uri']
294-
result = client.get(polling_uri)
295-
while result['taskState'] && result['taskState']['status'] == 'WAIT'
296-
sleep 10
297-
result = client.get polling_uri
303+
304+
client.poll_on_response(polling_uri) do |body|
305+
body && body['taskState'] && body['taskState']['status'] == 'WAIT'
306+
end
307+
end
308+
309+
# Executes MAQL expression and waits for it to be finished.
310+
#
311+
# @param maql [String] MAQL expression
312+
# @return [Hash] Result of executing MAQL
313+
def execute_maql(maql)
314+
ldm_links = client.get(md[GoodData::Model::LDM_CTG])
315+
ldm_uri = Links.new(ldm_links)[GoodData::Model::LDM_MANAGE_CTG]
316+
response = client.post(ldm_uri, manage: { maql: maql })
317+
polling_uri = response['entries'].first['link']
318+
319+
client.poll_on_response(polling_uri) do |body|
320+
body && body['wTaskStatus'] && body['wTaskStatus']['status'] == 'RUNNING'
298321
end
299322
end
300323

@@ -674,7 +697,7 @@ def partial_md_export(objects, options = {})
674697

675698
alias_method :transfer_objects, :partial_md_export
676699

677-
# Helper for getting reports of a project
700+
# Helper for getting processes of a project
678701
#
679702
# @param [String | Number | Object] Anything that you can pass to GoodData::Report[id]
680703
# @return [GoodData::Report | Array<GoodData::Report>] report instance or list
@@ -725,7 +748,7 @@ def reload!
725748
# @param [String | Number | Object] Anything that you can pass to GoodData::Report[id]
726749
# @return [GoodData::Report | Array<GoodData::Report>] report instance or list
727750
def reports(id = :all)
728-
GoodData::Report[id, project: self]
751+
GoodData::Report[id, project: self, client: client]
729752
end
730753

731754
# Helper for getting report definitions of a project

lib/gooddata/models/project_creator.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,11 @@ def migrate_datasets(spec, opts = { :client => GoodData.connection })
7474
end
7575

7676
response = client.get(link)
77-
ldm_links = client.get project.md[LDM_CTG]
78-
ldm_uri = Links.new(ldm_links)[LDM_MANAGE_CTG]
7977

8078
chunks = pick_correct_chunks(response['projectModelDiff']['updateScripts'])
8179
chunks['updateScript']['maqlDdlChunks'].each do |chunk|
82-
response = client.post ldm_uri, 'manage' => { 'maql' => chunk }
83-
polling_url = response['entries'].first['link']
84-
polling_result = client.poll_on_response(polling_url) do |body|
85-
body['wTaskStatus']['status'] == 'RUNNING'
86-
end
87-
88-
fail 'Creating dataset failed' if polling_result['wTaskStatus']['status'] == 'ERROR'
80+
result = project.execute_maql(chunk)
81+
fail 'Creating dataset failed' if result['wTaskStatus']['status'] == 'ERROR'
8982
end
9083

9184
bp.datasets.zip(GoodData::Model::ToManifest.to_manifest(bp.to_hash)).each do |ds|

lib/gooddata/models/report_data_result.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def diff(otherDataResult)
8585
differences
8686
end
8787

88+
def empty?
89+
false
90+
end
91+
8892
private
8993

9094
def each_level(table, level, children, lookup)

lib/gooddata/models/schema_blueprint.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ def find_column_by_type(type, all = nil)
261261
DatasetBlueprint.find_column_by_type(to_hash, type, all)
262262
end
263263

264+
# Returns identifier for dataset
265+
#
266+
# @return [String] identifier
267+
def identifier
268+
GoodData::Model.identifier_for(to_hash)
269+
end
270+
264271
# Creates a DatasetBlueprint
265272
#
266273
# @param dataset [Hash] Dataset blueprint
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
puts 'HELLO WORLD'
196 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)