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

Patch: update GET job list to API v2 #175

Merged
merged 3 commits into from
Dec 5, 2024
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## lifebit-ai/cloudos-cli: changelog

## v2.13.0 (2024-12-03)

### Feature

- Adds new `--archived` flag to `cloudos job list` to allow getting archived jobs list.

### Patch

- Updates GET job list to use API v2 endpoint.

## v2.12.0 (2024-11-27)

### Feature
Expand Down
6 changes: 5 additions & 1 deletion cloudos/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ def job_status(apikey,
'value corresponds to the first page to retrieve. Default=1.'),
type=int,
default=1)
@click.option('--archived',
help=('When this flag is used, only archived jobs list is collected.'),
is_flag=True)
@click.option('--verbose',
help='Whether to print information messages or not.',
is_flag=True)
Expand All @@ -722,6 +725,7 @@ def list_jobs(apikey,
all_fields,
last_n_jobs,
page,
archived,
verbose,
disable_ssl_verification,
ssl_cert):
Expand All @@ -744,7 +748,7 @@ def list_jobs(apikey,
except ValueError:
print("[ERROR] last-n-jobs value was not valid. Please use a positive int or 'all'")
raise
my_jobs_r = cl.get_job_list(workspace_id, last_n_jobs, page, verify_ssl)
my_jobs_r = cl.get_job_list(workspace_id, last_n_jobs, page, archived, verify_ssl)
if output_format == 'csv':
my_jobs = cl.process_job_list(my_jobs_r, all_fields)
my_jobs.to_csv(outfile, index=False)
Expand Down
2 changes: 1 addition & 1 deletion cloudos/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.12.0'
__version__ = '2.13.0'
16 changes: 12 additions & 4 deletions cloudos/clos.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def cromwell_switch(self, workspace_id, action, verify=True):
raise BadRequestException(r)
return r

def get_job_list(self, workspace_id, last_n_jobs=30, page=1, verify=True):
def get_job_list(self, workspace_id, last_n_jobs=30, page=1, archived=False,
verify=True):
"""Get jobs from a CloudOS workspace.

Parameters
Expand All @@ -225,6 +226,8 @@ def get_job_list(self, workspace_id, last_n_jobs=30, page=1, verify=True):
very large int or 'all' to get all user's jobs.
page : int
Response page to get.
archived : bool
When True, only the archived jobs are retrieved.
verify: [bool|string]
Whether to use SSL verification or not. Alternatively, if
a string is passed, it will be interpreted as the path to
Expand All @@ -239,8 +242,12 @@ def get_job_list(self, workspace_id, last_n_jobs=30, page=1, verify=True):
"Content-type": "application/json",
"apikey": self.apikey
}
r = retry_requests_get("{}/api/v1/jobs?teamId={}&page={}".format(self.cloudos_url,
workspace_id, page),
if archived:
archived_status = "true"
else:
archived_status = "false"
r = retry_requests_get("{}/api/v2/jobs?teamId={}&page={}&archived.status={}".format(
self.cloudos_url, workspace_id, page, archived_status),
headers=headers, verify=verify)
if r.status_code >= 400:
raise BadRequestException(r)
Expand All @@ -260,7 +267,8 @@ def get_job_list(self, workspace_id, last_n_jobs=30, page=1, verify=True):
else:
next_to_get = jobs_to_get
return content['jobs'] + self.get_job_list(workspace_id, last_n_jobs=next_to_get,
page=page+1, verify=verify)
page=page+1, archived=archived,
verify=verify)
if jobs_to_get < 0:
return content['jobs'][:jobs_to_get]

Expand Down
2 changes: 1 addition & 1 deletion cloudos/queue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_job_queues(self):

@staticmethod
def process_queue_list(r, all_fields=False):
"""Process a job list from a self.get_job_list call.
"""Process a queue list from a self.get_job_queues call.

Parameters
----------
Expand Down
14 changes: 8 additions & 6 deletions tests/test_clos/test_get_job_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ def test_get_job_list_correct_response():
API request is mocked and replicated with json files
"""
create_json = load_json_file(INPUT)
params = {"teamId": WORKSPACE_ID, "page": 1}
params = {"teamId": WORKSPACE_ID, "page": 1,
"archived.status": "false"}
header = {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=UTF-8",
"apikey": APIKEY
}
search_str = f"teamId={WORKSPACE_ID}&page=1"
search_str = f"teamId={WORKSPACE_ID}&page=1&archived.status=false"
# mock GET method with the .json
responses.add(
responses.GET,
url=f"{CLOUDOS_URL}/api/v1/jobs?{search_str}",
url=f"{CLOUDOS_URL}/api/v2/jobs?{search_str}",
body=create_json,
headers=header,
match=[matchers.query_param_matcher(params)],
Expand All @@ -54,17 +55,18 @@ def test_get_job_list_incorrect_response():
error_message = {"statusCode": 400, "code": "BadRequest",
"message": "Bad Request.", "time": "2022-11-23_17:31:07"}
error_json = json.dumps(error_message)
params = {"teamId": WORKSPACE_ID, "page": 1}
params = {"teamId": WORKSPACE_ID, "page": 1,
"archived.status": "false"}
header = {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=UTF-8",
"apikey": APIKEY
}
search_str = f"teamId={WORKSPACE_ID}&page=1"
search_str = f"teamId={WORKSPACE_ID}&page=1&archived.status=false"
# mock GET method with the .json
responses.add(
responses.GET,
url=f"{CLOUDOS_URL}/api/v1/jobs?{search_str}",
url=f"{CLOUDOS_URL}/api/v2/jobs?{search_str}",
body=error_json,
headers=header,
match=[matchers.query_param_matcher(params)],
Expand Down
7 changes: 4 additions & 3 deletions tests/test_errors/test_bad_request_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ def test_bad_request_exception():
API request is mocked and replicated with json files
"""
create_json = load_json_file(INPUT)
params = {"teamId": WORKSPACE_ID, "page": 1}
params = {"teamId": WORKSPACE_ID, "page": 1,
"archived.status": "false"}
header = {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=UTF-8",
"apikey": APIKEY
}
search_str = f"teamId={WORKSPACE_ID}&page=1"
search_str = f"teamId={WORKSPACE_ID}&page=1&archived.status=false"
# mock GET method with the .json
responses.add(
responses.GET,
url=f"{CLOUDOS_URL}/api/v1/jobs?{search_str}",
url=f"{CLOUDOS_URL}/api/v2/jobs?{search_str}",
body=create_json,
headers=header,
match=[matchers.query_param_matcher(params)],
Expand Down
Loading