use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class FileDistributionStatusTest method require_different_statuses_many_hosts.
@Test
public void require_different_statuses_many_hosts() throws IOException {
application = createApplication("localhost", "localhost2");
Map<String, Double> fileReferenceStatuses = new HashMap<>();
fileReferenceStatuses.put("1234", 0.2);
fileReferenceStatuses.put("abcd", 1.0);
HostStatus localhost = statusWithError("localhost", Status.IN_PROGRESS, fileReferenceStatuses, "connection timed out");
Map<String, Double> fileReferenceStatuses2 = new HashMap<>();
fileReferenceStatuses2.put("1234", 1.0);
HostStatus localhost2 = statusFinished("localhost2", Status.FINISHED, fileReferenceStatuses2);
FileDistributionStatus status = new MockStatus(new HashSet<>(Arrays.asList(localhost, localhost2)));
application = createApplication("localhost", "localhost2");
HttpResponse response = getStatus(status, application);
assertResponse(200, "{" + "\"hosts\":[" + "{\"hostname\":\"localhost\"," + "\"status\":\"IN_PROGRESS\"," + "\"message\":\"connection timed out\"," + "\"fileReferences\":[" + "{\"1234\":0.2},{\"abcd\":1.0}]}," + "{\"hostname\":\"localhost2\"," + "\"status\":\"FINISHED\"," + "\"fileReferences\":[" + "{\"1234\":1.0}]}" + "]," + "\"status\":\"IN_PROGRESS\"}", response);
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class AccessLogRequestHandler method handle.
@Override
public HttpResponse handle(HttpRequest request) {
final List<String> uris = circularArrayAccessLogKeeper.getUris();
return new HttpResponse(200) {
@Override
public void render(OutputStream outputStream) throws IOException {
JsonGenerator generator = jsonFactory.createGenerator(outputStream);
generator.writeStartObject();
generator.writeArrayFieldStart("entries");
for (String uri : uris) {
generator.writeStartObject();
generator.writeStringField("url", uri);
generator.writeEndObject();
}
generator.writeEndArray();
generator.writeEndObject();
generator.close();
}
};
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class AccessLogRequestHandlerTest method testManyLogLines.
@Test
public void testManyLogLines() throws IOException {
keeper.addUri("foo");
keeper.addUri("foo");
HttpResponse response = handler.handle(null);
response.render(out);
assertThat(out.toString(), is("{\"entries\":[{\"url\":\"foo\"},{\"url\":\"foo\"}]}"));
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class MockServiceTest method testNoHandlerFound.
@Test
public void testNoHandlerFound() throws InterruptedException, IOException {
HttpResponse response = runHandler(com.yahoo.jdisc.http.HttpRequest.Method.DELETE, "/foo/bar");
assertThat(response.getStatus(), is(404));
assertResponseContents(response, "DELETE:/foo/bar was not found");
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class RestApi method handleVisit.
private HttpResponse handleVisit(RestUri restUri, HttpRequest request) throws RestApiException {
String documentSelection = Optional.ofNullable(request.getProperty(SELECTION)).orElse("");
if (restUri.getGroup().isPresent() && !restUri.getGroup().get().value.isEmpty()) {
if (!documentSelection.isEmpty()) {
// TODO why is this restriction in place? Document selection allows composition of location predicate and other expressions
return Response.createErrorResponse(400, "Visiting does not support setting value for group/value in combination with expression, try using only expression parameter instead.", restUri, RestUri.apiErrorCodes.GROUP_AND_EXPRESSION_ERROR);
}
RestUri.Group group = restUri.getGroup().get();
if (group.name == 'n') {
documentSelection = "id.user=" + group.value;
} else {
documentSelection = "id.group='" + group.value + "'";
}
}
OperationHandler.VisitOptions options;
try {
options = visitOptionsFromRequest(request);
} catch (BadRequestParameterException e) {
return createInvalidParameterResponse(e.getParameter(), e.getMessage());
}
final OperationHandler.VisitResult visit = operationHandler.visit(restUri, documentSelection, options);
final ObjectNode resultNode = mapper.createObjectNode();
visit.token.ifPresent(t -> resultNode.put(CONTINUATION, t));
resultNode.putArray(DOCUMENTS).addPOJO(visit.documentsAsJsonList);
resultNode.put(PATH_NAME, restUri.getRawPath());
HttpResponse httpResponse = new HttpResponse(200) {
@Override
public String getContentType() {
return APPLICATION_JSON;
}
@Override
public void render(OutputStream outputStream) throws IOException {
try {
outputStream.write(resultNode.toString().getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
return httpResponse;
}
Aggregations