Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (2021) The Delta Lake Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.delta.storage.commit.uccommitcoordinator;

import io.unitycatalog.client.ApiClient;
import io.unitycatalog.client.ApiClientBuilder;
import io.unitycatalog.client.auth.TokenProvider;
import io.unitycatalog.client.retry.JitterDelayRetryPolicy;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;

abstract class UCTokenBasedApiClientProvider {
private ApiClient apiClient;

protected UCTokenBasedApiClientProvider(
String baseUri,
TokenProvider tokenProvider,
Map<String, String> appVersions) {
this.apiClient = buildApiClient(baseUri, tokenProvider, appVersions);
}

protected UCTokenBasedApiClientProvider(
String baseUri,
TokenProvider tokenProvider,
Map<String, String> appVersions,
String catalog) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this catalog still using ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the catalog arg is used by UCDeltaTokenBasedRestClient to probe catalog-scoped Delta API support; the shared provider constructor keeps the same signature so OSS and DBR can stay close.

// The catalog is consumed by subclasses that probe catalog-scoped Delta API support.
this(baseUri, tokenProvider, appVersions);
}

private static ApiClient buildApiClient(
String baseUri,
TokenProvider tokenProvider,
Map<String, String> appVersions) {
Objects.requireNonNull(baseUri, "baseUri must not be null");
Objects.requireNonNull(tokenProvider, "tokenProvider must not be null");
Objects.requireNonNull(appVersions, "appVersions must not be null");

ApiClientBuilder builder = ApiClientBuilder.create()
.uri(baseUri)
.tokenProvider(tokenProvider)
.retryPolicy(JitterDelayRetryPolicy.builder().build());

appVersions.forEach((name, version) -> {
if (version != null) {
builder.addAppVersion(name, version);
}
});

return builder.build();
}

protected ApiClient getApiClient() {
return apiClient;
}

public void close() throws IOException {
apiClient = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.delta.storage.commit.uniform.IcebergMetadata;
import io.delta.storage.commit.uniform.UniformMetadata;
import io.unitycatalog.client.ApiClient;
import io.unitycatalog.client.ApiClientBuilder;
import io.unitycatalog.client.ApiException;
import io.unitycatalog.client.api.DeltaCommitsApi;
import io.unitycatalog.client.api.MetastoresApi;
Expand Down Expand Up @@ -83,7 +82,7 @@
* @see GetCommitsResponse
* @see TokenProvider
*/
public class UCTokenBasedRestClient implements UCClient {
public class UCTokenBasedRestClient extends UCTokenBasedApiClientProvider implements UCClient {

private DeltaCommitsApi deltaCommitsApi;
private MetastoresApi metastoresApi;
Expand All @@ -109,21 +108,20 @@ public UCTokenBasedRestClient(
String baseUri,
TokenProvider tokenProvider,
Map<String, String> appVersions) {
Objects.requireNonNull(baseUri, "baseUri must not be null");
Objects.requireNonNull(tokenProvider, "tokenProvider must not be null");
Objects.requireNonNull(appVersions, "appVersions must not be null");

ApiClientBuilder builder = ApiClientBuilder.create()
.uri(baseUri)
.tokenProvider(tokenProvider);

appVersions.forEach((name, version) -> {
if (version != null) {
builder.addAppVersion(name, version);
}
});
super(baseUri, tokenProvider, appVersions);
ApiClient apiClient = getApiClient();
this.deltaCommitsApi = new DeltaCommitsApi(apiClient);
this.metastoresApi = new MetastoresApi(apiClient);
this.tablesApi = new TablesApi(apiClient);
}

ApiClient apiClient = builder.build();
public UCTokenBasedRestClient(
String baseUri,
TokenProvider tokenProvider,
Map<String, String> appVersions,
String catalog) {
super(baseUri, tokenProvider, appVersions, catalog);
ApiClient apiClient = getApiClient();
this.deltaCommitsApi = new DeltaCommitsApi(apiClient);
this.metastoresApi = new MetastoresApi(apiClient);
this.tablesApi = new TablesApi(apiClient);
Expand Down Expand Up @@ -233,6 +231,7 @@ public GetCommitsResponse getCommits(

@Override
public void close() throws IOException {
super.close();
// Nulling out the API instances makes them eligible for GC. Once garbage collected,
// the underlying connection pool is freed and destroyed.
this.deltaCommitsApi = null;
Expand Down
Loading