Class: VectorAmp::IngestionResource
- Inherits:
-
Object
- Object
- VectorAmp::IngestionResource
- Defined in:
- lib/vector_amp/ingestion.rb
Overview
Ingestion API resource for sources, jobs, and direct file uploads.
Instance Method Summary collapse
-
#cancel_job(job_id) ⇒ Hash
Cancel an ingestion job.
-
#cleanup_unused_sources ⇒ Hash
Delete all unused (unreferenced) sources.
-
#complete_upload(source_id, job_id:, file_ids:) ⇒ Hash
Complete a file upload job after files have been PUT to presigned URLs.
-
#create(source = nil, **options) ⇒ Hash
Alias for #create_source.
-
#create_confluence(cloud_id: nil, base_url: nil, name: nil, auth_mode: "basic", username: nil, api_token: nil, spaces: nil, include_attachments: false, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a Confluence source.
-
#create_file_upload(name: nil, description: nil, metadata: nil, storage_provider: "s3", sync_mode: "full", **config) ⇒ Hash
Create a file-upload source.
-
#create_gcs(bucket:, name: nil, prefix: nil, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a Google Cloud Storage source.
-
#create_github(installation_id:, repositories:, name: nil, ref_mode: nil, refs: nil, excluded_refs: nil, active_branch_days: nil, include_pull_requests: nil, include_review_threads: nil, include_direct_commits: nil, include_globs: nil, exclude_globs: nil, max_file_size_bytes: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a GitHub source backed by the VectorAmp GitHub App.
-
#create_gitlab(groups: nil, projects: nil, name: nil, auth_mode: "oauth", gitlab_url: "https://gitlab.com", access_token: nil, connection_id: nil, ref_mode: nil, refs: nil, excluded_refs: nil, active_branch_days: nil, include_merge_requests: nil, include_review_threads: nil, include_direct_commits: nil, include_globs: nil, exclude_globs: nil, max_file_size_bytes: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a GitLab source for gitlab.com or a self-managed instance.
-
#create_google_drive(name: nil, folder_ids: nil, file_ids: nil, auth_mode: nil, service_account_json: nil, oauth_credentials: nil, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a Google Drive source.
- #create_jira(cloud_id:, name: nil, access_token: nil, project_keys: nil, jql: nil, include_comments: true, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Object
-
#create_s3(bucket:, name: nil, prefix: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create an S3 source.
-
#create_source(source = nil, source_type: nil, name: nil, config: nil, description: nil, metadata: nil) ⇒ Hash
Create an ingestion source from a Source object/hash or explicit options.
-
#create_web(start_urls:, name: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a web source.
-
#delete_source(source_id, force: false) ⇒ Hash
Delete an ingestion source.
-
#get_job(job_id) ⇒ Hash
Fetch an ingestion job.
-
#get_source(source_id) ⇒ Hash
Fetch an ingestion source.
-
#ingest_files(dataset_id:, paths:, source_name: nil, description: nil, metadata: {}) ⇒ Hash
Upload local files by auto-creating a
file_uploadsource, initializing presigned uploads, and completing the upload job. -
#init_upload(source_id, files) ⇒ Hash
Initialize presigned uploads for source files.
- #initialize(transport) ⇒ IngestionResource constructor
-
#job_files(job_id) ⇒ Hash
List files attached to an ingestion job.
-
#job_statistics(job_id) ⇒ Hash
Fetch ingestion job statistics.
-
#list_jobs(dataset_id: nil, limit: 50, offset: 0) ⇒ Hash
List ingestion jobs.
-
#list_sources(limit: 50, offset: 0) ⇒ Hash
List ingestion sources.
-
#list_unused_sources(limit: 50, offset: 0) ⇒ Hash
List sources that are not referenced by any job, schedule, or dataset.
-
#retry_job(job_id) ⇒ Hash
Retry an eligible failed or cancelled ingestion job as a fresh full rerun.
-
#source_references(source_id) ⇒ Hash
List references (jobs, schedules, datasets) that use a source.
-
#start_job(source_id:, dataset_id:, pipeline_id: nil) ⇒ Hash
Start an ingestion job for a source and dataset.
-
#validate_source(source_type:, config:) ⇒ Hash
Validate a source type and config without creating a source.
Constructor Details
#initialize(transport) ⇒ IngestionResource
13 14 15 |
# File 'lib/vector_amp/ingestion.rb', line 13 def initialize(transport) @transport = transport end |
Instance Method Details
#cancel_job(job_id) ⇒ Hash
Cancel an ingestion job.
395 396 397 |
# File 'lib/vector_amp/ingestion.rb', line 395 def cancel_job(job_id) @transport.request(:delete, "/ingestion/jobs/#{job_id}/cancel") end |
#cleanup_unused_sources ⇒ Hash
Delete all unused (unreferenced) sources.
51 52 53 |
# File 'lib/vector_amp/ingestion.rb', line 51 def cleanup_unused_sources @transport.request(:post, "/ingestion/sources/cleanup") end |
#complete_upload(source_id, job_id:, file_ids:) ⇒ Hash
Complete a file upload job after files have been PUT to presigned URLs.
446 447 448 |
# File 'lib/vector_amp/ingestion.rb', line 446 def complete_upload(source_id, job_id:, file_ids:) @transport.request(:post, "/ingestion/sources/#{source_id}/upload/complete", body: { job_id: job_id, file_ids: file_ids }) end |
#create(source = nil, **options) ⇒ Hash
Alias for #create_source.
91 92 93 |
# File 'lib/vector_amp/ingestion.rb', line 91 def create(source = nil, **) create_source(source, **) end |
#create_confluence(cloud_id: nil, base_url: nil, name: nil, auth_mode: "basic", username: nil, api_token: nil, spaces: nil, include_attachments: false, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a Confluence source.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/vector_amp/ingestion.rb', line 209 def create_confluence(cloud_id: nil, base_url: nil, name: nil, auth_mode: "basic", username: nil, api_token: nil, spaces: nil, include_attachments: false, connection_id: nil, description: nil, metadata: nil, **config) create_source(ConfluenceSource.new( cloud_id: cloud_id, base_url: base_url, name: name, auth_mode: auth_mode, username: username, api_token: api_token, spaces: spaces, include_attachments: , connection_id: connection_id, description: description, metadata: , **config )) end |
#create_file_upload(name: nil, description: nil, metadata: nil, storage_provider: "s3", sync_mode: "full", **config) ⇒ Hash
Create a file-upload source.
331 332 333 334 335 336 337 338 339 340 |
# File 'lib/vector_amp/ingestion.rb', line 331 def create_file_upload(name: nil, description: nil, metadata: nil, storage_provider: "s3", sync_mode: "full", **config) create_source(FileUploadSource.new( name: name, description: description, metadata: , storage_provider: storage_provider, sync_mode: sync_mode, **config )) end |
#create_gcs(bucket:, name: nil, prefix: nil, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a Google Cloud Storage source.
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/vector_amp/ingestion.rb', line 140 def create_gcs(bucket:, name: nil, prefix: nil, connection_id: nil, description: nil, metadata: nil, **config) create_source(GCSSource.new( bucket: bucket, name: name, prefix: prefix, connection_id: connection_id, description: description, metadata: , **config )) end |
#create_github(installation_id:, repositories:, name: nil, ref_mode: nil, refs: nil, excluded_refs: nil, active_branch_days: nil, include_pull_requests: nil, include_review_threads: nil, include_direct_commits: nil, include_globs: nil, exclude_globs: nil, max_file_size_bytes: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a GitHub source backed by the VectorAmp GitHub App.
Install the VectorAmp GitHub App from the Sources page in the app first and pass the resulting installation id here; the SDK never handles a GitHub token.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/vector_amp/ingestion.rb', line 248 def create_github(installation_id:, repositories:, name: nil, ref_mode: nil, refs: nil, excluded_refs: nil, active_branch_days: nil, include_pull_requests: nil, include_review_threads: nil, include_direct_commits: nil, include_globs: nil, exclude_globs: nil, max_file_size_bytes: nil, description: nil, metadata: nil, **config) create_source(GitHubSource.new( installation_id: installation_id, repositories: repositories, name: name, ref_mode: ref_mode, refs: refs, excluded_refs: excluded_refs, active_branch_days: active_branch_days, include_pull_requests: include_pull_requests, include_review_threads: include_review_threads, include_direct_commits: include_direct_commits, include_globs: include_globs, exclude_globs: exclude_globs, max_file_size_bytes: max_file_size_bytes, description: description, metadata: , **config )) end |
#create_gitlab(groups: nil, projects: nil, name: nil, auth_mode: "oauth", gitlab_url: "https://gitlab.com", access_token: nil, connection_id: nil, ref_mode: nil, refs: nil, excluded_refs: nil, active_branch_days: nil, include_merge_requests: nil, include_review_threads: nil, include_direct_commits: nil, include_globs: nil, exclude_globs: nil, max_file_size_bytes: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a GitLab source for gitlab.com or a self-managed instance.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/vector_amp/ingestion.rb', line 294 def create_gitlab(groups: nil, projects: nil, name: nil, auth_mode: "oauth", gitlab_url: "https://gitlab.com", access_token: nil, connection_id: nil, ref_mode: nil, refs: nil, excluded_refs: nil, active_branch_days: nil, include_merge_requests: nil, include_review_threads: nil, include_direct_commits: nil, include_globs: nil, exclude_globs: nil, max_file_size_bytes: nil, description: nil, metadata: nil, **config) create_source(GitLabSource.new( groups: groups, projects: projects, name: name, auth_mode: auth_mode, gitlab_url: gitlab_url, access_token: access_token, connection_id: connection_id, ref_mode: ref_mode, refs: refs, excluded_refs: excluded_refs, active_branch_days: active_branch_days, include_merge_requests: include_merge_requests, include_review_threads: include_review_threads, include_direct_commits: include_direct_commits, include_globs: include_globs, exclude_globs: exclude_globs, max_file_size_bytes: max_file_size_bytes, description: description, metadata: , **config )) end |
#create_google_drive(name: nil, folder_ids: nil, file_ids: nil, auth_mode: nil, service_account_json: nil, oauth_credentials: nil, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a Google Drive source.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/vector_amp/ingestion.rb', line 179 def create_google_drive(name: nil, folder_ids: nil, file_ids: nil, auth_mode: nil, service_account_json: nil, oauth_credentials: nil, connection_id: nil, description: nil, metadata: nil, **config) create_source(GoogleDriveSource.new( name: name, folder_ids: folder_ids, file_ids: file_ids, auth_mode: auth_mode, service_account_json: service_account_json, oauth_credentials: oauth_credentials, connection_id: connection_id, description: description, metadata: , **config )) end |
#create_jira(cloud_id:, name: nil, access_token: nil, project_keys: nil, jql: nil, include_comments: true, connection_id: nil, description: nil, metadata: nil, **config) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/vector_amp/ingestion.rb', line 152 def create_jira(cloud_id:, name: nil, access_token: nil, project_keys: nil, jql: nil, include_comments: true, connection_id: nil, description: nil, metadata: nil, **config) create_source(JiraSource.new( cloud_id: cloud_id, name: name, access_token: access_token, project_keys: project_keys, jql: jql, include_comments: include_comments, connection_id: connection_id, description: description, metadata: , **config )) end |
#create_s3(bucket:, name: nil, prefix: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create an S3 source.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/vector_amp/ingestion.rb', line 120 def create_s3(bucket:, name: nil, prefix: nil, description: nil, metadata: nil, **config) create_source(S3Source.new( name: name, bucket: bucket, prefix: prefix, description: description, metadata: , **config )) end |
#create_source(source = nil, source_type: nil, name: nil, config: nil, description: nil, metadata: nil) ⇒ Hash
Create an ingestion source from a Source object/hash or explicit options.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vector_amp/ingestion.rb', line 78 def create_source(source = nil, source_type: nil, name: nil, config: nil, description: nil, metadata: nil) body = source ? source_create_body(source) : ( source_type: source_type, name: name, description: description, config: config, metadata: ) @transport.request(:post, "/ingestion/sources", body: body) end |
#create_web(start_urls:, name: nil, description: nil, metadata: nil, **config) ⇒ Hash
Create a web source.
102 103 104 105 106 107 108 109 110 |
# File 'lib/vector_amp/ingestion.rb', line 102 def create_web(start_urls:, name: nil, description: nil, metadata: nil, **config) create_source(WebSource.new( name: name, start_urls: start_urls, description: description, metadata: , **config )) end |
#delete_source(source_id, force: false) ⇒ Hash
Delete an ingestion source.
36 37 38 39 |
# File 'lib/vector_amp/ingestion.rb', line 36 def delete_source(source_id, force: false) query = force ? { force: true } : nil @transport.request(:delete, "/ingestion/sources/#{source_id}", query: query) end |
#get_job(job_id) ⇒ Hash
Fetch an ingestion job.
367 368 369 |
# File 'lib/vector_amp/ingestion.rb', line 367 def get_job(job_id) @transport.request(:get, "/ingestion/jobs/#{job_id}") end |
#get_source(source_id) ⇒ Hash
Fetch an ingestion source.
28 29 30 |
# File 'lib/vector_amp/ingestion.rb', line 28 def get_source(source_id) @transport.request(:get, "/ingestion/sources/#{source_id}") end |
#ingest_files(dataset_id:, paths:, source_name: nil, description: nil, metadata: {}) ⇒ Hash
Upload local files by auto-creating a file_upload source, initializing presigned uploads, and completing the upload job.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/vector_amp/ingestion.rb', line 406 def ingest_files(dataset_id:, paths:, source_name: nil, description: nil, metadata: {}) files = Array(paths).map { |path| Pathname(path) } raise ArgumentError, "paths must not be empty" if files.empty? source = create_file_upload( name: source_name, description: description, metadata: ( || {}).merge(dataset_id: dataset_id) ) source_id = source.fetch("id") { source.fetch(:id) } init = init_upload(source_id, files) upload_files_to_presigned_urls(files, init.fetch("uploads")) job_id = init.fetch("job_id") response = complete_upload(source_id, job_id: job_id, file_ids: init.fetch("uploads").map { |upload| upload.fetch("file_id") }) response["job_id"] ||= job_id if response.is_a?(Hash) response end |
#init_upload(source_id, files) ⇒ Hash
Initialize presigned uploads for source files.
429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/vector_amp/ingestion.rb', line 429 def init_upload(source_id, files) payload = Array(files).map do |file| path = Pathname(file) { name: path.to_s, size_bytes: path.size, content_type: content_type_for(path) } end @transport.request(:post, "/ingestion/sources/#{source_id}/upload/init", body: { files: payload }) end |
#job_files(job_id) ⇒ Hash
List files attached to an ingestion job.
381 382 383 |
# File 'lib/vector_amp/ingestion.rb', line 381 def job_files(job_id) @transport.request(:get, "/ingestion/jobs/#{job_id}/files") end |
#job_statistics(job_id) ⇒ Hash
Fetch ingestion job statistics.
388 389 390 |
# File 'lib/vector_amp/ingestion.rb', line 388 def job_statistics(job_id) @transport.request(:get, "/ingestion/jobs/#{job_id}/statistics") end |
#list_jobs(dataset_id: nil, limit: 50, offset: 0) ⇒ Hash
List ingestion jobs.
360 361 362 |
# File 'lib/vector_amp/ingestion.rb', line 360 def list_jobs(dataset_id: nil, limit: 50, offset: 0) @transport.request(:get, "/ingestion/jobs", query: Utils.compact_hash(dataset_id: dataset_id, limit: limit, offset: offset)) end |
#list_sources(limit: 50, offset: 0) ⇒ Hash
List ingestion sources.
21 22 23 |
# File 'lib/vector_amp/ingestion.rb', line 21 def list_sources(limit: 50, offset: 0) @transport.request(:get, "/ingestion/sources", query: { limit: limit, offset: offset }) end |
#list_unused_sources(limit: 50, offset: 0) ⇒ Hash
List sources that are not referenced by any job, schedule, or dataset.
45 46 47 |
# File 'lib/vector_amp/ingestion.rb', line 45 def list_unused_sources(limit: 50, offset: 0) @transport.request(:get, "/ingestion/sources/unused", query: { limit: limit, offset: offset }) end |
#retry_job(job_id) ⇒ Hash
Retry an eligible failed or cancelled ingestion job as a fresh full rerun.
374 375 376 |
# File 'lib/vector_amp/ingestion.rb', line 374 def retry_job(job_id) @transport.request(:post, "/ingestion/jobs/#{job_id}/retry") end |
#source_references(source_id) ⇒ Hash
List references (jobs, schedules, datasets) that use a source.
58 59 60 |
# File 'lib/vector_amp/ingestion.rb', line 58 def source_references(source_id) @transport.request(:get, "/ingestion/sources/#{source_id}/references") end |
#start_job(source_id:, dataset_id:, pipeline_id: nil) ⇒ Hash
Start an ingestion job for a source and dataset.
347 348 349 350 351 352 353 |
# File 'lib/vector_amp/ingestion.rb', line 347 def start_job(source_id:, dataset_id:, pipeline_id: nil) @transport.request(:post, "/ingestion/jobs", body: Utils.compact_hash( source_id: source_id, dataset_id: dataset_id, pipeline_id: pipeline_id )) end |
#validate_source(source_type:, config:) ⇒ Hash
Validate a source type and config without creating a source.
66 67 68 |
# File 'lib/vector_amp/ingestion.rb', line 66 def validate_source(source_type:, config:) @transport.request(:post, "/ingestion/sources/validate", body: { source_type: source_type, config: config }) end |