From 47ade73adc4742487c1c98777da4d0a1e2c61f5d Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 24 Jun 2015 11:00:35 +0000 Subject: [PATCH] refs #200: Create accouting-lib library https://support.d4science.org/issues/200 Implementing aggregation facilities git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115503 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../datamodel/AggregatedUsageRecord.java | 9 +------ .../datamodel/AggregationStrategy.java | 13 +++++----- .../aggregated/JobUsageRecord.java | 12 --------- .../aggregated/PortletUsageRecord.java | 13 ---------- .../aggregated/ServiceUsageRecord.java | 12 +++------ .../aggregated/StorageUsageRecord.java | 12 --------- ...ServiceUsageRecordAggregationStrategy.java | 25 +++++++++++++++++++ 7 files changed, 37 insertions(+), 59 deletions(-) diff --git a/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java index 8586ac7..1c81f3a 100644 --- a/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java @@ -4,20 +4,13 @@ package org.gcube.accounting.datamodel; import org.gcube.accounting.exception.InvalidValueException; -import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public interface AggregatedUsageRecord extends SingleUsageRecord { +public interface AggregatedUsageRecord, B extends SingleUsageRecord> extends SingleUsageRecord { public T getAggregatedUsageRecord(B b) throws InvalidValueException ; - /** - * Aggregate the Record provided as parameter with this record if Aggregatable - * @throws NotAggregatableRecordsExceptions - */ - public void aggregate(T record) throws NotAggregatableRecordsExceptions; - } diff --git a/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java b/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java index 499abb9..7ff5cbe 100644 --- a/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java +++ b/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java @@ -15,7 +15,7 @@ import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public abstract class AggregationStrategy { +public abstract class AggregationStrategy, B extends SingleUsageRecord> { protected T t; protected Set aggregationField; @@ -58,17 +58,18 @@ public abstract class AggregationStrategy aggregatedUsageRecord = ((AggregatedUsageRecord) t); - aggregatedUsageRecord.aggregate(aggregatedUsageRecord.getAggregatedUsageRecord(record)); + t.getAggregatedUsageRecord(record); + t = reallyAggregate(t); - throw new NotAggregatableRecordsExceptions(""); + return t; }catch(NotAggregatableRecordsExceptions e){ throw e; }catch(Exception ex){ diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/JobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/JobUsageRecord.java index 45adb93..f0d5944 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/JobUsageRecord.java @@ -8,7 +8,6 @@ import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** * This Class is for library internal use only @@ -42,16 +41,5 @@ public class JobUsageRecord extends org.gcube.accounting.datamodel.implementatio return null; } - /** - * {@inheritDoc} - */ - @Override - public void aggregate(JobUsageRecord record) - throws NotAggregatableRecordsExceptions { - // TODO Auto-generated method stub - - } - - } diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/PortletUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/PortletUsageRecord.java index f2332ad..3206770 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/PortletUsageRecord.java @@ -8,7 +8,6 @@ import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** * This Class is for library internal use only @@ -43,16 +42,4 @@ public class PortletUsageRecord extends org.gcube.accounting.datamodel.implement return null; } - /** - * {@inheritDoc} - */ - @Override - public void aggregate(PortletUsageRecord record) - throws NotAggregatableRecordsExceptions { - // TODO Auto-generated method stub - - } - - - } diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/ServiceUsageRecord.java index cb79b07..2f23374 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/ServiceUsageRecord.java @@ -49,9 +49,6 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.implement this.setMaxInvocationTime(duration); this.resourceProperties.put(AGGREGATED, true); } - - - public int getInvocationCount() { return (Integer) this.resourceProperties.get(INVOCATION_COUNT); @@ -77,10 +74,8 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.implement setResourceProperty(MIN_INVOCATION_TIME, minInvocationTime); } - /** - * {@inheritDoc} - */ - @Override + + /* public void aggregate(ServiceUsageRecord record) { try { this.setInvocationCount(this.getInvocationCount() + record.getInvocationCount()); @@ -100,7 +95,8 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.implement throw new UnsupportedOperationException(e.getCause()); } } - + */ + /** * {@inheritDoc} */ diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/StorageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/StorageUsageRecord.java index b7f1502..f6b795a 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/StorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregated/StorageUsageRecord.java @@ -8,7 +8,6 @@ import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** * This Class is for library internal use only @@ -41,16 +40,5 @@ public class StorageUsageRecord extends org.gcube.accounting.datamodel.implement // TODO Auto-generated method stub return null; } - - /** - * {@inheritDoc} - */ - @Override - public void aggregate(StorageUsageRecord record) - throws NotAggregatableRecordsExceptions { - // TODO Auto-generated method stub - - } - } diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java index 1e8bd9b..865e695 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java @@ -5,6 +5,7 @@ package org.gcube.accounting.datamodel.implementations.aggregationstrategy; import org.gcube.accounting.datamodel.AggregationStrategy; import org.gcube.accounting.datamodel.implementations.aggregated.ServiceUsageRecord; +import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ @@ -24,4 +25,28 @@ public class ServiceUsageRecordAggregationStrategy extends AggregationStrategy t.getMaxInvocationTime()){ + t.setMaxInvocationTime(max); + } + + long min = record.getMinInvocationTime(); + if(min < t.getMinInvocationTime()){ + t.setMinInvocationTime(min); + } + + }catch(Exception e){ + throw new UnsupportedOperationException(e.getCause()); + } + + return t; + } + }