Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
3efa152d
Commit
3efa152d
authored
2 years ago
by
Charlotte Hausman
Browse files
Options
Downloads
Patches
Plain Diff
Add option for returning HTCondor ID without logging in.
parent
736c9a4c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!922
Add option for returning HTCondor ID without logging in.
Pipeline
#5128
passed
2 years ago
Stage: cache-build
Stage: build
Stage: unit-test
Stage: test-coverage
Stage: push
Stage: deploy-coverage-page
Stage: generate-yaml
Stage: trigger
Stage: deploy
Stage: e2e-test
Stage: .post
Pipeline: workspaces
#5129
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/cli/executables/pexable/wf_inspector/wf_inspector/inspector.py
+64
-22
64 additions, 22 deletions
...xecutables/pexable/wf_inspector/wf_inspector/inspector.py
with
64 additions
and
22 deletions
apps/cli/executables/pexable/wf_inspector/wf_inspector/inspector.py
+
64
−
22
View file @
3efa152d
...
...
@@ -71,9 +71,29 @@ def make_arg_parser() -> argparse.ArgumentParser:
action
=
"
store
"
,
help
=
"
the workflow request ID of the running workflow
"
,
)
arg_parser
.
add_argument
(
"
-c
"
,
"
--condor
"
,
action
=
"
store_true
"
,
required
=
False
,
help
=
"
Return only the HTCondor ID for the given workflow request id
"
,
)
return
arg_parser
def
is_docker
()
->
bool
:
"""
Determine if we
'
re in a docker container
:return: boolean
"""
host
=
os
.
environ
.
get
(
"
HOSTNAME
"
)
if
any
(
char
.
isdigit
()
for
char
in
host
):
return
True
return
False
def
get_container_id_by_substr
(
substr
:
str
)
->
Optional
[
bytes
]:
"""
Get ID of running container searched on a substring of its name
...
...
@@ -81,14 +101,15 @@ def get_container_id_by_substr(substr: str) -> Optional[bytes]:
:param substr: Substring to search on
:return: Container ID, if found; else None
"""
result
=
subprocess
.
run
([
"
docker
"
,
"
ps
"
,
"
-q
"
,
"
-f
"
,
f
"
name=
{
substr
}
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
if
result
.
returncode
==
0
:
if
len
(
result
.
stdout
)
>
0
:
# Container was found matching substr
return
result
.
stdout
.
strip
()
return
None
logger
.
error
(
"
Docker command not accessible. Docker is either not installed or you lack permissions to use it.
"
)
logger
.
info
(
"
Are you running this from within a Docker container? Docker is not installed in containers.
"
)
if
is_docker
()
is
False
:
result
=
subprocess
.
run
([
"
docker
"
,
"
ps
"
,
"
-q
"
,
"
-f
"
,
f
"
name=
{
substr
}
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
if
result
.
returncode
==
0
:
if
len
(
result
.
stdout
)
>
0
:
# Container was found matching substr
return
result
.
stdout
.
strip
()
return
None
logger
.
error
(
"
Docker command not accessible. Docker is either not installed or you lack permissions to use it.
"
)
logger
.
info
(
"
Are you running this from within a Docker container? Docker is not installed in containers.
"
)
return
None
...
...
@@ -126,12 +147,20 @@ def get_running_class_ads(workflow_container_id: bytes) -> List[ClassAd]:
:param workflow_container_id: ID of the running workflow container
:return: List of ClassAd JSON
"""
running_jobs
=
subprocess
.
run
(
[
"
docker
"
,
"
exec
"
,
"
-it
"
,
workflow_container_id
,
"
condor_q
"
,
"
-json
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
running_jobs_json
=
json
.
loads
(
running_jobs
.
stdout
)
if
workflow_container_id
is
None
:
running_jobs
=
subprocess
.
run
([
"
condor_q
"
,
"
-json
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
else
:
running_jobs
=
subprocess
.
run
(
[
"
docker
"
,
"
exec
"
,
"
-it
"
,
workflow_container_id
,
"
condor_q
"
,
"
-json
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
return
running_jobs_json
if
running_jobs
.
stdout
:
running_jobs_json
=
json
.
loads
(
running_jobs
.
stdout
)
return
running_jobs_json
else
:
if
workflow_container_id
is
None
:
workflow_container_id
=
"
workspaces-workflow-1
"
raise
NoJobFoundError
(
f
"
No running jobs found for container
{
workflow_container_id
}
.
"
)
def
is_dag_job
(
running_jobs_json
:
List
[
ClassAd
],
htcondor_job_id
:
int
)
->
bool
:
...
...
@@ -197,18 +226,28 @@ def list_running_jobs(workflow_container_id: bytes):
:param workflow_container_id: ID of the running workflow container
"""
logger
.
warning
(
"
HTCondor job ID not found!
"
)
running_jobs
=
subprocess
.
run
(
[
"
docker
"
,
"
exec
"
,
"
-it
"
,
workflow_container_id
,
"
condor_q
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
condor_q_output
=
running_jobs
.
stdout
.
decode
(
"
ascii
"
).
strip
()
logger
.
info
(
"
Here are the jobs currently running on the cluster
\n
"
)
logger
.
info
(
"
%s
\n
"
,
condor_q_output
)
logger
.
info
(
"
Is your job still running?
"
)
if
workflow_container_id
is
None
:
running_jobs
=
subprocess
.
run
([
"
condor_q
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
condor_q_output
=
running_jobs
.
stdout
.
decode
(
"
ascii
"
).
strip
()
logger
.
info
(
"
Here are the jobs currently running on the cluster
\n
"
)
logger
.
info
(
"
%s
\n
"
,
condor_q_output
)
logger
.
info
(
"
Is your job still running?
"
)
else
:
running_jobs
=
subprocess
.
run
(
[
"
docker
"
,
"
exec
"
,
"
-it
"
,
workflow_container_id
,
"
condor_q
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
condor_q_output
=
running_jobs
.
stdout
.
decode
(
"
ascii
"
).
strip
()
logger
.
info
(
"
Here are the jobs currently running on the cluster
\n
"
)
logger
.
info
(
"
%s
\n
"
,
condor_q_output
)
logger
.
info
(
"
Is your job still running?
"
)
def
main
():
args
=
make_arg_parser
().
parse_args
()
request_id
=
args
.
workflow_request_id
condor
=
args
.
condor
workflow_container_id
=
get_container_id_by_substr
(
"
workflow
"
)
# Get HTCondor ID for workflow request
...
...
@@ -233,5 +272,8 @@ def main():
list_running_jobs
(
workflow_container_id
)
return
logger
.
info
(
"
Success! Your job has ID %s. Logging in now...
"
,
htcondor_job_id
)
ssh_to_condor_job
(
workflow_container_id
,
htcondor_job_id
)
if
condor
is
True
:
logger
.
info
(
"
Success! Your job has ID %s.
"
,
htcondor_job_id
)
else
:
logger
.
info
(
"
Success! Your job has ID %s. Logging in now...
"
,
htcondor_job_id
)
ssh_to_condor_job
(
workflow_container_id
,
htcondor_job_id
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment