From 4ee25fb66c5ec713e5a5807079d3168e70ee1ca2 Mon Sep 17 00:00:00 2001 From: "databricks-ci-ghec-2[bot]" <184307802+databricks-ci-ghec-2[bot]@users.noreply.github.com> Date: Fri, 27 Feb 2026 09:43:29 +0000 Subject: [PATCH] Update SDK to bde0ceb3e78e7f24d00713e088a77e0ad008cbc5 --- .codegen/_openapi_sha | 2 +- .gitattributes | 15 ++ NEXT_CHANGELOG.md | 4 +- .../sdk/service/apps/AppResource.java | 16 ++ .../sdk/service/apps/AppResourcePostgres.java | 74 ++++++++ ...AppResourcePostgresPostgresPermission.java | 10 ++ .../networking/CreateEndpointRequest.java | 5 +- .../networking/ListEndpointsRequest.java | 4 +- .../postgres/CreateDatabaseOperation.java | 162 ++++++++++++++++++ .../postgres/CreateDatabaseRequest.java | 87 ++++++++++ .../sdk/service/postgres/Database.java | 124 ++++++++++++++ .../postgres/DatabaseDatabaseSpec.java | 74 ++++++++ .../postgres/DatabaseDatabaseStatus.java | 62 +++++++ .../postgres/DatabaseOperationMetadata.java | 28 +++ .../postgres/DeleteDatabaseOperation.java | 161 +++++++++++++++++ .../postgres/DeleteDatabaseRequest.java | 44 +++++ .../service/postgres/GetDatabaseRequest.java | 44 +++++ .../postgres/ListDatabasesRequest.java | 79 +++++++++ .../postgres/ListDatabasesResponse.java | 60 +++++++ .../sdk/service/postgres/PostgresAPI.java | 54 ++++++ .../sdk/service/postgres/PostgresImpl.java | 87 ++++++++++ .../sdk/service/postgres/PostgresService.java | 19 ++ .../postgres/UpdateDatabaseOperation.java | 162 ++++++++++++++++++ .../postgres/UpdateDatabaseRequest.java | 85 +++++++++ 24 files changed, 1458 insertions(+), 4 deletions(-) create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgres.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgresPostgresPermission.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseOperation.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseRequest.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/Database.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseSpec.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseStatus.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseOperationMetadata.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseOperation.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseRequest.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetDatabaseRequest.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesRequest.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesResponse.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseOperation.java create mode 100755 databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseRequest.java diff --git a/.codegen/_openapi_sha b/.codegen/_openapi_sha index 74a1330dc..4aecc500a 100755 --- a/.codegen/_openapi_sha +++ b/.codegen/_openapi_sha @@ -1 +1 @@ -1455a7a0955cf9d56364646fe54cdc1b143a2829 \ No newline at end of file +bde0ceb3e78e7f24d00713e088a77e0ad008cbc5 \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index aa25358e3..2510002e8 100755 --- a/.gitattributes +++ b/.gitattributes @@ -74,6 +74,8 @@ databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourceGen databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourceGenieSpaceGenieSpacePermission.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourceJob.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourceJobJobPermission.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgres.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgresPostgresPermission.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourceSecret.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourceSecretSecretPermission.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourceServingEndpoint.java linguist-generated=true @@ -2152,16 +2154,24 @@ databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/BranchStat databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/BranchStatusState.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateBranchOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateBranchRequest.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseOperation.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateEndpointOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateEndpointRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateProjectOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateProjectRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateRoleOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateRoleRequest.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/Database.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseCredential.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseSpec.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseStatus.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseOperationMetadata.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabricksServiceExceptionWithDetailsProto.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteBranchOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteBranchRequest.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseOperation.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteEndpointOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteEndpointRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteProjectOperation.java linguist-generated=true @@ -2181,6 +2191,7 @@ databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/EndpointTy databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ErrorCode.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GenerateDatabaseCredentialRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetBranchRequest.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetDatabaseRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetEndpointRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetOperationRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetProjectRequest.java linguist-generated=true @@ -2188,6 +2199,8 @@ databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetRoleReq databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/InitialEndpointSpec.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListBranchesRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListBranchesResponse.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesRequest.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesResponse.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListEndpointsRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListEndpointsResponse.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListProjectsRequest.java linguist-generated=true @@ -2217,6 +2230,8 @@ databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/RoleRoleSp databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/RoleRoleStatus.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateBranchOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateBranchRequest.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseOperation.java linguist-generated=true +databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateEndpointOperation.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateEndpointRequest.java linguist-generated=true databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateProjectOperation.java linguist-generated=true diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 9f44d8ca5..6530b6261 100755 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -16,4 +16,6 @@ * Add `dataframeSchema`, `filterCondition` and `transformationSql` fields for `com.databricks.sdk.service.ml.DeltaTableSource`. * Add `environmentVersion` field for `com.databricks.sdk.service.pipelines.PipelinesEnvironment`. * Add `resetCheckpointSelection` field for `com.databricks.sdk.service.pipelines.StartUpdate`. -* [Breaking] Remove `oauth2AppClientId` and `oauth2AppIntegrationId` fields for `com.databricks.sdk.service.apps.Space`. \ No newline at end of file +* [Breaking] Remove `oauth2AppClientId` and `oauth2AppIntegrationId` fields for `com.databricks.sdk.service.apps.Space`. +* Add `createDatabase()`, `deleteDatabase()`, `getDatabase()`, `listDatabases()` and `updateDatabase()` methods for `workspaceClient.postgres()` service. +* Add `postgres` field for `com.databricks.sdk.service.apps.AppResource`. \ No newline at end of file diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResource.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResource.java index 451b240fa..f2dffc5ae 100755 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResource.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResource.java @@ -37,6 +37,10 @@ public class AppResource { @JsonProperty("name") private String name; + /** */ + @JsonProperty("postgres") + private AppResourcePostgres postgres; + /** */ @JsonProperty("secret") private AppResourceSecret secret; @@ -116,6 +120,15 @@ public String getName() { return name; } + public AppResource setPostgres(AppResourcePostgres postgres) { + this.postgres = postgres; + return this; + } + + public AppResourcePostgres getPostgres() { + return postgres; + } + public AppResource setSecret(AppResourceSecret secret) { this.secret = secret; return this; @@ -164,6 +177,7 @@ public boolean equals(Object o) { && Objects.equals(genieSpace, that.genieSpace) && Objects.equals(job, that.job) && Objects.equals(name, that.name) + && Objects.equals(postgres, that.postgres) && Objects.equals(secret, that.secret) && Objects.equals(servingEndpoint, that.servingEndpoint) && Objects.equals(sqlWarehouse, that.sqlWarehouse) @@ -180,6 +194,7 @@ public int hashCode() { genieSpace, job, name, + postgres, secret, servingEndpoint, sqlWarehouse, @@ -196,6 +211,7 @@ public String toString() { .add("genieSpace", genieSpace) .add("job", job) .add("name", name) + .add("postgres", postgres) .add("secret", secret) .add("servingEndpoint", servingEndpoint) .add("sqlWarehouse", sqlWarehouse) diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgres.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgres.java new file mode 100755 index 000000000..f16acb6a7 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgres.java @@ -0,0 +1,74 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.apps; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; + +@Generated +public class AppResourcePostgres { + /** */ + @JsonProperty("branch") + private String branch; + + /** */ + @JsonProperty("database") + private String database; + + /** */ + @JsonProperty("permission") + private AppResourcePostgresPostgresPermission permission; + + public AppResourcePostgres setBranch(String branch) { + this.branch = branch; + return this; + } + + public String getBranch() { + return branch; + } + + public AppResourcePostgres setDatabase(String database) { + this.database = database; + return this; + } + + public String getDatabase() { + return database; + } + + public AppResourcePostgres setPermission(AppResourcePostgresPostgresPermission permission) { + this.permission = permission; + return this; + } + + public AppResourcePostgresPostgresPermission getPermission() { + return permission; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AppResourcePostgres that = (AppResourcePostgres) o; + return Objects.equals(branch, that.branch) + && Objects.equals(database, that.database) + && Objects.equals(permission, that.permission); + } + + @Override + public int hashCode() { + return Objects.hash(branch, database, permission); + } + + @Override + public String toString() { + return new ToStringer(AppResourcePostgres.class) + .add("branch", branch) + .add("database", database) + .add("permission", permission) + .toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgresPostgresPermission.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgresPostgresPermission.java new file mode 100755 index 000000000..e3fc9d382 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/apps/AppResourcePostgresPostgresPermission.java @@ -0,0 +1,10 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.apps; + +import com.databricks.sdk.support.Generated; + +@Generated +public enum AppResourcePostgresPostgresPermission { + CAN_CONNECT_AND_CREATE, +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/CreateEndpointRequest.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/CreateEndpointRequest.java index bfe97984e..1f75b7530 100755 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/CreateEndpointRequest.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/CreateEndpointRequest.java @@ -14,7 +14,10 @@ public class CreateEndpointRequest { @JsonProperty("endpoint") private Endpoint endpoint; - /** */ + /** + * The parent resource name of the account under which the endpoint is created. Format: + * `accounts/{account_id}`. + */ @JsonIgnore private String parent; public CreateEndpointRequest setEndpoint(Endpoint endpoint) { diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/ListEndpointsRequest.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/ListEndpointsRequest.java index 9e529b595..80b7354dd 100755 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/ListEndpointsRequest.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/networking/ListEndpointsRequest.java @@ -20,7 +20,9 @@ public class ListEndpointsRequest { @QueryParam("page_token") private String pageToken; - /** */ + /** + * The parent resource name of the account to list endpoints for. Format: `accounts/{account_id}`. + */ @JsonIgnore private String parent; public ListEndpointsRequest setPageSize(Long pageSize) { diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseOperation.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseOperation.java new file mode 100755 index 000000000..47292df1d --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseOperation.java @@ -0,0 +1,162 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.core.DatabricksException; +import com.databricks.sdk.core.utils.SerDeUtils; +import com.databricks.sdk.service.common.lro.LroOptions; +import com.databricks.sdk.support.Generated; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.Duration; +import java.util.Optional; +import java.util.concurrent.TimeoutException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Wrapper for interacting with a long-running createDatabase operation. Provides methods to wait + * for completion, check status, cancel, and access metadata. + */ +@Generated +public class CreateDatabaseOperation { + private static final Logger LOG = LoggerFactory.getLogger(CreateDatabaseOperation.class); + + private final PostgresService impl; + private Operation operation; + private final ObjectMapper objectMapper; + + public CreateDatabaseOperation(PostgresService impl, Operation operation) { + this.impl = impl; + this.operation = operation; + this.objectMapper = SerDeUtils.createMapper(); + } + + /** + * Wait for the operation to complete and return the resulting Database. Waits indefinitely if no + * timeout is specified. + * + * @return the created Database + * @throws TimeoutException if the operation doesn't complete within the timeout + * @throws DatabricksException if the operation fails + */ + public Database waitForCompletion() throws TimeoutException { + return waitForCompletion(Optional.empty()); + } + + /** + * Wait for the operation to complete and return the resulting Database. + * + * @param options the options for configuring the wait behavior, can be empty for defaults + * @return the created Database + * @throws TimeoutException if the operation doesn't complete within the timeout + * @throws DatabricksException if the operation fails + */ + public Database waitForCompletion(Optional options) throws TimeoutException { + Optional timeout = options.flatMap(LroOptions::getTimeout); + long deadline = + timeout.isPresent() + ? System.currentTimeMillis() + timeout.get().toMillis() + : Long.MAX_VALUE; + String statusMessage = "polling operation..."; + int attempt = 1; + + while (System.currentTimeMillis() < deadline) { + // Refresh the operation state + refreshOperation(); + + if (operation.getDone() != null && operation.getDone()) { + // Operation completed, check for success or failure + if (operation.getError() != null) { + String errorMsg = "unknown error"; + if (operation.getError().getMessage() != null + && !operation.getError().getMessage().isEmpty()) { + errorMsg = operation.getError().getMessage(); + } + + if (operation.getError().getErrorCode() != null) { + errorMsg = String.format("[%s] %s", operation.getError().getErrorCode(), errorMsg); + } + + throw new DatabricksException("Operation failed: " + errorMsg); + } + + // Operation completed successfully, unmarshal response + if (operation.getResponse() == null) { + throw new DatabricksException("Operation completed but no response available"); + } + + try { + JsonNode responseJson = objectMapper.valueToTree(operation.getResponse()); + return objectMapper.treeToValue(responseJson, Database.class); + } catch (JsonProcessingException e) { + throw new DatabricksException( + "Failed to unmarshal database response: " + e.getMessage(), e); + } + } + + // Operation still in progress, wait before polling again + String prefix = String.format("operation=%s", operation.getName()); + int sleep = Math.min(attempt, 10); // sleep 10s max per attempt + LOG.info("{}: operation in progress (sleeping ~{}s)", prefix, sleep); + + try { + Thread.sleep((long) (sleep * 1000L + Math.random() * 1000)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new DatabricksException("Current thread was interrupted", e); + } + attempt++; + } + + String timeoutMessage = + timeout.isPresent() + ? String.format("Operation timed out after %s: %s", timeout.get(), statusMessage) + : String.format("Operation timed out: %s", statusMessage); + throw new TimeoutException(timeoutMessage); + } + + /** + * Get the operation name. + * + * @return the operation name + */ + public String getName() { + return operation.getName(); + } + + /** + * Get the operation metadata. + * + * @return the operation metadata, or null if not available + * @throws DatabricksException if the metadata cannot be deserialized + */ + public DatabaseOperationMetadata getMetadata() { + if (operation.getMetadata() == null) { + return null; + } + + try { + JsonNode metadataJson = objectMapper.valueToTree(operation.getMetadata()); + return objectMapper.treeToValue(metadataJson, DatabaseOperationMetadata.class); + } catch (JsonProcessingException e) { + throw new DatabricksException("Failed to unmarshal operation metadata: " + e.getMessage(), e); + } + } + + /** + * Check if the operation is done. This method refreshes the operation state before checking. + * + * @return true if the operation is complete, false otherwise + * @throws DatabricksException if the status check fails + */ + public boolean isDone() { + refreshOperation(); + return operation.getDone() != null && operation.getDone(); + } + + /** Refresh the operation state by polling the server. */ + private void refreshOperation() { + operation = impl.getOperation(new GetOperationRequest().setName(operation.getName())); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseRequest.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseRequest.java new file mode 100755 index 000000000..d8d655ff9 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/CreateDatabaseRequest.java @@ -0,0 +1,87 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.QueryParam; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; + +@Generated +public class CreateDatabaseRequest { + /** The desired specification of a Database. */ + @JsonProperty("database") + private Database database; + + /** + * The ID to use for the Database, which will become the final component of the database's + * resource name. This ID becomes the database name in postgres. + * + *

This value should be 4-63 characters, and only use characters available in DNS names, as + * defined by RFC-1123 + * + *

If database_id is not specified in the request, it is generated automatically. + */ + @JsonIgnore + @QueryParam("database_id") + private String databaseId; + + /** + * The Branch where this Database will be created. Format: + * projects/{project_id}/branches/{branch_id} + */ + @JsonIgnore private String parent; + + public CreateDatabaseRequest setDatabase(Database database) { + this.database = database; + return this; + } + + public Database getDatabase() { + return database; + } + + public CreateDatabaseRequest setDatabaseId(String databaseId) { + this.databaseId = databaseId; + return this; + } + + public String getDatabaseId() { + return databaseId; + } + + public CreateDatabaseRequest setParent(String parent) { + this.parent = parent; + return this; + } + + public String getParent() { + return parent; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CreateDatabaseRequest that = (CreateDatabaseRequest) o; + return Objects.equals(database, that.database) + && Objects.equals(databaseId, that.databaseId) + && Objects.equals(parent, that.parent); + } + + @Override + public int hashCode() { + return Objects.hash(database, databaseId, parent); + } + + @Override + public String toString() { + return new ToStringer(CreateDatabaseRequest.class) + .add("database", database) + .add("databaseId", databaseId) + .add("parent", parent) + .toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/Database.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/Database.java new file mode 100755 index 000000000..6fc91dde3 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/Database.java @@ -0,0 +1,124 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.protobuf.Timestamp; +import java.util.Objects; + +/** Database represents a Postgres database within a Branch. */ +@Generated +public class Database { + /** A timestamp indicating when the database was created. */ + @JsonProperty("create_time") + private Timestamp createTime; + + /** + * The resource name of the database. Format: + * projects/{project_id}/branches/{branch_id}/databases/{database_id} + */ + @JsonProperty("name") + private String name; + + /** The branch containing this database. Format: projects/{project_id}/branches/{branch_id} */ + @JsonProperty("parent") + private String parent; + + /** The desired state of the Database. */ + @JsonProperty("spec") + private DatabaseDatabaseSpec spec; + + /** The observed state of the Database. */ + @JsonProperty("status") + private DatabaseDatabaseStatus status; + + /** A timestamp indicating when the database was last updated. */ + @JsonProperty("update_time") + private Timestamp updateTime; + + public Database setCreateTime(Timestamp createTime) { + this.createTime = createTime; + return this; + } + + public Timestamp getCreateTime() { + return createTime; + } + + public Database setName(String name) { + this.name = name; + return this; + } + + public String getName() { + return name; + } + + public Database setParent(String parent) { + this.parent = parent; + return this; + } + + public String getParent() { + return parent; + } + + public Database setSpec(DatabaseDatabaseSpec spec) { + this.spec = spec; + return this; + } + + public DatabaseDatabaseSpec getSpec() { + return spec; + } + + public Database setStatus(DatabaseDatabaseStatus status) { + this.status = status; + return this; + } + + public DatabaseDatabaseStatus getStatus() { + return status; + } + + public Database setUpdateTime(Timestamp updateTime) { + this.updateTime = updateTime; + return this; + } + + public Timestamp getUpdateTime() { + return updateTime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Database that = (Database) o; + return Objects.equals(createTime, that.createTime) + && Objects.equals(name, that.name) + && Objects.equals(parent, that.parent) + && Objects.equals(spec, that.spec) + && Objects.equals(status, that.status) + && Objects.equals(updateTime, that.updateTime); + } + + @Override + public int hashCode() { + return Objects.hash(createTime, name, parent, spec, status, updateTime); + } + + @Override + public String toString() { + return new ToStringer(Database.class) + .add("createTime", createTime) + .add("name", name) + .add("parent", parent) + .add("spec", spec) + .add("status", status) + .add("updateTime", updateTime) + .toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseSpec.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseSpec.java new file mode 100755 index 000000000..3c0f98f1c --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseSpec.java @@ -0,0 +1,74 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; + +@Generated +public class DatabaseDatabaseSpec { + /** + * The name of the Postgres database. + * + *

This expects a valid Postgres identifier as specified in the link below. + * https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS Required + * when creating the Database. + * + *

To rename, pass a valid postgres identifier when updating the Database. + */ + @JsonProperty("postgres_database") + private String postgresDatabase; + + /** + * The name of the role that owns the database. Format: + * projects/{project_id}/branches/{branch_id}/roles/{role_id} + * + *

To change the owner, pass valid existing Role name when updating the Database + * + *

A database always has an owner. + */ + @JsonProperty("role") + private String role; + + public DatabaseDatabaseSpec setPostgresDatabase(String postgresDatabase) { + this.postgresDatabase = postgresDatabase; + return this; + } + + public String getPostgresDatabase() { + return postgresDatabase; + } + + public DatabaseDatabaseSpec setRole(String role) { + this.role = role; + return this; + } + + public String getRole() { + return role; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DatabaseDatabaseSpec that = (DatabaseDatabaseSpec) o; + return Objects.equals(postgresDatabase, that.postgresDatabase) + && Objects.equals(role, that.role); + } + + @Override + public int hashCode() { + return Objects.hash(postgresDatabase, role); + } + + @Override + public String toString() { + return new ToStringer(DatabaseDatabaseSpec.class) + .add("postgresDatabase", postgresDatabase) + .add("role", role) + .toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseStatus.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseStatus.java new file mode 100755 index 000000000..80a25ed7b --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseDatabaseStatus.java @@ -0,0 +1,62 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; + +@Generated +public class DatabaseDatabaseStatus { + /** The name of the Postgres database. */ + @JsonProperty("postgres_database") + private String postgresDatabase; + + /** + * The name of the role that owns the database. Format: + * projects/{project_id}/branches/{branch_id}/roles/{role_id} + */ + @JsonProperty("role") + private String role; + + public DatabaseDatabaseStatus setPostgresDatabase(String postgresDatabase) { + this.postgresDatabase = postgresDatabase; + return this; + } + + public String getPostgresDatabase() { + return postgresDatabase; + } + + public DatabaseDatabaseStatus setRole(String role) { + this.role = role; + return this; + } + + public String getRole() { + return role; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DatabaseDatabaseStatus that = (DatabaseDatabaseStatus) o; + return Objects.equals(postgresDatabase, that.postgresDatabase) + && Objects.equals(role, that.role); + } + + @Override + public int hashCode() { + return Objects.hash(postgresDatabase, role); + } + + @Override + public String toString() { + return new ToStringer(DatabaseDatabaseStatus.class) + .add("postgresDatabase", postgresDatabase) + .add("role", role) + .toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseOperationMetadata.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseOperationMetadata.java new file mode 100755 index 000000000..f48aa3833 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DatabaseOperationMetadata.java @@ -0,0 +1,28 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import java.util.Objects; + +@Generated +public class DatabaseOperationMetadata { + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + + @Override + public String toString() { + return new ToStringer(DatabaseOperationMetadata.class).toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseOperation.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseOperation.java new file mode 100755 index 000000000..52806dd52 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseOperation.java @@ -0,0 +1,161 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.core.DatabricksException; +import com.databricks.sdk.core.utils.SerDeUtils; +import com.databricks.sdk.service.common.lro.LroOptions; +import com.databricks.sdk.support.Generated; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.Duration; +import java.util.Optional; +import java.util.concurrent.TimeoutException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Wrapper for interacting with a long-running deleteDatabase operation. Provides methods to wait + * for completion, check status, cancel, and access metadata. + */ +@Generated +public class DeleteDatabaseOperation { + private static final Logger LOG = LoggerFactory.getLogger(DeleteDatabaseOperation.class); + + private final PostgresService impl; + private Operation operation; + private final ObjectMapper objectMapper; + + public DeleteDatabaseOperation(PostgresService impl, Operation operation) { + this.impl = impl; + this.operation = operation; + this.objectMapper = SerDeUtils.createMapper(); + } + + /** + * Wait for the operation to complete and return the resulting . Waits indefinitely if no timeout + * is specified. + * + * @return the created + * @throws TimeoutException if the operation doesn't complete within the timeout + * @throws DatabricksException if the operation fails + */ + public void waitForCompletion() throws TimeoutException { + waitForCompletion(Optional.empty()); + } + + /** + * Wait for the operation to complete and return the resulting . + * + * @param options the options for configuring the wait behavior, can be empty for defaults + * @return the created + * @throws TimeoutException if the operation doesn't complete within the timeout + * @throws DatabricksException if the operation fails + */ + public void waitForCompletion(Optional options) throws TimeoutException { + Optional timeout = options.flatMap(LroOptions::getTimeout); + long deadline = + timeout.isPresent() + ? System.currentTimeMillis() + timeout.get().toMillis() + : Long.MAX_VALUE; + String statusMessage = "polling operation..."; + int attempt = 1; + + while (System.currentTimeMillis() < deadline) { + // Refresh the operation state + refreshOperation(); + + if (operation.getDone() != null && operation.getDone()) { + // Operation completed, check for success or failure + if (operation.getError() != null) { + String errorMsg = "unknown error"; + if (operation.getError().getMessage() != null + && !operation.getError().getMessage().isEmpty()) { + errorMsg = operation.getError().getMessage(); + } + + if (operation.getError().getErrorCode() != null) { + errorMsg = String.format("[%s] %s", operation.getError().getErrorCode(), errorMsg); + } + + throw new DatabricksException("Operation failed: " + errorMsg); + } + + // Operation completed successfully, unmarshal response + if (operation.getResponse() == null) { + throw new DatabricksException("Operation completed but no response available"); + } + + try { + JsonNode responseJson = objectMapper.valueToTree(operation.getResponse()); + objectMapper.treeToValue(responseJson, Void.class); + } catch (JsonProcessingException e) { + throw new DatabricksException("Failed to unmarshal response: " + e.getMessage(), e); + } + } + + // Operation still in progress, wait before polling again + String prefix = String.format("operation=%s", operation.getName()); + int sleep = Math.min(attempt, 10); // sleep 10s max per attempt + LOG.info("{}: operation in progress (sleeping ~{}s)", prefix, sleep); + + try { + Thread.sleep((long) (sleep * 1000L + Math.random() * 1000)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new DatabricksException("Current thread was interrupted", e); + } + attempt++; + } + + String timeoutMessage = + timeout.isPresent() + ? String.format("Operation timed out after %s: %s", timeout.get(), statusMessage) + : String.format("Operation timed out: %s", statusMessage); + throw new TimeoutException(timeoutMessage); + } + + /** + * Get the operation name. + * + * @return the operation name + */ + public String getName() { + return operation.getName(); + } + + /** + * Get the operation metadata. + * + * @return the operation metadata, or null if not available + * @throws DatabricksException if the metadata cannot be deserialized + */ + public DatabaseOperationMetadata getMetadata() { + if (operation.getMetadata() == null) { + return null; + } + + try { + JsonNode metadataJson = objectMapper.valueToTree(operation.getMetadata()); + return objectMapper.treeToValue(metadataJson, DatabaseOperationMetadata.class); + } catch (JsonProcessingException e) { + throw new DatabricksException("Failed to unmarshal operation metadata: " + e.getMessage(), e); + } + } + + /** + * Check if the operation is done. This method refreshes the operation state before checking. + * + * @return true if the operation is complete, false otherwise + * @throws DatabricksException if the status check fails + */ + public boolean isDone() { + refreshOperation(); + return operation.getDone() != null && operation.getDone(); + } + + /** Refresh the operation state by polling the server. */ + private void refreshOperation() { + operation = impl.getOperation(new GetOperationRequest().setName(operation.getName())); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseRequest.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseRequest.java new file mode 100755 index 000000000..5ac8256db --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/DeleteDatabaseRequest.java @@ -0,0 +1,44 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; + +@Generated +public class DeleteDatabaseRequest { + /** + * The resource name of the postgres database. Format: + * projects/{project_id}/branches/{branch_id}/databases/{database_id} + */ + @JsonIgnore private String name; + + public DeleteDatabaseRequest setName(String name) { + this.name = name; + return this; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DeleteDatabaseRequest that = (DeleteDatabaseRequest) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public String toString() { + return new ToStringer(DeleteDatabaseRequest.class).add("name", name).toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetDatabaseRequest.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetDatabaseRequest.java new file mode 100755 index 000000000..6bae6ce96 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/GetDatabaseRequest.java @@ -0,0 +1,44 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; + +@Generated +public class GetDatabaseRequest { + /** + * The name of the Database to retrieve. Format: + * projects/{project_id}/branches/{branch_id}/databases/{database_id} + */ + @JsonIgnore private String name; + + public GetDatabaseRequest setName(String name) { + this.name = name; + return this; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetDatabaseRequest that = (GetDatabaseRequest) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public String toString() { + return new ToStringer(GetDatabaseRequest.class).add("name", name).toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesRequest.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesRequest.java new file mode 100755 index 000000000..489ebd6cc --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesRequest.java @@ -0,0 +1,79 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.QueryParam; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; + +@Generated +public class ListDatabasesRequest { + /** Upper bound for items returned. */ + @JsonIgnore + @QueryParam("page_size") + private Long pageSize; + + /** Pagination token to go to the next page of Databases. Requests first page if absent. */ + @JsonIgnore + @QueryParam("page_token") + private String pageToken; + + /** + * The Branch that owns this collection of databases. Format: + * projects/{project_id}/branches/{branch_id} + */ + @JsonIgnore private String parent; + + public ListDatabasesRequest setPageSize(Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public Long getPageSize() { + return pageSize; + } + + public ListDatabasesRequest setPageToken(String pageToken) { + this.pageToken = pageToken; + return this; + } + + public String getPageToken() { + return pageToken; + } + + public ListDatabasesRequest setParent(String parent) { + this.parent = parent; + return this; + } + + public String getParent() { + return parent; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ListDatabasesRequest that = (ListDatabasesRequest) o; + return Objects.equals(pageSize, that.pageSize) + && Objects.equals(pageToken, that.pageToken) + && Objects.equals(parent, that.parent); + } + + @Override + public int hashCode() { + return Objects.hash(pageSize, pageToken, parent); + } + + @Override + public String toString() { + return new ToStringer(ListDatabasesRequest.class) + .add("pageSize", pageSize) + .add("pageToken", pageToken) + .add("parent", parent) + .toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesResponse.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesResponse.java new file mode 100755 index 000000000..bab40012e --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/ListDatabasesResponse.java @@ -0,0 +1,60 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collection; +import java.util.Objects; + +@Generated +public class ListDatabasesResponse { + /** List of databases. */ + @JsonProperty("databases") + private Collection databases; + + /** Pagination token to request the next page of databases. */ + @JsonProperty("next_page_token") + private String nextPageToken; + + public ListDatabasesResponse setDatabases(Collection databases) { + this.databases = databases; + return this; + } + + public Collection getDatabases() { + return databases; + } + + public ListDatabasesResponse setNextPageToken(String nextPageToken) { + this.nextPageToken = nextPageToken; + return this; + } + + public String getNextPageToken() { + return nextPageToken; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ListDatabasesResponse that = (ListDatabasesResponse) o; + return Objects.equals(databases, that.databases) + && Objects.equals(nextPageToken, that.nextPageToken); + } + + @Override + public int hashCode() { + return Objects.hash(databases, nextPageToken); + } + + @Override + public String toString() { + return new ToStringer(ListDatabasesResponse.class) + .add("databases", databases) + .add("nextPageToken", nextPageToken) + .toString(); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresAPI.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresAPI.java index 5fa8cce5d..d2344fabf 100755 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresAPI.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresAPI.java @@ -43,6 +43,16 @@ public CreateBranchOperation createBranch(CreateBranchRequest request) { return new CreateBranchOperation(impl, operation); } + /** + * Create a Database. + * + *

Creates a database in the specified branch. A branch can have multiple databases. + */ + public CreateDatabaseOperation createDatabase(CreateDatabaseRequest request) { + Operation operation = impl.createDatabase(request); + return new CreateDatabaseOperation(impl, operation); + } + /** Creates a new compute endpoint in the branch. */ public CreateEndpointOperation createEndpoint(CreateEndpointRequest request) { Operation operation = impl.createEndpoint(request); @@ -74,6 +84,16 @@ public DeleteBranchOperation deleteBranch(DeleteBranchRequest request) { return new DeleteBranchOperation(impl, operation); } + public DeleteDatabaseOperation deleteDatabase(String name) { + return deleteDatabase(new DeleteDatabaseRequest().setName(name)); + } + + /** Delete a Database. */ + public DeleteDatabaseOperation deleteDatabase(DeleteDatabaseRequest request) { + Operation operation = impl.deleteDatabase(request); + return new DeleteDatabaseOperation(impl, operation); + } + public DeleteEndpointOperation deleteEndpoint(String name) { return deleteEndpoint(new DeleteEndpointRequest().setName(name)); } @@ -118,6 +138,15 @@ public Branch getBranch(GetBranchRequest request) { return impl.getBranch(request); } + public Database getDatabase(String name) { + return getDatabase(new GetDatabaseRequest().setName(name)); + } + + /** Get a Database. */ + public Database getDatabase(GetDatabaseRequest request) { + return impl.getDatabase(request); + } + public Endpoint getEndpoint(String name) { return getEndpoint(new GetEndpointRequest().setName(name)); } @@ -179,6 +208,25 @@ public Iterable listBranches(ListBranchesRequest request) { }); } + public Iterable listDatabases(String parent) { + return listDatabases(new ListDatabasesRequest().setParent(parent)); + } + + /** List Databases. */ + public Iterable listDatabases(ListDatabasesRequest request) { + return new Paginator<>( + request, + impl::listDatabases, + ListDatabasesResponse::getDatabases, + response -> { + String token = response.getNextPageToken(); + if (token == null || token.isEmpty()) { + return null; + } + return request.setPageToken(token); + }); + } + public Iterable listEndpoints(String parent) { return listEndpoints(new ListEndpointsRequest().setParent(parent)); } @@ -244,6 +292,12 @@ public UpdateBranchOperation updateBranch(UpdateBranchRequest request) { return new UpdateBranchOperation(impl, operation); } + /** Update a Database. */ + public UpdateDatabaseOperation updateDatabase(UpdateDatabaseRequest request) { + Operation operation = impl.updateDatabase(request); + return new UpdateDatabaseOperation(impl, operation); + } + /** * Updates the specified compute endpoint. You can update autoscaling limits, suspend timeout, or * enable/disable the compute endpoint. diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresImpl.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresImpl.java index 890a8364e..b225c0d28 100755 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresImpl.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresImpl.java @@ -34,6 +34,24 @@ public Operation createBranch(CreateBranchRequest request) { } } + @Override + public Operation createDatabase(CreateDatabaseRequest request) { + String path = String.format("/api/2.0/postgres/%s/databases", request.getParent()); + try { + Request req = new Request("POST", path, apiClient.serialize(request.getDatabase())); + + ApiClient.setQuery(req, request); + req.withHeader("Accept", "application/json"); + req.withHeader("Content-Type", "application/json"); + if (apiClient.workspaceId() != null) { + req.withHeader("X-Databricks-Org-Id", apiClient.workspaceId()); + } + return apiClient.execute(req, Operation.class); + } catch (IOException e) { + throw new DatabricksException("IO error: " + e.getMessage(), e); + } + } + @Override public Operation createEndpoint(CreateEndpointRequest request) { String path = String.format("/api/2.0/postgres/%s/endpoints", request.getParent()); @@ -105,6 +123,23 @@ public Operation deleteBranch(DeleteBranchRequest request) { } } + @Override + public Operation deleteDatabase(DeleteDatabaseRequest request) { + String path = String.format("/api/2.0/postgres/%s", request.getName()); + try { + Request req = new Request("DELETE", path); + + ApiClient.setQuery(req, request); + req.withHeader("Accept", "application/json"); + if (apiClient.workspaceId() != null) { + req.withHeader("X-Databricks-Org-Id", apiClient.workspaceId()); + } + return apiClient.execute(req, Operation.class); + } catch (IOException e) { + throw new DatabricksException("IO error: " + e.getMessage(), e); + } + } + @Override public Operation deleteEndpoint(DeleteEndpointRequest request) { String path = String.format("/api/2.0/postgres/%s", request.getName()); @@ -191,6 +226,23 @@ public Branch getBranch(GetBranchRequest request) { } } + @Override + public Database getDatabase(GetDatabaseRequest request) { + String path = String.format("/api/2.0/postgres/%s", request.getName()); + try { + Request req = new Request("GET", path); + + ApiClient.setQuery(req, request); + req.withHeader("Accept", "application/json"); + if (apiClient.workspaceId() != null) { + req.withHeader("X-Databricks-Org-Id", apiClient.workspaceId()); + } + return apiClient.execute(req, Database.class); + } catch (IOException e) { + throw new DatabricksException("IO error: " + e.getMessage(), e); + } + } + @Override public Endpoint getEndpoint(GetEndpointRequest request) { String path = String.format("/api/2.0/postgres/%s", request.getName()); @@ -276,6 +328,23 @@ public ListBranchesResponse listBranches(ListBranchesRequest request) { } } + @Override + public ListDatabasesResponse listDatabases(ListDatabasesRequest request) { + String path = String.format("/api/2.0/postgres/%s/databases", request.getParent()); + try { + Request req = new Request("GET", path); + + ApiClient.setQuery(req, request); + req.withHeader("Accept", "application/json"); + if (apiClient.workspaceId() != null) { + req.withHeader("X-Databricks-Org-Id", apiClient.workspaceId()); + } + return apiClient.execute(req, ListDatabasesResponse.class); + } catch (IOException e) { + throw new DatabricksException("IO error: " + e.getMessage(), e); + } + } + @Override public ListEndpointsResponse listEndpoints(ListEndpointsRequest request) { String path = String.format("/api/2.0/postgres/%s/endpoints", request.getParent()); @@ -345,6 +414,24 @@ public Operation updateBranch(UpdateBranchRequest request) { } } + @Override + public Operation updateDatabase(UpdateDatabaseRequest request) { + String path = String.format("/api/2.0/postgres/%s", request.getName()); + try { + Request req = new Request("PATCH", path, apiClient.serialize(request.getDatabase())); + + ApiClient.setQuery(req, request); + req.withHeader("Accept", "application/json"); + req.withHeader("Content-Type", "application/json"); + if (apiClient.workspaceId() != null) { + req.withHeader("X-Databricks-Org-Id", apiClient.workspaceId()); + } + return apiClient.execute(req, Operation.class); + } catch (IOException e) { + throw new DatabricksException("IO error: " + e.getMessage(), e); + } + } + @Override public Operation updateEndpoint(UpdateEndpointRequest request) { String path = String.format("/api/2.0/postgres/%s", request.getName()); diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresService.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresService.java index a3096a4bc..d2577bd81 100755 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresService.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/PostgresService.java @@ -26,6 +26,13 @@ public interface PostgresService { /** Creates a new database branch in the project. */ Operation createBranch(CreateBranchRequest createBranchRequest); + /** + * Create a Database. + * + *

Creates a database in the specified branch. A branch can have multiple databases. + */ + Operation createDatabase(CreateDatabaseRequest createDatabaseRequest); + /** Creates a new compute endpoint in the branch. */ Operation createEndpoint(CreateEndpointRequest createEndpointRequest); @@ -41,6 +48,9 @@ public interface PostgresService { /** Deletes the specified database branch. */ Operation deleteBranch(DeleteBranchRequest deleteBranchRequest); + /** Delete a Database. */ + Operation deleteDatabase(DeleteDatabaseRequest deleteDatabaseRequest); + /** Deletes the specified compute endpoint. */ Operation deleteEndpoint(DeleteEndpointRequest deleteEndpointRequest); @@ -57,6 +67,9 @@ DatabaseCredential generateDatabaseCredential( /** Retrieves information about the specified database branch. */ Branch getBranch(GetBranchRequest getBranchRequest); + /** Get a Database. */ + Database getDatabase(GetDatabaseRequest getDatabaseRequest); + /** * Retrieves information about the specified compute endpoint, including its connection details * and operational state. @@ -78,6 +91,9 @@ DatabaseCredential generateDatabaseCredential( /** Returns a paginated list of database branches in the project. */ ListBranchesResponse listBranches(ListBranchesRequest listBranchesRequest); + /** List Databases. */ + ListDatabasesResponse listDatabases(ListDatabasesRequest listDatabasesRequest); + /** Returns a paginated list of compute endpoints in the branch. */ ListEndpointsResponse listEndpoints(ListEndpointsRequest listEndpointsRequest); @@ -96,6 +112,9 @@ DatabaseCredential generateDatabaseCredential( */ Operation updateBranch(UpdateBranchRequest updateBranchRequest); + /** Update a Database. */ + Operation updateDatabase(UpdateDatabaseRequest updateDatabaseRequest); + /** * Updates the specified compute endpoint. You can update autoscaling limits, suspend timeout, or * enable/disable the compute endpoint. diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseOperation.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseOperation.java new file mode 100755 index 000000000..d228c88bd --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseOperation.java @@ -0,0 +1,162 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.core.DatabricksException; +import com.databricks.sdk.core.utils.SerDeUtils; +import com.databricks.sdk.service.common.lro.LroOptions; +import com.databricks.sdk.support.Generated; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.Duration; +import java.util.Optional; +import java.util.concurrent.TimeoutException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Wrapper for interacting with a long-running updateDatabase operation. Provides methods to wait + * for completion, check status, cancel, and access metadata. + */ +@Generated +public class UpdateDatabaseOperation { + private static final Logger LOG = LoggerFactory.getLogger(UpdateDatabaseOperation.class); + + private final PostgresService impl; + private Operation operation; + private final ObjectMapper objectMapper; + + public UpdateDatabaseOperation(PostgresService impl, Operation operation) { + this.impl = impl; + this.operation = operation; + this.objectMapper = SerDeUtils.createMapper(); + } + + /** + * Wait for the operation to complete and return the resulting Database. Waits indefinitely if no + * timeout is specified. + * + * @return the created Database + * @throws TimeoutException if the operation doesn't complete within the timeout + * @throws DatabricksException if the operation fails + */ + public Database waitForCompletion() throws TimeoutException { + return waitForCompletion(Optional.empty()); + } + + /** + * Wait for the operation to complete and return the resulting Database. + * + * @param options the options for configuring the wait behavior, can be empty for defaults + * @return the created Database + * @throws TimeoutException if the operation doesn't complete within the timeout + * @throws DatabricksException if the operation fails + */ + public Database waitForCompletion(Optional options) throws TimeoutException { + Optional timeout = options.flatMap(LroOptions::getTimeout); + long deadline = + timeout.isPresent() + ? System.currentTimeMillis() + timeout.get().toMillis() + : Long.MAX_VALUE; + String statusMessage = "polling operation..."; + int attempt = 1; + + while (System.currentTimeMillis() < deadline) { + // Refresh the operation state + refreshOperation(); + + if (operation.getDone() != null && operation.getDone()) { + // Operation completed, check for success or failure + if (operation.getError() != null) { + String errorMsg = "unknown error"; + if (operation.getError().getMessage() != null + && !operation.getError().getMessage().isEmpty()) { + errorMsg = operation.getError().getMessage(); + } + + if (operation.getError().getErrorCode() != null) { + errorMsg = String.format("[%s] %s", operation.getError().getErrorCode(), errorMsg); + } + + throw new DatabricksException("Operation failed: " + errorMsg); + } + + // Operation completed successfully, unmarshal response + if (operation.getResponse() == null) { + throw new DatabricksException("Operation completed but no response available"); + } + + try { + JsonNode responseJson = objectMapper.valueToTree(operation.getResponse()); + return objectMapper.treeToValue(responseJson, Database.class); + } catch (JsonProcessingException e) { + throw new DatabricksException( + "Failed to unmarshal database response: " + e.getMessage(), e); + } + } + + // Operation still in progress, wait before polling again + String prefix = String.format("operation=%s", operation.getName()); + int sleep = Math.min(attempt, 10); // sleep 10s max per attempt + LOG.info("{}: operation in progress (sleeping ~{}s)", prefix, sleep); + + try { + Thread.sleep((long) (sleep * 1000L + Math.random() * 1000)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new DatabricksException("Current thread was interrupted", e); + } + attempt++; + } + + String timeoutMessage = + timeout.isPresent() + ? String.format("Operation timed out after %s: %s", timeout.get(), statusMessage) + : String.format("Operation timed out: %s", statusMessage); + throw new TimeoutException(timeoutMessage); + } + + /** + * Get the operation name. + * + * @return the operation name + */ + public String getName() { + return operation.getName(); + } + + /** + * Get the operation metadata. + * + * @return the operation metadata, or null if not available + * @throws DatabricksException if the metadata cannot be deserialized + */ + public DatabaseOperationMetadata getMetadata() { + if (operation.getMetadata() == null) { + return null; + } + + try { + JsonNode metadataJson = objectMapper.valueToTree(operation.getMetadata()); + return objectMapper.treeToValue(metadataJson, DatabaseOperationMetadata.class); + } catch (JsonProcessingException e) { + throw new DatabricksException("Failed to unmarshal operation metadata: " + e.getMessage(), e); + } + } + + /** + * Check if the operation is done. This method refreshes the operation state before checking. + * + * @return true if the operation is complete, false otherwise + * @throws DatabricksException if the status check fails + */ + public boolean isDone() { + refreshOperation(); + return operation.getDone() != null && operation.getDone(); + } + + /** Refresh the operation state by polling the server. */ + private void refreshOperation() { + operation = impl.getOperation(new GetOperationRequest().setName(operation.getName())); + } +} diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseRequest.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseRequest.java new file mode 100755 index 000000000..62ee9e186 --- /dev/null +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/service/postgres/UpdateDatabaseRequest.java @@ -0,0 +1,85 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package com.databricks.sdk.service.postgres; + +import com.databricks.sdk.support.Generated; +import com.databricks.sdk.support.QueryParam; +import com.databricks.sdk.support.ToStringer; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.protobuf.FieldMask; +import java.util.Objects; + +@Generated +public class UpdateDatabaseRequest { + /** + * The Database to update. + * + *

The database's `name` field is used to identify the database to update. Format: + * projects/{project_id}/branches/{branch_id}/databases/{database_id} + */ + @JsonProperty("database") + private Database database; + + /** + * The resource name of the database. Format: + * projects/{project_id}/branches/{branch_id}/databases/{database_id} + */ + @JsonIgnore private String name; + + /** The list of fields to update. If unspecified, all fields will be updated when possible. */ + @JsonIgnore + @QueryParam("update_mask") + private FieldMask updateMask; + + public UpdateDatabaseRequest setDatabase(Database database) { + this.database = database; + return this; + } + + public Database getDatabase() { + return database; + } + + public UpdateDatabaseRequest setName(String name) { + this.name = name; + return this; + } + + public String getName() { + return name; + } + + public UpdateDatabaseRequest setUpdateMask(FieldMask updateMask) { + this.updateMask = updateMask; + return this; + } + + public FieldMask getUpdateMask() { + return updateMask; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UpdateDatabaseRequest that = (UpdateDatabaseRequest) o; + return Objects.equals(database, that.database) + && Objects.equals(name, that.name) + && Objects.equals(updateMask, that.updateMask); + } + + @Override + public int hashCode() { + return Objects.hash(database, name, updateMask); + } + + @Override + public String toString() { + return new ToStringer(UpdateDatabaseRequest.class) + .add("database", database) + .add("name", name) + .add("updateMask", updateMask) + .toString(); + } +}