Manage schemas directly through the Schema Registry REST API to list schemas, register
schema versions, check compatibility, and perform other schema operations.
The Schema Registry REST API gives you direct access to the schemas stored in Schema Registry.
Use the REST API when you need to run schema operations from scripts or custom tooling, or when
you need to inspect or manage schemas without access to the UI.
To access the API and manage schemas, you get the Schema Registry URL and client credentials
from Anywhere Cloud Console and exchange the credentials for a bearer token using
the OAuth token endpoint. You obtain the CA certificates from the Kafka client configuration
bundle that Cloudera Surveyor provides on the Client
Configurations tab.
Perform the credential provisioning steps in this task while logged in to Anywhere Cloud Console as a user who has the Ranger policies required for the API
calls you want to perform. The credentials you create inherit that user's access.
This task walks you through some basic schema management operations with example API calls.
If you are unsure which Schema Registry Ranger policies you need, log in as a user who is
added to a policy that grants full access to Schema Registry.
You must have access to a Bash-compatible shell environment with curl and
jq.
Get the Schema Registry URL from Anywhere Cloud Console.
In Anywhere Cloud Console, go to Admin Center > Apps > Deployed Engines.
Find and click the entry for your Schema Registry instance.
In the Endpoints table, get the URL from the
landingPage row.
You can copy the URL with the option. The URL includes
the /api/v1 suffix.
Assign the URL you copied to an environment variable.
Gather the values required for credential provisioning.
Log in to Anywhere Cloud Console.
Look up and record your domain from your Anywhere Cloud Console console
URL.
Your domain is the portion of the URL that comes after console.. For
example, if your console URL is https://console.my-awc.cloudera.com, your
domain is my-awc.cloudera.com.
Obtain and record the hadoop-jwt session cookie from your browser's
developer tools.
To do this, open browser developer tools and navigate to the
Cookies section. Find the hadoop-jwt cookie and
record its value.
To open browser developer tools:
Chrome: Press F12 and go to Application > Cookies.
Firefox: Press F12 and go to Storage > Cookies.
Safari: Press Cmd+Option+I and go to Storage > Cookies.
Open your local terminal and set your domain and hadoop-jwt session
cookie as environment variables.
The following command prompts you to enter each value. The cookie value is not displayed
as you type.
Client credentials are used by applications to authenticate directly with the OAuth server.
You can request client credentials through a provisioning endpoint using your session
cookie.
Call the credential provisioning endpoint and save the response to a file.
The client_id and client_secret fields are your client
credentials. The principal field is the user principal those credentials
are bound to. It matches the user you were logged in as in Anywhere Cloud Console when you obtained the hadoop-jwt session
cookie used to call the provisioning endpoint. When your client connects, Apache Ranger
authorizes it as this principal. The example shows admin; in your
environment, the value is your Anywhere Cloud Console login username. The
issued_at field is informational only.
Optional: Save the client credentials from credentials.json to a password
manager or another secure location for future use.
Client credentials are long-lived and can be reused for other clients or programmatic
API calls.
Access Cloudera Surveyor.
In Anywhere Cloud Console, go to Streams
Messaging
Find and click the entry for your Cloudera Surveyor
instance.
Download the client configuration bundle from Cloudera Surveyor.
In Cloudera Surveyor, go to Clusters and
select your Kafka cluster.
Go to the Client Configurations tab.
Click Download All.
Extract the archive to a working directory and keep all files in the same
directory.
Some paths in the configuration files are relative, so all files must remain in the same
directory.
Exchange your client credentials for a bearer token.
Set your client credentials as environment variables.
Use the client_id and client_secret values that you
recorded from credentials.json. The following command prompts you to
enter each value. The client secret is not displayed as you type.
Request a bearer token from the OAuth token endpoint and store it in an environment
variable.
Run the following command from the directory where you extracted the client configuration
bundle. The command stores the token in the ACCESS_TOKEN variable and does
not print it.
Perform basic schema management operations with the Schema Registry REST API.
With SR_URL, ACCESS_TOKEN, and
ca-bundle.crt from earlier steps, complete the following substeps in order.
They cover common schema management operations. You will create and evolve an example schema
named my-schema.
The response is a JSON object with an entities array that lists the
schemas you are authorized to view. On a fresh registry, the response is
{"entities":[]}.
The response shows "version":2 and the evolved schema text.
You accessed Schema Registry through its REST API and performed common schema management
operations: you created a schema entity, registered schema versions, checked compatibility
before evolving the schema, and retrieved versions. You can now use the same authentication flow
and CA certificates to run any Schema Registry REST API operation.
For the full endpoint catalog, see the Schema Registry REST API reference.
If your bearer token expires, obtain a new one by doing Step 6.b.