Skip to content

Commit d2a6e3a

Browse files
committed
fix
1 parent e9983f5 commit d2a6e3a

File tree

1 file changed

+166
-5
lines changed

1 file changed

+166
-5
lines changed

ruby/example_code/glue/glue_wrapper.rb

Lines changed: 166 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
# snippet-start:[ruby.example_code.glue.GlueWrapper.full]
88
# snippet-start:[ruby.example_code.glue.GlueWrapper.decl]
99

10-
# The `GlueWrapper` class serves as a wrapper around the AWS Glue API,
11-
# providing a simplified interface for common operations.
12-
# It encapsulates the functionality of the AWS SDK for Glue and provides methods for interacting with Glue crawlers,
13-
# databases, tables, jobs, and S3 resources.
10+
# The `GlueWrapper` class serves as a wrapper around the AWS Glue API, providing a simplified interface for common operations.
11+
# It encapsulates the functionality of the AWS SDK for Glue and provides methods for interacting with Glue crawlers, databases, tables, jobs, and S3 resources.
1412
# The class initializes with a Glue client and a logger, allowing it to make API calls and log any errors or informational messages.
1513
class GlueWrapper
1614
def initialize(glue_client, logger)
@@ -76,7 +74,170 @@ def start_crawler(name)
7674
end
7775
# snippet-end:[ruby.example_code.glue.StartCrawler]
7876

