summaryrefslogtreecommitdiffstats
path: root/tenant-cd
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2019-06-13 14:58:20 +0200
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2019-06-13 14:58:20 +0200
commit46fe15a103d2fc467c25426e184c4e0d5360490d (patch)
tree9423ea8fb3bc0ee9212f615ed6878df071ac2588 /tenant-cd
parent1e74107ce3a0781c6250473a4874c2d19123d23e (diff)
Allow using the built-in authentication to search, returning a raw result
Diffstat (limited to 'tenant-cd')
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java4
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/Search.java8
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java15
3 files changed, 18 insertions, 9 deletions
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java
index 4bdc63fca1a..9895f9df3a2 100644
--- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java
+++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java
@@ -25,7 +25,7 @@ public class Query {
this.parameters = parameters;
}
- /** Creates a query with the given raw query part. */
+ /** Creates a query with the given raw query part, e.g. {@code Query.ofRaw("yql=select * ...")}. */
public static Query ofRaw(String rawQuery) {
if (rawQuery.isBlank())
throw new IllegalArgumentException("Query can not be blank.");
@@ -36,7 +36,7 @@ public class Query {
.collect(toUnmodifiableMap(pair -> pair[0], pair -> pair[1])));
}
- /** Creates a query with the given name-value pairs. */
+ /** Creates a query with the given name-value pairs, e.g. {@code Query.ofParameters(Map.of("yql", "select * ..."))}. */
public static Query ofParameters(Map<String, String> parameters) {
if (parameters.isEmpty())
throw new IllegalArgumentException("Parameters can not be empty.");
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Search.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Search.java
index a6c1d188591..ace6262bb7c 100644
--- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Search.java
+++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Search.java
@@ -9,6 +9,14 @@ import java.util.Map;
*/
public class Search {
+ private final String raw;
+
+ public Search(String raw) {
+ this.raw = raw;
+ }
+
+ public String rawOutput() { return raw; }
+
// hits
// coverage
// searched
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
index d2bf153b86a..02c34501dd2 100644
--- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
+++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
@@ -19,6 +19,7 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
/**
@@ -60,11 +61,11 @@ public class HttpEndpoint implements TestEndpoint {
public Search search(Query query) {
try {
URI target = endpoint.resolve(searchApiPath).resolve("?" + query.rawQuery());
- HttpRequest request = HttpRequest.newBuilder()
- .timeout(query.timeout().orElse(Duration.ofMillis(500))
- .plus(Duration.ofSeconds(1)))
- .uri(target)
- .build();
+ HttpRequest request = authenticator.authenticated(HttpRequest.newBuilder()
+ .timeout(query.timeout().orElse(Duration.ofMillis(500))
+ .plus(Duration.ofSeconds(1)))
+ .uri(target))
+ .build();
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
if (response.statusCode() / 100 != 2) // TODO consider allowing 504 if specified.
throw new RuntimeException("Non-OK status code " + response.statusCode() + " at " + target +
@@ -78,9 +79,9 @@ public class HttpEndpoint implements TestEndpoint {
}
static Search toSearch(byte[] body) {
- Inspector rootObject = new JsonDecoder().decode(new Slime(), body).get();
// TODO jvenstad
- return new Search();
+ // Inspector rootObject = new JsonDecoder().decode(new Slime(), body).get();
+ return new Search(new String(body, UTF_8));
}
@Override