Skip to content
Snippets Groups Projects
Commit 01c32abd authored by Charlotte Hausman's avatar Charlotte Hausman Committed by Jim Sheckard
Browse files

add capability level access to inspector

parent d0afc457
No related branches found
No related tags found
1 merge request!991add capability level access to inspector
Pipeline #5855 passed
Pipeline: workspaces

#5858

    ......@@ -66,7 +66,7 @@ def make_arg_parser() -> argparse.ArgumentParser:
    formatter_class=argparse.RawTextHelpFormatter,
    )
    arg_parser.add_argument(
    "workflow_request_id",
    "request_id",
    type=int,
    action="store",
    help="the workflow request ID of the running workflow",
    ......@@ -78,6 +78,14 @@ def make_arg_parser() -> argparse.ArgumentParser:
    required=False,
    help="Return only the HTCondor ID for the given workflow request id",
    )
    arg_parser.add_argument(
    "-v",
    "--version",
    nargs=1,
    action="store",
    required=False,
    help="Run the inspector with a capability request id and version id",
    )
    return arg_parser
    ......@@ -140,6 +148,44 @@ def get_wf_request_htcondor_id(workflow_request_id: str) -> int:
    raise NoSuchWorkflowRequestError(f"No workflow request found with ID {workflow_request_id}")
    def get_capability_request_htcondor_id(capability_request_id: str, version_id: str) -> int:
    """
    Given a capability request ID, get the HTCondor job ID that corresponds
    :param capability_request_id: ID of workflow request
    :param version_id: ID of the capability version
    :return: HTCondor job ID for workflow request
    :raises NoIdForWorkflow if no ID was found for the workflow
    """
    if os.environ["CAPO_PROFILE"] == "docker":
    capability_url = "http://localhost:3457"
    workflow_url = "http://localhost:3456"
    else:
    # Non-local scenario; use normal CAPO setting
    capability_url = CapoConfig().settings("edu.nrao.workspaces.CapabilitySettings").externalServiceUrl
    workflow_url = CapoConfig().settings("edu.nrao.workspaces.WorkflowSettings").serviceUrl
    response = requests.get(
    f"{capability_url}/capability/requests/{capability_request_id}/version/{version_id}/execution"
    )
    if response.status_code == http.HTTPStatus.OK:
    response2 = requests.get(
    # About "name" in URL: workflow name not necessary for this endpoint, so any string works here
    f"{workflow_url}/workflows/name/requests/{response.json()['current_workflow_request_id']}/htcondor_id"
    )
    if response2.status_code == http.HTTPStatus.OK:
    htcondor_id = response2.json()["htcondor_job_id"]
    if htcondor_id != "None":
    return int(htcondor_id)
    raise NoIdForWorkflowError
    raise NoSuchWorkflowRequestError(f"No capability request found with ID {capability_request_id}")
    def get_running_class_ads(workflow_container_id: bytes) -> List[ClassAd]:
    """
    Query the cluster for a list of the ClassAds of all running jobs in JSON format
    ......@@ -245,15 +291,21 @@ def list_running_jobs(workflow_container_id: bytes):
    def main():
    args = make_arg_parser().parse_args()
    request_id = args.workflow_request_id
    request_id = args.request_id
    condor = args.condor
    from_cap_request = args.version
    workflow_container_id = get_container_id_by_substr("workflow")
    # Get HTCondor ID for workflow request
    logger.info("Getting HTCondor ID for workflow request %s", request_id)
    try:
    htcondor_job_id = get_wf_request_htcondor_id(request_id)
    if from_cap_request is not None:
    # Get HTCondor ID for capability request
    logger.info("Getting HTCondor ID for capability request %s", request_id)
    htcondor_job_id = get_capability_request_htcondor_id(request_id, args.version[0])
    else:
    # Get HTCondor ID for workflow request
    logger.info("Getting HTCondor ID for workflow request %s", request_id)
    htcondor_job_id = get_wf_request_htcondor_id(request_id)
    except NoIdForWorkflowError:
    logger.warning("No HTCondor ID found for workflow request %s", request_id)
    list_running_jobs(workflow_container_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