From 88364230a892f8351ab423d3e57904f6e46d499a Mon Sep 17 00:00:00 2001 From: mchades Date: Tue, 12 Nov 2024 21:46:00 +0800 Subject: [PATCH] replace UnauthorizedException with ConnectionFailedException --- .../jdbc/converter/JdbcExceptionConverter.java | 4 ++-- .../doris/converter/DorisExceptionConverter.java | 3 ++- .../doris/integration/test/CatalogDorisIT.java | 4 ++-- .../mysql/integration/test/CatalogMysqlIT.java | 4 ++-- .../integration/test/CatalogOceanBaseIT.java | 4 ++-- .../converter/PostgreSqlExceptionConverter.java | 4 ++-- .../integration/test/CatalogPostgreSqlIT.java | 4 ++-- .../integration/test/TestMultipleJDBCLoad.java | 4 ++-- .../lakehouse/paimon/utils/CatalogUtils.java | 4 ++-- .../integration/test/CatalogPaimonJdbcIT.java | 4 ++-- .../org/apache/gravitino/client/ErrorHandlers.java | 3 --- .../gravitino/dto/responses/ErrorConstants.java | 3 --- .../gravitino/dto/responses/ErrorResponse.java | 13 ------------- .../iceberg/common/utils/IcebergCatalogUtil.java | 4 ++-- .../server/web/rest/ExceptionHandlers.java | 4 ---- 15 files changed, 22 insertions(+), 44 deletions(-) diff --git a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcExceptionConverter.java b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcExceptionConverter.java index e6b449db0d9..d4a60c8dbf9 100644 --- a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcExceptionConverter.java +++ b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcExceptionConverter.java @@ -19,12 +19,12 @@ package org.apache.gravitino.catalog.jdbc.converter; import java.sql.SQLException; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.GravitinoRuntimeException; import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.exceptions.NoSuchTableException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; import org.apache.gravitino.exceptions.TableAlreadyExistsException; -import org.apache.gravitino.exceptions.UnauthorizedException; /** Interface for converter JDBC exceptions to Gravitino exceptions. */ public class JdbcExceptionConverter { @@ -54,7 +54,7 @@ public GravitinoRuntimeException toGravitinoException(final SQLException sqlExce default: if (sqlException.getMessage() != null && sqlException.getMessage().contains("Access denied")) { - return new UnauthorizedException(sqlException, sqlException.getMessage()); + return new ConnectionFailedException(sqlException, sqlException.getMessage()); } return new GravitinoRuntimeException(sqlException, sqlException.getMessage()); } diff --git a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisExceptionConverter.java b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisExceptionConverter.java index cd073a7d9f8..ccdd4c7da20 100644 --- a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisExceptionConverter.java +++ b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisExceptionConverter.java @@ -22,6 +22,7 @@ import java.sql.SQLException; import java.util.regex.Pattern; import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.GravitinoRuntimeException; import org.apache.gravitino.exceptions.NoSuchColumnException; import org.apache.gravitino.exceptions.NoSuchPartitionException; @@ -110,7 +111,7 @@ public GravitinoRuntimeException toGravitinoException(SQLException se) { return new PartitionAlreadyExistsException(se, se.getMessage()); default: if (se.getMessage() != null && se.getMessage().contains("Access denied")) { - return new UnauthorizedException(se, se.getMessage()); + return new ConnectionFailedException(se, se.getMessage()); } return new GravitinoRuntimeException(se, se.getMessage()); } diff --git a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.java b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.java index e6ac486100f..ca04c03c40f 100644 --- a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.java +++ b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.java @@ -42,10 +42,10 @@ import org.apache.gravitino.SupportsSchemas; import org.apache.gravitino.catalog.jdbc.config.JdbcConfig; import org.apache.gravitino.client.GravitinoMetalake; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.NoSuchPartitionException; import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; -import org.apache.gravitino.exceptions.UnauthorizedException; import org.apache.gravitino.integration.test.container.ContainerSuite; import org.apache.gravitino.integration.test.container.DorisContainer; import org.apache.gravitino.integration.test.util.BaseIT; @@ -474,7 +474,7 @@ void testTestConnection() { Exception exception = assertThrows( - UnauthorizedException.class, + ConnectionFailedException.class, () -> metalake.testConnection( GravitinoITUtils.genRandomName("doris_it_catalog"), diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java index e1c97ff387c..6b8c824d001 100644 --- a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java +++ b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java @@ -45,10 +45,10 @@ import org.apache.gravitino.catalog.jdbc.config.JdbcConfig; import org.apache.gravitino.catalog.mysql.integration.test.service.MysqlService; import org.apache.gravitino.client.GravitinoMetalake; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.exceptions.NotFoundException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; -import org.apache.gravitino.exceptions.UnauthorizedException; import org.apache.gravitino.integration.test.container.ContainerSuite; import org.apache.gravitino.integration.test.container.MySQLContainer; import org.apache.gravitino.integration.test.util.BaseIT; @@ -274,7 +274,7 @@ void testTestConnection() throws SQLException { Exception exception = assertThrows( - UnauthorizedException.class, + ConnectionFailedException.class, () -> metalake.testConnection( GravitinoITUtils.genRandomName("mysql_it_catalog"), diff --git a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java index dbcacde54ad..4b5181c74f0 100644 --- a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java +++ b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java @@ -43,10 +43,10 @@ import org.apache.gravitino.catalog.jdbc.config.JdbcConfig; import org.apache.gravitino.catalog.oceanbase.integration.test.service.OceanBaseService; import org.apache.gravitino.client.GravitinoMetalake; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.exceptions.NotFoundException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; -import org.apache.gravitino.exceptions.UnauthorizedException; import org.apache.gravitino.integration.test.container.ContainerSuite; import org.apache.gravitino.integration.test.container.OceanBaseContainer; import org.apache.gravitino.integration.test.util.BaseIT; @@ -340,7 +340,7 @@ void testTestConnection() throws SQLException { Exception exception = assertThrows( - UnauthorizedException.class, + ConnectionFailedException.class, () -> metalake.testConnection( GravitinoITUtils.genRandomName("oceanbase_it_catalog"), diff --git a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlExceptionConverter.java b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlExceptionConverter.java index de6f5999336..4bae02cf725 100644 --- a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlExceptionConverter.java +++ b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlExceptionConverter.java @@ -20,12 +20,12 @@ import java.sql.SQLException; import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.GravitinoRuntimeException; import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.exceptions.NoSuchTableException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; import org.apache.gravitino.exceptions.TableAlreadyExistsException; -import org.apache.gravitino.exceptions.UnauthorizedException; public class PostgreSqlExceptionConverter extends JdbcExceptionConverter { @@ -49,7 +49,7 @@ public GravitinoRuntimeException toGravitinoException(SQLException se) { } } else { if (se.getMessage() != null && se.getMessage().contains("password authentication failed")) { - return new UnauthorizedException(se.getMessage(), se); + return new ConnectionFailedException(se.getMessage(), se); } return new GravitinoRuntimeException(se.getMessage(), se); } diff --git a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java index 00feca9ac48..558775014dc 100644 --- a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java +++ b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java @@ -44,9 +44,9 @@ import org.apache.gravitino.catalog.jdbc.config.JdbcConfig; import org.apache.gravitino.catalog.postgresql.integration.test.service.PostgreSqlService; import org.apache.gravitino.client.GravitinoMetalake; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; -import org.apache.gravitino.exceptions.UnauthorizedException; import org.apache.gravitino.integration.test.container.ContainerSuite; import org.apache.gravitino.integration.test.container.PGImageName; import org.apache.gravitino.integration.test.container.PostgreSQLContainer; @@ -254,7 +254,7 @@ void testTestConnection() throws SQLException { Exception exception = assertThrows( - UnauthorizedException.class, + ConnectionFailedException.class, () -> metalake.testConnection( GravitinoITUtils.genRandomName("postgresql_it_catalog"), diff --git a/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/TestMultipleJDBCLoad.java b/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/TestMultipleJDBCLoad.java index c3680b05eb8..40e437a0f25 100644 --- a/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/TestMultipleJDBCLoad.java +++ b/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/TestMultipleJDBCLoad.java @@ -31,7 +31,7 @@ import org.apache.gravitino.Catalog; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.client.GravitinoMetalake; -import org.apache.gravitino.exceptions.UnauthorizedException; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.iceberg.common.IcebergConfig; import org.apache.gravitino.integration.test.container.MySQLContainer; import org.apache.gravitino.integration.test.container.PostgreSQLContainer; @@ -103,7 +103,7 @@ public void testCreateMultipleJdbcInIceberg() throws URISyntaxException, SQLExce // test wrong password Exception exception = Assertions.assertThrows( - UnauthorizedException.class, + ConnectionFailedException.class, () -> metalake.testConnection( mysqlCatalogName, diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.java index f9aa529ae3c..3ae48576cdd 100644 --- a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.java +++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.java @@ -40,7 +40,7 @@ import org.apache.gravitino.catalog.lakehouse.paimon.authentication.AuthenticationConfig; import org.apache.gravitino.catalog.lakehouse.paimon.authentication.kerberos.KerberosClient; import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonBackendCatalogWrapper; -import org.apache.gravitino.exceptions.UnauthorizedException; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.hadoop.conf.Configuration; import org.apache.paimon.catalog.Catalog; import org.apache.paimon.catalog.CatalogContext; @@ -115,7 +115,7 @@ public static Catalog loadCatalogBackendWithSimpleAuth(PaimonConfig paimonConfig } catch (RuntimeException e) { if (e.getCause() instanceof SQLException && e.getCause().getMessage().contains("Access denied")) { - throw new UnauthorizedException(e, e.getMessage()); + throw new ConnectionFailedException(e, e.getMessage()); } throw e; } diff --git a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonJdbcIT.java b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonJdbcIT.java index c39bbba8caf..3eb14f132f5 100644 --- a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonJdbcIT.java +++ b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonJdbcIT.java @@ -22,7 +22,7 @@ import java.util.Map; import org.apache.gravitino.Catalog; import org.apache.gravitino.catalog.lakehouse.paimon.PaimonCatalogPropertiesMetadata; -import org.apache.gravitino.exceptions.UnauthorizedException; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.integration.test.container.HiveContainer; import org.apache.gravitino.integration.test.util.GravitinoITUtils; import org.junit.jupiter.api.Assertions; @@ -71,7 +71,7 @@ void testTestConnection() { Exception exception = Assertions.assertThrows( - UnauthorizedException.class, + ConnectionFailedException.class, () -> metalake.testConnection( GravitinoITUtils.genRandomName("paimon_it_catalog"), diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/ErrorHandlers.java b/clients/client-java/src/main/java/org/apache/gravitino/client/ErrorHandlers.java index bb477e53049..3dcf6672ae6 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/ErrorHandlers.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/ErrorHandlers.java @@ -470,9 +470,6 @@ public void accept(ErrorResponse errorResponse) { case ErrorConstants.NON_EMPTY_CODE: throw new NonEmptyCatalogException(errorMessage); - case ErrorConstants.UNAUTHORIZED_CODE: - throw new UnauthorizedException(errorMessage); - default: super.accept(errorResponse); } diff --git a/common/src/main/java/org/apache/gravitino/dto/responses/ErrorConstants.java b/common/src/main/java/org/apache/gravitino/dto/responses/ErrorConstants.java index 1e1cdced2e4..4953463d74b 100644 --- a/common/src/main/java/org/apache/gravitino/dto/responses/ErrorConstants.java +++ b/common/src/main/java/org/apache/gravitino/dto/responses/ErrorConstants.java @@ -54,9 +54,6 @@ public class ErrorConstants { /** Error codes for drop an in use entity. */ public static final int IN_USE_CODE = 1010; - /** Error codes for unauthorized operation. */ - public static final int UNAUTHORIZED_CODE = 1011; - /** Error codes for invalid state. */ public static final int UNKNOWN_ERROR_CODE = 1100; diff --git a/common/src/main/java/org/apache/gravitino/dto/responses/ErrorResponse.java b/common/src/main/java/org/apache/gravitino/dto/responses/ErrorResponse.java index d3cc95e4ace..015743bbfe9 100644 --- a/common/src/main/java/org/apache/gravitino/dto/responses/ErrorResponse.java +++ b/common/src/main/java/org/apache/gravitino/dto/responses/ErrorResponse.java @@ -306,19 +306,6 @@ public static ErrorResponse oauthError(int code, String type, String message) { return new ErrorResponse(code, type, message, null); } - /** - * Create a new unauthorized error instance of {@link ErrorResponse}. - * - * @param type The type of the error. - * @param message The message of the error. - * @param throwable The throwable that caused the error. - * @return The new instance. - */ - public static ErrorResponse unauthorized(String type, String message, Throwable throwable) { - return new ErrorResponse( - ErrorConstants.UNAUTHORIZED_CODE, type, message, getStackTrace(throwable)); - } - /** * Create a new unsupported operation error instance of {@link ErrorResponse}. * diff --git a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergCatalogUtil.java b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergCatalogUtil.java index 463c8b266f5..a2402082fbe 100644 --- a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergCatalogUtil.java +++ b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergCatalogUtil.java @@ -31,7 +31,7 @@ import java.util.Locale; import java.util.Map; import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants; -import org.apache.gravitino.exceptions.UnauthorizedException; +import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.iceberg.common.ClosableHiveCatalog; import org.apache.gravitino.iceberg.common.IcebergCatalogBackend; import org.apache.gravitino.iceberg.common.IcebergConfig; @@ -144,7 +144,7 @@ private static JdbcCatalog loadJdbcCatalog(IcebergConfig icebergConfig) { } catch (UncheckedSQLException e) { if (e.getCause() instanceof SQLException && e.getCause().getMessage().contains("Access denied")) { - throw new UnauthorizedException(e, e.getMessage()); + throw new ConnectionFailedException(e, e.getMessage()); } throw e; } diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java b/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java index 9f60b5bd4bf..8d1ba85657e 100644 --- a/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java +++ b/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java @@ -45,7 +45,6 @@ import org.apache.gravitino.exceptions.TagAlreadyAssociatedException; import org.apache.gravitino.exceptions.TagAlreadyExistsException; import org.apache.gravitino.exceptions.TopicAlreadyExistsException; -import org.apache.gravitino.exceptions.UnauthorizedException; import org.apache.gravitino.exceptions.UserAlreadyExistsException; import org.apache.gravitino.server.web.Utils; import org.eclipse.jetty.util.StringUtil; @@ -139,9 +138,6 @@ public static Response handleTestConnectionException(Exception e) { } else if (e instanceof NotInUseException) { response = ErrorResponse.notInUse(e.getClass().getSimpleName(), e.getMessage(), e); - } else if (e instanceof UnauthorizedException) { - response = ErrorResponse.unauthorized(e.getClass().getSimpleName(), e.getMessage(), e); - } else { return Utils.internalError(e.getMessage(), e); }