Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Glue] Implement batch_get_jobs #6241

Merged
merged 3 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions moto/glue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,13 @@ def batch_get_crawlers(self, crawler_names: List[str]) -> List[Dict[str, Any]]:
crawlers.append(crawler.as_dict())
return crawlers

def batch_get_jobs(self, job_names: List[str]) -> List[Dict[str, Any]]:
jobs = []
for job_name in job_names:
if job_name in self.jobs:
jobs.append(self.jobs[job_name].as_dict())
return jobs


class FakeDatabase(BaseModel):
def __init__(self, database_name: str, database_input: Dict[str, Any]):
Expand Down
11 changes: 11 additions & 0 deletions moto/glue/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,16 @@ def batch_get_crawlers(self) -> str:
}
)

def batch_get_jobs(self) -> str:
job_names = self._get_param("JobNames")
jobs = self.glue_backend.batch_get_jobs(job_names)
jobs_not_found = list(set(job_names) - set(map(lambda job: job["Name"], jobs)))
return json.dumps(
{
"Jobs": jobs,
"JobsNotFound": jobs_not_found,
}
)

def get_partition_indexes(self) -> str:
return json.dumps({"PartitionIndexDescriptorList": []})
11 changes: 11 additions & 0 deletions tests/test_glue/test_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ def test_list_jobs_next_token_logic_does_not_create_infinite_loop():
assert not next_token


@mock_glue
def test_batch_get_jobs():
client = create_glue_client()
job_name = create_test_job(client)

response = client.batch_get_jobs(JobNames=[job_name, "job-not-found"])

assert len(response["Jobs"]) == 1
assert len(response["JobsNotFound"]) == 1


def create_glue_client():
return boto3.client("glue", region_name="us-east-1")

Expand Down