-
Notifications
You must be signed in to change notification settings - Fork 818
[#9009]improvement(lance-rest-server): add ITs for LRS namespace operations #9008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33d17b9
e91be3f
65ec483
c9a738d
9b47908
657bb49
a289055
0384cf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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); | ||
| List<String> updatedServiceNames = new ArrayList<>(); | ||
| for (String serviceName : serviceNames) { | ||
| if (!serviceName.equalsIgnoreCase(serviceToRemove)) { | ||
| updatedServiceNames.add(serviceName); | ||
| } | ||
| } | ||
|
|
||
| String updatedValue = String.join(",", updatedServiceNames); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
@@ -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); | ||
| } | ||
|
|
@@ -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(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
|
|
||
| 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 | ||
|
|
@@ -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); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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( | ||
|
|
@@ -344,7 +346,7 @@ private CreateNamespaceResponse createOrUpdateCatalog( | |
| CatalogChange[] changes = | ||
| buildChanges( | ||
| properties, | ||
| catalog.properties(), | ||
| removeInUseProperty(catalog.properties()), | ||
| CatalogChange::setProperty, | ||
| CatalogChange::removeProperty, | ||
| CatalogChange[]::new); | ||
|
|
@@ -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)); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we remove this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used to remove the Because we use |
||
| private CreateNamespaceResponse createOrUpdateSchema( | ||
| String catalogName, | ||
| String schemaName, | ||
|
|
@@ -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( | ||
|
|
@@ -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()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this
splitToListalso do thetrimto avoid some invisible characters like white space?There was a problem hiding this comment.
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: