xunliu commented on code in PR #3912:
URL: https://github.com/apache/gravitino/pull/3912#discussion_r1665723262
##########
integration-test/src/test/java/com/datastrato/gravitino/integration/test/authorization/ranger/RangerIT.java:
##########
@@ -5,69 +5,313 @@
package com.datastrato.gravitino.integration.test.authorization.ranger;
import com.datastrato.gravitino.integration.test.container.ContainerSuite;
+import com.datastrato.gravitino.integration.test.container.HiveContainer;
+import com.datastrato.gravitino.integration.test.container.TrinoContainer;
import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.ranger.RangerClient;
import org.apache.ranger.RangerServiceException;
+import org.apache.ranger.plugin.model.RangerPolicy;
import org.apache.ranger.plugin.model.RangerService;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-@Tag("gravitino-docker-test")
public class RangerIT {
- private static final String serviceName = "trino-test";
- private static final String trinoType = "trino";
+ private static final Logger LOG = LoggerFactory.getLogger(RangerIT.class);
+ protected static final String RANGER_TRINO_REPO_NAME = "trinoDev";
+ private static final String RANGER_TRINO_TYPE = "trino";
+ protected static final String RANGER_HIVE_REPO_NAME = "hiveDev";
+ private static final String RANGER_HIVE_TYPE = "hive";
+ protected static final String RANGER_HDFS_REPO_NAME = "hdfsDev";
+ private static final String RANGER_HDFS_TYPE = "hdfs";
private static RangerClient rangerClient;
private static final ContainerSuite containerSuite =
ContainerSuite.getInstance();
@BeforeAll
public static void setup() {
containerSuite.startRangerContainer();
-
rangerClient = containerSuite.getRangerContainer().rangerClient;
}
@AfterAll
public static void cleanup() throws RangerServiceException {
- if (rangerClient != null) {
- rangerClient.deleteService(serviceName);
+ try {
+ if (rangerClient != null) {
+ if (rangerClient.getService(RANGER_TRINO_REPO_NAME) != null) {
+ rangerClient.deleteService(RANGER_TRINO_REPO_NAME);
+ }
+ if (rangerClient.getService(RANGER_HIVE_REPO_NAME) != null) {
+ rangerClient.deleteService(RANGER_HIVE_REPO_NAME);
+ }
+ }
+ } catch (RangerServiceException e) {
+ // ignore
}
}
- @Test
- public void testCreateTrinoService() throws RangerServiceException {
+ public void createRangerTrinoRepository(String tirnoIp) {
String usernameKey = "username";
String usernameVal = "admin";
String jdbcKey = "jdbc.driverClassName";
String jdbcVal = "io.trino.jdbc.TrinoDriver";
String jdbcUrlKey = "jdbc.url";
- String jdbcUrlVal = "http://localhost:8080";
+ String jdbcUrlVal = String.format("http:hive2://%s:%d", tirnoIp,
TrinoContainer.TRINO_PORT);
RangerService service = new RangerService();
- service.setType(trinoType);
- service.setName(serviceName);
+ service.setType(RANGER_TRINO_TYPE);
+ service.setName(RANGER_TRINO_REPO_NAME);
service.setConfigs(
ImmutableMap.<String, String>builder()
.put(usernameKey, usernameVal)
.put(jdbcKey, jdbcVal)
.put(jdbcUrlKey, jdbcUrlVal)
.build());
- RangerService createdService = rangerClient.createService(service);
- Assertions.assertNotNull(createdService);
+ try {
+ RangerService createdService = rangerClient.createService(service);
+ Assertions.assertNotNull(createdService);
+
+ Map<String, String> filter =
+ ImmutableMap.of(RangerRef.SEARCH_FILTER_SERVICE_NAME,
RANGER_TRINO_REPO_NAME);
+ List<RangerService> services = rangerClient.findServices(filter);
+ Assertions.assertEquals(services.get(0).getType(), RANGER_TRINO_TYPE);
+ Assertions.assertEquals(services.get(0).getName(),
RANGER_TRINO_REPO_NAME);
+ Assertions.assertEquals(services.get(0).getConfigs().get(usernameKey),
usernameVal);
+ Assertions.assertEquals(services.get(0).getConfigs().get(jdbcKey),
jdbcVal);
+ Assertions.assertEquals(services.get(0).getConfigs().get(jdbcUrlKey),
jdbcUrlVal);
+ } catch (RangerServiceException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void createRangerHiveRepository(String hiveIp, boolean
cleanAllPolicy) {
+ try {
+ if (null != rangerClient.getService(RANGER_HIVE_REPO_NAME)) {
+ return;
+ }
+ } catch (RangerServiceException e) {
+ LOG.error("Error while fetching service: {}", e.getMessage());
+ }
+
+ String usernameKey = "username";
+ String usernameVal = "admin";
+ String passwordKey = "password";
+ String passwordVal = "admin";
+ String jdbcKey = "jdbc.driverClassName";
+ String jdbcVal = "org.apache.hive.jdbc.HiveDriver";
+ String jdbcUrlKey = "jdbc.url";
+ String jdbcUrlVal =
+ String.format("jdbc:hive2://%s:%d", hiveIp,
HiveContainer.HIVE_SERVICE_PORT);
- Map<String, String> filter = Collections.emptyMap();
- List<RangerService> services = rangerClient.findServices(filter);
- Assertions.assertEquals(services.get(0).getName(), serviceName);
- Assertions.assertEquals(services.get(0).getType(), trinoType);
- Assertions.assertEquals(services.get(0).getConfigs().get(usernameKey),
usernameVal);
- Assertions.assertEquals(services.get(0).getConfigs().get(jdbcKey),
jdbcVal);
- Assertions.assertEquals(services.get(0).getConfigs().get(jdbcUrlKey),
jdbcUrlVal);
+ RangerService service = new RangerService();
+ service.setType(RANGER_HIVE_TYPE);
+ service.setName(RANGER_HIVE_REPO_NAME);
+ service.setConfigs(
+ ImmutableMap.<String, String>builder()
+ .put(usernameKey, usernameVal)
+ .put(passwordKey, passwordVal)
+ .put(jdbcKey, jdbcVal)
+ .put(jdbcUrlKey, jdbcUrlVal)
+ .build());
+
+ try {
+ RangerService createdService = rangerClient.createService(service);
+ Assertions.assertNotNull(createdService);
+
+ Map<String, String> filter =
+ ImmutableMap.of(RangerRef.SEARCH_FILTER_SERVICE_NAME,
RANGER_HIVE_REPO_NAME);
+ List<RangerService> services = rangerClient.findServices(filter);
+ Assertions.assertEquals(services.get(0).getType(), RANGER_HIVE_TYPE);
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]