envoi-mam-agent 1.3.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/envoi/ingest_service/client.rb +130 -0
- data/lib/envoi/mam/agent/cli/commands/s3-to-eis.rb +66 -0
- data/lib/envoi/mam/agent/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd5eb9858be86d36b652b9760314d6664c57f440
|
4
|
+
data.tar.gz: 59c7b8dfc9f82e6350f8a8c77d3cadd168b150c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a9aefa6eace13a770f3b952931a024bd2e959f590f3300149bfeba6a045c582531db683b32106005c098e1b4bade5f4ff3acc7fb76290a2ee2bb30bfcb0abcd
|
7
|
+
data.tar.gz: f8157b85c98363e723a22d553953be922cada020c7aa93fe355944f998eb1b14aac845b4961008026d0836c52dfe988cd77e7f03d04063f3790966ff4c819b49
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Envoi
|
6
|
+
|
7
|
+
class IngestService
|
8
|
+
|
9
|
+
class Client
|
10
|
+
|
11
|
+
attr_accessor :logger, :http, :uri, :request, :response, :headers
|
12
|
+
attr_accessor :log_request_body, :log_response_body, :log_pretty_print_body
|
13
|
+
|
14
|
+
def initialize(args = {})
|
15
|
+
initialize_logger(args)
|
16
|
+
|
17
|
+
url = args[:url]
|
18
|
+
app_name = args[:app_name]
|
19
|
+
url = "#{url}?appname=#{app_name}"
|
20
|
+
|
21
|
+
@default_source_bucket_name = args[:s3_source_bucket_name] || args[:source_bucket_name]
|
22
|
+
@default_target_bucket_name = args[:s3_target_bucket_name] || args[:target_bucket_name]
|
23
|
+
@default_allow_reimport = args.fetch(:allow_reimport, false)
|
24
|
+
|
25
|
+
@uri = URI.parse(url)
|
26
|
+
@headers = {
|
27
|
+
'Accept' => 'application/json',
|
28
|
+
'Content-Type' => 'application/json'
|
29
|
+
}
|
30
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
31
|
+
@http.use_ssl = true
|
32
|
+
|
33
|
+
@default_app_name = args[:app_name]
|
34
|
+
|
35
|
+
@log_pretty_print_body = true
|
36
|
+
@log_request_body = true
|
37
|
+
@log_response_body = true
|
38
|
+
@parse_response = true
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize_logger(args = { })
|
42
|
+
@logger = args[:logger] || Logger.new(STDOUT)
|
43
|
+
end
|
44
|
+
|
45
|
+
def job_create(path, source_bucket_name = @default_source_bucket_name, target_bucket_name = @default_target_bucket_name, options = { })
|
46
|
+
allow_reimport = options.fetch(:allow_reimport, @default_allow_reimport)
|
47
|
+
|
48
|
+
args_out = { path: path, sourceBucket: source_bucket_name, targetBucket: target_bucket_name }
|
49
|
+
args_out[:allowReimport] = allow_reimport unless allow_reimport.nil?
|
50
|
+
|
51
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
52
|
+
request.body = JSON.generate(args_out)
|
53
|
+
send_request(request)
|
54
|
+
response.code == '200'
|
55
|
+
end
|
56
|
+
|
57
|
+
def job_create_old(path)
|
58
|
+
args_out = [ path ]
|
59
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
60
|
+
request.body = JSON.generate(args_out)
|
61
|
+
send_request(request)
|
62
|
+
response.code == '200'
|
63
|
+
end
|
64
|
+
|
65
|
+
# Formats a HTTPRequest or HTTPResponse body for log output.
|
66
|
+
# @param [HTTPRequest|HTTPResponse] obj
|
67
|
+
# @return [String]
|
68
|
+
def format_body_for_log_output(obj)
|
69
|
+
if obj.content_type == 'application/json'
|
70
|
+
if @log_pretty_print_body
|
71
|
+
_body = obj.body
|
72
|
+
output = JSON.pretty_generate(JSON.parse(_body)) rescue _body
|
73
|
+
return output
|
74
|
+
else
|
75
|
+
return obj.body
|
76
|
+
end
|
77
|
+
elsif obj.content_type == 'application/xml'
|
78
|
+
return obj.body
|
79
|
+
else
|
80
|
+
return obj.body.inspect
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def response_parsed
|
85
|
+
@response_parsed ||= begin
|
86
|
+
response_body = response.respond_to?(:body) ? response.body : ''
|
87
|
+
logger.debug { "Parsing Response." }
|
88
|
+
|
89
|
+
case response.content_type
|
90
|
+
when 'application/json'
|
91
|
+
response_body.empty? ? response_body : JSON.parse(response_body) # rescue response
|
92
|
+
else
|
93
|
+
response_body
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# @param [HTTPRequest] request
|
100
|
+
def send_request(request)
|
101
|
+
@response_parsed = nil
|
102
|
+
@request = request
|
103
|
+
logger.debug { %(REQUEST: #{request.method} http#{http.use_ssl? ? 's' : ''}://#{http.address}:#{http.port}#{request.path} HEADERS: #{request.to_hash.inspect} #{log_request_body and request.request_body_permitted? ? "\n-- BODY BEGIN --\n#{format_body_for_log_output(request)}\n-- BODY END --" : ''}) }
|
104
|
+
max_retries = 3
|
105
|
+
retries = 0
|
106
|
+
loop do
|
107
|
+
should_retry = false
|
108
|
+
|
109
|
+
@request_time_start = Time.now
|
110
|
+
@response = http.request(request)
|
111
|
+
@request_time_end = Time.now
|
112
|
+
logger.debug { %(RESPONSE: #{response.inspect} HEADERS: #{response.to_hash.inspect} #{log_response_body and response.respond_to?(:body) ? "\n-- BODY BEGIN --\n#{format_body_for_log_output(response)}\n-- BODY END--" : ''}\nTook: #{@request_time_end - @request_time_start} seconds) }
|
113
|
+
#logger.debug { "Parse Response? #{@parse_response}" }
|
114
|
+
|
115
|
+
if retries < max_retries && ['504'].include?(@response.code)
|
116
|
+
retries += 1
|
117
|
+
should_retry = true
|
118
|
+
end
|
119
|
+
|
120
|
+
break unless should_retry
|
121
|
+
end
|
122
|
+
@parse_response ? response_parsed : response.body
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# Installation
|
3
|
+
# `gem install aws-sdk-s3`
|
4
|
+
#
|
5
|
+
require 'optparse'
|
6
|
+
require 'pp'
|
7
|
+
require 'csv'
|
8
|
+
|
9
|
+
require 'envoi/utils/s3_enumerator'
|
10
|
+
require 'envoi/ingest_service/client'
|
11
|
+
|
12
|
+
|
13
|
+
ARGV << '--help' if ARGV.empty?
|
14
|
+
args = {
|
15
|
+
show_summary: true,
|
16
|
+
eis_url: 'https://6bxyr9mdti.execute-api.us-east-1.amazonaws.com/latest/createElemental',
|
17
|
+
s3_object_key_prefix: '',
|
18
|
+
preview_only: false
|
19
|
+
}
|
20
|
+
op = OptionParser.new
|
21
|
+
op.on('--app-name [APPNAME]', '' ) { |v| args[:app_name] = v }
|
22
|
+
op.on('--source-bucket [BUCKETNAME]', 'The bucket to get objects from.') { |v| args[:s3_source_bucket_name] = v }
|
23
|
+
op.on('--target-bucket [BUCKETNAME]', '') { |v| args[:s3_target_bucket_name] = v }
|
24
|
+
op.on('--aws-access-key [KEY]', '') { |v| args[:aws_access_key_id] = v }
|
25
|
+
op.on('--aws-secret-key [KEY]', '') { |v| args[:aws_secret_access_key] = v }
|
26
|
+
op.on('--aws-profile [PROFILENAME]', '') { |v| args[:aws_profile] = v }
|
27
|
+
op.on('--aws-region [REGION]', 'The AWS region what the bucket is located.') { |v| args[:aws_region] = v }
|
28
|
+
op.on('--limit [LIMIT]', 'Limit the number of results') { |v| args[:limit] = v }
|
29
|
+
op.on('--key-prefix [KEYPREFIX]', 'The object key prefix to limit the results by.') { |v| args[:s3_object_key_prefix] = v }
|
30
|
+
op.on('--eis-url [URL]', 'The URL for the Envoi Ingest Service.',
|
31
|
+
"default: #{args[:eis_url]}") { |v| args[:eis_url] = v }
|
32
|
+
op.on('--[no-]allow-reimport', 'Determines if files existing in the database will be re-imported.') { |v| args[:allow_reimport] = v }
|
33
|
+
op.on('--[no-]preview', 'Output paths with summary and stop.',
|
34
|
+
"default: #{args[:preview_mode] ? 'true' : 'false'}") { |v| args[:preview_only] = v }
|
35
|
+
op.on('--[no-]summary', 'Output the paths and calculate the number of assets.',
|
36
|
+
"default: #{args[:show_summary] ? 'true' : 'false'}",) { |v| args[:show_summary] = v }
|
37
|
+
|
38
|
+
op.on('-h', '--help', 'Print help (this message) and exit') { puts op; exit }
|
39
|
+
op.parse!
|
40
|
+
|
41
|
+
s3_enum = S3Enumerator.new(args)
|
42
|
+
s3_enum.run
|
43
|
+
exit if args[:preview_only]
|
44
|
+
|
45
|
+
app_name = args[:app_name]
|
46
|
+
eis_url = args[:eis_url]
|
47
|
+
s3_source_bucket_name = args[:s3_source_bucket_name]
|
48
|
+
s3_target_bucket_name = args[:s3_target_bucket_name]
|
49
|
+
|
50
|
+
eis_args = {
|
51
|
+
url: eis_url,
|
52
|
+
app_name: app_name,
|
53
|
+
source_bucket_name: s3_source_bucket_name,
|
54
|
+
target_bucket_name: s3_target_bucket_name,
|
55
|
+
allow_reimport: args[:allow_reimport]
|
56
|
+
}
|
57
|
+
|
58
|
+
eis = Envoi::IngestService::Client.new(eis_args)
|
59
|
+
|
60
|
+
s3_enum.process_files do |object|
|
61
|
+
full_path = File.join(s3_enum.s3_bucket_region, s3_source_bucket_name, object.key)
|
62
|
+
raise "Error Creating Job for '#{full_path}':\n#{eis.response.body}" unless eis.job_create(object.key)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envoi-mam-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Whitson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asperalm
|
@@ -258,6 +258,7 @@ files:
|
|
258
258
|
- lib/cantemo/portal/api/client.rb
|
259
259
|
- lib/envoi/aspera/watch_service/client.rb
|
260
260
|
- lib/envoi/aspera/watch_service/watch_folder.rb
|
261
|
+
- lib/envoi/ingest_service/client.rb
|
261
262
|
- lib/envoi/mam/agent.rb
|
262
263
|
- lib/envoi/mam/agent/cli.rb
|
263
264
|
- lib/envoi/mam/agent/cli/commands.rb
|
@@ -265,6 +266,7 @@ files:
|
|
265
266
|
- lib/envoi/mam/agent/cli/commands/mediaconvert-retry.rb
|
266
267
|
- lib/envoi/mam/agent/cli/commands/mediasilo.rb
|
267
268
|
- lib/envoi/mam/agent/cli/commands/restore.rb
|
269
|
+
- lib/envoi/mam/agent/cli/commands/s3-to-eis.rb
|
268
270
|
- lib/envoi/mam/agent/cli/commands/vidispine.rb
|
269
271
|
- lib/envoi/mam/agent/cli/commands/wiredrive.rb
|
270
272
|
- lib/envoi/mam/agent/config_service_client.rb
|