CLI for Cloudera Lakehouse Optimizer

On Anywhere Cloud, use the Restish CLI or the Cloudera Lakehouse Optimizer landing page API explorer to call Cloudera Lakehouse Optimizer REST APIs for policies, associations, and maintenance tasks. Restish commands are generated from openapi.json.

Non-graphical clients on Anywhere Cloud

You can trigger Cloudera Lakehouse Optimizer APIs without the maintenance UI using either of the following clients:

  • API explorer: Interactive OpenAPI UI on the Cloudera Lakehouse Optimizer landing page. Use it to review endpoints, send authenticated requests, and copy curl examples when your user has a Cloudera Lakehouse Optimizer application role. See Accessing the Cloudera Lakehouse Optimizer API and Accessing Cloudera Lakehouse Optimizer.
  • Restish CLI: Open-source client that builds commands from the same OpenAPI specification at runtime (for example, restish clo health-check). Configure OAuth client credentials from the Anywhere Cloud Console before you run Restish commands.

Prerequisites for using Restish

  1. Deploy Cloudera Lakehouse Optimizer on Anywhere Cloud and complete post-deploy Ranger and Cloudera Data Engineering setup.
  2. Assign a Cloudera Lakehouse Optimizer application role (administrator, operator, or monitor) in the Anywhere Cloud Console. See Configuring roles for Cloudera Lakehouse Optimizer users.
  3. Provision API access key credentials and register Restish for Cloudera Lakehouse Optimizer as described in the optional Restish steps in Accessing Cloudera Lakehouse Optimizer (API Explorer POST for access keys, ~/.config/restish/restish.json, restish api sync clo).
  4. Install the Restish CLI on your workstation. Use a build certified by your security team.

CLI help

After you configure Restish, list Cloudera Lakehouse Optimizer commands with:

restish clo --help

For help on a specific operation, append --help to the command (for example, restish clo dry-run --help). Run restish api auth inspect clo to verify OAuth credentials.

For a summary of common Restish operations, see CLI options for Cloudera Lakehouse Optimizer. For bearer tokens when you use curl instead of Restish, see Generating tokens and accessing Cloudera Lakehouse Optimizer REST APIs.

CLI options for Cloudera Lakehouse Optimizer

On Anywhere Cloud, Restish exposes Cloudera Lakehouse Optimizer REST operations as restish clo subcommands. Run restish clo --help for the complete list from your deployment's openapi.json.

Getting help

restish clo --help
restish clo health-check --help
restish api auth inspect clo

Command names and flags match the OpenAPI specification. If your deployment version adds or renames operations, synchronize Restish after upgrades:

restish api sync clo

Common Restish commands

The following table summarizes frequently used restish clo commands on Anywhere Cloud. Equivalent operations are available in the landing page API explorer.

Restish command Description
health-check Health check for the Cloudera Lakehouse Optimizer service (same as GET /config/health).
ui-list-scripts List default and catalog-level policy script resources.
create-policy-definition-json Create a policy definition from JSON resources.
update-policy-definition-json Update an existing policy definition.
delete-policy-definition Delete a policy definition for a scope such as *, catalog.namespace.*, or catalog.namespace.table.
create-policy-associations Create associations between tables or namespaces and a policy (catalog.namespace.table or catalog.namespace.* targets).
set-table-policy Assign a single policy to a table.
update-table-policy Add, remove, or replace policies on a table subscription.
delete-table-policy Remove a policy from a table.
dry-run / dry-run-policy Preview maintenance actions for a policy on a table without executing them (catalog.namespace.table path).
evaluate-policy Run evaluation (and execution, when applicable) for a policy on a table.
list-recent-tasks List recent maintenance tasks; filter with --table, --policy, or --count. OpenAPI may also expose get-recent-tasks.
fetch-stats Query table statistics.
list-tasks List maintenance tasks with cursor-based pagination.
get-by-id Retrieve a task by ID.
ui-list-timezones List time zones supported for policy cron schedules.
ui-get-policy-details Read policy metadata and result.versions[] before download.
ui-download-policy-version / download-policy-version Download policy scripts or arguments for a policy version ID.
put-namespace / update-namespace Register or reschedule a namespace after policy or cron changes.

Additional command groups (for example, config, namespaces, policies, tables, and task details) appear in the output of restish clo --help.

Creating and associating policies

An Administrator creates a Cloudera Lakehouse Optimizer policy with a name, description, selectable Iceberg maintenance actions, and adjustable parameters. Associate the policy with Iceberg tables, namespaces, or catalogs.

  1. Configure Restish for Cloudera Lakehouse Optimizer on Anywhere Cloud.

    Complete API access key setup and restish.json registration as described in CLI for Cloudera Lakehouse Optimizer. Synchronize the OpenAPI specification, then open the command list:

    restish api sync clo
    restish clo
  2. Perform a health check and verify the default ClouderaAdaptive policy.
    restish clo health-check
    restish clo ui-list-scripts
    restish clo fetch-active-policies

    Use ui-list-scripts to confirm the default script resources (for example, ClouderaAdaptive) are available. Confirm that the service is healthy and that the default adaptive policy is listed. For the same check with curl, see Verifying service health and viewing default Cloudera Lakehouse Optimizer policy.

  3. Create a Cloudera Lakehouse Optimizer policy.

    Run restish clo create-policy-definition-json --help and pass policy JSON that matches POST /policies/definition. Set the policy name in the request body. The base64-encoded arguments include the JEXL script reference, optional description, schedule (cron), and constants that enable and configure Iceberg maintenance actions:

    • Data file compaction (rewriteDataFiles)
    • Orphan file removal (deleteOrphanFiles)
    • Positional delete rewrite (rewritePositionDelete)
    • Snapshot expiration (expireSnapshot)
    • Manifest rewrite (rewriteManifest)

    For field descriptions, see JSON file. For REST examples, see Define policy resources using REST APIs.

  4. Associate the policy with Iceberg tables, a namespace, or catalogs.

    Use restish clo create-policy-associations. Each association target uses <catalog>.<namespace>.<table> or a namespace wildcard <catalog>.<namespace>.*. Replace catalog, namespace, and table names with your Cloudera Harmony Catalog objects.

    restish clo create-policy-associations <POLICY NAME> \
      'associations: ["<CATALOG>.<NAMESPACE>.<TABLE or *>"]'

    Examples:

    # All tables in a namespace (catalog.namespace.*)
    restish clo create-policy-associations ExpireSnapshotsOnly \
      'associations: ["harmonycatalog.ns_expire_snapshots.*"]'
    # Specific table (catalog.namespace.table)
    restish clo create-policy-associations ExpireSnapshotsOnly \
      'associations: ["harmonycatalog.ns_expire_snapshots.tbl_many_snaps"]'
    # Multiple targets in one call
    restish clo create-policy-associations ExpireSnapshotsOnly \
      'associations: ["harmonycatalog.ns_expire_snapshots.*", "harmonycatalog.ns_other.specific_table"]'

    From a JSON file:

    restish --rsh-insecure clo create-policy-associations ExpireSnapshotsOnly \
      @association.json

    where association.json contains:

    {"associations": ["harmonycatalog.ns_expire_snapshots.*"]}

    Use --rsh-insecure only when you work with untrusted HTTPS certificates. For single-table subscription APIs, see restish clo set-table-policy --help and restish clo get-association-details --help.

To schedule the policy with a cron expression, see Scheduling policies with a cron expression using the CLI. To run the policy on demand, see Running policies on demand using the CLI.

Scheduling policies with a cron expression using the CLI

On Anywhere Cloud, define a Quartz-style cron expression and optional timezone in policy resources with Restish so Cloudera Lakehouse Optimizer evaluates associated tables on a recurring schedule.

On Anywhere Cloud, use Restish for CLI scheduling steps. Configure Restish as described in CLI for Cloudera Lakehouse Optimizer.
Cron expressions define when Cloudera Lakehouse Optimizer runs the evaluation phase for schedule-based policies. Cron syntax follows the Quartz scheduler format (for example, 0 0 4 * * ? * runs daily at 04:00). For syntax details, see Quartz cron triggers or an online CRON expression generator.

Set the schedule in the base64-encoded policy arguments JSON that you pass to restish clo create-policy-definition-json or restish clo update-policy-definition-json. Include cron and, when required, timezone alongside action constants. For field examples, see JSON file and Clouderaadaptive Resources.

  1. List supported time zones for timezone in policy resources.
    restish clo ui-list-timezones
    restish clo ui-list-timezones --help
  2. Include cron and timezone in the policy resources when you create or update a policy.
  3. After associations are in place, reschedule the namespace.
    restish clo update-namespace --help

    Equivalent REST operation: PATCH /namespaces/{namespace}. See Scheduling policies with a cron expression using REST APIs.

