Skip to content
Snippets Groups Projects
Commit 3efa152d authored by Charlotte Hausman's avatar Charlotte Hausman
Browse files

Add option for returning HTCondor ID without logging in.

parent 736c9a4c
No related branches found
No related tags found
1 merge request!922Add option for returning HTCondor ID without logging in.
Pipeline #5128 passed
Pipeline: workspaces

#5129

    ......@@ -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)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment