refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Implementing buffer strategy git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115719 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b5d001383b
commit
bbf40324f8
|
@ -43,16 +43,17 @@ public abstract class AggregationScheduler {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
protected AggregationScheduler(){
|
protected AggregationScheduler(){
|
||||||
this.records = new HashMap<String, List<AggregationStrategy>>();
|
this.records = new HashMap<String, List<AggregationStrategy>>();
|
||||||
|
unaggregableRecords = new ArrayList<UsageRecord>();
|
||||||
totalBufferedRecords = 0;
|
totalBufferedRecords = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
protected Class<? extends AggregatedUsageRecord> getAggregatedUsageRecordClass(String usageRecordName) throws ClassNotFoundException {
|
protected Class<? extends AggregatedUsageRecord> getAggregatedUsageRecordClass(String usageRecordName) throws ClassNotFoundException {
|
||||||
Class<? extends AggregatedUsageRecord> clz = null;
|
Class<? extends AggregatedUsageRecord> clz;
|
||||||
String aggregatedURFullyQualifiedName = null;
|
String aggregatedURFullyQualifiedName;
|
||||||
try {
|
try {
|
||||||
Package aggregatedPackage = org.gcube.accounting.datamodel.aggregation.ServiceUsageRecord.class.getPackage();
|
Package aggregatedPackage = org.gcube.accounting.datamodel.aggregation.ServiceUsageRecord.class.getPackage();
|
||||||
aggregatedURFullyQualifiedName = String.format("%s%s", aggregatedPackage.getName(), usageRecordName);
|
aggregatedURFullyQualifiedName = String.format("%s.%s", aggregatedPackage.getName(), usageRecordName);
|
||||||
clz = (Class<? extends AggregatedUsageRecord>) Class.forName(aggregatedURFullyQualifiedName);
|
clz = (Class<? extends AggregatedUsageRecord>) Class.forName(aggregatedURFullyQualifiedName);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
logger.error("Unable To find the Aggregation Class for {}", usageRecordName);
|
logger.error("Unable To find the Aggregation Class for {}", usageRecordName);
|
||||||
|
@ -74,11 +75,11 @@ public abstract class AggregationScheduler {
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
protected Class<? extends AggregationStrategy> getAggregattionStrategyUsageRecordClass(String usageRecordName) throws ClassNotFoundException {
|
protected Class<? extends AggregationStrategy> getAggregattionStrategyUsageRecordClass(String usageRecordName) throws ClassNotFoundException {
|
||||||
Class<? extends AggregationStrategy> clz = null;
|
Class<? extends AggregationStrategy> clz;
|
||||||
String aggregationStrategyName = null;
|
String aggregationStrategyName;
|
||||||
try {
|
try {
|
||||||
Package aggregationStrategyPackage = org.gcube.accounting.datamodel.aggregation.aggregationstrategy.ServiceUsageRecordAggregationStrategy.class.getPackage();
|
Package aggregationStrategyPackage = org.gcube.accounting.datamodel.aggregation.aggregationstrategy.ServiceUsageRecordAggregationStrategy.class.getPackage();
|
||||||
aggregationStrategyName = String.format("%s%s", aggregationStrategyPackage.getName(), usageRecordName);
|
aggregationStrategyName = String.format("%s.%s%s", aggregationStrategyPackage.getName(), usageRecordName, AggregationStrategy.class.getSimpleName());
|
||||||
clz = (Class<? extends AggregationStrategy>) Class.forName(aggregationStrategyName);
|
clz = (Class<? extends AggregationStrategy>) Class.forName(aggregationStrategyName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable To find the Aggregation Strategy Class for {}", usageRecordName);
|
logger.error("Unable To find the Aggregation Strategy Class for {}", usageRecordName);
|
||||||
|
|
|
@ -75,7 +75,7 @@ public abstract class Persistence {
|
||||||
if(persistence==null){
|
if(persistence==null){
|
||||||
persistence = fallback;
|
persistence = fallback;
|
||||||
}
|
}
|
||||||
persistence.account(TestUsageRecord.createTestServiceUsageRecord());
|
persistence.accountWithFallback(TestUsageRecord.createTestServiceUsageRecord());
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
logger.error("Unable to instance a Persistence Implementation. Using fallback as default",
|
logger.error("Unable to instance a Persistence Implementation. Using fallback as default",
|
||||||
e.getCause());
|
e.getCause());
|
||||||
|
@ -162,6 +162,7 @@ public abstract class Persistence {
|
||||||
* @throws InvalidValueException if the Record Validation Fails
|
* @throws InvalidValueException if the Record Validation Fails
|
||||||
*/
|
*/
|
||||||
public void account(final SingleUsageRecord usageRecord) throws InvalidValueException{
|
public void account(final SingleUsageRecord usageRecord) throws InvalidValueException{
|
||||||
|
/*
|
||||||
Runnable runnable = new Runnable(){
|
Runnable runnable = new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
|
@ -185,6 +186,25 @@ public abstract class Persistence {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
pool.execute(runnable);
|
pool.execute(runnable);
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
//usageRecord.validate();
|
||||||
|
aggregationScheduler.aggregate(usageRecord, new PersistenceExecutor(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void persist(UsageRecord... usageRecords) throws Exception {
|
||||||
|
persistence.accountWithFallback(usageRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} catch (InvalidValueException e) {
|
||||||
|
logger.error("Error validating UsageRecord", e.getCause());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error accounting UsageRecord", e.getCause());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void close() throws Exception;
|
public abstract void close() throws Exception;
|
||||||
|
|
Loading…
Reference in New Issue