Cloudera Lakehouse Optimizer initiates table maintenance according to the CRON schedule in the policy. For on-demand runs, see Running policies on demand using the CLI.

Running policies on demand using the CLI

On Anywhere Cloud, manually dry run or evaluate a Cloudera Lakehouse Optimizer policy for a table with Restish. Use dry run first to preview maintenance actions without executing them.

On-demand execution runs outside the cron schedule defined in the policy. Configure Restish (see CLI for Cloudera Lakehouse Optimizer), ensure the policy is associated with the table, and use administrator or operator roles (see Cloudera Lakehouse Optimizer roles and access).

Identify the table with <catalog>.<namespace>.<table> (for example, harmonycatalog.ns_expire_snapshots.tbl_many_snaps).

  1. Optional: Dry run the policy.

    Dry run returns maintenance actions that would run without submitting Spark jobs.

    restish clo dry-run-policy <POLICY NAME> \
      <CATALOG>.<NAMESPACE>.<TABLE>
    restish clo dry-run-policy ExpireSnapshotsOnly \
      harmonycatalog.ns_expire_snapshots.tbl_many_snaps

    Run restish clo dry-run --help if your synced OpenAPI exposes the operation as dry-run.

  2. Evaluate the policy on the table.

    Evaluation runs maintenance when the policy requires execution.

    restish clo evaluate-policy <POLICY NAME> \
      <CATALOG>.<NAMESPACE>.<TABLE>
    restish clo evaluate-policy ExpireSnapshotsOnly \
      harmonycatalog.ns_expire_snapshots.tbl_many_snaps

    Note the task ID in the response for the monitor step.

  3. Monitor the maintenance task.
    restish clo list-recent-tasks
    # Filter by table
    restish clo list-recent-tasks \
      --table harmonycatalog.ns_expire_snapshots.tbl_many_snaps
    # Filter by policy name
    restish clo list-recent-tasks \
      --policy ExpireSnapshotsOnly
    # Limit the number of tasks returned
    restish clo list-recent-tasks --count 2

    Retrieve one task by ID:

    restish clo get-by-id --help

    For equivalent REST steps, see Running policies on demand using REST APIs.

Performing dry runs on policies

Perform a dry run on a Cloudera Lakehouse Optimizer policy to preview maintenance actions without running them. On Anywhere Cloud, use the CLI or REST APIs.

On Anywhere Cloud, dry run generates table maintenance actions but does not initiate maintenance. Use one of the following:

For feature-level summary, see Cloudera Lakehouse Optimizer features.

Editing and deleting policies

On Anywhere Cloud, update or delete policy definitions with Restish. Operators can update policies; only administrators can delete policies. See Cloudera Lakehouse Optimizer roles and access.

Configure Restish before you run these commands. See CLI for Cloudera Lakehouse Optimizer.
  • Update an existing policy.

    Run restish clo update-policy-definition-json --help and pass updated policy JSON (JEXL script and base64-encoded arguments).

    For the same change with REST, use PATCH /policies/resource. See Define policy resources using REST APIs.

  • Delete the specified policy.

    restish clo delete-policy-definition permanently deletes the policy definition for a resource scope. Provide the policy name and scope:

    restish clo delete-policy-definition \
      <POLICY NAME> <SCOPE>

    Scope examples:

    • * — catalog level
    • harmonycatalog.ns_expire_snapshots.* — namespace level
    • harmonycatalog.ns_expire_snapshots.tbl_many_snaps — table level
    restish clo delete-policy-definition \
      ExpireSnapshotsOnly harmonycatalog.ns_expire_snapshots.*
  • Download the policy scripts, arguments, or both for a policy version before you edit a policy.
    1. Get the policy version ID.
      restish clo ui-get-policy-details <POLICY NAME>

      Copy the version UUID from result.versions[] in the output.

    2. Download that version.

      Returns the script and arguments or constants for the version.

      restish clo ui-download-policy-version \
        <POLICY NAME> <POLICY VERSION ID>

      Non-UI OpenAPI operation: restish clo download-policy-version --help.