Skip to main content
Version: v0.64.0

Get deployment statuses

This example demonstrates how you can get the deployment statuses and some other useful metadata, such as the example request payload and scoring URLs, for the experiments in a specified project.

Before you begin
  • Create a project in MLOps and link experiments to the project. For this example, we are using the project created in the Driverless AI example.
  • Install PrettyTable.
  • You will need the values for the following constants in order to successfully carry out the task. Contact your administrator to obtain deployment specific values.
ConstantValueDescription
MLOPS_API_URLUsually: https://api.mlops.my.domainDefines the URL for the MLOps Gateway component. You can verify the correct URL by navigating to the API URL in your browser. It should provide a page with a list of available routes.
TOKEN_ENDPOINT_URL
https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token
Defines the token endpoint URL of the Identity Provider. This uses Keycloak as the Identity Provider. Keycloak Realm should be provided.
REFRESH_TOKEN<your-refresh-token>Defines the user's refresh token
CLIENT_ID<your-client-id>Sets the client id for authentication. This is the client you will be using to connect to MLOps.
PROJECT_NAMEStandardFlowDefines a project name that the script will be using. This is the project from which you want to get the deployment statuses and other metadata. In this example, this is defined as StandardFlow because we are using the project created in the Driverless AI example.

The following steps demonstrate how you can use the MLOps Python client to get the deployment statuses, and some other useful metadata for the experiments in a specified project.

  1. Download the GetDeploymentStatuses.py file.

  2. Change the values of the following constants in your GetDeploymentStatuses.py file as given in the preceding data table.

    GetDeploymentStatuses.py
    ### Constants
    MLOPS_API_URL = <MLOPS_API_URL>
    TOKEN_ENDPOINT_URL = <TOKEN_ENDPOINT_URL>
    REFRESH_TOKEN = <REFRESH_TOKEN>
    CLIENT_ID = <CLIENT_ID>
    PROJECT_NAME = <PROJECT_NAME>
    GetDeploymentStatuses.py
    ### Constants
    MLOPS_API_URL = "https://api.mlops.my.domain"
    TOKEN_ENDPOINT_URL="https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token"
    REFRESH_TOKEN="<your-refresh-token>"
    CLIENT_ID="<your-mlops-client>"
    PROJECT_NAME = "StandardFlow"
  3. Run the GetDeploymentStatuses.py file.

    python3 GetDeploymentStatuses.py
  4. This gives the deployment status and some other metadata of the experiments of the specified project.

    +-----------------------+-------------+---------+-------------------+-------------------+-------------------+---------------------------+
    | Experiment Name | Environment | State | Deployment Type | Scorer Type | Scorer URL | Get Sample Request URL |
    +-----------------------+-------------+---------+-------------------+-------------------+-------------------+---------------------------+
    | CreditCardExample-111 | DEV | HEALTHY | single-deployment | MOJO2_REST_SCORER | <your-scorer-url> | <your-sample-request-url> |
    +-----------------------+-------------+---------+-------------------+-------------------+-------------------+---------------------------+

Example walkthrough

The following steps provide a walkthrough of each of the sections in the GetDeploymentStatuses.py file.

  1. Set up the token provider using an existing refresh token.

  2. Set up the MLOps client.

  3. Get the projects of all users and look for the ID of the specified project.

    GetDeploymentStatuses.py
    # Getting all user's projects.
    projects: mlops.StorageListProjectsResponse = (
    mlops_client.storage.project.list_projects(mlops.StorageListProjectsRequest())
    )

    # Looking for the ID of the selected project.
    for p in projects.project:
    if p.display_name == PROJECT_NAME:
    prj_id = p.id
    break
    else:
    raise LookupError("Requested project not found")
  4. Get all the deployments of the specified project.

    GetDeploymentStatuses.py
    deployments: mlops.DeployListProjectDeploymentsResponse = (
    mlops_client.deployer.deployment.list_project_deployments(
    mlops.DeployListProjectDeploymentsRequest(project_id=prj_id)
    )
    )
  5. Get all the deployment environments for the specified project.

    GetDeploymentStatuses.py
    deployment_envs: mlops.StorageListDeploymentEnvironmentsResponse = (
    mlops_client.storage.deployment_environment.list_deployment_environments(
    mlops.StorageListDeploymentEnvironmentsRequest(project_id=prj_id)
    )
    )
  6. Get all the deployment statuses for the specified project.

    GetDeploymentStatuses.py
    statuses: mlops.DeployListDeploymentStatusesResponse = (
    mlops_client.deployer.deployment_status.list_deployment_statuses(
    mlops.DeployListDeploymentStatusesRequest(project_id=prj_id)
    )
    )
  7. Get a list of all the experiments in the project to load additional metadata for the experiment.

    GetDeploymentStatuses.py
    experiments: mlops.StorageListExperimentsResponse = (
    mlops_client.storage.experiment.list_experiments(
    mlops.StorageListExperimentsRequest(project_id=prj_id)
    )
    )
  8. Create some temporary data which are then used to create the output table in the next step.

    GetDeploymentStatuses.py
    deployment_properties = {
    d.id: {
    "exp_id": d.single_deployment.deployment_composition.experiment_id,
    "env_id": d.deployment_environment_id,
    "type": get_deployment_type(d),
    }
    for d in deployments.deployment
    }
    deployment_envs_names = {
    de.id: de.display_name for de in deployment_envs.deployment_environment
    }
    experiment_names = {e.id: e.display_name for e in experiments.experiment}
  9. Finally, create the output table with the deployment status and other retrieved metadata.

    GetDeploymentStatuses.py
    # Setting up output table's field names.
    pp = PrettyTable(
    field_names=[
    "Experiment Name",
    "Environment",
    "State",
    "Deployment Type",
    "Scorer Type",
    "Scorer URL",
    "Get Sample Request URL",
    ]
    )

    # Creating the output table.
    for ds in statuses.deployment_status:
    d_properties = deployment_properties[ds.deployment_id]
    pp.add_row(
    [
    experiment_names[d_properties["exp_id"]],
    deployment_envs_names[d_properties["env_id"]],
    ds.state,
    d_properties["type"],
    ds.scorer.type,
    ds.scorer.score.url,
    ds.scorer.sample_request.url,
    ]
    )

    print(pp)

Feedback