boolean hasNewFiles = false;
boolean hasTags = false;
long lastProcessed = lastProcessTime(AwsUtils.monthDateFormat.print(dataTime));
for (BillingFile billingFile: filesToProcess.get(dataTime)) {
S3ObjectSummary objectSummary = billingFile.s3ObjectSummary;
if (objectSummary.getLastModified().getTime() < lastProcessed) {
logger.info("data has been processed. ignoring " + objectSummary.getKey() + "...");
continue;
}
hasNewFiles = true;
}
if (!hasNewFiles) {
logger.info("data has been processed. ignoring all files at " + AwsUtils.monthDateFormat.print(dataTime));
continue;
}
long processTime = new DateTime(DateTimeZone.UTC).getMillis();
for (BillingFile billingFile: filesToProcess.get(dataTime)) {
S3ObjectSummary objectSummary = billingFile.s3ObjectSummary;
String fileKey = objectSummary.getKey();
File file = new File(config.localDir, fileKey.substring(billingFile.prefix.length()));
logger.info("trying to download " + fileKey + "...");
boolean downloaded = AwsUtils.downloadFileIfChangedSince(objectSummary.getBucketName(), billingFile.prefix, file, lastProcessed,
billingFile.accountId, billingFile.accessRoleName, billingFile.externalId);
if (downloaded)
logger.info("downloaded " + fileKey);
else {
logger.info("file already downloaded " + fileKey + "...");
}
logger.info("processing " + fileKey + "...");
boolean withTags = fileKey.contains("with-resources-and-tags");
hasTags = hasTags || withTags;
processingMonitor = false;
processBillingZipFile(file, withTags);
logger.info("done processing " + fileKey);
}
if (monitorFilesToProcess.get(dataTime) != null) {
for (BillingFile monitorBillingFile: monitorFilesToProcess.get(dataTime)) {
S3ObjectSummary monitorObjectSummary = monitorBillingFile.s3ObjectSummary;
if (monitorObjectSummary != null) {
String monitorFileKey = monitorObjectSummary.getKey();
logger.info("processing " + monitorFileKey + "...");
File monitorFile = new File(config.localDir, monitorFileKey.substring(monitorFileKey.lastIndexOf("/") + 1));
logger.info("trying to download " + monitorFileKey + "...");
boolean downloaded = AwsUtils.downloadFileIfChangedSince(monitorObjectSummary.getBucketName(), monitorBillingFile.prefix, monitorFile, lastProcessed,
monitorBillingFile.accountId, monitorBillingFile.accessRoleName, monitorBillingFile.externalId);
if (downloaded)
logger.info("downloaded " + monitorFile);
else
logger.warn(monitorFile + "already downloaded...");