79-
# Additional methods omitted for brevity...
77+
# snippet-start:[ruby.example_code.glue.DeleteCrawler]
78+
# Deletes a crawler with the specified name.
79+
#
80+
# @param name [String] The name of the crawler to delete.
81+
# @return [void]
82+
def delete_crawler(name)
83+
@glue_client.delete_crawler(name: name)
84+
rescue Aws::Glue::Errors::ServiceError => e
85+
@logger.error("Glue could not delete crawler #{name}: \n#{e.message}")
86+
raise
87+
end
88+
# snippet-end:[ruby.example_code.glue.DeleteCrawler]
89+
90+
# snippet-start:[ruby.example_code.glue.GetDatabase]
91+
# Retrieves information about a specific database.
92+
#
93+
# @param name [String] The name of the database to retrieve information about.
94+
# @return [Aws::Glue::Types::Database, nil] The database object if found, or nil if not found.
95+
def get_database(name)
96+
response = @glue_client.get_database(name: name)
97+
response.database
98+
rescue Aws::Glue::Errors::GlueException => e
99+
@logger.error("Glue could not get database #{name}: \n#{e.message}")
100+
raise
101+
end
102+
# snippet-end:[ruby.example_code.glue.GetDatabase]
103+
104+
# snippet-start:[ruby.example_code.glue.GetTables]
105+
# Retrieves a list of tables in the specified database.
106+
#
107+
# @param db_name [String] The name of the database to retrieve tables from.
108+
# @return [Array<Aws::Glue::Types::Table>]
109+
def get_tables(db_name)
110+
response = @glue_client.get_tables(database_name: db_name)
111+
response.table_list
112+
rescue Aws::Glue::Errors::GlueException => e
113+
@logger.error("Glue could not get tables #{db_name}: \n#{e.message}")
114+
raise
115+
end
116+
# snippet-end:[ruby.example_code.glue.GetTables]
117+
118+
# snippet-start:[ruby.example_code.glue.CreateJob]
119+
# Creates a new job with the specified configuration.
120+
#
121+
# @param name [String] The name of the job.
122+
# @param description [String] The description of the job.
123+
# @param role_arn [String] The ARN of the IAM role to be used by the job.
124+
# @param script_location [String] The location of the ETL script for the job.
125+
# @return [void]
126+
def create_job(name, description, role_arn, script_location)
127+
@glue_client.create_job(
128+
name: name,
129+
description: description,
130+
role: role_arn,
131+
command: {
132+
name: 'glueetl',
133+
script_location: script_location,
134+
python_version: '3'
135+
},
136+
glue_version: '3.0'
137+
)
138+
rescue Aws::Glue::Errors::GlueException => e
139+
@logger.error("Glue could not create job #{name}: \n#{e.message}")
140+
raise
141+
end
142+
# snippet-end:[ruby.example_code.glue.CreateJob]
143+
144+
# snippet-start:[ruby.example_code.glue.StartJobRun]
145+
# Starts a job run for the specified job.
146+
#
147+
# @param name [String] The name of the job to start the run for.
148+
# @param input_database [String] The name of the input database for the job.
149+
# @param input_table [String] The name of the input table for the job.
150+
# @param output_bucket_name [String] The name of the output S3 bucket for the job.
151+
# @return [String] The ID of the started job run.
152+
def start_job_run(name, input_database, input_table, output_bucket_name)
153+
response = @glue_client.start_job_run(
154+
job_name: name,
155+
arguments: {
156+
'--input_database': input_database,
157+
'--input_table': input_table,
158+
'--output_bucket_url': "s3://#{output_bucket_name}/"
159+
}
160+
)
161+
response.job_run_id
162+
rescue Aws::Glue::Errors::GlueException => e
163+
@logger.error("Glue could not start job run #{name}: \n#{e.message}")
164+
raise
165+
end
166+
# snippet-end:[ruby.example_code.glue.StartJobRun]
167+
168+
# snippet-start:[ruby.example_code.glue.ListJobs]
169+
# Retrieves a list of jobs in AWS Glue.
170+
#
171+
# @return [Aws::Glue::Types::ListJobsResponse]
172+
def list_jobs
173+
@glue_client.list_jobs
174+
rescue Aws::Glue::Errors::GlueException => e
175+
@logger.error("Glue could not list jobs: \n#{e.message}")
176+
raise
177+
end
178+
# snippet-end:[ruby.example_code.glue.ListJobs]
179+
180+
# snippet-start:[ruby.example_code.glue.GetJobRuns]
181+
# Retrieves a list of job runs for the specified job.
182+
#
183+
# @param job_name [String] The name of the job to retrieve job runs for.
184+
# @return [Array<Aws::Glue::Types::JobRun>]
185+
def get_job_runs(job_name)
186+
response = @glue_client.get_job_runs(job_name: job_name)
187+
response.job_runs
188+
rescue Aws::Glue::Errors::GlueException => e
189+
@logger.error("Glue could not get job runs: \n#{e.message}")
190+
end
191+
# snippet-end:[ruby.example_code.glue.GetJobRuns]
192+
193+
# snippet-start:[ruby.example_code.glue.GetJobRun]
194+
# Retrieves data for a specific job run.
195+
#
196+
# @param job_name [String] The name of the job run to retrieve data for.
197+
# @return [Glue::Types::GetJobRunResponse]
198+
def get_job_run(job_name, run_id)
199+
@glue_client.get_job_run(job_name: job_name, run_id: run_id)
200+
rescue Aws::Glue::Errors::GlueException => e
201+
@logger.error("Glue could not get job runs: \n#{e.message}")
202+
end
203+
# snippet-end:[ruby.example_code.glue.GetJobRun]
204+
205+
# snippet-start:[ruby.example_code.glue.DeleteJob]
206+
# Deletes a job with the specified name.
207+
#
208+
# @param job_name [String] The name of the job to delete.
209+
# @return [void]
210+
def delete_job(job_name)
211+
@glue_client.delete_job(job_name: job_name)
212+
rescue Aws::Glue::Errors::ServiceError => e
213+
@logger.error("Glue could not delete job: \n#{e.message}")
214+
end
215+
# snippet-end:[ruby.example_code.glue.DeleteJob]
216+
217+
# snippet-start:[ruby.example_code.glue.DeleteTable]
218+
# Deletes a table with the specified name.
219+
#
220+
# @param database_name [String] The name of the catalog database in which the table resides.
221+
# @param table_name [String] The name of the table to be deleted.
222+
# @return [void]
223+
def delete_table(database_name, table_name)
224+
@glue_client.delete_table(database_name: database_name, name: table_name)
225+
rescue Aws::Glue::Errors::ServiceError => e
226+
@logger.error("Glue could not delete job: \n#{e.message}")
227+
end
228+
# snippet-end:[ruby.example_code.glue.DeleteTable]
229+
230+
# snippet-start:[ruby.example_code.glue.DeleteDatabase]
231+
# Removes a specified database from a Data Catalog.
232+
#
233+
# @param database_name [String] The name of the database to delete.
234+
# @return [void]
235+
def delete_database(database_name)
236+
@glue_client.delete_database(name: database_name)
237+
rescue Aws::Glue::Errors::ServiceError => e
238+
@logger.error("Glue could not delete database: \n#{e.message}")
239+
end
240+
# snippet-end:[ruby.example_code.glue.DeleteDatabase]
80241

81242
# Uploads a job script file to an S3 bucket.
82243
#

0 commit comments

Comments
 (0)