Fix to support old usage records

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-aggregator-se-plugin@154348 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-09-21 07:53:53 +00:00
parent 5c90b8b5b4
commit f531cd4e8c
1 changed files with 16 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import org.gcube.accounting.aggregator.utility.Constant;
import org.gcube.accounting.aggregator.utility.Utility;
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.AggregatedRecord;
@ -112,7 +113,9 @@ public class Aggregator {
}
}
private static final String USAGE_RECORD_TYPE = "usageRecordType";
private static final String SINGLE = "Single";
private static final String SIMPLE = "Simple";
protected void retrieveAndAggregate(ViewResult viewResult) throws Exception {
AggregatorBuffer aggregatorBuffer = new AggregatorBuffer();
@ -130,9 +133,9 @@ public class Aggregator {
try {
JsonObject content = row.document().content();
if(content.containsKey("usageRecordType")){
String recordType = content.getString("usageRecordType");
content.removeKey("usageRecordType");
if(content.containsKey(USAGE_RECORD_TYPE)){
String recordType = content.getString(USAGE_RECORD_TYPE);
content.removeKey(USAGE_RECORD_TYPE);
content.put(Record.RECORD_TYPE, recordType);
}
@ -143,10 +146,15 @@ public class Aggregator {
if(!aggregated){
String recordType = content.getString(Record.RECORD_TYPE);
content.put(Record.RECORD_TYPE, "Simple" + recordType);
content.put(Record.RECORD_TYPE, SINGLE + recordType);
}
String recordType = content.getString(Record.RECORD_TYPE);
if(recordType.contains(SIMPLE)){
recordType.replace(SIMPLE, SINGLE);
}
String record = content.toString();
// Backup the Record on local file
@ -201,7 +209,6 @@ public class Aggregator {
protected void aggregateRow(AggregatorBuffer aggregatorBuffer, String json) throws Exception {
Record record = RecordUtility.getRecord(json);
try {
record.validate();
}catch (InvalidValueException e) {
@ -215,6 +222,9 @@ public class Aggregator {
if(record.getResourceProperty(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME)==null) {
record.setResourceProperty(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME, record.getResourceProperty(ServiceUsageRecord.DURATION));
}
if(record.getResourceProperty(AggregatedServiceUsageRecord.CALLER_QUALIFIER)==null) {
record.setResourceProperty(AggregatedServiceUsageRecord.CALLER_QUALIFIER, AbstractServiceUsageRecord.UNKNOWN);
}
}
record.validate();
}