git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115499 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e4c8558c7f
commit
28525346d1
|
@ -4,27 +4,20 @@
|
|||
package org.gcube.accounting.datamodel;
|
||||
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecorsExceptions;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*/
|
||||
public interface AggregatedUsageRecord<T extends B, B extends SingleUsageRecord> extends UsageRecord {
|
||||
public interface AggregatedUsageRecord<T extends B, B extends SingleUsageRecord> extends SingleUsageRecord {
|
||||
|
||||
|
||||
public T getAggregatedUsageRecord(B b) throws InvalidValueException ;
|
||||
|
||||
/**
|
||||
* Aggregate the Record provided as parameter with this record if Aggregatable
|
||||
* @throws NotAggregatableRecorsExceptions
|
||||
* @throws NotAggregatableRecordsExceptions
|
||||
*/
|
||||
public void aggregate(T record) throws NotAggregatableRecorsExceptions;
|
||||
public void aggregate(T record) throws NotAggregatableRecordsExceptions;
|
||||
|
||||
/* *
|
||||
*
|
||||
* @param records
|
||||
* @return
|
||||
* /
|
||||
public Collection<T> aggregate(List<? extends B> records);
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.accounting.exception.NotAggregatableRecorsExceptions;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
|
@ -58,21 +58,21 @@ public abstract class AggregationStrategy<T extends B, B extends SingleUsageReco
|
|||
return true;
|
||||
}
|
||||
|
||||
public void aggregate(B record) throws NotAggregatableRecorsExceptions {
|
||||
public void aggregate(B record) throws NotAggregatableRecordsExceptions {
|
||||
try{
|
||||
if(isAggregable(record)){
|
||||
throw new NotAggregatableRecorsExceptions("The Record provided as argument has different values for field wich must be common to be aggragatable");
|
||||
throw new NotAggregatableRecordsExceptions("The Record provided as argument has different values for field wich must be common to be aggragatable");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
AggregatedUsageRecord<T, B> aggregatedUsageRecord = ((AggregatedUsageRecord<T, B>) t);
|
||||
aggregatedUsageRecord.aggregate(aggregatedUsageRecord.getAggregatedUsageRecord(record));
|
||||
|
||||
throw new NotAggregatableRecorsExceptions("");
|
||||
}catch(NotAggregatableRecorsExceptions e){
|
||||
throw new NotAggregatableRecordsExceptions("");
|
||||
}catch(NotAggregatableRecordsExceptions e){
|
||||
throw e;
|
||||
}catch(Exception ex){
|
||||
throw new NotAggregatableRecorsExceptions(ex.getCause());
|
||||
throw new NotAggregatableRecordsExceptions(ex.getCause());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Map;
|
|||
|
||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecorsExceptions;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
|
||||
|
||||
/**
|
||||
* This Class is for library internal use only
|
||||
|
@ -47,7 +47,7 @@ public class JobUsageRecord extends org.gcube.accounting.datamodel.implementatio
|
|||
*/
|
||||
@Override
|
||||
public void aggregate(JobUsageRecord record)
|
||||
throws NotAggregatableRecorsExceptions {
|
||||
throws NotAggregatableRecordsExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Map;
|
|||
|
||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecorsExceptions;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
|
||||
|
||||
/**
|
||||
* This Class is for library internal use only
|
||||
|
@ -48,7 +48,7 @@ public class PortletUsageRecord extends org.gcube.accounting.datamodel.implement
|
|||
*/
|
||||
@Override
|
||||
public void aggregate(PortletUsageRecord record)
|
||||
throws NotAggregatableRecorsExceptions {
|
||||
throws NotAggregatableRecordsExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Map;
|
|||
|
||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecorsExceptions;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
|
||||
|
||||
/**
|
||||
* This Class is for library internal use only
|
||||
|
@ -47,7 +47,7 @@ public class StorageUsageRecord extends org.gcube.accounting.datamodel.implement
|
|||
*/
|
||||
@Override
|
||||
public void aggregate(StorageUsageRecord record)
|
||||
throws NotAggregatableRecorsExceptions {
|
||||
throws NotAggregatableRecordsExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
|
@ -7,26 +7,26 @@ package org.gcube.accounting.exception;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class NotAggregatableRecorsExceptions extends Exception {
|
||||
public class NotAggregatableRecordsExceptions extends Exception {
|
||||
|
||||
/**
|
||||
* Generated serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = -1477792189431118048L;
|
||||
|
||||
public NotAggregatableRecorsExceptions() {
|
||||
public NotAggregatableRecordsExceptions() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NotAggregatableRecorsExceptions(String message) {
|
||||
public NotAggregatableRecordsExceptions(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NotAggregatableRecorsExceptions(Throwable cause) {
|
||||
public NotAggregatableRecordsExceptions(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public NotAggregatableRecorsExceptions(String message, Throwable cause) {
|
||||
public NotAggregatableRecordsExceptions(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import java.util.ServiceLoader;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.implementations.ServiceUsageRecord;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
@ -81,7 +81,7 @@ public abstract class Persistence {
|
|||
}
|
||||
}
|
||||
|
||||
public static SingleUsageRecord createTestUsageRecord(){
|
||||
public static BasicUsageRecord createTestUsageRecord(){
|
||||
ServiceUsageRecord serviceUsageRecord = new ServiceUsageRecord();
|
||||
try {
|
||||
serviceUsageRecord.setConsumerId("accounting");
|
||||
|
@ -158,7 +158,7 @@ public abstract class Persistence {
|
|||
*/
|
||||
protected abstract void reallyAccount(UsageRecord usageRecord) throws Exception;
|
||||
|
||||
private void accountWithFallback(SingleUsageRecord usageRecord) throws Exception {
|
||||
private void accountWithFallback(BasicUsageRecord usageRecord) throws Exception {
|
||||
String persistenceName = getInstance().getClass().getSimpleName();
|
||||
try {
|
||||
//logger.debug("Going to account {} using {}", usageRecord, persistenceName);
|
||||
|
@ -187,7 +187,7 @@ public abstract class Persistence {
|
|||
* so that the {@link #UsageRecord} can be recorder later.
|
||||
* @param usageRecord the {@link #UsageRecord} to persist
|
||||
*/
|
||||
public void account(final SingleUsageRecord usageRecord){
|
||||
public void account(final BasicUsageRecord usageRecord){
|
||||
Runnable runnable = new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.datamodel.persistence;
|
|||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.persistence.Persistence;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -36,7 +36,7 @@ public class PersistenceTest {
|
|||
int quantity = 3000;
|
||||
Calendar startTestTime = new GregorianCalendar();
|
||||
for(int i=0; i< quantity; i++){
|
||||
SingleUsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
BasicUsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
persistence.account(usageRecord);
|
||||
}
|
||||
Calendar stopTestTime = new GregorianCalendar();
|
||||
|
|
Loading…
Reference in New Issue