### Wait for Cluster Creation with Custom Timeout Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md This example demonstrates creating a cluster and waiting for it to reach the RUNNING state. It specifies a custom timeout of 10 minutes for the operation. If the cluster is not running within this period, a timeout error will occur. ```java CreateCluster request = new CreateCluster() .setClusterName("test-cluster") .setSparkVersion("13.0.x-scala2.12") .setNodeTypeId("i3.xlarge") .setAutoterminationMinutes(10L) .setNumWorkers(1L); ClusterInfo cluster = workspace.clusters().create(request).get(Duration.ofMinutes(10)); ``` -------------------------------- ### Example Databricks SDK Log Output Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Illustrates typical debug log output from the Databricks SDK for Java, showing a GET request and a truncated JSON response. Sensitive data like tokens are automatically redacted. ```text 2023-03-22 21:19:21,702 [databricks.sdk][DEBUG] GET /api/2.1/clusters/list < 200 OK < { < "clusters": [ < { < "autotermination_minutes": 60, < "cluster_id": "1109-115255-s1w13zjj", < "cluster_name": "DEFAULT Test Cluster", < ... truncated for brevity < }, < "... (47 additional elements)" < ] < } ``` -------------------------------- ### Create New Feature Branch Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Create a new branch for your work before starting development. ```bash git checkout -b new-branch-name ``` -------------------------------- ### Instantiate AccountClient and List Workspaces Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Instantiate the `AccountClient` to access account-level APIs and list all associated workspaces. Requires `WorkspaceClient`, `AccountClient`, `DatabricksConfig`, `ClusterInfo`, and `ListClustersRequest` imports. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.AccountClient; import com.databricks.sdk.core.DatabricksConfig; import com.databricks.sdk.service.compute.ClusterInfo; import com.databricks.sdk.service.compute.ListClustersRequest; public class App { public static void main(String[] args) { AccountClient account = new AccountClient(); for (Workspace w : account.workspaces().list()) { System.out.println(w.getWorkspaceName()); } } } ``` -------------------------------- ### Configure Workspace and Account Clients in Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Instantiate WorkspaceClient and AccountClient using a Databricks profile. Both clients will share the same host and profile configuration. A WorkspaceClient for a different workspace can be created by specifying an additional workspace ID. ```java import com.databricks.sdk.AccountClient; import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.DatabricksConfig; ... // Both clients share the same host and profile WorkspaceClient workspace = new WorkspaceClient(new DatabricksConfig().setProfile("unified")); AccountClient account = new AccountClient(new DatabricksConfig().setProfile("unified")); // A WorkspaceClient for a different workspace under the same host and account WorkspaceClient otherWorkspace = new WorkspaceClient( new DatabricksConfig().setProfile("unified").setWorkspaceId("2345678901")); ``` -------------------------------- ### Apply Spotless Code Formatting Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Run the Spotless code formatting plugin to ensure code style consistency. This can be done via IntelliJ or the command line. ```bash mvn spotless:apply ``` -------------------------------- ### Instantiate WorkspaceClient and List Clusters Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Instantiate the `WorkspaceClient` to interact with a Databricks workspace and list all available clusters. Requires `WorkspaceClient`, `AccountClient`, `DatabricksConfig`, `ClusterInfo`, and `ListClustersRequest` imports. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.AccountClient; import com.databricks.sdk.core.DatabricksConfig; import com.databricks.sdk.service.compute.ClusterInfo; import com.databricks.sdk.service.compute.ListClustersRequest; public class App { public static void main(String[] args) { WorkspaceClient workspace = new WorkspaceClient(); for (ClusterInfo c : workspace.clusters().list(new ListClustersRequest())) { System.out.println(c.getClusterName()); } } } ``` -------------------------------- ### Import Shaded Databricks SDK for Java Classes Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Demonstrates how to import classes from a shaded JAR of the Databricks SDK for Java. Prepend 'shaded.' to all imports when using the shaded JAR. ```java import shaded.com.databricks.sdk.WorkspaceClient; import shaded.com.databricks.sdk.AccountClient; import shaded.com.databricks.sdk.core.DatabricksConfig; import shaded.com.databricks.sdk.service.compute.ClusterInfo; import shaded.com.databricks.sdk.service.compute.ListClustersRequest; ``` -------------------------------- ### Stage and Commit Changes Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Stage all changes and commit them with a descriptive message, including a sign-off. ```bash git add -A git commit -s -m "commit message here" ``` -------------------------------- ### Handle Cluster Not Found Error in Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Demonstrates how to catch a `ResourceDoesNotExist` exception when attempting to retrieve a cluster that does not exist. Ensure the `com.databricks.sdk.WorkspaceClient` is initialized. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.errors.platform.ResourceDoesNotExist; import com.databricks.sdk.service.compute.ClusterDetails; public class ErrorDemo { public static void main(String[] args) { WorkspaceClient w = new WorkspaceClient(); try { ClusterDetails c = w.clusters().get("1234-5678-9012"); } catch (ResourceDoesNotExist e) { System.out.println("Cluster not found: " + e.getMessage()); } } } ``` -------------------------------- ### Default Authentication Flow Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Instantiate `WorkspaceClient` without arguments to use the default authentication flow, which relies on Databricks configuration profiles or environment variables. ```java import com.databricks.sdk.WorkspaceClient; ... WorkspaceClient workspace = new WorkspaceClient(); workspace. // press for autocompletion ``` -------------------------------- ### Iterate Over Paginated Job Runs in Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md This snippet demonstrates how to iterate through all jobs and their runs, collecting job details, run durations, and the latest run state. It utilizes the Paginator abstraction to lazily load data. Ensure WorkspaceClient is initialized. ```java Map allJobs = new HashMap<>(); Map> durations = new HashMap<>(); Map latestState = new HashMap<>(); WorkspaceClient workspace = new WorkspaceClient(); for (BaseJob job : workspace.jobs().list(new ListJobsRequest())) { allJobs.put(job.getJobId(), job); for (BaseRun run : workspace.jobs().listRuns(new ListRunsRequest().setJobId(job.getJobId()).setExpandTasks(false))) { durations.computeIfAbsent(job.getJobId(), k -> new ArrayList<>()).add(run.getRunDuration()); if (!latestState.containsKey(job.getJobId())) { latestState.put(job.getJobId(), run); continue; } if (run.getEndTime() < latestState.get(job.getJobId()).getEndTime()) { continue; } latestState.put(job.getJobId(), run); } } // JobSummary is a custom POJO. List summary = new ArrayList<>(); for (Map.Entry entry : latestState.entrySet()) { Long jobId = entry.getKey(); BaseRun run = entry.getValue(); BaseJob job = allJobs.get(jobId); List jobDurations = durations.get(jobId); JobSummary jobSummary = new JobSummary( job.getSettings().getName(), run.getState().getResultState(), ZonedDateTime.ofInstant(Instant.ofEpochMilli(run.getEndTime()), ZoneId.of("UTC")), jobDurations.stream().mapToLong(Long::longValue).average().orElse(0) ); summary.add(jobSummary); } summary.stream() .sorted(Comparator.comparing(JobSummary::getLastFinished).reversed()) .forEach(jobSummary -> LOGGER.info("Latest: {}", jobSummary)); ``` -------------------------------- ### Build Shaded JAR for Databricks SDK for Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Builds a shaded JAR of the Databricks SDK for Java. This is useful to avoid version conflicts when using the SDK on Databricks Runtime. ```shell cd shaded mvn package ls -l target # The target directory includes a file "shaded-databricks-sdk-X.Y.Z.jar". ``` -------------------------------- ### Configure Google Service Account Authentication in Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Configure the Databricks SDK for Java to authenticate using a Google Cloud Platform service account. This is useful when running applications on GCP infrastructure or when needing to impersonate a specific service account. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.DatabricksConfig; ... DatabricksConfig config=new DatabricksConfig() .setAuthType("google-credentials") .setHost("https://my-databricks-instance.com") .setGoogleServiceAccgount("google-service-account"); WorkspaceClient workspace=new WorkspaceClient(config); ``` -------------------------------- ### Clone Databricks Java SDK Repository Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Clone the Databricks Java SDK repository to your local system after forking it. ```bash git clone git@github.com:YOUR_USER_NAME/databricks-sdk-java.git ``` -------------------------------- ### Configure Databricks Token Authentication in Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Use this snippet to configure the Databricks SDK for Java to use Databricks token authentication. Ensure you provide the correct host URL and your personal access token. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.DatabricksConfig; ... DatabricksConfig config=new DatabricksConfig() .setAuthType("pat") .setHost("https://my-databricks-instance.com") .setToken("my-token"); WorkspaceClient workspace=new WorkspaceClient(config); ``` -------------------------------- ### Add Databricks SDK for Java Dependency Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Include this dependency in your `pom.xml` to add the Databricks SDK for Java to your project. ```xml com.databricks databricks-sdk-java 0.0.1 ``` -------------------------------- ### Enable Debug HTTP Headers Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Enable this option to log HTTP headers for debugging purposes. Be cautious as headers may contain sensitive information like access tokens. The default is false. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.DatabricksConfig; ... DatabricksConfig config=new DatabricksConfig() .setDebugHeaders(true); WorkspaceClient workspace=new WorkspaceClient(config); ``` -------------------------------- ### Enable Databricks SDK Debug Logging Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Configure SLF4J logging to enable debug level for the Databricks SDK. Add this line to your log4j.properties file. ```properties log4j.logger.com.databricks.sdk=DEBUG ``` -------------------------------- ### Configure Azure Client Secret Authentication in Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Use this configuration when authenticating to Databricks using an Azure Active Directory service principal with a client secret. Ensure you have the necessary Azure details like tenant ID, client ID, and client secret. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.DatabricksConfig; ... DatabricksConfig config=new DatabricksConfig() .setAuthType("azure-client-secret") .setHost("https://my-databricks-instance.com") .setAzureTenantId("tenant-id") .setAzureClientId("client-id") .setAzureClientSecret("client-secret"); WorkspaceClient workspace=new WorkspaceClient(config); ``` -------------------------------- ### Override .databrickscfg Profile Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Use this snippet to specify a custom connection profile from your .databrickscfg file instead of the default. Ensure the profile name matches an entry in your configuration file. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.DatabricksConfig; ... DatabricksConfig config=new DatabricksConfig() .setProfile("MYPROFILE"); WorkspaceClient workspace=new WorkspaceClient(config); ``` -------------------------------- ### Push Changes to Remote Repository Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Push your committed changes to your origin branch on GitHub. ```bash git push origin branch-name ``` -------------------------------- ### Force Azure CLI Authentication in Databricks SDK for Java Source: https://github.com/databricks/databricks-sdk-java/blob/main/README.md Use this snippet to force Azure CLI authentication, bypassing other methods. Ensure your Databricks host is correctly configured. ```java import com.databricks.sdk.WorkspaceClient; import com.databricks.sdk.core.DatabricksConfig; ... // Force Azure CLI authentication — skip all other methods DatabricksConfig config = new DatabricksConfig() .setHost("https://mycompany.databricks.com") .setAuthType("azure-cli"); WorkspaceClient workspace = new WorkspaceClient(config); ``` -------------------------------- ### Automatically Sign Off Commit Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Configure git user name and email to automatically sign off commits using 'git commit -s'. ```git git commit -s -m "Your commit message" ``` -------------------------------- ### Sign Off Commit Message Source: https://github.com/databricks/databricks-sdk-java/blob/main/CONTRIBUTING.md Add a 'Signed-off-by' line to your commit message to certify compliance with contribution terms. Use your real name. ```git Signed-off-by: Joe Smith ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.