From d6039fb7d8372e6d1548fa3dcb402e9ba088b6cf Mon Sep 17 00:00:00 2001 From: yantian Date: Wed, 8 Jan 2025 17:56:15 +0800 Subject: [PATCH] fix alter table case fail in RESTCatalogMockServerTest --- .../paimon/rest/DefaultErrorHandler.java | 1 + .../org/apache/paimon/rest/RESTCatalog.java | 5 ++++ .../UnsupportedOperationException.java | 26 +++++++++++++++++++ .../paimon/rest/MockRESTCatalogServer.java | 8 +++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 paimon-core/src/main/java/org/apache/paimon/rest/exceptions/UnsupportedOperationException.java diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/DefaultErrorHandler.java b/paimon-core/src/main/java/org/apache/paimon/rest/DefaultErrorHandler.java index 2e1eaefdef76..944b986b3f1d 100644 --- a/paimon-core/src/main/java/org/apache/paimon/rest/DefaultErrorHandler.java +++ b/paimon-core/src/main/java/org/apache/paimon/rest/DefaultErrorHandler.java @@ -26,6 +26,7 @@ import org.apache.paimon.rest.exceptions.RESTException; import org.apache.paimon.rest.exceptions.ServiceFailureException; import org.apache.paimon.rest.exceptions.ServiceUnavailableException; +import org.apache.paimon.rest.exceptions.UnsupportedOperationException; import org.apache.paimon.rest.responses.ErrorResponse; /** Default error handler. */ diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java index 74ab3a2ab1f4..02d58f3f0f59 100644 --- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java @@ -41,6 +41,7 @@ import org.apache.paimon.rest.exceptions.BadRequestException; import org.apache.paimon.rest.exceptions.ForbiddenException; import org.apache.paimon.rest.exceptions.NoSuchResourceException; +import org.apache.paimon.rest.exceptions.ServiceFailureException; import org.apache.paimon.rest.requests.AlterDatabaseRequest; import org.apache.paimon.rest.requests.AlterTableRequest; import org.apache.paimon.rest.requests.CreateDatabaseRequest; @@ -367,6 +368,10 @@ public void alterTable( throw new ColumnAlreadyExistException(identifier, e.resourceName()); } catch (ForbiddenException e) { throw new TableNoPermissionException(identifier, e); + } catch (org.apache.paimon.rest.exceptions.UnsupportedOperationException e) { + throw new UnsupportedOperationException(e.getMessage()); + } catch (ServiceFailureException e) { + throw new IllegalStateException(e.getMessage()); } } diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/exceptions/UnsupportedOperationException.java b/paimon-core/src/main/java/org/apache/paimon/rest/exceptions/UnsupportedOperationException.java new file mode 100644 index 000000000000..3d4a9f2d5e42 --- /dev/null +++ b/paimon-core/src/main/java/org/apache/paimon/rest/exceptions/UnsupportedOperationException.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.rest.exceptions; + +/** Exception thrown on HTTP 501 - UnsupportedOperationException. */ +public class UnsupportedOperationException extends RESTException { + public UnsupportedOperationException(String message, Object... args) { + super(String.format(message, args)); + } +} diff --git a/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java b/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java index 4bf8a2e2d31e..3a02fb1137b6 100644 --- a/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java +++ b/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java @@ -152,6 +152,12 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio new ErrorResponse( null, null, e.getCause().getCause().getMessage(), 400); return mockResponse(response, 400); + } else if (e instanceof UnsupportedOperationException) { + response = new ErrorResponse(null, null, e.getMessage(), 501); + return mockResponse(response, 501); + } else if (e instanceof IllegalStateException) { + response = new ErrorResponse(null, null, e.getMessage(), 500); + return mockResponse(response, 500); } return new MockResponse().setResponseCode(500); } @@ -185,7 +191,7 @@ private static MockResponse databaseApiHandler( response = new GetDatabaseResponse(database.name(), database.options()); return mockResponse(response, 200); } else if (request.getMethod().equals("DELETE")) { - catalog.dropDatabase(databaseName, true, false); + catalog.dropDatabase(databaseName, true, true); return new MockResponse().setResponseCode(200); } return new MockResponse().setResponseCode(404);