use of org.apache.hive.ptest.api.response.TestLogResponse in project hive by apache.
the class ExecutionController method testLog.
@RequestMapping(value = "/testLog", method = RequestMethod.POST)
@ResponseBody
public TestLogResponse testLog(@RequestBody TestLogRequest logsRequest, BindingResult result) {
String testHandle = logsRequest.getTestHandle();
Test testExecution = mTests.get(testHandle);
if (result.hasErrors() || Strings.nullToEmpty(logsRequest.getTestHandle()).trim().isEmpty() || testExecution == null || logsRequest.getLength() > MAX_READ_SIZE) {
return new TestLogResponse(Status.illegalArgument());
}
File outputFile = testExecution.getOutputFile();
if (outputFile == null || logsRequest.getOffset() > outputFile.length()) {
return new TestLogResponse(Status.illegalArgument());
}
RandomAccessFile fileHandle = null;
try {
fileHandle = new RandomAccessFile(outputFile, "r");
long offset = logsRequest.getOffset();
fileHandle.seek(offset);
int readLength = 0;
if (offset < fileHandle.length()) {
readLength = (int) Math.min(fileHandle.length() - offset, logsRequest.getLength());
}
byte[] buffer = new byte[readLength];
fileHandle.readFully(buffer);
offset += readLength;
return new TestLogResponse(Status.ok(), offset, new String(buffer, Charsets.UTF_8));
} catch (IOException e) {
LOG.info("Unexpected IO error reading " + testExecution.getOutputFile(), e);
return new TestLogResponse(Status.internalError(e.getMessage()));
} finally {
if (fileHandle != null) {
try {
fileHandle.close();
} catch (IOException e) {
LOG.warn("Error closing " + outputFile, e);
}
}
}
}
use of org.apache.hive.ptest.api.response.TestLogResponse in project hive by apache.
the class PTestClient method post.
private <S extends GenericResponse> S post(Object payload, boolean agressiveRetry) throws Exception {
EndPointResponsePair endPointResponse = Preconditions.checkNotNull(REQUEST_TO_ENDPOINT.get(payload.getClass()), payload.getClass().getName());
HttpPost request = new HttpPost(mApiEndPoint + endPointResponse.getEndpoint());
try {
String payloadString = mMapper.writeValueAsString(payload);
StringEntity params = new StringEntity(payloadString);
request.addHeader("content-type", "application/json");
request.setEntity(params);
if (agressiveRetry) {
mHttpClient.setHttpRequestRetryHandler(new PTestHttpRequestRetryHandler());
}
HttpResponse httpResponse = mHttpClient.execute(request);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() != 200) {
throw new IllegalStateException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
}
String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
@SuppressWarnings("unchecked") S result = (S) endPointResponse.getResponseClass().cast(mMapper.readValue(response, endPointResponse.getResponseClass()));
Status.assertOK(result.getStatus());
if (System.getProperty("DEBUG_PTEST_CLIENT") != null) {
System.err.println("payload " + payloadString);
if (result instanceof TestLogResponse) {
System.err.println("response " + ((TestLogResponse) result).getOffset() + " " + ((TestLogResponse) result).getStatus());
} else {
System.err.println("response " + response);
}
}
Thread.sleep(1000);
return result;
} finally {
request.abort();
}
}
use of org.apache.hive.ptest.api.response.TestLogResponse in project hive by apache.
the class PTestClient method printLogs.
private long printLogs(String testHandle, long offset) throws Exception {
TestLogRequest logsRequest = new TestLogRequest(testHandle, offset, 64 * 1024);
TestLogResponse logsResponse = post(logsRequest, true);
System.out.print(logsResponse.getBody());
return logsResponse.getOffset();
}
Aggregations