Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
FANNG1 committed Oct 17, 2024
1 parent b72294a commit 6b37a88
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ public void initialize(
resultConf.put("catalog_uuid", info.id().toString());
IcebergConfig icebergConfig = new IcebergConfig(resultConf);

this.icebergCatalogWrapper =
new IcebergCatalogWrapper(
icebergConfig);
this.icebergCatalogWrapper = new IcebergCatalogWrapper(icebergConfig);
this.icebergCatalogWrapperHelper =
new IcebergCatalogWrapperHelper(icebergCatalogWrapper.getCatalog());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public class TestIcebergTableUpdate {

@BeforeEach
public void init() {
icebergCatalogWrapper =
new IcebergCatalogWrapper(new IcebergConfig(Collections.emptyMap()));
icebergCatalogWrapper = new IcebergCatalogWrapper(new IcebergConfig(Collections.emptyMap()));
icebergCatalogWrapperHelper =
new IcebergCatalogWrapperHelper(icebergCatalogWrapper.getCatalog());
createNamespace(TEST_NAMESPACE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@

package org.apache.gravitino.credential;

import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.Map;
import org.apache.gravitino.utils.PrincipalUtils;

public class CredentialProviderManager {

public void registerCredentialProvider(String catalogName, CredentialProvider credentialProvider) {

}
public void registerCredentialProvider(
String catalogName, CredentialProvider credentialProvider) {}

public void unregisterCredentialProvider(String catalogName) {

}
public void unregisterCredentialProvider(String catalogName) {}

public CredentialProvider getCredentialProvider(String catalogName) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
package org.apache.gravitino.credential;

import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.utils.PrincipalUtils;

public class CredentialUtils {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.apache.gravitino.iceberg.common.IcebergConfig;

/**
* {@code IcebergCatalogConfigProvider} is an interface defining how Iceberg REST catalog server gets
* Iceberg catalog configurations.
* {@code IcebergCatalogConfigProvider} is an interface defining how Iceberg REST catalog server
* gets Iceberg catalog configurations.
*/
public interface IcebergCatalogConfigProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import lombok.Getter;
import lombok.Setter;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.credential.CredentialProvider;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.common.utils.IcebergCatalogUtil;
Expand Down Expand Up @@ -103,8 +102,6 @@ public IcebergCatalogWrapper(IcebergConfig icebergConfig) {
key -> catalogPropertiesToClientKeys.contains(key));

this.catalogPropertiesMap = icebergConfig.getIcebergCatalogProperties();


}

private void validateNamespace(Optional<Namespace> namespace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class ConfigBasedIcebergCatalogConfigProvider implements IcebergCatalogCo
public static final Logger LOG =
LoggerFactory.getLogger(ConfigBasedIcebergCatalogConfigProvider.class);

public static final String CONFIG_BASE_ICEBERG_CATALOG_CONFIG_PROVIDER_NAME = "config-based-provider";
public static final String CONFIG_BASE_ICEBERG_CATALOG_CONFIG_PROVIDER_NAME =
"config-based-provider";

@VisibleForTesting Map<String, IcebergConfig> catalogConfigs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.gravitino.client.GravitinoAdminClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.common.ops.IcebergCatalogWrapper;
import org.apache.gravitino.iceberg.common.ops.IcebergCatalogConfigProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.apache.gravitino.credential.CredentialProviderFactory;
import org.apache.gravitino.credential.CredentialProviderManager;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.common.ops.IcebergCatalogWrapper;
import org.apache.gravitino.iceberg.common.ops.IcebergCatalogConfigProvider;
import org.apache.gravitino.iceberg.common.ops.IcebergCatalogWrapper;
import org.apache.gravitino.iceberg.provider.ConfigBasedIcebergCatalogConfigProvider;
import org.apache.gravitino.iceberg.provider.GravitinoBasedIcebergCatalogConfigProvider;
import org.slf4j.Logger;
Expand Down Expand Up @@ -70,7 +70,7 @@ public IcebergCatalogWrapperManager(Map<String, String> properties) {
TimeUnit.MILLISECONDS)
.removalListener(
(k, v, c) -> {
String catalogName = (String)k;
String catalogName = (String) k;
LOG.info("Remove IcebergCatalogWrapper cache {}.", catalogName);
closeIcebergCatalogWrapper((IcebergCatalogWrapper) v);
credentialProviderManager.unregisterCredentialProvider(catalogName);
Expand Down Expand Up @@ -115,7 +115,8 @@ private IcebergCatalogWrapper createCatalogWrapper(String catalogName) {
IcebergConfig config = icebergConfig.get();
String credentialProviderType = config.get(IcebergConfig.CREDENTIAL_PROVIDER_TYPE);
if (StringUtils.isNotBlank(credentialProviderType)) {
CredentialProvider credentialProvider = CredentialProviderFactory.create(credentialProviderType, config.getAllConfig());
CredentialProvider credentialProvider =
CredentialProviderFactory.create(credentialProviderType, config.getAllConfig());
credentialProviderManager.registerCredentialProvider(catalogName, credentialProvider);
}

Expand All @@ -137,7 +138,8 @@ private String getCatalogName(String rawPrefix) {
private IcebergCatalogConfigProvider createProvider(Map<String, String> properties) {
String providerName =
(new IcebergConfig(properties)).get(IcebergConfig.ICEBERG_REST_CATALOG_PROVIDER);
String className = ICEBERG_CATALOG_CONFIG_PROVIDER_NAMES.getOrDefault(providerName, providerName);
String className =
ICEBERG_CATALOG_CONFIG_PROVIDER_NAMES.getOrDefault(providerName, providerName);
LOG.info("Load Iceberg catalog provider: {}.", className);
try {
Class<?> providerClz = Class.forName(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.credential.CredentialProvider;
import org.apache.gravitino.credential.CredentialProviderManager;
import org.apache.gravitino.credential.CredentialPropertyUtils;
import org.apache.gravitino.credential.CredentialProvider;
import org.apache.gravitino.credential.CredentialUtils;
import org.apache.gravitino.iceberg.service.IcebergCatalogWrapperManager;
import org.apache.gravitino.iceberg.service.IcebergObjectMapper;
Expand Down Expand Up @@ -112,7 +111,10 @@ public Response createTable(
accessDelegation,
isCredentialVending);
if (isCredentialVending) {
LoadTableResponse loadTableResponse = icebergCatalogWrapperManager.getOps(prefix).createTable(RESTUtil.decodeNamespace(namespace), createTableRequest);
LoadTableResponse loadTableResponse =
icebergCatalogWrapperManager
.getOps(prefix)
.createTable(RESTUtil.decodeNamespace(namespace), createTableRequest);
return IcebergRestUtils.ok(injectCredentialConfig(prefix, loadTableResponse));
} else {
return IcebergRestUtils.ok(
Expand Down Expand Up @@ -245,20 +247,26 @@ private String SerializeUpdateTableRequest(UpdateTableRequest updateTableRequest
}
}

private LoadTableResponse injectCredentialConfig(String prefix,
LoadTableResponse loadTableResponse) {
CredentialProvider credentialProvider = icebergCatalogWrapperManager.getCredentialProvider(prefix);
private LoadTableResponse injectCredentialConfig(
String prefix, LoadTableResponse loadTableResponse) {
CredentialProvider credentialProvider =
icebergCatalogWrapperManager.getCredentialProvider(prefix);
if (credentialProvider == null) {
throw new RuntimeException("Doesn't support credential vending");
}
Credential credential = CredentialUtils.vendCredential(credentialProvider,
loadTableResponse.tableMetadata().location());
Credential credential =
CredentialUtils.vendCredential(
credentialProvider, loadTableResponse.tableMetadata().location());
if (credential == null) {
throw new RuntimeException("Couldn't generate credential for " + credentialProvider.credentialType());
throw new RuntimeException(
"Couldn't generate credential for " + credentialProvider.credentialType());
}
Map<String, String> credentialConfig = CredentialPropertyUtils.toIcebergProperties(credential);
return LoadTableResponse.builder().withTableMetadata(loadTableResponse.tableMetadata())
.addAllConfig(loadTableResponse.config()).addAllConfig(credentialConfig).build();
return LoadTableResponse.builder()
.withTableMetadata(loadTableResponse.tableMetadata())
.addAllConfig(loadTableResponse.config())
.addAllConfig(credentialConfig)
.build();
}

private boolean isCredentialVending(String accessDelegation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.gravitino.iceberg.service.rest;

import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.common.ops.IcebergCatalogWrapper;
import org.apache.gravitino.iceberg.provider.ConfigBasedIcebergCatalogConfigProvider;

public class ConfigBasedIcebergCatalogWrapperProviderForTest
Expand Down

0 comments on commit 6b37a88

Please sign in to comment.