Merge branch 'gerrit/neo' into 'gerrit/trinity'
Change-Id: I6be5e6c2106e34c374f42eba67060fe82b356a05
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 eaeb082..ed0a68a 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 @@
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.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.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 @@
@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 @@
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 8b16889..8a163d2 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/api.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/api.xml
@@ -41,6 +41,12 @@
</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>
</compilation-unit>
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 0000000..d6d5636
--- /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/