Skip to content
Merged
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
Expand Up @@ -124,7 +124,7 @@ public abstract class CatalogIcebergBaseIT extends BaseIT {

@BeforeAll
public void startup() throws Exception {
super.ignoreAuxRestService = false;
super.ignoreIcebergAuxRestService = false;
super.startIntegrationTest();
containerSuite.startHiveContainer();
initIcebergCatalogProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void startIntegrationTest() {
// Config kerberos configuration for Gravitino server
addKerberosConfig();

super.ignoreAuxRestService = false;
super.ignoreIcebergAuxRestService = false;
// Start Gravitino server
super.startIntegrationTest();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected String flinkByPass(String key) {
protected abstract String getProvider();

private void initIcebergRestServiceEnv() {
super.ignoreAuxRestService = false;
super.ignoreIcebergAuxRestService = false;
Map<String, String> icebergRestServiceConfigs = new HashMap<>();
icebergRestServiceConfigs.put(
"gravitino."
Expand Down
3 changes: 3 additions & 0 deletions integration-test-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ dependencies {
testImplementation(project(":clients:client-java"))
testImplementation(project(":common"))
testImplementation(project(":core"))
testImplementation(project(":lance:lance-common")) {
exclude("*")
}
testImplementation(project(":server"))
testImplementation(project(":server-common"))
testImplementation(libs.bundles.jetty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
package org.apache.gravitino.integration.test;

import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static org.apache.gravitino.lance.common.config.LanceConfig.GRAVITINO_NAMESPACE_BACKEND;
import static org.apache.gravitino.lance.common.config.LanceConfig.LANCE_CONFIG_PREFIX;
import static org.apache.gravitino.lance.common.config.LanceConfig.NAMESPACE_BACKEND;
import static org.apache.gravitino.lance.common.config.LanceConfig.NAMESPACE_BACKEND_URI;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
Expand All @@ -27,6 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -50,6 +55,7 @@
import org.apache.gravitino.server.GravitinoServer;
import org.apache.gravitino.server.ServerConfig;
import org.apache.gravitino.server.web.JettyServerConfig;
import org.junit.platform.commons.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -78,11 +84,32 @@ public MiniGravitino(MiniGravitinoContext context) throws IOException {
mockConfDir.mkdirs();
}

private void removeAuxRestConfiguration(Properties properties) {
// Disable Iceberg REST service
properties.remove(
AuxiliaryServiceManager.GRAVITINO_AUX_SERVICE_PREFIX
+ AuxiliaryServiceManager.AUX_SERVICE_NAMES);
private void removeAuxRestConfiguration(Properties properties, String serviceToRemove) {
String value =
properties.getProperty(
AuxiliaryServiceManager.GRAVITINO_AUX_SERVICE_PREFIX
+ AuxiliaryServiceManager.AUX_SERVICE_NAMES);
if (StringUtils.isNotBlank(value) && StringUtils.isNotBlank(serviceToRemove)) {
List<String> serviceNames = COMMA.splitToList(value);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this splitToList also do the trim to avoid some invisible characters like white space?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes. Here is the definition of COMMA:

private static final Splitter COMMA = Splitter.on(",").omitEmptyStrings().trimResults();

List<String> updatedServiceNames = new ArrayList<>();
for (String serviceName : serviceNames) {
if (!serviceName.equalsIgnoreCase(serviceToRemove)) {
updatedServiceNames.add(serviceName);
}
}

String updatedValue = String.join(",", updatedServiceNames);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the updatedServiceNames is empty, shall we remove the config?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, fixed

if (StringUtils.isBlank(updatedValue)) {
properties.remove(
AuxiliaryServiceManager.GRAVITINO_AUX_SERVICE_PREFIX
+ AuxiliaryServiceManager.AUX_SERVICE_NAMES);
} else {
properties.setProperty(
AuxiliaryServiceManager.GRAVITINO_AUX_SERVICE_PREFIX
+ AuxiliaryServiceManager.AUX_SERVICE_NAMES,
updatedValue);
}
}
}

public void start() throws Exception {
Expand All @@ -103,9 +130,18 @@ public void start() throws Exception {
serverConfig.loadPropertiesFromFile(
new File(ITUtils.joinPath(mockConfDir.getAbsolutePath(), "gravitino.conf")));

// Disable auxiliary rest service.
if (context.ignoreAuxRestService) {
removeAuxRestConfiguration(properties);
if (context.ignoreIcebergAuxRestService) {
// Disable auxiliary rest service.
removeAuxRestConfiguration(properties, "iceberg-rest");
LOG.info("Iceberg auxiliary REST service is disabled for MiniGravitino.");
ITUtils.overwriteConfigFile(
ITUtils.joinPath(mockConfDir.getAbsolutePath(), "gravitino.conf"), properties);
}

if (context.ignoreLanceAuxRestService) {
// Disable auxiliary rest service.
removeAuxRestConfiguration(properties, "lance-rest");
LOG.info("Lance auxiliary REST service is disabled for MiniGravitino.");
ITUtils.overwriteConfigFile(
ITUtils.joinPath(mockConfDir.getAbsolutePath(), "gravitino.conf"), properties);
}
Expand Down Expand Up @@ -230,20 +266,38 @@ Map<String, String> getIcebergRestServiceConfigs() throws IOException {
return customConfigs;
}

private Map<String, String> getLanceRestServiceConfigs() throws IOException {
private Map<String, String> getLanceRestServiceConfigs(Map<String, String> configMap)
throws IOException {
if (context.ignoreLanceAuxRestService) {
return Collections.emptyMap();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use Collections.emptyMap().


Map<String, String> customConfigs = new HashMap<>();

String lanceJarPath = Paths.get("lance", "lance-rest-server", "build", "libs").toString();
String lanceConfigPath =
Paths.get("lance", "lance-rest-server", "src", "main", "resources").toString();
customConfigs.put(
"gravitino.lance-rest." + AuxiliaryServiceManager.AUX_SERVICE_CLASSPATH,
LANCE_CONFIG_PREFIX + AuxiliaryServiceManager.AUX_SERVICE_CLASSPATH,
String.join(",", lanceJarPath, lanceConfigPath));

customConfigs.put(
"gravitino.lance-rest." + JettyServerConfig.WEBSERVER_HTTP_PORT.getKey(),
LANCE_CONFIG_PREFIX + JettyServerConfig.WEBSERVER_HTTP_PORT.getKey(),
String.valueOf(RESTUtils.findAvailablePort(4000, 5000)));
return customConfigs;

if (GRAVITINO_NAMESPACE_BACKEND.equals(
configMap.getOrDefault(NAMESPACE_BACKEND.getKey(), NAMESPACE_BACKEND.getDefaultValue()))) {
// Set the Lance REST service to use the Gravitino server URI
String gravitinoUri =
String.format(
"http://%s:%s",
"localhost",
configMap.get(
GravitinoServer.WEBSERVER_CONF_PREFIX
+ JettyServerConfig.WEBSERVER_HTTP_PORT.getKey()));
customConfigs.put(LANCE_CONFIG_PREFIX + NAMESPACE_BACKEND_URI.getKey(), gravitinoUri);
}
return ImmutableMap.copyOf(customConfigs);
}

// Customize the config file
Expand All @@ -255,7 +309,7 @@ private void customizeConfigFile(String configTempFileName, String configFileNam
String.valueOf(RESTUtils.findAvailablePort(2000, 3000)));

configMap.putAll(getIcebergRestServiceConfigs());
configMap.putAll(getLanceRestServiceConfigs());
configMap.putAll(getLanceRestServiceConfigs(configMap));
configMap.putAll(context.customConfig);

ITUtils.rewriteConfigFile(configTempFileName, configFileName, configMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@

public class MiniGravitinoContext {
Map<String, String> customConfig;
final boolean ignoreAuxRestService;
final boolean ignoreIcebergAuxRestService;
final boolean ignoreLanceAuxRestService;

public MiniGravitinoContext(Map<String, String> customConfig, boolean ignoreAuxRestService) {
public MiniGravitinoContext(
Map<String, String> customConfig,
boolean ignoreIcebergAuxRestService,
boolean ignoreLanceAuxRestService) {
this.customConfig = customConfig;
this.ignoreAuxRestService = ignoreAuxRestService;
this.ignoreIcebergAuxRestService = ignoreIcebergAuxRestService;
this.ignoreLanceAuxRestService = ignoreLanceAuxRestService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.apache.gravitino.Configs.ENTITY_RELATIONAL_JDBC_BACKEND_PATH;
import static org.apache.gravitino.integration.test.util.TestDatabaseName.PG_CATALOG_POSTGRESQL_IT;
import static org.apache.gravitino.integration.test.util.TestDatabaseName.PG_JDBC_BACKEND;
import static org.apache.gravitino.lance.common.config.LanceConfig.LANCE_CONFIG_PREFIX;
import static org.apache.gravitino.lance.common.config.LanceConfig.METALAKE_NAME;
import static org.apache.gravitino.server.GravitinoServer.WEBSERVER_CONF_PREFIX;

import com.google.common.base.Splitter;
Expand Down Expand Up @@ -102,7 +104,9 @@ public class BaseIT {

protected Map<String, String> customConfigs = new HashMap<>();

protected boolean ignoreAuxRestService = true;
protected boolean ignoreIcebergAuxRestService = true;

protected boolean ignoreLanceAuxRestService = true;

public String DOWNLOAD_MYSQL_JDBC_DRIVER_URL =
"https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.26/mysql-connector-java-8.0.26.jar";
Expand Down Expand Up @@ -133,6 +137,16 @@ public void registerCustomConfigs(Map<String, String> configs) {
customConfigs.putAll(configs);
}

protected int getLanceRESTServerPort() {
JettyServerConfig lanceServerConfig =
JettyServerConfig.fromConfig(serverConfig, LANCE_CONFIG_PREFIX);
return lanceServerConfig.getHttpPort();
}

protected String getLanceRESTServerMetalakeName() {
return serverConfig.getRawString(LANCE_CONFIG_PREFIX + METALAKE_NAME.getKey());
}

private void rewriteGravitinoServerConfig() throws IOException {
String gravitinoHome = System.getenv("GRAVITINO_HOME");
Path configPath = Paths.get(gravitinoHome, "conf", GravitinoServer.CONF_FILE);
Expand Down Expand Up @@ -329,8 +343,15 @@ public void startIntegrationTest() throws Exception {

serverConfig = new ServerConfig();
customConfigs.put(ENTITY_RELATIONAL_JDBC_BACKEND_PATH.getKey(), file.getAbsolutePath());
if (!ignoreLanceAuxRestService) {
customConfigs.put(
LANCE_CONFIG_PREFIX + METALAKE_NAME.getKey(),
GravitinoITUtils.genRandomName("LanceRESTService_metalake"));
}
if (testMode != null && testMode.equals(ITUtils.EMBEDDED_TEST_MODE)) {
MiniGravitinoContext context = new MiniGravitinoContext(customConfigs, ignoreAuxRestService);
MiniGravitinoContext context =
new MiniGravitinoContext(
customConfigs, ignoreIcebergAuxRestService, ignoreLanceAuxRestService);
miniGravitino = new MiniGravitino(context);
miniGravitino.start();
serverConfig = miniGravitino.getServerConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.apache.gravitino.SchemaChange;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.CatalogAlreadyExistsException;
import org.apache.gravitino.exceptions.CatalogInUseException;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchSchemaException;
import org.apache.gravitino.exceptions.NonEmptyCatalogException;
Expand Down Expand Up @@ -332,7 +333,8 @@ private CreateNamespaceResponse createOrUpdateCatalog(
// Catalog exists, handle based on mode
switch (mode) {
case EXIST_OK:
response.setProperties(Maps.newHashMap());
response.setProperties(
Optional.ofNullable(catalog.properties()).orElse(Collections.emptyMap()));
return response;
case CREATE:
throw LanceNamespaceException.conflict(
Expand All @@ -344,7 +346,7 @@ private CreateNamespaceResponse createOrUpdateCatalog(
CatalogChange[] changes =
buildChanges(
properties,
catalog.properties(),
removeInUseProperty(catalog.properties()),
CatalogChange::setProperty,
CatalogChange::removeProperty,
CatalogChange[]::new);
Expand All @@ -356,6 +358,12 @@ private CreateNamespaceResponse createOrUpdateCatalog(
}
}

private Map<String, String> removeInUseProperty(Map<String, String> properties) {
return properties.entrySet().stream()
.filter(e -> !e.getKey().equalsIgnoreCase(Catalog.PROPERTY_IN_USE))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's used to remove the in-use property from the old catalog when creating a catalog namespace with overwrite mode.

Because we use removeOldCatalogProperty and setNewCatalogProperty to achieve this, the in-use property in the catalog is reserved and cannot be used in removePropertyChange.

private CreateNamespaceResponse createOrUpdateSchema(
String catalogName,
String schemaName,
Expand All @@ -378,7 +386,8 @@ private CreateNamespaceResponse createOrUpdateSchema(
// Schema exists, handle based on mode
switch (mode) {
case EXIST_OK:
response.setProperties(Maps.newHashMap());
response.setProperties(
Optional.ofNullable(schema.properties()).orElse(Collections.emptyMap()));
return response;
case CREATE:
throw LanceNamespaceException.conflict(
Expand Down Expand Up @@ -422,9 +431,9 @@ private DropNamespaceResponse dropCatalog(
}
return new DropNamespaceResponse(); // SKIP mode
}
} catch (NonEmptyCatalogException e) {
} catch (NonEmptyCatalogException | CatalogInUseException e) {
throw LanceNamespaceException.badRequest(
String.format("Catalog %s is not empty.", catalogName),
String.format("Catalog %s is not empty or in used", catalogName),
NonEmptyCatalogException.class.getSimpleName(),
catalogName,
CommonUtil.formatCurrentStackTrace());
Expand Down
17 changes: 17 additions & 0 deletions lance/lance-rest-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,24 @@ dependencies {
implementation(libs.jackson.datatype.jdk8)
implementation(libs.jackson.datatype.jsr310)

testImplementation(project(":clients:client-java"))
testImplementation(project(":server"))
testImplementation(project(":integration-test-common", "testArtifacts"))

testImplementation(libs.commons.io)
testImplementation(libs.jersey.test.framework.core) {
exclude(group = "org.junit.jupiter")
}
testImplementation(libs.jersey.test.framework.provider.jetty) {
exclude(group = "org.junit.jupiter")
}

testImplementation(libs.junit.jupiter.api)
testImplementation(libs.mockito.inline)
testImplementation(libs.mysql.driver)
testImplementation(libs.postgresql.driver)
testImplementation(libs.testcontainers)

testRuntimeOnly(libs.junit.jupiter.engine)
}

Expand Down
Loading