cnvrg 0.0.150000 → 0.0.1520000
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cnvrg/api.rb +0 -1
- data/lib/cnvrg/cli.rb +62 -43
- data/lib/cnvrg/datafiles.rb +198 -175
- data/lib/cnvrg/dataset.rb +1 -1
- data/lib/cnvrg/version.rb +3 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8350e6b16c815de7c51ea0020bec8e8ee3f760f4
|
4
|
+
data.tar.gz: 45a2c3cec4e0fa3450b6674a8f554c210db57af7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb635cb17695ed08f6ee86a175ff18ed5e43fcad39a21f0b3037566605e212c3ff7ec32f535e128e58ba51d9ac446c69d90a9c57450bdede057ebfb48b02aff3
|
7
|
+
data.tar.gz: 20e44b71140893d5aeca636e9f985b92f66471596d9d83a44196f263ffbed2caae9532ffa645aeb5f20158140cadc771bf659201dc91fa9766aa06f7f5eddd3d
|
data/lib/cnvrg/api.rb
CHANGED
data/lib/cnvrg/cli.rb
CHANGED
@@ -1151,6 +1151,7 @@ module Cnvrg
|
|
1151
1151
|
|
1152
1152
|
end
|
1153
1153
|
|
1154
|
+
|
1154
1155
|
desc 'data upload', 'push data'
|
1155
1156
|
method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
|
1156
1157
|
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
@@ -1237,8 +1238,9 @@ module Cnvrg
|
|
1237
1238
|
exit(1)
|
1238
1239
|
end
|
1239
1240
|
say "Uploading data", Thor::Shell::Color::BLUE
|
1241
|
+
log_file = "#{home_dir}/.cnvrg/tmp/upload_#{File.basename(tar_path)}.log"
|
1240
1242
|
res = false
|
1241
|
-
|
1243
|
+
res = @files.upload_tar_file(tar_path, tar_path, commit_sha1)
|
1242
1244
|
|
1243
1245
|
if res
|
1244
1246
|
say "Commiting data", Thor::Shell::Color::BLUE
|
@@ -1257,12 +1259,19 @@ module Cnvrg
|
|
1257
1259
|
end
|
1258
1260
|
|
1259
1261
|
else
|
1262
|
+
if File.exist? log_file
|
1263
|
+
@files.upload_data_log_file(log_file,log_file,commit_sha1)
|
1264
|
+
end
|
1265
|
+
|
1266
|
+
|
1260
1267
|
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1261
1268
|
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1262
1269
|
|
1263
1270
|
|
1264
1271
|
@files.rollback_commit(commit_sha1)
|
1265
1272
|
say "Can't upload, Rolling Back all changes.", Thor::Shell::Color::RED
|
1273
|
+
say "Error log: #{log_file}", Thor::Shell::Color::RED
|
1274
|
+
|
1266
1275
|
exit(1)
|
1267
1276
|
end
|
1268
1277
|
|
@@ -1274,6 +1283,9 @@ module Cnvrg
|
|
1274
1283
|
log_end(-1)
|
1275
1284
|
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1276
1285
|
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1286
|
+
if File.exist? log_file
|
1287
|
+
@files.upload_data_log_file(log_file,log_file,commit_sha1)
|
1288
|
+
end
|
1277
1289
|
|
1278
1290
|
|
1279
1291
|
@files.rollback_commit(commit_sha1)
|
@@ -1285,39 +1297,26 @@ module Cnvrg
|
|
1285
1297
|
say "Seems there is no internet connection", Thor::Shell::Color::RED
|
1286
1298
|
|
1287
1299
|
end
|
1300
|
+
if File.exist? log_file
|
1301
|
+
@files.upload_data_log_file(log_file,log_file,commit_sha1)
|
1302
|
+
end
|
1288
1303
|
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1289
1304
|
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1290
1305
|
|
1291
1306
|
log_end(-1, e.message)
|
1292
1307
|
@files.rollback_commit(commit_sha1)
|
1293
1308
|
say "Exception while trying to upload, Rolling back", Thor::Shell::Color::RED
|
1294
|
-
|
1295
|
-
end
|
1296
|
-
if verbose
|
1297
|
-
say "#{check} Done", Thor::Shell::Color::BLUE
|
1298
|
-
if successful_updates.size >0
|
1299
|
-
say "Updated:", Thor::Shell::Color::GREEN
|
1300
|
-
suc = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
|
1301
|
-
say suc.join("\n"), Thor::Shell::Color::GREEN
|
1302
|
-
end
|
1303
|
-
if successful_deletions.size >0
|
1304
|
-
say "Deleted:", Thor::Shell::Color::GREEN
|
1305
|
-
del = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
|
1306
|
-
say del.join("\n"), Thor::Shell::Color::GREEN
|
1307
|
-
end
|
1309
|
+
say "Error log: #{log_file}", Thor::Shell::Color::RED
|
1308
1310
|
|
1309
1311
|
|
1310
|
-
|
1311
|
-
else
|
1312
|
-
say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN
|
1313
|
-
|
1312
|
+
exit(0)
|
1314
1313
|
end
|
1314
|
+
say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN
|
1315
|
+
|
1315
1316
|
|
1316
1317
|
|
1317
1318
|
rescue => e
|
1318
1319
|
log_end(-1, e.message)
|
1319
|
-
|
1320
|
-
|
1321
1320
|
say "Error occurd, \nAborting", Thor::Shell::Color::RED
|
1322
1321
|
@files.rollback_commit(commit_sha1)
|
1323
1322
|
exit(1)
|
@@ -2299,32 +2298,15 @@ module Cnvrg
|
|
2299
2298
|
begin
|
2300
2299
|
stdout.each do |line|
|
2301
2300
|
cur_time = Time.now
|
2302
|
-
if remote
|
2303
|
-
stats = usage_metrics_in_docker(docker_id)
|
2304
|
-
cpu = stats[0]
|
2305
|
-
memory = stats[1]
|
2306
|
-
else
|
2307
|
-
memory = memory_usage()
|
2308
|
-
cpu = cpu_usage()
|
2309
|
-
end
|
2310
|
-
|
2311
|
-
memory_total << memory.to_f
|
2312
|
-
cpu_total << cpu.to_f
|
2313
2301
|
real_time= Time.now-real
|
2314
2302
|
|
2315
2303
|
cur_log = { time: cur_time,
|
2316
2304
|
message: line,
|
2317
2305
|
type: "stdout",
|
2318
|
-
real: real_time
|
2319
|
-
|
2320
|
-
memory: memory
|
2306
|
+
real: real_time
|
2307
|
+
|
2321
2308
|
}
|
2322
|
-
|
2323
|
-
gpu_stats = gpu_util
|
2324
|
-
gpu_utilization = gpu_stats[0]
|
2325
|
-
gpu_memory_util = gpu_stats[1]
|
2326
|
-
cur_log.merge!(gpu_util:gpu_utilization,gpu_memory_util:gpu_memory_util)
|
2327
|
-
end
|
2309
|
+
|
2328
2310
|
|
2329
2311
|
if print_log
|
2330
2312
|
puts cur_log
|
@@ -2334,6 +2316,28 @@ module Cnvrg
|
|
2334
2316
|
begin
|
2335
2317
|
if time_to_upload !=0
|
2336
2318
|
if time_to_upload <= Time.now - start_loop
|
2319
|
+
if remote
|
2320
|
+
stats = usage_metrics_in_docker(docker_id)
|
2321
|
+
cpu = stats[0]
|
2322
|
+
memory = stats[1]
|
2323
|
+
if is_on_gpu
|
2324
|
+
gpu_stats = gpu_util
|
2325
|
+
gpu_utilization = gpu_stats[0]
|
2326
|
+
gpu_memory_util = gpu_stats[1]
|
2327
|
+
end
|
2328
|
+
else
|
2329
|
+
memory = memory_usage()
|
2330
|
+
cpu = cpu_usage()
|
2331
|
+
end
|
2332
|
+
log.each do |l|
|
2333
|
+
if remote and is_on_gpu
|
2334
|
+
l.merge!(cpu:cpu,memory:memory, gpu_util:gpu_utilization,gpu_memory_util:gpu_memory_util)
|
2335
|
+
else
|
2336
|
+
l.merge!(cpu:cpu,memory:memory)
|
2337
|
+
end
|
2338
|
+
end
|
2339
|
+
|
2340
|
+
|
2337
2341
|
#upload current log
|
2338
2342
|
# cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
|
2339
2343
|
# memory_average = memory_total.inject(0) { |sum, el| sum + el }.to_f / memory_total.size
|
@@ -4749,10 +4753,25 @@ module Cnvrg
|
|
4749
4753
|
|
4750
4754
|
end
|
4751
4755
|
$LOG = LogStashLogger.new(type: :file, path: logfile, sync: true)
|
4752
|
-
|
4756
|
+
remove_old_log_files()
|
4753
4757
|
end
|
4754
4758
|
end
|
4755
4759
|
|
4760
|
+
def remove_old_log_files()
|
4761
|
+
begin
|
4762
|
+
last_week = (Time.now - (7*24*60*60)).strftime("%Y-%m-%d")
|
4763
|
+
home = File.expand_path('~')
|
4764
|
+
log_files = Dir["#{home}/.cnvrg/tmp/*.log"]
|
4765
|
+
log_files.each do |l|
|
4766
|
+
if File.mtime(l).strftime("%Y-%m-%d") < last_week
|
4767
|
+
FileUtils.rm_rf(l)
|
4768
|
+
end
|
4769
|
+
end
|
4770
|
+
end
|
4771
|
+
|
4772
|
+
end
|
4773
|
+
|
4774
|
+
|
4756
4775
|
|
4757
4776
|
def verify_logged_in(in_dir=true)
|
4758
4777
|
log_handler()
|
@@ -5119,7 +5138,7 @@ module Cnvrg
|
|
5119
5138
|
if docker_id.nil?
|
5120
5139
|
docker_id = `cat /etc/hostname`
|
5121
5140
|
end
|
5122
|
-
|
5141
|
+
stats = `sudo docker stats #{docker_id} --no-stream --format "{{.CPUPerc}},{{.MemPerc}},{{.BlockIO}}"`
|
5123
5142
|
if !stats.nil?
|
5124
5143
|
conv = stats.split(",")
|
5125
5144
|
cpu = conv[0].gsub!("%","").to_f
|
data/lib/cnvrg/datafiles.rb
CHANGED
@@ -22,10 +22,9 @@ module Cnvrg
|
|
22
22
|
mime_type = MimeMagic.by_path(absolute_path)
|
23
23
|
content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
|
24
24
|
sha1 = Digest::SHA1.file(absolute_path).hexdigest
|
25
|
-
|
26
25
|
upload_resp = Cnvrg::API.request(@base_resource + "upload_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
|
27
26
|
commit_sha1: commit_sha1, file_name: file_name,
|
28
|
-
file_size: file_size, file_content_type: content_type,sha1:sha1})
|
27
|
+
file_size: file_size, file_content_type: content_type, sha1: sha1})
|
29
28
|
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
30
29
|
path = upload_resp["result"]["path"]
|
31
30
|
if file_size.to_f>= Cnvrg::Files::LARGE_FILE.to_f
|
@@ -41,44 +40,77 @@ module Cnvrg
|
|
41
40
|
end
|
42
41
|
return false
|
43
42
|
end
|
43
|
+
|
44
44
|
def upload_tar_file(absolute_path, relative_path, commit_sha1)
|
45
45
|
begin
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
file_name = File.basename relative_path
|
47
|
+
file_size = File.size(absolute_path).to_f
|
48
|
+
mime_type = MimeMagic.by_path(absolute_path)
|
49
|
+
content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
|
50
|
+
begin
|
51
|
+
chunked_bytes = [100, (file_size*0.01)].min
|
52
|
+
total_yanked = ""
|
53
|
+
open(absolute_path, "rb") do |f|
|
54
|
+
total_yanked = f.read(chunked_bytes)
|
55
|
+
end
|
56
|
+
if !total_yanked.empty?
|
57
|
+
sha1 = Digest::SHA1.hexdigest(total_yanked)
|
58
|
+
else
|
59
|
+
sha1 = Digest::SHA1.file(absolute_path).hexdigest
|
60
|
+
end
|
61
|
+
rescue
|
62
|
+
sha1 = Digest::SHA1.file(absolute_path).hexdigest
|
63
|
+
end
|
51
64
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
upload_resp = Cnvrg::API.request(@base_resource + "upload_tar_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
|
66
|
+
commit_sha1: commit_sha1, file_name: file_name,
|
67
|
+
file_size: file_size, file_content_type: content_type, sha1: sha1})
|
68
|
+
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
69
|
+
path = upload_resp["result"]["path"]
|
70
|
+
s3_res = upload_large_files_s3(upload_resp, absolute_path)
|
71
|
+
if s3_res
|
72
|
+
Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
|
73
|
+
blob_id: upload_resp["result"]["id"]})
|
74
|
+
return true
|
75
|
+
end
|
76
|
+
else
|
77
|
+
return false
|
62
78
|
end
|
63
|
-
else
|
64
|
-
return false
|
65
|
-
end
|
66
79
|
rescue => e
|
67
80
|
puts e.message
|
68
81
|
return false
|
69
82
|
end
|
70
83
|
|
71
84
|
end
|
72
|
-
|
85
|
+
|
86
|
+
def upload_log_file(absolute_path, relative_path, log_date)
|
73
87
|
file_name = File.basename relative_path
|
74
88
|
file_size = File.size(absolute_path).to_f
|
75
89
|
content_type = "text/x-log"
|
76
90
|
upload_resp = Cnvrg::API.request("/users/#{@owner}/" + "upload_cli_log", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
|
77
|
-
|
78
|
-
|
91
|
+
file_name: file_name, log_date: log_date,
|
92
|
+
file_size: file_size, file_content_type: content_type})
|
79
93
|
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
80
|
-
|
81
|
-
|
94
|
+
path = upload_resp["result"]["path"]
|
95
|
+
s3_res = upload_small_files_s3(path, absolute_path, "text/plain")
|
96
|
+
end
|
97
|
+
if s3_res
|
98
|
+
return true
|
99
|
+
end
|
100
|
+
return false
|
101
|
+
|
102
|
+
end
|
103
|
+
def upload_data_log_file(absolute_path, relative_path,data_commit_sha)
|
104
|
+
file_name = File.basename relative_path
|
105
|
+
file_size = File.size(absolute_path).to_f
|
106
|
+
content_type = "text/x-log"
|
107
|
+
upload_resp = Cnvrg::API.request("/users/#{@owner}/" + "upload_data_log", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
|
108
|
+
file_name: file_name, log_date: Time.now,
|
109
|
+
file_size: file_size, file_content_type: content_type,
|
110
|
+
data_commit_sha1:data_commit_sha})
|
111
|
+
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
112
|
+
path = upload_resp["result"]["path"]
|
113
|
+
s3_res = upload_small_files_s3(path, absolute_path, "text/plain")
|
82
114
|
end
|
83
115
|
if s3_res
|
84
116
|
return true
|
@@ -86,18 +118,20 @@ module Cnvrg
|
|
86
118
|
return false
|
87
119
|
|
88
120
|
end
|
89
|
-
|
121
|
+
|
122
|
+
|
123
|
+
def upload_exec_file(absolute_path, image_name, commit_id)
|
90
124
|
file_name = File.basename absolute_path
|
91
125
|
file_size = File.size(absolute_path).to_f
|
92
126
|
content_type = "application/zip"
|
93
127
|
begin
|
94
128
|
upload_resp = Cnvrg::API.request("users/#{@owner}/images/" + "upload_config", 'POST_FILE', {relative_path: absolute_path,
|
95
129
|
file_name: file_name,
|
96
|
-
image_name:image_name,
|
130
|
+
image_name: image_name,
|
97
131
|
file_size: file_size,
|
98
132
|
file_content_type: content_type,
|
99
133
|
project_slug: @project_slug,
|
100
|
-
commit_id:commit_id})
|
134
|
+
commit_id: commit_id})
|
101
135
|
# puts upload_resp
|
102
136
|
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
103
137
|
if upload_resp["result"]["image"] == -1
|
@@ -107,21 +141,20 @@ module Cnvrg
|
|
107
141
|
s3_res = upload_small_files_s3(path, absolute_path, content_type)
|
108
142
|
|
109
143
|
end
|
110
|
-
|
111
|
-
|
144
|
+
if s3_res
|
145
|
+
return upload_resp["result"]["id"]
|
146
|
+
end
|
147
|
+
return false
|
148
|
+
rescue SignalException
|
149
|
+
|
150
|
+
say "\nAborting"
|
151
|
+
exit(1)
|
112
152
|
end
|
113
|
-
return false
|
114
|
-
rescue SignalException
|
115
153
|
|
116
|
-
say "\nAborting"
|
117
|
-
exit(1)
|
118
154
|
end
|
119
155
|
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
156
|
|
124
|
-
|
157
|
+
def upload_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message, commit_id)
|
125
158
|
file_name = File.basename absolute_path
|
126
159
|
file_size = File.size(absolute_path).to_f
|
127
160
|
if is_base
|
@@ -131,41 +164,42 @@ module Cnvrg
|
|
131
164
|
content_type = "application/gzip"
|
132
165
|
end
|
133
166
|
begin
|
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
|
-
|
167
|
+
upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
|
168
|
+
file_name: file_name,
|
169
|
+
image_name: image_name,
|
170
|
+
file_size: file_size,
|
171
|
+
file_content_type: content_type,
|
172
|
+
is_public: is_public,
|
173
|
+
project_slug: @project_slug,
|
174
|
+
commit_id: commit_id,
|
175
|
+
dpkg: dpkg,
|
176
|
+
py2: libraries,
|
177
|
+
py3: libraries,
|
178
|
+
|
179
|
+
bash_history: bash,
|
180
|
+
commit_message: message,
|
181
|
+
is_base: is_base})
|
182
|
+
# puts upload_resp
|
183
|
+
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
184
|
+
path = upload_resp["result"]["path"]
|
185
|
+
s3_res = upload_small_files_s3(path, absolute_path, content_type)
|
186
|
+
if s3_res
|
187
|
+
commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
|
188
|
+
if Cnvrg::CLI.is_response_success(commit_resp, false)
|
189
|
+
return commit_resp["result"]["image"]
|
190
|
+
else
|
191
|
+
return false
|
192
|
+
end
|
160
193
|
|
194
|
+
end
|
161
195
|
end
|
162
|
-
|
163
|
-
|
164
|
-
rescue =>e
|
196
|
+
return false
|
197
|
+
rescue => e
|
165
198
|
end
|
166
199
|
|
167
200
|
end
|
168
|
-
|
201
|
+
|
202
|
+
def upload_cnvrg_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message)
|
169
203
|
file_name = File.basename absolute_path
|
170
204
|
file_size = File.size(absolute_path).to_f
|
171
205
|
if is_base
|
@@ -176,16 +210,16 @@ module Cnvrg
|
|
176
210
|
end
|
177
211
|
begin
|
178
212
|
upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
213
|
+
file_name: file_name,
|
214
|
+
image_name: image_name,
|
215
|
+
file_size: file_size,
|
216
|
+
file_content_type: content_type,
|
217
|
+
is_public: is_public,
|
218
|
+
dpkg: dpkg,
|
219
|
+
libraries: libraries,
|
220
|
+
bash_history: bash,
|
221
|
+
commit_message: message,
|
222
|
+
is_base: is_base})
|
189
223
|
# puts upload_resp
|
190
224
|
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
191
225
|
path = upload_resp["result"]["path"]
|
@@ -201,7 +235,7 @@ module Cnvrg
|
|
201
235
|
end
|
202
236
|
end
|
203
237
|
return false
|
204
|
-
rescue =>e
|
238
|
+
rescue => e
|
205
239
|
end
|
206
240
|
|
207
241
|
end
|
@@ -231,7 +265,7 @@ module Cnvrg
|
|
231
265
|
|
232
266
|
end
|
233
267
|
|
234
|
-
def
|
268
|
+
def upload_large_files_s3(upload_resp, file_path)
|
235
269
|
begin
|
236
270
|
sts_path = upload_resp["result"]["path_sts"]
|
237
271
|
# s4cmd_path = upload_resp["result"]["path_s4cmd"]
|
@@ -246,76 +280,62 @@ module Cnvrg
|
|
246
280
|
response = http.request request
|
247
281
|
body = response.read_body
|
248
282
|
end
|
249
|
-
|
250
|
-
|
251
|
-
s4cmd_install_suc = false
|
283
|
+
home_dir = File.expand_path('~')
|
284
|
+
log_file = "#{home_dir}/.cnvrg/tmp/upload_#{File.basename(file_path)}.log"
|
252
285
|
|
253
286
|
URLcrypt::key = [body].pack('H*')
|
254
|
-
|
255
|
-
|
256
|
-
|
287
|
+
client = Aws::S3::Client.new(:access_key_id => URLcrypt.decrypt(upload_resp["result"]["new_a"]),
|
288
|
+
:secret_access_key => URLcrypt.decrypt(upload_resp["result"]["new_s"]),
|
289
|
+
:region => URLcrypt.decrypt(upload_resp["result"]["region"]),
|
290
|
+
:logger => Logger.new(log_file),
|
291
|
+
:http_open_timeout => 60, :retry_limit => 20,
|
292
|
+
:http_wire_trace => true)
|
293
|
+
s3 = Aws::S3::Resource.new(client: client)
|
294
|
+
|
295
|
+
resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
|
296
|
+
object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
|
297
|
+
upload_file(file_path, {:use_accelerate_endpoint => true})
|
298
|
+
# s4cmd_path = upload_resp["result"]["path_s4cmd"]
|
257
299
|
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
300
|
+
# s4cmd_uri = URI.parse(s4cmd_path)
|
301
|
+
# s4cmd_http_object = Net::HTTP.new(s4cmd_uri.host, s4cmd_uri.port)
|
302
|
+
# s4cmd_http_object.use_ssl = true if s4cmd_uri.scheme == 'https'
|
303
|
+
# s4cmd_request = Net::HTTP::Get.new(s4cmd_path)
|
262
304
|
#
|
305
|
+
# s4cmd_body = ""
|
306
|
+
# s4cmd_http_object.start do |http|
|
307
|
+
# response = http.request s4cmd_request
|
308
|
+
# s4cmd_body = response.read_body
|
263
309
|
# end
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
#
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
#
|
288
|
-
# s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
|
289
|
-
# aws_access_key_id=aws_access_key_id,
|
290
|
-
# aws_secret_access_key=aws_secret_access_key)"," self.client = self.boto3.client('s3',
|
291
|
-
# aws_access_key_id='#{ URLcrypt.decrypt(upload_resp["result"]["sts_a"])}',
|
292
|
-
# aws_secret_access_key='#{URLcrypt.decrypt(upload_resp["result"]["sts_s"])}',
|
293
|
-
# aws_session_token='#{URLcrypt.decrypt(upload_resp["result"]["sts_st"])}')")
|
294
|
-
#
|
295
|
-
# tmp = Tempfile.new('s4cmd.py')
|
296
|
-
# tmp << s4cmd_new_body
|
297
|
-
# tmp.flush
|
298
|
-
# tmp.close
|
299
|
-
#
|
300
|
-
# is_success = false
|
301
|
-
# count = 0
|
302
|
-
# while !is_success and count <3
|
303
|
-
# resp = `python #{tmp.path} --num-threads=8 --max-singlepart-upload-size=#{MULTIPART_SPLIT} put -f #{file_path} s3://#{URLcrypt.decrypt(upload_resp["result"]["bucket"])}/#{upload_resp["result"]["path"]+"/"+File.basename(file_path)} > /dev/null 2>&1`
|
304
|
-
# is_success =$?.success?
|
305
|
-
# count +=1
|
306
|
-
#
|
307
|
-
# end
|
308
|
-
# resp= is_success
|
309
|
-
|
310
|
+
# s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
|
311
|
+
# aws_access_key_id=aws_access_key_id,
|
312
|
+
# aws_secret_access_key=aws_secret_access_key)", " self.client = self.boto3.client('s3',
|
313
|
+
# aws_access_key_id='#{ URLcrypt.decrypt(upload_resp["result"]["new_a"])}',
|
314
|
+
# aws_secret_access_key='#{URLcrypt.decrypt(upload_resp["result"]["new_s"])}')")
|
315
|
+
#
|
316
|
+
#
|
317
|
+
# tmp = Tempfile.new('s4cmd.py')
|
318
|
+
# tmp << s4cmd_new_body
|
319
|
+
# tmp.flush
|
320
|
+
# tmp.close
|
321
|
+
# #
|
322
|
+
# is_success = false
|
323
|
+
# count = 0
|
324
|
+
# while !is_success and count <3
|
325
|
+
# resp = `python #{tmp.path} --num-threads=8 --max-singlepart-upload-size=#{MULTIPART_SPLIT} put -f #{file_path} s3://#{URLcrypt.decrypt(upload_resp["result"]["bucket"])}/#{upload_resp["result"]["path"]+"/"+File.basename(file_path)} > /dev/null 2>&1 `
|
326
|
+
# is_success =$?.success?
|
327
|
+
# count +=1
|
328
|
+
#
|
329
|
+
# end
|
330
|
+
# resp= is_success
|
331
|
+
if resp == true
|
332
|
+
FileUtils.rm_rf(log_file)
|
310
333
|
end
|
311
334
|
|
312
335
|
return resp
|
313
336
|
|
314
337
|
rescue => e
|
315
338
|
puts e.message
|
316
|
-
# if File.exist? tmp
|
317
|
-
# FileUtils.rm_rf [tmp]
|
318
|
-
# end
|
319
339
|
return false
|
320
340
|
|
321
341
|
end
|
@@ -366,9 +386,10 @@ module Cnvrg
|
|
366
386
|
response = Cnvrg::API.request(@base_resource + "create_dir", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
|
367
387
|
return Cnvrg::CLI.is_response_success(response, false)
|
368
388
|
end
|
369
|
-
|
389
|
+
|
390
|
+
def download_file_s3(absolute_path, relative_path, project_home, conflict=false, commit_sha1=nil)
|
370
391
|
begin
|
371
|
-
res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path,commit_sha1:commit_sha1})
|
392
|
+
res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
|
372
393
|
Cnvrg::CLI.is_response_success(res, false)
|
373
394
|
if res["result"]
|
374
395
|
download_resp = res
|
@@ -376,38 +397,38 @@ module Cnvrg
|
|
376
397
|
|
377
398
|
absolute_path += ".conflict" if conflict
|
378
399
|
sts_path = download_resp["result"]["path_sts"]
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
400
|
+
uri = URI.parse(sts_path)
|
401
|
+
http_object = Net::HTTP.new(uri.host, uri.port)
|
402
|
+
http_object.use_ssl = true if uri.scheme == 'https'
|
403
|
+
request = Net::HTTP::Get.new(sts_path)
|
383
404
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
405
|
+
body = ""
|
406
|
+
http_object.start do |http|
|
407
|
+
response = http.request request
|
408
|
+
body = response.read_body
|
409
|
+
end
|
410
|
+
URLcrypt::key = [body].pack('H*')
|
411
|
+
s3 = Aws::S3::Client.new(
|
412
|
+
:access_key_id => URLcrypt.decrypt(download_resp["result"]["sts_a"]),
|
413
|
+
:secret_access_key => URLcrypt.decrypt(download_resp["result"]["sts_s"]),
|
414
|
+
:session_token => URLcrypt.decrypt(download_resp["result"]["sts_st"]),
|
415
|
+
:region => URLcrypt.decrypt(download_resp["result"]["region"]))
|
416
|
+
File.open(project_home+"/"+absolute_path, 'wb') do |file|
|
417
|
+
resp = s3.get_object({bucket: URLcrypt.decrypt(download_resp["result"]["bucket"]),
|
418
|
+
key: URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
|
419
|
+
end
|
399
420
|
return true
|
400
421
|
end
|
401
422
|
|
402
|
-
rescue =>e
|
423
|
+
rescue => e
|
403
424
|
return false
|
404
425
|
|
405
426
|
end
|
406
427
|
end
|
407
428
|
|
408
|
-
def download_data_file(commit_sha1,dataset_home)
|
429
|
+
def download_data_file(commit_sha1, dataset_home)
|
409
430
|
begin
|
410
|
-
res = Cnvrg::API.request(@base_resource + "download_data_file", 'POST', {commit_sha1:commit_sha1})
|
431
|
+
res = Cnvrg::API.request(@base_resource + "download_data_file", 'POST', {commit_sha1: commit_sha1})
|
411
432
|
Cnvrg::CLI.is_response_success(res, false)
|
412
433
|
if res["result"]
|
413
434
|
download_resp = res
|
@@ -432,13 +453,13 @@ module Cnvrg
|
|
432
453
|
:region => URLcrypt.decrypt(download_resp["result"]["region"]))
|
433
454
|
|
434
455
|
File.open(dataset_home+"/"+filename, 'wb') do |file|
|
435
|
-
resp = s3.get_object({
|
436
|
-
|
456
|
+
resp = s3.get_object({bucket: URLcrypt.decrypt(download_resp["result"]["bucket"]),
|
457
|
+
key: URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
|
437
458
|
end
|
438
459
|
return filename
|
439
460
|
end
|
440
461
|
|
441
|
-
rescue =>e
|
462
|
+
rescue => e
|
442
463
|
return false
|
443
464
|
|
444
465
|
end
|
@@ -468,27 +489,28 @@ module Cnvrg
|
|
468
489
|
def download_dir(dataset_home, absolute_path)
|
469
490
|
FileUtils.mkdir_p("#{dataset_home}/#{absolute_path}")
|
470
491
|
end
|
492
|
+
|
471
493
|
def revoke_download_dir(absolute_path)
|
472
494
|
puts FileUtils.rmtree("#{absolute_path}")
|
473
495
|
end
|
474
496
|
|
475
|
-
def revoke_download_file(absolute_path,filename,conflict=false)
|
497
|
+
def revoke_download_file(absolute_path, filename, conflict=false)
|
476
498
|
begin
|
477
|
-
|
499
|
+
file_location = absolute_path.gsub(/#{filename}\/?$/, "")
|
478
500
|
|
479
|
-
|
480
|
-
|
501
|
+
filename += ".conflict" if conflict
|
502
|
+
FileUtils.remove("#{file_location}/#{filename}")
|
481
503
|
return true
|
482
504
|
rescue
|
483
|
-
|
505
|
+
return false
|
484
506
|
end
|
485
507
|
end
|
486
508
|
|
487
509
|
def start_commit(new_branch)
|
488
510
|
|
489
|
-
response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {dataset_slug: @dataset_slug,new_branch:false,
|
511
|
+
response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {dataset_slug: @dataset_slug, new_branch: false,
|
490
512
|
username: @owner})
|
491
|
-
Cnvrg::CLI.is_response_success(response,false)
|
513
|
+
Cnvrg::CLI.is_response_success(response, false)
|
492
514
|
return response
|
493
515
|
end
|
494
516
|
|
@@ -496,8 +518,9 @@ module Cnvrg
|
|
496
518
|
response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1})
|
497
519
|
return response
|
498
520
|
end
|
499
|
-
|
500
|
-
|
521
|
+
|
522
|
+
def end_commit_tar(commit_sha1, cur_idx)
|
523
|
+
response = Cnvrg::API.request("#{base_resource}/commit/end_tar", 'POST', {commit_sha1: commit_sha1, idx: cur_idx})
|
501
524
|
return response
|
502
525
|
end
|
503
526
|
|
data/lib/cnvrg/dataset.rb
CHANGED
@@ -116,7 +116,7 @@ module Cnvrg
|
|
116
116
|
File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
|
117
117
|
File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless File.exist? ".cnvrgignore"
|
118
118
|
rescue => e
|
119
|
-
"Exception in init data: #
|
119
|
+
"Exception in init data: #"
|
120
120
|
return false
|
121
121
|
end
|
122
122
|
return true
|
data/lib/cnvrg/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cnvrg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1520000
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yochay Ettun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-07-
|
12
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -388,9 +388,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
388
388
|
version: '0'
|
389
389
|
requirements: []
|
390
390
|
rubyforge_project:
|
391
|
-
rubygems_version: 2.
|
391
|
+
rubygems_version: 2.6.12
|
392
392
|
signing_key:
|
393
393
|
specification_version: 4
|
394
394
|
summary: A CLI tool for interacting with cnvrg.io.
|
395
395
|
test_files: []
|
396
|
-
has_rdoc:
|