use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class DistributedLogManager method printResult.
private void printResult(Result<Long, Pageview> result) throws Exception {
while (result.next()) {
//advances the Result object and breaks if at end
//obtain current key
long resultKey = result.getKey();
//obtain current value object
Pageview resultPageview = result.get();
log.info("{} :", resultKey);
printPageview(resultPageview);
}
log.info("Number of pageviews from the query: {}", result.getOffset());
}
use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class DistributedLogManager method get.
/**
* Fetches a single pageview object with required fields and prints it
*/
private void get(long key, String[] fields) throws Exception {
Pageview pageview = cacheStore.get(key, fields);
printPageview(pageview);
}
use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class DistributedLogManager method get.
/**
* Fetches a single pageview object and prints it
*/
private void get(long key, boolean isCacheEnabled) throws Exception {
if (!isCacheEnabled) {
Pageview pageview = dataStore.get(key);
printPageview(pageview);
} else {
Pageview pageview = cacheStore.get(key);
printPageview(pageview);
}
}
use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class DistributedLogManager method parseLine.
/**
* Parses a single log line in combined log format using StringTokenizers
*/
private Pageview parseLine(String line) throws ParseException {
StringTokenizer matcher = new StringTokenizer(line);
//parse the log line
String ip = matcher.nextToken();
//discard
matcher.nextToken();
matcher.nextToken();
long timestamp = dateFormat.parse(matcher.nextToken("]").substring(2)).getTime();
matcher.nextToken("\"");
String request = matcher.nextToken("\"");
String[] requestParts = request.split(" ");
String httpMethod = requestParts[0];
String url = requestParts[1];
matcher.nextToken(" ");
int httpStatusCode = Integer.parseInt(matcher.nextToken());
int responseSize = Integer.parseInt(matcher.nextToken());
matcher.nextToken("\"");
String referrer = matcher.nextToken("\"");
matcher.nextToken("\"");
String userAgent = matcher.nextToken("\"");
//construct and return pageview object
Pageview pageview = new Pageview();
pageview.setIp(new Utf8(ip));
pageview.setTimestamp(timestamp);
pageview.setHttpMethod(new Utf8(httpMethod));
pageview.setUrl(new Utf8(url));
pageview.setHttpStatusCode(httpStatusCode);
pageview.setResponseSize(responseSize);
pageview.setReferrer(new Utf8(referrer));
pageview.setUserAgent(new Utf8(userAgent));
return pageview;
}
use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class DistributedLogManager method parse.
/**
* Parses a log file and store the contents at the data store.
*
* @param input the input file location
*/
private void parse(String input, boolean isCacheEnabled) throws Exception {
log.info("Parsing file: {}", input);
long lineCount = 0;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(input), Charset.defaultCharset()))) {
String line = reader.readLine();
do {
Pageview pageview = parseLine(line);
if (pageview != null) {
//store the pageview
storePageview(lineCount++, pageview, isCacheEnabled);
}
line = reader.readLine();
} while (line != null);
}
log.info("finished parsing file. Total number of log lines: {}", lineCount);
}
Aggregations