Class: Envoi::Mam::Vidispine::Agent
- Defined in:
- lib/envoi/mam/vidispine/agent.rb
Constant Summary collapse
- DEFAULT_SHAPE_TAG =
'original'
- DEFAULT_ASPERA_ARGS =
'-v -k3 --overwrite=diff -P 33001'
- DEFAULT_DESTINATION_PATH =
'.'
Constants inherited from Agent
Instance Attribute Summary collapse
-
#default_aspera_ascp_args ⇒ Object
Returns the value of attribute default_aspera_ascp_args.
-
#default_aspera_ascp_path ⇒ Object
Returns the value of attribute default_aspera_ascp_path.
-
#default_vidispine_shape_tag ⇒ Object
Returns the value of attribute default_vidispine_shape_tag.
Attributes inherited from Agent
#api_client, #config, #initial_args, #logger
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #download(args = { }) ⇒ Object
- #download_file(args, file) ⇒ Object
- #dry_run? ⇒ Boolean
- #initialize_api_client(args = { }) ⇒ Object
- #item_get_shape_by_tag(item_id, shape_tag) ⇒ Object
- #upload(args = { }) ⇒ Object
- #vidispine_config ⇒ Object
Methods inherited from Agent
#initialize, #initialize_logger, load_config_and_init, load_config_from_file, load_config_from_service, load_from_config_file, load_from_config_service, #notify, #run_operation, #shell_execute
Constructor Details
This class inherits a constructor from Envoi::Mam::Agent
Instance Attribute Details
#default_aspera_ascp_args ⇒ Object
Returns the value of attribute default_aspera_ascp_args.
18 19 20 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 18 def default_aspera_ascp_args @default_aspera_ascp_args end |
#default_aspera_ascp_path ⇒ Object
Returns the value of attribute default_aspera_ascp_path.
18 19 20 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 18 def default_aspera_ascp_path @default_aspera_ascp_path end |
#default_vidispine_shape_tag ⇒ Object
Returns the value of attribute default_vidispine_shape_tag.
18 19 20 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 18 def default_vidispine_shape_tag @default_vidispine_shape_tag end |
Instance Method Details
#after_initialize ⇒ Object
22 23 24 25 26 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 22 def after_initialize args = initial_args @default_aspera_ascp_path = args[:default_aspera_ascp_path] @default_aspera_args = args[:default_ascp_args] || DEFAULT_ASPERA_ARGS end |
#download(args = { }) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 62 def download(args = { }) item_id = args[:item_id] shape_id = args[:shape_id] unless shape_id && !shape_id.empty? shape_tag = args[:shape_tag] || default_vidispine_shape_tag shape_id = item_get_shape_by_tag(item_id, shape_tag) end logger.info { "Getting file path for Item ID: #{item_id} Shape ID: #{shape_id}"} item_shape_get_response = api_client.item_shape_get(:item_id => item_id, :shape_id => shape_id) files = item_shape_get_response['containerComponent']['file'] logger.debug { "Files: #{files}"} # file = files.first files = [ files.first ] # just do the first file for now files.each do |file| begin download_file(args, file) rescue => e logger.warn { "Exception: #{$!}" } end end logger.info { 'DONE' } end |
#download_file(args, file) ⇒ Object
89 90 91 92 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 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 89 def download_file(args, file) logger.debug { "File: #{file}"} transfer_type = args[:transfer_type] file_storage_id = file['storage'] file_path = file['path'] file_storage_config = vidispine_config['storages'][file_storage_id] unless file_storage_config && !file_storage_config.empty? raise Exception, "No configuration found for storage '#{file_storage_id}'" end logger.info { "Transferring File Path: '#{file_path}'" } preserve_path = args.fetch(:preserve_path, file_storage_config.fetch('preserve_path', true)) destination_path = args[:destination_path] || file_storage_config['destination_path'] || DEFAULT_DESTINATION_PATH relative_path = preserve_path ? File.dirname(file_path) : nil relative_path = nil if relative_path == '.' target_path = relative_path ? File.join(destination_path, relative_path) : destination_path target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/') aspera_config = file_storage_config['aspera'] if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?) client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self) return client.download(aspera_config, file_path, target_path) # download_using_aspera(aspera_config, file_path, target_path) end s3_config = file_storage_config['s3'] if (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?) target_path = File.(target_path) if target_path == '.' target_path = File.join(target_path, File.basename(file_path)) client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self) return client.download(s3_config, file_path, target_path) end logger.warn { "No Supported TransferClient Configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}Found in Storage Configuration." } end |
#dry_run? ⇒ Boolean
28 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 28 def dry_run?; @dry_run end |
#initialize_api_client(args = { }) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 34 def initialize_api_client(args = { }) _vidispine_config = vidispine_config @api_client = args[:vidispine_api_client] || begin vidispine_host = _vidispine_config['host'] vidispine_port = _vidispine_config['port'] vidispine_host_use_ssl = _vidispine_config['use_ssl'] vidispine_username = _vidispine_config['username'] vidispine_password = _vidispine_config['password'] client_args = { } client_args[:http_host_address] = vidispine_host if vidispine_host client_args[:http_host_port] = vidispine_port if vidispine_port client_args[:http_host_use_ssl] = vidispine_host_use_ssl if vidispine_host_use_ssl client_args[:username] = vidispine_username if vidispine_username client_args[:password] = vidispine_password if vidispine_password ::Vidispine::API::Utilities.new(client_args) end @default_vidispine_original_shape_tag = args[:default_shape_tag] || _vidispine_config['default_shape_tag'] || _vidispine_config['shape_tag'] || DEFAULT_SHAPE_TAG end |
#item_get_shape_by_tag(item_id, shape_tag) ⇒ Object
57 58 59 60 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 57 def item_get_shape_by_tag(item_id, shape_tag) item_shapes_get_response = api_client.item_shapes_get(:item_id => item_id, :tag => shape_tag) shape_id = item_shapes_get_response['uri'].first end |
#upload(args = { }) ⇒ Object
130 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 168 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 205 206 207 208 209 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 130 def upload(args = { }) file_path = args[:file_path] raise ArgumentError, "Path not found: '#{file_path}'" unless File.exists?(file_path) if File.directory?(file_path) # Non-recursive directory upload file_paths = Dir.glob(File.join(file_path, '*.*')) logger.debug { "File Paths: #{file_paths}"} file_paths.map { |fp| upload(args.merge(file_path: fp))} return file_paths end logger.debug { "Preparing to upload '#{file_path}'" } transfer_type = args[:transfer_type] || '' storage_id = args[:storage_id] vidispine_storage_config = vidispine_config['storages'][storage_id] unless vidispine_storage_config && !vidispine_storage_config.empty? raise "No configuration found for storage '#{storage_id}'" end should_import_file = args.fetch(:import_file, vidispine_storage_config.fetch('import', true)) should_preserve_path = args.fetch(:preserve_path, vidispine_storage_config.fetch('preserve_path', true)) destination_path = args[:destination_path] || vidispine_storage_config['destination_path'] || '/' relative_path = should_preserve_path ? File.dirname(file_path) : nil relative_path = File.(relative_path) if relative_path == '.' target_path = relative_path ? File.join(destination_path, relative_path) : destination_path target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/') # upload file transfer_response = begin aspera_config = vidispine_storage_config['aspera'] if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?) client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self) response = client.upload(aspera_config, file_path, target_path) end s3_config = vidispine_storage_config['s3'] if !response && (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?) _target_path = target_path _target_path = File.(_target_path) if target_path == '.' _target_path = File.join(_target_path, File.basename(file_path)) client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self) response = client.upload(s3_config, file_path, _target_path) end response end logger.warn { "No supported TransferClient configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}found in storage configuration." } unless transfer_response != nil _response = { transfer_response: transfer_response } return _response unless should_import_file item_id = args[:item_id] shape_tag = args[:shape_tag] || default_vidispine_shape_tag # attach file to item as shape path_on_storage = File.join(target_path, File.basename(file_path)) file_create_response = api_client.storage_file_create storage_id: storage_id, path: path_on_storage, state: 'CLOSED' file_id = file_create_response['id'] if item_id item_shape_import_response = vs_api.item_shape_import item_id: item_id, tag: shape_tag, fileId: file_id else item_shape_import_response = vs_api.item_add_using_file_path storage_id: storage_id, file_path: file_path, file_id: file_id, storage_path_map: { '/' => storage_id } end _response[:import_response] = item_shape_import_response _response end |
#vidispine_config ⇒ Object
30 31 32 |
# File 'lib/envoi/mam/vidispine/agent.rb', line 30 def vidispine_config config['vidispine'] || { } end |