-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Changes This PR makes several changes to examples and documentation for the Java SDK. 1. Add documentation comments for the Wait class and methods, describing when they are returned and how to use them to retrieve API responses. 2. Check in examples from https://docs.databricks.com/en/dev-tools/sdk-java.html as a reference for @PaulCornellDB for maintaining the docs page. This way, examples are updated as necessary to account for any changes in the SDK. 3. Refreshed all existing examples to work with the current version of the Java SDK. 4. Refactored all non-Spring Boot examples into a single maven project in `examples/docs` so that users can find all relevant examples in a single directory (examples/docs/src/main/java/com/databricks/sdk/examples). This also means that there are fewer `pom.xml` files that need to be maintained. 5. Bump the version of the Java SDK used in the example maven projects as part of the release flow. Later, as part of the release process, we may need to set the `SNAPSHOT` version to make it possible to test local changes to the SDK more easily. ## Tests - [x] Compilation of the maven projects in the `examples/` directory passes. - [ ] Unable to test the release workflow (as that forcibly resets to the last commit on main).
- Loading branch information
Showing
18 changed files
with
213 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.databricks</groupId> | ||
<artifactId>docs</artifactId> | ||
<version>0.0.1</version> | ||
|
||
<name>docs</name> | ||
<url>https://github.com/databricks/databricks-sdk-java</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-reload4j</artifactId> | ||
<version>2.0.7</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.databricks</groupId> | ||
<artifactId>databricks-sdk-java</artifactId> | ||
<version>0.14.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
examples/docs/src/main/java/com/databricks/example/CreateClusterExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.databricks.sdk.examples; | ||
|
||
import com.databricks.sdk.WorkspaceClient; | ||
import com.databricks.sdk.service.compute.ClusterDetails; | ||
import com.databricks.sdk.service.compute.CreateCluster; | ||
import com.databricks.sdk.service.compute.CreateClusterResponse; | ||
import com.databricks.sdk.support.Wait; | ||
import java.time.Duration; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class CreateClusterExample { | ||
public static void main(String[] args) throws TimeoutException { | ||
WorkspaceClient w = new WorkspaceClient(); | ||
|
||
// Creating a cluster returns immediately. | ||
Wait<ClusterDetails, CreateClusterResponse> wait = | ||
w.clusters() | ||
.create( | ||
new CreateCluster() | ||
.setClusterName("my-cluster") | ||
.setSparkVersion("12.2.x-scala2.12") | ||
.setNodeTypeId("i3.xlarge") | ||
.setAutoterminationMinutes(15L) | ||
.setNumWorkers(1L)); | ||
|
||
// Creating a cluster is a long-running operation. Wait for the cluster to finish | ||
// starting by calling the Wait.get() method. This waits for 20 minutes by default. | ||
ClusterDetails c = wait.get(); | ||
|
||
// Wait for a custom duration with the Wait.get(Duration timeout) method. | ||
c = wait.get(Duration.ofMinutes(10)); | ||
|
||
System.out.println( | ||
"View the cluster at " | ||
+ w.config().getHost() | ||
+ "#setting/clusters/" | ||
+ c.getClusterId() | ||
+ "/configuration\n"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
examples/docs/src/main/java/com/databricks/example/CreateJobExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.databricks.sdk.examples; | ||
|
||
import com.databricks.sdk.WorkspaceClient; | ||
import com.databricks.sdk.service.jobs.*; | ||
import java.util.*; | ||
|
||
public class CreateJobExample { | ||
public static void main(String[] args) { | ||
System.out.println("Some short name for the job (for example, my-job):"); | ||
Scanner in = new Scanner(System.in); | ||
String jobName = in.nextLine(); | ||
|
||
System.out.println("Some short description for the job (for example, My job):"); | ||
String description = in.nextLine(); | ||
|
||
System.out.println( | ||
"ID of the existing cluster in the workspace to run the job on (for example, 1234-567890-ab123cd4):"); | ||
String existingClusterId = in.nextLine(); | ||
|
||
System.out.println( | ||
"Workspace path of the notebook to run (for example, /Users/someone@example.com/my-notebook):"); | ||
String notebookPath = in.nextLine(); | ||
|
||
System.out.println("Some key to apply to the job's tasks (for example, my-key): "); | ||
String taskKey = in.nextLine(); | ||
|
||
System.out.println("Attempting to create the job. Please wait..."); | ||
|
||
WorkspaceClient w = new WorkspaceClient(); | ||
|
||
Map<String, String> map = new HashMap<>(); | ||
|
||
Collection<Task> tasks = | ||
Arrays.asList( | ||
new Task() | ||
.setDescription(description) | ||
.setExistingClusterId(existingClusterId) | ||
.setNotebookTask( | ||
new NotebookTask() | ||
.setBaseParameters(map) | ||
.setNotebookPath(notebookPath) | ||
.setSource(Source.WORKSPACE)) | ||
.setTaskKey(taskKey)); | ||
|
||
CreateResponse j = w.jobs().create(new CreateJob().setName(jobName).setTasks(tasks)); | ||
|
||
System.out.println("View the job at " + w.config().getHost() + "/#job/" + j.getJobId()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/docs/src/main/java/com/databricks/example/DeleteClusterExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.databricks.sdk.examples; | ||
|
||
import com.databricks.sdk.WorkspaceClient; | ||
import java.util.Scanner; | ||
|
||
public class DeleteClusterExample { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("ID of cluster to delete (for example, 1234-567890-ab123cd4):"); | ||
|
||
Scanner in = new Scanner(System.in); | ||
String c_id = in.nextLine(); | ||
WorkspaceClient w = new WorkspaceClient(); | ||
|
||
w.clusters().permanentDelete(c_id); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/docs/src/main/java/com/databricks/example/ListAccountGroupsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.databricks.sdk.examples; | ||
|
||
import com.databricks.sdk.AccountClient; | ||
import com.databricks.sdk.service.iam.Group; | ||
import com.databricks.sdk.service.iam.ListAccountGroupsRequest; | ||
|
||
public class ListAccountGroupsExample { | ||
public static void main(String[] args) { | ||
AccountClient a = new AccountClient(); | ||
|
||
for (Group g : a.groups().list((new ListAccountGroupsRequest()))) { | ||
System.out.println(g.getDisplayName()); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/docs/src/main/java/com/databricks/example/ListClustersExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.databricks.sdk.examples; | ||
|
||
import com.databricks.sdk.WorkspaceClient; | ||
import com.databricks.sdk.service.compute.ClusterDetails; | ||
import com.databricks.sdk.service.compute.ListClustersRequest; | ||
|
||
public class ListClustersExample { | ||
public static void main(String[] args) { | ||
WorkspaceClient w = new WorkspaceClient(); | ||
|
||
for (ClusterDetails c : w.clusters().list(new ListClustersRequest())) { | ||
System.out.println(c.getClusterName()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.