Add links to node/job details to summaries
Change-Id: I012acbf10eb6f11a625a2a5e51eed1421d8fd046
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1530
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
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 1d37baf..34086e7 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
@@ -42,7 +42,6 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.netty.handler.codec.http.HttpHeaderNames;
-import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
public class ClusterApiServlet extends AbstractServlet {
@@ -72,7 +71,7 @@
try {
ObjectNode json;
response.setStatus(HttpResponseStatus.OK);
- switch (path(request)) {
+ switch (localPath(request)) {
case "":
json = getClusterStateJSON(request, "");
break;
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java
index 776f884..d680e6e 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java
@@ -52,7 +52,7 @@
try {
ObjectNode json;
response.setStatus(HttpResponseStatus.OK);
- if ("".equals(path(request))) {
+ if ("".equals(localPath(request))) {
json = (ObjectNode) getClusterStateJSON(request, "../").get("cc");
} else {
json = processNode(request, hcc);
@@ -70,13 +70,13 @@
}
private ObjectNode processNode(IServletRequest request, IHyracksClientConnection hcc) throws Exception {
- String pathInfo = path(request);
- if (pathInfo.endsWith("/")) {
+ String localPath = localPath(request);
+ if (localPath.endsWith("/")) {
throw new IllegalArgumentException();
}
- String[] parts = pathInfo.substring(1).split("/");
+ String[] parts = localPath.substring(1).split("/");
- if ("".equals(pathInfo)) {
+ if ("".equals(localPath)) {
return (ObjectNode) getClusterStateJSON(request, "../../").get("cc");
} else if (parts.length == 1) {
switch (parts[0]) {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
index 366007d..ffe62b4 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
@@ -63,7 +63,7 @@
response.setStatus(HttpResponseStatus.OK);
om.enable(SerializationFeature.INDENT_OUTPUT);
try {
- if (!"".equals(path(request))) {
+ if (!"".equals(localPath(request))) {
throw new IllegalArgumentException();
}
json = getClusterDiagnosticsJSON();
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
index ca0888b..07e70ab 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
@@ -60,7 +60,7 @@
try {
ObjectNode json;
response.setStatus(HttpResponseStatus.OK);
- if ("".equals(path(request))) {
+ if ("".equals(localPath(request))) {
json = om.createObjectNode();
json.set("ncs", getClusterStateJSON(request, "../").get("ncs"));
} else {
@@ -81,11 +81,11 @@
}
private ObjectNode processNode(IServletRequest request, IHyracksClientConnection hcc) throws Exception {
- String pathInfo = path(request);
- if (pathInfo.endsWith("/")) {
+ String localPath = localPath(request);
+ if (localPath.endsWith("/")) {
throw new IllegalArgumentException();
}
- String[] parts = pathInfo.substring(1).split("/");
+ String[] parts = localPath.substring(1).split("/");
final String node = parts[0];
if (parts.length == 1) {
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/ApplicationInstallationHandler.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/ApplicationInstallationHandler.java
index 991649a..9745091 100755
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/ApplicationInstallationHandler.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/ApplicationInstallationHandler.java
@@ -54,11 +54,11 @@
@Override
public void handle(IServletRequest request, IServletResponse response) {
- String path = path(request);
- while (path.startsWith("/")) {
- path = path.substring(1);
+ String localPath = localPath(request);
+ while (localPath.startsWith("/")) {
+ localPath = localPath.substring(1);
}
- final String[] params = path.split("&");
+ final String[] params = localPath.split("&");
if (params.length != 2 || params[0].isEmpty() || params[1].isEmpty()) {
response.setStatus(HttpResponseStatus.BAD_REQUEST);
return;
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/JobsRESTAPIFunction.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/JobsRESTAPIFunction.java
index ebd055d..6acc18a 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/JobsRESTAPIFunction.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/JobsRESTAPIFunction.java
@@ -18,17 +18,25 @@
*/
package org.apache.hyracks.control.cc.web;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.apache.hyracks.api.job.JobId;
import org.apache.hyracks.control.cc.ClusterControllerService;
import org.apache.hyracks.control.cc.web.util.IJSONOutputFunction;
+import org.apache.hyracks.control.cc.web.util.JSONOutputRequestUtil;
import org.apache.hyracks.control.cc.work.GetActivityClusterGraphJSONWork;
import org.apache.hyracks.control.cc.work.GetJobRunJSONWork;
import org.apache.hyracks.control.cc.work.GetJobSummariesJSONWork;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class JobsRESTAPIFunction implements IJSONOutputFunction {
+
+ private static final String[] DETAILS = new String[] { "job-run", "job-activity-graph" };
+
private ClusterControllerService ccs;
public JobsRESTAPIFunction(ClusterControllerService ccs) {
@@ -36,7 +44,7 @@
}
@Override
- public ObjectNode invoke(String[] arguments) throws Exception {
+ public ObjectNode invoke(String host, String servletPath, String[] arguments) throws Exception {
ObjectMapper om = new ObjectMapper();
ObjectNode result = om.createObjectNode();
switch (arguments.length) {
@@ -47,7 +55,7 @@
case 0: {
GetJobSummariesJSONWork gjse = new GetJobSummariesJSONWork(ccs.getJobManager());
ccs.getWorkQueue().scheduleAndSync(gjse);
- result.set("result", gjse.getSummaries());
+ result.set("result", enhanceSummaries(gjse.getSummaries(), host, servletPath));
break;
}
@@ -69,4 +77,17 @@
}
return result;
}
+
+ private static ArrayNode enhanceSummaries(final ArrayNode summaries, String host, String servletPath)
+ throws URISyntaxException {
+ for (int i = 0; i < summaries.size(); ++i) {
+ ObjectNode node = (ObjectNode) summaries.get(i);
+ final String jid = node.get("job-id").asText();
+ for (String field : DETAILS) {
+ URI uri = JSONOutputRequestUtil.uri(host, servletPath, jid + "/" + field);
+ node.put(field, uri.toString());
+ }
+ }
+ return summaries;
+ }
}
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/NodesRESTAPIFunction.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/NodesRESTAPIFunction.java
index 3b4918c..5c4ae5b 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/NodesRESTAPIFunction.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/NodesRESTAPIFunction.java
@@ -18,12 +18,17 @@
*/
package org.apache.hyracks.control.cc.web;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.apache.hyracks.control.cc.ClusterControllerService;
import org.apache.hyracks.control.cc.web.util.IJSONOutputFunction;
+import org.apache.hyracks.control.cc.web.util.JSONOutputRequestUtil;
import org.apache.hyracks.control.cc.work.GetNodeDetailsJSONWork;
import org.apache.hyracks.control.cc.work.GetNodeSummariesJSONWork;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class NodesRESTAPIFunction implements IJSONOutputFunction {
@@ -34,7 +39,7 @@
}
@Override
- public ObjectNode invoke(String[] arguments) throws Exception {
+ public ObjectNode invoke(String host, String servletPath, String[] arguments) throws Exception {
ObjectMapper om = new ObjectMapper();
ObjectNode result = om.createObjectNode();
switch (arguments.length) {
@@ -42,11 +47,11 @@
if ("".equals(arguments[0])) {
GetNodeSummariesJSONWork gnse = new GetNodeSummariesJSONWork(ccs.getNodeManager());
ccs.getWorkQueue().scheduleAndSync(gnse);
- result.set("result", gnse.getSummaries());
+ result.set("result", enhanceSummaries(gnse.getSummaries(), host, servletPath));
} else {
String nodeId = arguments[0];
- GetNodeDetailsJSONWork gnde = new GetNodeDetailsJSONWork(ccs.getNodeManager(), ccs.getCCConfig(),
- nodeId, true, true);
+ GetNodeDetailsJSONWork gnde =
+ new GetNodeDetailsJSONWork(ccs.getNodeManager(), ccs.getCCConfig(), nodeId, true, true);
ccs.getWorkQueue().scheduleAndSync(gnde);
result.set("result", gnde.getDetail());
}
@@ -54,4 +59,14 @@
}
return result;
}
+
+ private static ArrayNode enhanceSummaries(final ArrayNode summaries, String host, String servletPath)
+ throws URISyntaxException {
+ for (int i = 0; i < summaries.size(); ++i) {
+ ObjectNode node = (ObjectNode) summaries.get(i);
+ URI detailsUri = JSONOutputRequestUtil.uri(host, servletPath, node.get("node-id").asText());
+ node.put("details", detailsUri.toString());
+ }
+ return summaries;
+ }
}
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/StateDumpRESTAPIFunction.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/StateDumpRESTAPIFunction.java
index 0657f59..ee22768 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/StateDumpRESTAPIFunction.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/StateDumpRESTAPIFunction.java
@@ -36,7 +36,7 @@
}
@Override
- public ObjectNode invoke(String[] arguments) throws Exception {
+ public ObjectNode invoke(String host, String servletPath, String[] arguments) throws Exception {
GatherStateDumpsWork gsdw = new GatherStateDumpsWork(ccs);
ccs.getWorkQueue().scheduleAndSync(gsdw);
StateDumpRun sdr = gsdw.getStateDumpRun();
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/IJSONOutputFunction.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/IJSONOutputFunction.java
index ab0a581..580bd06 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/IJSONOutputFunction.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/IJSONOutputFunction.java
@@ -21,5 +21,5 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
public interface IJSONOutputFunction {
- public ObjectNode invoke(String[] arguments) throws Exception;
+ ObjectNode invoke(String host, String servletPath, String[] arguments) throws Exception;
}
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/JSONOutputRequestHandler.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/JSONOutputRequestHandler.java
index 25ceaff..b39915f 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/JSONOutputRequestHandler.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/JSONOutputRequestHandler.java
@@ -31,7 +31,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
public class JSONOutputRequestHandler extends AbstractServlet {
@@ -46,20 +45,23 @@
@Override
protected void get(IServletRequest request, IServletResponse response) {
- String path = path(request);
- while (path.startsWith("/")) {
- path = path.substring(1);
+ String localPath = localPath(request);
+ String servletPath = servletPath(request);
+ String host = host(request);
+ while (localPath.startsWith("/")) {
+ localPath = localPath.substring(1);
}
- String[] parts = path.split("/");
- ObjectNode result = invoke(response, parts);
+ String[] parts = localPath.split("/");
+
+ ObjectNode result = invoke(response, host, servletPath, parts);
if (result != null) {
deliver(response, result);
}
}
- protected ObjectNode invoke(IServletResponse response, String[] parts) {
+ protected ObjectNode invoke(IServletResponse response, String host, String servletPath, String[] parts) {
try {
- return fn.invoke(parts);
+ return fn.invoke(host, servletPath, parts);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Exception invoking " + fn.getClass().getName(), e);
response.setStatus(HttpResponseStatus.BAD_REQUEST);
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/JSONOutputRequestUtil.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/JSONOutputRequestUtil.java
new file mode 100644
index 0000000..69f0571
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/web/util/JSONOutputRequestUtil.java
@@ -0,0 +1,39 @@
+/*
+ * 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.hyracks.control.cc.web.util;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+public class JSONOutputRequestUtil {
+
+ private JSONOutputRequestUtil() {}
+
+ public static URI uri(String host, String prefix, String path) throws URISyntaxException {
+ String name = host;
+ int port = 80;
+ int index = host.indexOf(':');
+ if (index > 0) {
+ String[] split = host.split(":");
+ name = split[0];
+ port = Integer.valueOf(split[1]);
+ }
+ return new URI("http", null, name, port, prefix + "/" + path, null, null);
+ }
+}
diff --git a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/JobStatusAPIIntegrationTest.java b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/JobStatusAPIIntegrationTest.java
index dbc6151..f2f8061 100644
--- a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/JobStatusAPIIntegrationTest.java
+++ b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/JobStatusAPIIntegrationTest.java
@@ -21,6 +21,7 @@
import static org.apache.hyracks.tests.integration.TestUtil.httpGetAsObject;
import java.io.IOException;
+import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hyracks.api.constraints.PartitionConstraintHelper;
@@ -118,26 +119,35 @@
return res;
}
- private String getJobStatus(JobId jid) throws IOException, URISyntaxException {
+ private ObjectNode getJobSummary(JobId jId) throws IOException, URISyntaxException {
ArrayNode jobArray = getJobs();
for (JsonNode n : jobArray) {
ObjectNode o = (ObjectNode) n;
- if (JobId.parse(o.get("job-id").asText()).equals(jid)) {
- return o.get("status").asText();
+ if (JobId.parse(o.get("job-id").asText()).equals(jId)) {
+ return o;
}
}
return null;
}
+ private String getJobStatus(JobId jId) throws IOException, URISyntaxException {
+ ObjectNode o = getJobSummary(jId);
+ return o != null ? o.get("status").asText() : null;
+ }
+
protected ArrayNode getJobs() throws URISyntaxException, IOException {
return ((ArrayNode) httpGetAsObject(ROOT_PATH).get("result"));
}
protected ObjectNode getJobActivityGraph(JobId jId) throws URISyntaxException, IOException {
- return httpGetAsObject(ROOT_PATH + "/" + jId.toString() + "/job-activity-graph");
+ ObjectNode o = getJobSummary(jId);
+ URI uri = new URI(o.get("job-activity-graph").asText());
+ return httpGetAsObject(uri);
}
protected ObjectNode getJobRun(JobId jId) throws URISyntaxException, IOException {
- return httpGetAsObject(ROOT_PATH + "/" + jId.toString() + "/job-run");
+ ObjectNode o = getJobSummary(jId);
+ URI uri = new URI(o.get("job-run").asText());
+ return httpGetAsObject(uri);
}
}
diff --git a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/NodesAPIIntegrationTest.java b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/NodesAPIIntegrationTest.java
index ead70b1..6f05600 100644
--- a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/NodesAPIIntegrationTest.java
+++ b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/NodesAPIIntegrationTest.java
@@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@@ -29,12 +30,13 @@
import org.junit.Assert;
import org.junit.Test;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class NodesAPIIntegrationTest extends AbstractIntegrationTest {
- static final String[] NODE_SUMMARY_FIELDS = { "node-id", "heap-used", "system-load-average" };
+ static final String[] NODE_SUMMARY_FIELDS = { "node-id", "heap-used", "system-load-average", "details" };
static final String[] NODE_DETAILS_FIELDS = { "node-id", "os-name", "arch", "os-version", "num-processors",
"vm-name", "vm-version", "vm-vendor", "classpath", "library-path", "boot-classpath", "input-arguments",
@@ -52,9 +54,7 @@
@Test
public void testNodeSummaries() throws Exception {
- ObjectNode res = httpGetAsObject(ROOT_PATH);
- Assert.assertTrue(res.has("result"));
- ArrayNode nodes = (ArrayNode) res.get("result");
+ ArrayNode nodes = getNodeSummaries();
final int size = nodes.size();
Assert.assertEquals(2, size);
for (int i = 0; i < size; ++i) {
@@ -62,11 +62,19 @@
}
}
+ protected ArrayNode getNodeSummaries() throws URISyntaxException, IOException {
+ ObjectNode res = httpGetAsObject(ROOT_PATH);
+ Assert.assertTrue(res.has("result"));
+ return (ArrayNode) res.get("result");
+ }
+
@Test
public void testNodeDetails() throws Exception {
- List<String> nodeIds = getNodeIds();
- for (String nodeId : nodeIds) {
- ObjectNode res = httpGetAsObject(ROOT_PATH + "/" + nodeId);
+ ArrayNode nodes = getNodeSummaries();
+ for (JsonNode n : nodes) {
+ ObjectNode o = (ObjectNode) n;
+ URI uri = new URI(o.get("details").asText());
+ ObjectNode res = httpGetAsObject(uri);
checkNodeFields((ObjectNode) res.get("result"), NODE_DETAILS_FIELDS);
}
}
@@ -93,9 +101,7 @@
}
private List<String> getNodeIds() throws IOException, URISyntaxException {
- ObjectNode res = httpGetAsObject(ROOT_PATH);
- Assert.assertTrue(res.has("result"));
- ArrayNode nodes = (ArrayNode) res.get("result");
+ ArrayNode nodes = getNodeSummaries();
final int size = nodes.size();
List<String> nodeIds = new ArrayList<>();
for (int i = 0; i < size; ++i) {
diff --git a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestUtil.java b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestUtil.java
index a855d53..d53a04c 100644
--- a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestUtil.java
@@ -42,14 +42,18 @@
return new URI("http", null, HOST, PORT, path, null, null);
}
- static InputStream httpGetAsInputStream(String path) throws URISyntaxException, IOException {
+ static InputStream httpGetAsInputStream(URI uri) throws URISyntaxException, IOException {
HttpClient client = HttpClients.createMinimal();
- HttpResponse response = client.execute(new HttpGet(uri(path)));
+ HttpResponse response = client.execute(new HttpGet(uri));
return response.getEntity().getContent();
}
static String httpGetAsString(String path) throws URISyntaxException, IOException {
- InputStream resultStream = httpGetAsInputStream(path);
+ return httpGetAsString(uri(path));
+ }
+
+ static String httpGetAsString(URI uri) throws URISyntaxException, IOException {
+ InputStream resultStream = httpGetAsInputStream(uri);
return IOUtils.toString(resultStream, Charset.defaultCharset());
}
@@ -60,4 +64,8 @@
static ObjectNode httpGetAsObject(String path) throws URISyntaxException, IOException {
return getResultAsJson(httpGetAsString(path));
}
+
+ static ObjectNode httpGetAsObject(URI uri) throws URISyntaxException, IOException {
+ return getResultAsJson(httpGetAsString(uri));
+ }
}
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java
index 37ef3bb..cb9deea 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java
@@ -27,6 +27,7 @@
import org.apache.hyracks.http.api.IServletRequest;
import org.apache.hyracks.http.api.IServletResponse;
+import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
@@ -124,12 +125,26 @@
response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
}
- public String path(IServletRequest request) {
+ public String host(IServletRequest request) {
+ return request.getHttpRequest().headers().get(HttpHeaderNames.HOST);
+ }
+
+ public String localPath(IServletRequest request) {
+ final String uri = request.getHttpRequest().uri();
+ return uri.substring(trim(uri));
+ }
+
+ public String servletPath(IServletRequest request) {
+ final String uri = request.getHttpRequest().uri();
+ return uri.substring(0, trim(uri));
+ }
+
+ protected int trim(final String uri) {
int trim = -1;
if (paths.length > 1) {
for (int i = 0; i < paths.length; i++) {
String path = paths[i].indexOf('*') >= 0 ? paths[i].substring(0, paths[i].indexOf('*')) : paths[0];
- if (request.getHttpRequest().uri().indexOf(path) == 0) {
+ if (uri.indexOf(path) == 0) {
trim = trims[i];
break;
}
@@ -137,7 +152,7 @@
} else {
trim = trims[0];
}
- return request.getHttpRequest().uri().substring(trim);
+ return trim;
}
@Override