throw new LogServiceException(e.getMessage());
}
}
Future<LogQueryResult> fetchAsync(LogQuery query) {
LogReadRequest request = new LogReadRequest();
request.setAppId(ApiProxy.getCurrentEnvironment().getAppId());
Long startTimeUs = query.getStartTimeUsec();
if (startTimeUs != null) {
request.setStartTime(startTimeUs);
}
Long endTimeUs = query.getEndTimeUsec();
if (endTimeUs != null) {
request.setEndTime(endTimeUs);
}
request.setCount(query.getBatchSize());
if (query.getMinLogLevel() != null) {
request.setMinimumLogLevel(query.getMinLogLevel().ordinal());
}
request.setIncludeIncomplete(query.getIncludeIncomplete());
request.setIncludeAppLogs(query.getIncludeAppLogs());
Set<Pair<String, String>> convertedModuleVersions = Sets.newHashSet();
if (query.getMajorVersionIds().isEmpty() && query.getModuleVersions().isEmpty()) {
String currentVersionId = ApiProxy.getCurrentEnvironment().getVersionId();
String versionId = currentVersionId.split("\\.")[0];
convertedModuleVersions.add(Pair.of("default", versionId));
}
if (query.getMajorVersionIds().size() > 0) {
for (String versionId : query.getMajorVersionIds()) {
convertedModuleVersions.add(Pair.of("default", versionId));
}
} else if (query.getModuleVersions().size() > 0) {
convertedModuleVersions.addAll(query.getModuleVersions());
}
for (Pair<String, String> moduleVersion : convertedModuleVersions) {
LogModuleVersion requestModuleVersion = request.addModuleVersion();
if (!moduleVersion.first.equals("default")) {
requestModuleVersion.setModuleId(moduleVersion.first);
}
requestModuleVersion.setVersionId(moduleVersion.second);
}
for (String requestId : query.getRequestIds()) {
request.addRequestId(requestId);
}
String offset = query.getOffset();
if (offset != null) {
request.setOffset(LogQueryResult.parseOffset(offset));
}
final LogQuery finalizedQuery = query;
ApiProxy.ApiConfig apiConfig = new ApiProxy.ApiConfig();
Future<byte[]> responseBytes = ApiProxy.makeAsyncCall(PACKAGE,
READ_RPC_NAME, request.toByteArray(), apiConfig);
return new FutureWrapper<byte[], LogQueryResult>(responseBytes) {
@Override
protected LogQueryResult wrap(byte[] responseBytes) {
LogReadResponse response = new LogReadResponse();
response.mergeFrom(responseBytes);