long currentTimeMillis = System.currentTimeMillis();
boolean isSuccessful = true;
String recordType = null;
ChukwaRecordKey key = new ChukwaRecordKey();
ChukwaRecord record = new ChukwaRecord();
try {
int batch = 0;
while (reader.next(key, record)) {
String sqlTime = DatabaseWriter.formatTimeStamp(record.getTime());
log.debug("Timestamp: " + record.getTime());
log.debug("DataType: " + key.getReduceType());
String[] fields = record.getFields();
String table = null;
String[] priKeys = null;
HashMap<String, HashMap<String, String>> hashReport = new HashMap<String, HashMap<String, String>>();
StringBuilder normKey = new StringBuilder();
String node = record.getValue("csource");
recordType = key.getReduceType().toLowerCase();
String dbKey = "report.db.name." + recordType;
if (dbTables.containsKey(dbKey)) {
String[] tmp = mdlConfig.findTableName(mdlConfig.get(dbKey), record
.getTime(), record.getTime());
table = tmp[0];
} else {
log.debug(dbKey + " does not exist.");
continue;
}
log.debug("table name:" + table);
try {
priKeys = mdlConfig.get("report.db.primary.key." + recordType).split(
",");
} catch (Exception nullException) {
}
for (String field : fields) {
String keyName = escape(field.toLowerCase(), newSpace);
String keyValue = escape(record.getValue(field).toLowerCase(),
newSpace);
StringBuilder buildKey = new StringBuilder();
buildKey.append("normalize.");
buildKey.append(recordType);
buildKey.append(".");
buildKey.append(keyName);
if (normalize.containsKey(buildKey.toString())) {
if (normKey.toString().equals("")) {
normKey.append(keyName);
normKey.append(".");
normKey.append(keyValue);
} else {
normKey.append(".");
normKey.append(keyName);
normKey.append(".");
normKey.append(keyValue);
}
}
StringBuilder normalizedKey = new StringBuilder();
normalizedKey.append("metric.");
normalizedKey.append(recordType);
normalizedKey.append(".");
normalizedKey.append(normKey);
if (hashReport.containsKey(node)) {
HashMap<String, String> tmpHash = hashReport.get(node);
tmpHash.put(normalizedKey.toString(), keyValue);
hashReport.put(node, tmpHash);
} else {
HashMap<String, String> tmpHash = new HashMap<String, String>();
tmpHash.put(normalizedKey.toString(), keyValue);
hashReport.put(node, tmpHash);
}
}
for (String field : fields) {
String valueName = escape(field.toLowerCase(), newSpace);
String valueValue = escape(record.getValue(field).toLowerCase(),
newSpace);
StringBuilder buildKey = new StringBuilder();
buildKey.append("metric.");
buildKey.append(recordType);
buildKey.append(".");