Skip to content

Commit

Permalink
replace UnauthorizedException with ConnectionFailedException
Browse files Browse the repository at this point in the history
  • Loading branch information
mchades committed Nov 12, 2024
1 parent 2cb05dd commit 8836423
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -474,7 +474,7 @@ void testTestConnection() {

Exception exception =
assertThrows(
UnauthorizedException.class,
ConnectionFailedException.class,
() ->
metalake.testConnection(
GravitinoITUtils.genRandomName("doris_it_catalog"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -274,7 +274,7 @@ void testTestConnection() throws SQLException {

Exception exception =
assertThrows(
UnauthorizedException.class,
ConnectionFailedException.class,
() ->
metalake.testConnection(
GravitinoITUtils.genRandomName("mysql_it_catalog"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -340,7 +340,7 @@ void testTestConnection() throws SQLException {

Exception exception =
assertThrows(
UnauthorizedException.class,
ConnectionFailedException.class,
() ->
metalake.testConnection(
GravitinoITUtils.genRandomName("oceanbase_it_catalog"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -254,7 +254,7 @@ void testTestConnection() throws SQLException {

Exception exception =
assertThrows(
UnauthorizedException.class,
ConnectionFailedException.class,
() ->
metalake.testConnection(
GravitinoITUtils.genRandomName("postgresql_it_catalog"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testCreateMultipleJdbcInIceberg() throws URISyntaxException, SQLExce
// test wrong password
Exception exception =
Assertions.assertThrows(
UnauthorizedException.class,
ConnectionFailedException.class,
() ->
metalake.testConnection(
mysqlCatalogName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,7 +71,7 @@ void testTestConnection() {

Exception exception =
Assertions.assertThrows(
UnauthorizedException.class,
ConnectionFailedException.class,
() ->
metalake.testConnection(
GravitinoITUtils.genRandomName("paimon_it_catalog"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8836423

Please sign in to comment.