This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 2c4f9cca5126969abfc61b8b6cac0177f81d22e1 Author: Michael Blow <[email protected]> AuthorDate: Thu Nov 16 19:32:09 2023 -0500 [NO ISSUE][*DB] Return 404 (not 500) on unknown cluster api path Change-Id: I2d5a981cc8268a27b36331302997b90f39be7055 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17961 Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Reviewed-by: Hussain Towaileb <[email protected]> --- .../asterix/api/http/server/ClusterApiServlet.java | 17 ++++++++------- .../src/test/resources/runtimets/api.xml | 6 ++++++ .../api/cluster_state_5/cluster_state_5.1.get.http | 25 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java index eaeb08297f..ed0a68a8ee 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java @@ -21,7 +21,6 @@ package org.apache.asterix.api.http.server; import static org.apache.asterix.api.http.server.ServletConstants.ASTERIX_APP_CONTEXT_INFO_ATTR; import java.io.IOException; -import java.io.PrintWriter; import java.util.concurrent.ConcurrentMap; import java.util.function.Predicate; @@ -29,6 +28,7 @@ import org.apache.asterix.common.dataflow.ICcApplicationContext; import org.apache.hyracks.api.config.IOption; import org.apache.hyracks.api.config.Section; import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.api.exceptions.IFormattedException; import org.apache.hyracks.control.common.config.ConfigUtils; import org.apache.hyracks.control.common.controllers.ControllerConfig; import org.apache.hyracks.http.api.IServletRequest; @@ -36,7 +36,6 @@ import org.apache.hyracks.http.api.IServletResponse; import org.apache.hyracks.http.server.AbstractServlet; import org.apache.hyracks.http.server.utils.HttpUtil; import org.apache.hyracks.util.JSONUtil; -import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -67,7 +66,6 @@ public class ClusterApiServlet extends AbstractServlet { @Override protected void get(IServletRequest request, IServletResponse response) throws IOException { HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, request); - PrintWriter responseWriter = response.writer(); try { ObjectNode json; response.setStatus(HttpResponseStatus.OK); @@ -81,15 +79,18 @@ public class ClusterApiServlet extends AbstractServlet { default: throw new IllegalArgumentException(); } - JSONUtil.writeNode(responseWriter, json); + JSONUtil.writeNode(response.writer(), json); } catch (IllegalArgumentException e) { // NOSONAR - exception not logged or rethrown sendError(response, HttpResponseStatus.NOT_FOUND); } catch (Exception e) { - LOGGER.log(Level.INFO, "exception thrown for " + request, e); - response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); - responseWriter.write(e.toString()); + LOGGER.info("exception thrown for {}", request, e); + if (e instanceof IFormattedException) { + sendError(response, HttpResponseStatus.INTERNAL_SERVER_ERROR, (IFormattedException) e); + } else { + sendError(response, HttpResponseStatus.INTERNAL_SERVER_ERROR, e.toString()); + + } } - responseWriter.flush(); } @Override diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/api.xml b/asterixdb/asterix-app/src/test/resources/runtimets/api.xml index 8b168891e5..8a163d2fa3 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/api.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/api.xml @@ -40,6 +40,12 @@ <output-dir compare="Text">cluster_state_4</output-dir> </compilation-unit> </test-case> + <test-case FilePath="api"> + <compilation-unit name="cluster_state_5"> + <output-dir compare="Text">cluster_state_5</output-dir> + <expected-error>HTTP/1.1 404 Not Found</expected-error> + </compilation-unit> + </test-case> <test-case FilePath="api"> <compilation-unit name="cluster_state_cc_1"> <output-dir compare="Text">cluster_state_cc_1</output-dir> diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_5/cluster_state_5.1.get.http b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_5/cluster_state_5.1.get.http new file mode 100644 index 0000000000..d6d5636abf --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_5/cluster_state_5.1.get.http @@ -0,0 +1,25 @@ +/* + * 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. + */ +/* + * Test case Name : cluster_state_2 + * Description : test cluster state api malformed uri (404) + * Expected Result : Negative + * Date : 7th September 2016 + */ +/admin/cluster/
