Using Spark with Cloudera AI Workbench

Connect Cloudera AI Workbench to a remote Spark Connect session running in Cloudera Data Engineering to run Spark workloads using Spark Connect.

  • You must have a Deployed Cloudera AI Experience.
  • You must have a Deployed Cloudera Data Engineering Experience.
  • You must have the Spark Connect session name.
  • You must have the Knox credentials, the [***CLIENT ID***] and the [***CLIENT SECRET***] for the deployed Cloudera Data Engineering Experience:
    CONSOLE=<CONSOLE_URL>
    KNOX=${CONSOLE/console./knox.}
    
    read -s "PASS?Password: "
    echo
    
    export HADOOP_JWT=$(curl -sk -u "<YOUR_USER>:$PASS" -D - -o /dev/null \
        "https://$KNOX/gateway/knox-cdpsso/api/v1/websso?originalUrl=https://$CONSOLE/" \
        | grep -i 'set-cookie: hadoop-jwt' \
        | sed -E 's/.*hadoop-jwt=([^;]+).*/\1/' \
        | tr -d '\r')
    
    echo "${HADOOP_JWT:0:24}..."

    Otherwise, if LDAP login is not enabled:

    1. Access the CDE console using your web browser to log in.

    2. Navigate to DevTools then select Application > Cookies.

    3. Locate the hadoop-jwt cookie and copy the long string value starting with eyJ.

  • You must fetch the Cloudera Anywhere Cloud credentials:

    CONSOLE=<CONSOLE_URL>
    curl -sk -H "Cookie: hadoop-jwt=$HADOOP_JWT" -H "Content-Type: application/json" \
      -X POST "https://$CONSOLE/api/v0/auth/access-keys/credentials" \
      -d '{"description":"spark-connect"}'
    
    Response (HTTP 201):
    
    {"client_id":"<client_id>","client_secret":"<secret>,"principal":"<principal>","issued_at":"…"}
  • Retrieve the CA certificates for the Knox endpoint from the Anywhere Cloud Console and for the Cloudera Data Engineering cluster endpoint from the Cloudera Data Engineering cluster. For information about retrieving certificates, see Trusting the CA Certificate

    Then import the certificates into the Cloudera AI Workbench as described in Managing CA certificates for Cloudera AI Workbench.

  • You must obtain the following information from Cloudera Data Engineering:
    • The Spark 3.5.4 or Spark 4.1.1 Virtual Cluster Jobs API URL of a Cloudera Data Engineering Experience from Virtual Cluster Details > Actions. Copy the Jobs API URL.
    • The Cloudera Anywhere Cloud Console URL.

      You must not have a trailing slash in the URL.

  1. Create a Cloudera Data Engineering Spark Connect Session.
    1. Select Deployed Experiences in the left navigation pane on the Anywhere Cloud Console.
      The list of deployed experiences is displayed.
    2. Search for the required Cloudera Data Engineering instance.
      Verify that the status of the instance is Deployed.
    3. Click on the URL in the UI URL column.

      The Cloudera Data Engineering home page is displayed.

    4. Go to Sessions in the left navigation menu and click Create Session.
      1. Enter a Name for the session.
      2. Select Spark Connect for the Type of the Session.
      3. Provide other configuration details as required.
      4. Click Create to create the Session with Spark Connect Type.

      When the Spark Connect Session is ready, continue to the deployed Cloudera AI Workbench.

  2. Optional: Perform the following steps if you use self-signed or separate Certificate Authorities between the Cloudera AI and the Cloudera Data Engineering.
    1. Select Deployed Experiences in the left navigation pane on the Anywhere Cloud Console.
      The list of deployed experiences is displayed.
    2. Search for the required Cloudera AI instance.
      Verify that the status of the instance is Deployed.
    3. Click on the URL in the UI URL column.

      The authentication window for the Cloudera AI UI is displayed.

    4. Select AI Workbenches in the left navigation menu.
    5. Select the View Details Actions menu next to the required Cloudera AI Workbench.
      Figure 1. Viewing details for the required Cloudera AI Workbench
    6. Upload the Certificate Authority certificate used by the Cloudera Data Engineering.
      Figure 2. Certificate upload
    7. Refresh the certificates for this Cloudera AI Workbench instance.
      • Select the Refresh Certificate option from the menu.
      Figure 3. Refreshing certificates
  3. Create Cloudera AI Workbench Session and access Cloudera Data Engineering Spark Connect Session.
    1. Select Deployed Experiences in the left navigation pane on the Anywhere Cloud Console.
      The list of deployed experiences is displayed.
    2. Search for the required Cloudera AI instance.
      Verify that the status of the instance is Deployed.
    3. Click on the URL in the UI URL column.

      The authentication window for the Cloudera AI UI is displayed.

    4. Provide the required credentials and log in to the Cloudera AI UI.

      The Cloudera AI home page is displayed.

    5. Select Projects in the left navigation menu.
    1. Click New Project
    2. Specify the PySparkConnect Template in the Initial Setup section.
    3. Update the following details in the simple_config.py configuration details:
      • vcluster-endpoint - Specify the Virtual Cluster Jobs API URL.

      • cdp-endpoint - The cdp-endpoint value is the same as the Cloudera Anywhere Cloud Console URL.

        You must not have a trailing slash in the URL.

      • You must have the Knox credentials, the [***CLIENT ID***] and the [***CLIENT SECRET***] for the deployed Cloudera Data Engineering Experience.
      • SESSION_NAME, as defined in step 1.d.i
    4. Create a new Cloudera AI session.
    1. Go to your project's Overview page.
    2. Click New Session.
    3. Enable the Spark Connect Addon.

      For Spark 4.1.1 use Python 3.14 Runtime and for Spark 3.5.4, use a Python 3.11 Runtime.

    4. Run the simple_config.py script.
    5. Run the spark_connect_example.py script.