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:
parent
5c90b8b5b4
commit
f531cd4e8c
|
@ -12,6 +12,7 @@ import org.gcube.accounting.aggregator.utility.Constant;
|
||||||
import org.gcube.accounting.aggregator.utility.Utility;
|
import org.gcube.accounting.aggregator.utility.Utility;
|
||||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||||
|
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||||
import org.gcube.documentstore.exception.InvalidValueException;
|
import org.gcube.documentstore.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.AggregatedRecord;
|
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 {
|
protected void retrieveAndAggregate(ViewResult viewResult) throws Exception {
|
||||||
AggregatorBuffer aggregatorBuffer = new AggregatorBuffer();
|
AggregatorBuffer aggregatorBuffer = new AggregatorBuffer();
|
||||||
|
@ -130,9 +133,9 @@ public class Aggregator {
|
||||||
try {
|
try {
|
||||||
JsonObject content = row.document().content();
|
JsonObject content = row.document().content();
|
||||||
|
|
||||||
if(content.containsKey("usageRecordType")){
|
if(content.containsKey(USAGE_RECORD_TYPE)){
|
||||||
String recordType = content.getString("usageRecordType");
|
String recordType = content.getString(USAGE_RECORD_TYPE);
|
||||||
content.removeKey("usageRecordType");
|
content.removeKey(USAGE_RECORD_TYPE);
|
||||||
content.put(Record.RECORD_TYPE, recordType);
|
content.put(Record.RECORD_TYPE, recordType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +146,15 @@ public class Aggregator {
|
||||||
|
|
||||||
if(!aggregated){
|
if(!aggregated){
|
||||||
String recordType = content.getString(Record.RECORD_TYPE);
|
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();
|
String record = content.toString();
|
||||||
|
|
||||||
// Backup the Record on local file
|
// Backup the Record on local file
|
||||||
|
@ -201,7 +209,6 @@ public class Aggregator {
|
||||||
|
|
||||||
protected void aggregateRow(AggregatorBuffer aggregatorBuffer, String json) throws Exception {
|
protected void aggregateRow(AggregatorBuffer aggregatorBuffer, String json) throws Exception {
|
||||||
Record record = RecordUtility.getRecord(json);
|
Record record = RecordUtility.getRecord(json);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
record.validate();
|
record.validate();
|
||||||
}catch (InvalidValueException e) {
|
}catch (InvalidValueException e) {
|
||||||
|
@ -215,6 +222,9 @@ public class Aggregator {
|
||||||
if(record.getResourceProperty(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME)==null) {
|
if(record.getResourceProperty(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME)==null) {
|
||||||
record.setResourceProperty(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME, record.getResourceProperty(ServiceUsageRecord.DURATION));
|
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();
|
record.validate();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue