use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class LogAnalytics method run.
@Override
public int run(String[] args) throws Exception {
DataStore<Long, Pageview> inStore;
DataStore<String, MetricDatum> outStore;
Configuration conf = new Configuration();
if (args.length > 0) {
String dataStoreClass = args[0];
inStore = DataStoreFactory.getDataStore(dataStoreClass, Long.class, Pageview.class, conf);
if (args.length > 1) {
dataStoreClass = args[1];
}
outStore = DataStoreFactory.getDataStore(dataStoreClass, String.class, MetricDatum.class, conf);
} else {
inStore = DataStoreFactory.getDataStore(Long.class, Pageview.class, conf);
outStore = DataStoreFactory.getDataStore(String.class, MetricDatum.class, conf);
}
Job job = createJob(inStore, outStore, 3);
boolean success = job.waitForCompletion(true);
inStore.close();
outStore.close();
log.info("Log completed with {}", (success ? "success" : "failure"));
return success ? 0 : 1;
}
use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class LogManager 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) 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);
}
line = reader.readLine();
} while (line != null);
}
log.info("finished parsing file. Total number of log lines: {}", lineCount);
}
use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class LogManager 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 LogManager method get.
/** Fetches a single pageview object and prints it*/
private void get(long key) throws Exception {
Pageview pageview = dataStore.get(key);
printPageview(pageview);
}
use of org.apache.gora.tutorial.log.generated.Pageview in project gora by apache.
the class LogManager 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());
}
Aggregations