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