Java SDK
We now present a high-level Java API as a type-safe and gentle wrapper for the OpenMetadata backend. The open-source OpenMetadata SDK for Java simplifies provisioning, managing, and using OpenMetadata resources from the Java application code.The OpenMetadata SDK for Java libraries build on top of the underlying OpenMetadata REST API, allows you to use those APIs through familiar Java paradigms. However, you can always use the REST API directly from Java code, if you prefer to do so. You can find the source code for the OpenMetadata libraries in the GitHub repository. As an open-source project, contributions are always welcome! You can add the below Maven Dependency for the OpenMetadata Java SDK.
Connect to the OpenMetadata Server
To connect to your OpenMetadata server, you need:- Server URL: The URL where your OpenMetadata instance is running, ending in
/api. For example,http://localhost:8585/api. - Access token: A JSON Web Token (JWT) for a user or bot. See Authentication to learn how to get one.
header adds a custom header to every request:
Authenticate with a JWT Token
The Java SDK authenticates with a JWT access token that you pass toaccessToken(...). This is the same for every sign-in method on your OpenMetadata server, including Google, Okta, Auth0, Azure, and custom OpenID Connect (OIDC). Generate a bot token or a personal access token in OpenMetadata and use it here.
If your server doesn’t require authentication, leave out accessToken(...).
Use the Fluent API
The fluent classes, such asTables, Users, and Teams, work with a default client. Register your client once with OM.init, and the fluent classes use it:
Use the Service Clients
Every entity type has a service on the client, such asclient.tables(), client.users(), and client.dashboards(). These services offer methods such as create, get, getByName, list, update, delete, and restore. Below are some examples:
- Create a table
- Get a table by fully qualified name
- Search
Handle Errors
When the server returns an error, the SDK throws anOpenMetadataException. Use getStatusCode() to see which error it was:
Bulk Create with Conflict Outcomes
TestCases and GlossaryTerms in org.openmetadata.sdk.fluent can create several entities in one request and return a typed BulkCreateResult with an outcome for every input.
SKIP: The default. Inputs whose fully qualified name already exists, or that repeat inside the request, are reported as skipped. All other valid inputs are created.FAIL: Conflicting inputs are reported as failed. All other valid inputs are still created. This is not an all-or-nothing request.
getCreatedCount(),getSkippedCount(), andgetFailedCount(): Totals for the request.getResults(): One outcome per input, in request order. Each has an index, a status, and the fully qualified name. Created entities also have an ID. Skipped and failed inputs have a reason (ALREADY_EXISTS,DUPLICATE_IN_REQUEST, orVALIDATION_ERROR) and a message.
OpenMetadataException. Bulk create requires a server that supports the onConflict parameter. The service overload client.testCases().createMany(requests) is unchanged and still returns the list of created entities.