Skip to content

Commit

Permalink
Use existing Globus login to request new consents; Add balsam job mod…
Browse files Browse the repository at this point in the history
…ify command
  • Loading branch information
Thomas Uram committed Jan 13, 2023
1 parent c29a850 commit b428b59
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
24 changes: 24 additions & 0 deletions balsam/cmdline/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,30 @@ def ls(
list_table(job_qs, client)


@job.command()
@click.option("-i", "--id", "job_ids", multiple=True, type=int)
@click.option("-s", "--state", "state", type=str)
def modify(job_ids: List[int], state: List[str]) -> None:
"""
Modify Jobs
1) Modify Job State
balsam job modify --id 41 --id 42 --id 43 -s RESTART_READY
"""
client: RESTClient = load_client()
jobs = client.Job.objects.all()
if job_ids:
jobs = jobs.filter(id=job_ids)
else:
raise click.BadParameter("Provide either list of Job ids or tags to delete")
count = jobs.count()
assert count is not None
for job in jobs:
job.state = state
job.save()


@job.command()
@click.option("-i", "--id", "job_ids", multiple=True, type=int)
@click.option("-t", "--tag", "tags", multiple=True, type=str, callback=validate_tags)
Expand Down
9 changes: 7 additions & 2 deletions balsam/cmdline/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,20 @@ def globus_login(endpoint_id: str) -> None:
"""
Get credentials for the Globus CLI
Necessary before any Globus CLI commands which require authentication will work
Necessary before any Globus CLI commands which require authentication will work.
This command directs you to the page necessary to permit the Globus CLI to make API
calls for you, and gets the OAuth2 tokens needed to use those permissions.
"""
# if not forcing, stop if user already logged in
if globus_auth.check_logged_in():
click.echo("You are already logged in!")
# user is logged in already, but let's ensure consents are in place for the
# requested endpoints
# FIXME: Since the globus API doesn't allow query of consents, we should
# should store the list of successful consents so we know if this is needed
globus_auth.do_link_auth_flow(force_new_client=False, endpoint_ids=endpoint_id)
return

globus_auth.do_link_auth_flow(force_new_client=True, endpoint_ids=endpoint_id)

click.echo("You have successfully logged in to the Globus CLI!")
click.echo("You have successfully logged in to Globus")
5 changes: 5 additions & 0 deletions balsam/platform/app_run/app_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def start(self) -> None:
self._set_envs()
cmdline = self._build_preamble() + self._build_cmdline()
logger.info(f"{self.__class__.__name__} Popen: {cmdline}")

import inspect

logger.info(f"current stack top: {inspect.stack()[0][1]}")

self._outfile = self._open_outfile()
self._pre_popen()

Expand Down
1 change: 1 addition & 0 deletions balsam/platform/scheduler/pbs_sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def _parse_status_output(raw_output: str) -> Dict[int, SchedulerJobStatus]:
for jobidstr, job in j["Jobs"].items():
status = {}
try:
jobidstr = jobidstr.replace("[]", "")
jobid = int(jobidstr.split(".")[0])
status["scheduler_id"] = jobid
except ValueError:
Expand Down
2 changes: 2 additions & 0 deletions balsam/platform/transfer/globus_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def submit_sdk(src_endpoint: UUID, dest_endpoint: UUID, batch: Sequence[SrcDestR
try:
res = client.submit_transfer(transfer_data)
except GlobusAPIError as exc:
import traceback
traceback.print_exc()
raise TransferSubmitError(str(exc))
task_id = res.get("task_id", None)
if task_id is None:
Expand Down
6 changes: 3 additions & 3 deletions balsam/util/globus_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def internal_auth_client(requires_instance: bool = False, force_new_client: bool
write_option(CLIENT_ID_OPTNAME, client_id)
write_option(CLIENT_SECRET_OPTNAME, client_secret)

return ConfidentialAppAuthClient(client_id, client_secret, app_name="Globus CLI")
return ConfidentialAppAuthClient(client_id, client_secret, app_name="Balsam")

# if we already have a client, just return it
elif existing:
return ConfidentialAppAuthClient(client_id, client_secret, app_name="Globus CLI")
return ConfidentialAppAuthClient(client_id, client_secret, app_name="Balsam")

# fall-back to a native client to not break old logins
# TOOD: eventually remove this behavior
Expand All @@ -220,7 +220,7 @@ def get_client() -> RetryingTransferClient:
on_refresh=_update_tokens,
)

return RetryingTransferClient(authorizer=authorizer, app_name="Globus CLI v2.1.0")
return RetryingTransferClient(authorizer=authorizer, app_name="Balsam")


def exchange_code_and_store_config(auth_client: EitherAuthClient, auth_code: str) -> None:
Expand Down

0 comments on commit b428b59

Please sign in to comment.