From 9995c4873b9403cf9ae392c86a86377199f764b7 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 29 Jul 2015 12:41:28 +0000 Subject: [PATCH] Renamed classes to avoid name and import conflicts git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@117529 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 2 +- ...ord.java => AggregatedJobUsageRecord.java} | 11 +++--- ...java => AggregatedPortletUsageRecord.java} | 11 +++--- ...java => AggregatedServiceUsageRecord.java} | 17 +++++---- ...java => AggregatedStorageUsageRecord.java} | 17 +++++---- ...rd.java => AggregatedTaskUsageRecord.java} | 11 +++--- .../scheduler/AggregationScheduler.java | 38 ++++++++++--------- ...ServiceUsageRecordAggregationStrategy.java | 21 +++++----- ...StorageUsageRecordAggregationStrategy.java | 21 +++++----- .../datamodel/BasicUsageRecord.java | 18 ++++++++- .../accounting/datamodel/RawUsageRecord.java | 9 +++++ .../accounting/datamodel/UsageRecord.java | 6 +++ ...ecord.java => AbstractJobUsageRecord.java} | 18 +++++++-- ...d.java => AbstractPortletUsageRecord.java} | 16 ++++++-- ...d.java => AbstractServiceUsageRecord.java} | 16 ++++++-- ...d.java => AbstractStorageUsageRecord.java} | 16 ++++++-- ...cord.java => AbstractTaskUsageRecord.java} | 16 ++++++-- .../datamodel/basetypes/TestUsageRecord.java | 4 +- .../usagerecords/JobUsageRecord.java | 3 +- .../usagerecords/PortletUsageRecord.java | 3 +- .../usagerecords/ServiceUsageRecord.java | 3 +- .../usagerecords/StorageUsageRecord.java | 3 +- .../usagerecords/TaskUsageRecord.java | 3 +- .../validators/ValidDataTypeValidator.java | 2 +- .../ValidOperationTypeValidator.java | 2 +- .../aggregation/ServiceUsageRecordTest.java | 8 ++-- ...iceUsageRecordAggregationStrategyTest.java | 18 +++++---- ...ageUsageRecordAggregationStrategyTest.java | 16 ++++---- .../usagerecords/ServiceUsageRecordTest.java | 12 +++--- .../usagerecords/StorageUsageRecordTest.java | 14 +++---- 30 files changed, 225 insertions(+), 130 deletions(-) rename src/main/java/org/gcube/accounting/aggregation/{JobUsageRecord.java => AggregatedJobUsageRecord.java} (59%) rename src/main/java/org/gcube/accounting/aggregation/{TaskUsageRecord.java => AggregatedPortletUsageRecord.java} (57%) rename src/main/java/org/gcube/accounting/aggregation/{ServiceUsageRecord.java => AggregatedServiceUsageRecord.java} (75%) rename src/main/java/org/gcube/accounting/aggregation/{StorageUsageRecord.java => AggregatedStorageUsageRecord.java} (65%) rename src/main/java/org/gcube/accounting/aggregation/{PortletUsageRecord.java => AggregatedTaskUsageRecord.java} (58%) rename src/main/java/org/gcube/accounting/datamodel/basetypes/{JobUsageRecord.java => AbstractJobUsageRecord.java} (91%) rename src/main/java/org/gcube/accounting/datamodel/basetypes/{PortletUsageRecord.java => AbstractPortletUsageRecord.java} (87%) rename src/main/java/org/gcube/accounting/datamodel/basetypes/{ServiceUsageRecord.java => AbstractServiceUsageRecord.java} (85%) rename src/main/java/org/gcube/accounting/datamodel/basetypes/{StorageUsageRecord.java => AbstractStorageUsageRecord.java} (92%) rename src/main/java/org/gcube/accounting/datamodel/basetypes/{TaskUsageRecord.java => AbstractTaskUsageRecord.java} (93%) diff --git a/pom.xml b/pom.xml index efabcd8..72ab899 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.accounting accounting-lib - 1.0.2-SNAPSHOT + 1.1.0-SNAPSHOT Accounting Library Accounting Library jar diff --git a/src/main/java/org/gcube/accounting/aggregation/JobUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/AggregatedJobUsageRecord.java similarity index 59% rename from src/main/java/org/gcube/accounting/aggregation/JobUsageRecord.java rename to src/main/java/org/gcube/accounting/aggregation/AggregatedJobUsageRecord.java index cc2c0c1..b21b453 100644 --- a/src/main/java/org/gcube/accounting/aggregation/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/AggregatedJobUsageRecord.java @@ -7,13 +7,15 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.exception.InvalidValueException; /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class JobUsageRecord extends org.gcube.accounting.datamodel.basetypes.JobUsageRecord implements AggregatedUsageRecord { +public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements AggregatedUsageRecord { /** * Generated Serial Version UID @@ -24,12 +26,12 @@ public class JobUsageRecord extends org.gcube.accounting.datamodel.basetypes.Job this.resourceProperties.put(AGGREGATED, true); } - public JobUsageRecord(){ + public AggregatedJobUsageRecord(){ super(); init(); } - public JobUsageRecord(Map properties) throws InvalidValueException{ + public AggregatedJobUsageRecord(Map properties) throws InvalidValueException{ super(properties); init(); } @@ -38,8 +40,7 @@ public class JobUsageRecord extends org.gcube.accounting.datamodel.basetypes.Job * {@inheritDoc} */ @Override - public JobUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.usagerecords.JobUsageRecord b) + public AggregatedJobUsageRecord getAggregatedUsageRecord(JobUsageRecord b) throws InvalidValueException { // TODO Auto-generated method stub return null; diff --git a/src/main/java/org/gcube/accounting/aggregation/TaskUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/AggregatedPortletUsageRecord.java similarity index 57% rename from src/main/java/org/gcube/accounting/aggregation/TaskUsageRecord.java rename to src/main/java/org/gcube/accounting/aggregation/AggregatedPortletUsageRecord.java index 5b0b4b5..003dcb4 100644 --- a/src/main/java/org/gcube/accounting/aggregation/TaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/AggregatedPortletUsageRecord.java @@ -7,13 +7,15 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractPortletUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord; import org.gcube.accounting.exception.InvalidValueException; /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class TaskUsageRecord extends org.gcube.accounting.datamodel.basetypes.TaskUsageRecord implements AggregatedUsageRecord { +public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord implements AggregatedUsageRecord { /** @@ -25,12 +27,12 @@ public class TaskUsageRecord extends org.gcube.accounting.datamodel.basetypes.Ta this.resourceProperties.put(AGGREGATED, true); } - public TaskUsageRecord(){ + public AggregatedPortletUsageRecord(){ super(); init(); } - public TaskUsageRecord(Map properties) throws InvalidValueException{ + public AggregatedPortletUsageRecord(Map properties) throws InvalidValueException{ super(properties); init(); } @@ -39,8 +41,7 @@ public class TaskUsageRecord extends org.gcube.accounting.datamodel.basetypes.Ta * {@inheritDoc} */ @Override - public TaskUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord usageRecord) + public AggregatedPortletUsageRecord getAggregatedUsageRecord(PortletUsageRecord usageRecord) throws InvalidValueException { // TODO Auto-generated method stub return null; diff --git a/src/main/java/org/gcube/accounting/aggregation/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/AggregatedServiceUsageRecord.java similarity index 75% rename from src/main/java/org/gcube/accounting/aggregation/ServiceUsageRecord.java rename to src/main/java/org/gcube/accounting/aggregation/AggregatedServiceUsageRecord.java index 9807e97..f1706aa 100644 --- a/src/main/java/org/gcube/accounting/aggregation/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/AggregatedServiceUsageRecord.java @@ -8,8 +8,10 @@ import java.util.Calendar; import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord; import org.gcube.accounting.datamodel.decorators.AggregatedField; import org.gcube.accounting.datamodel.decorators.RequiredField; +import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.datamodel.validations.annotations.ValidLong; import org.gcube.accounting.exception.InvalidValueException; @@ -17,7 +19,7 @@ import org.gcube.accounting.exception.InvalidValueException; * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord implements AggregatedUsageRecord { +public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord implements AggregatedUsageRecord { /** * Generated Serial Version UID @@ -26,7 +28,7 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetypes // Redefining DURATION to Set @AggregatedField @RequiredField @ValidLong @AggregatedField - public static final String DURATION = org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord.DURATION; + public static final String DURATION = org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord.DURATION; @RequiredField @ValidLong @AggregatedField public static final String MAX_INVOCATION_TIME = "maxInvocationTime"; @@ -37,17 +39,17 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetypes this.resourceProperties.put(AGGREGATED, true); } - public ServiceUsageRecord(){ + public AggregatedServiceUsageRecord(){ super(); init(); } - protected ServiceUsageRecord(Map properties) throws InvalidValueException{ + protected AggregatedServiceUsageRecord(Map properties) throws InvalidValueException{ super(properties); init(); } - public ServiceUsageRecord(org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord record) throws InvalidValueException{ + public AggregatedServiceUsageRecord(org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord record) throws InvalidValueException{ super(record.getResourceProperties()); this.setOperationCount(1); long duration = record.getDuration(); @@ -90,10 +92,9 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetypes * {@inheritDoc} */ @Override - public ServiceUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord usageRecord) + public AggregatedServiceUsageRecord getAggregatedUsageRecord(ServiceUsageRecord usageRecord) throws InvalidValueException { - return new ServiceUsageRecord(usageRecord); + return new AggregatedServiceUsageRecord(usageRecord); } } diff --git a/src/main/java/org/gcube/accounting/aggregation/StorageUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/AggregatedStorageUsageRecord.java similarity index 65% rename from src/main/java/org/gcube/accounting/aggregation/StorageUsageRecord.java rename to src/main/java/org/gcube/accounting/aggregation/AggregatedStorageUsageRecord.java index f92afdf..746fe28 100644 --- a/src/main/java/org/gcube/accounting/aggregation/StorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/AggregatedStorageUsageRecord.java @@ -8,8 +8,10 @@ import java.util.Calendar; import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord; import org.gcube.accounting.datamodel.decorators.AggregatedField; import org.gcube.accounting.datamodel.decorators.RequiredField; +import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; import org.gcube.accounting.datamodel.validations.annotations.ValidLong; import org.gcube.accounting.exception.InvalidValueException; @@ -17,7 +19,7 @@ import org.gcube.accounting.exception.InvalidValueException; * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetypes.StorageUsageRecord implements AggregatedUsageRecord { +public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord implements AggregatedUsageRecord { /** * Generated Serial Version UID @@ -26,23 +28,23 @@ public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetypes // Redefining DATA_VOLUME to Set @AggregatedField @RequiredField @ValidLong @AggregatedField - public static final String DATA_VOLUME = org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.DATA_VOLUME; + public static final String DATA_VOLUME = org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DATA_VOLUME; private void init(){ this.resourceProperties.put(AGGREGATED, true); } - public StorageUsageRecord() { + public AggregatedStorageUsageRecord() { super(); init(); } - public StorageUsageRecord(Map properties) throws InvalidValueException{ + public AggregatedStorageUsageRecord(Map properties) throws InvalidValueException{ super(properties); init(); } - public StorageUsageRecord(org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord record) throws InvalidValueException{ + public AggregatedStorageUsageRecord(org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord record) throws InvalidValueException{ super(record.getResourceProperties()); this.setOperationCount(1); Calendar creationTime = record.getCreationTime(); @@ -67,10 +69,9 @@ public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetypes * {@inheritDoc} */ @Override - public StorageUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord usageRecord) + public AggregatedStorageUsageRecord getAggregatedUsageRecord(StorageUsageRecord usageRecord) throws InvalidValueException { - return new StorageUsageRecord(usageRecord); + return new AggregatedStorageUsageRecord(usageRecord); } } diff --git a/src/main/java/org/gcube/accounting/aggregation/PortletUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/AggregatedTaskUsageRecord.java similarity index 58% rename from src/main/java/org/gcube/accounting/aggregation/PortletUsageRecord.java rename to src/main/java/org/gcube/accounting/aggregation/AggregatedTaskUsageRecord.java index 321bed5..70c0ea1 100644 --- a/src/main/java/org/gcube/accounting/aggregation/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/AggregatedTaskUsageRecord.java @@ -7,13 +7,15 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.AggregatedUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord; import org.gcube.accounting.exception.InvalidValueException; /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetypes.PortletUsageRecord implements AggregatedUsageRecord { +public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implements AggregatedUsageRecord { /** @@ -25,12 +27,12 @@ public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetypes this.resourceProperties.put(AGGREGATED, true); } - public PortletUsageRecord(){ + public AggregatedTaskUsageRecord(){ super(); init(); } - public PortletUsageRecord(Map properties) throws InvalidValueException{ + public AggregatedTaskUsageRecord(Map properties) throws InvalidValueException{ super(properties); init(); } @@ -39,8 +41,7 @@ public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetypes * {@inheritDoc} */ @Override - public PortletUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord usageRecord) + public AggregatedTaskUsageRecord getAggregatedUsageRecord(TaskUsageRecord usageRecord) throws InvalidValueException { // TODO Auto-generated method stub return null; diff --git a/src/main/java/org/gcube/accounting/aggregation/scheduler/AggregationScheduler.java b/src/main/java/org/gcube/accounting/aggregation/scheduler/AggregationScheduler.java index 4ecd7fe..af3576c 100644 --- a/src/main/java/org/gcube/accounting/aggregation/scheduler/AggregationScheduler.java +++ b/src/main/java/org/gcube/accounting/aggregation/scheduler/AggregationScheduler.java @@ -7,6 +7,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gcube.accounting.aggregation.AggregatedServiceUsageRecord; +import org.gcube.accounting.aggregation.strategy.ServiceUsageRecordAggregationStrategy; import org.gcube.accounting.datamodel.AggregatedUsageRecord; import org.gcube.accounting.datamodel.AggregationStrategy; import org.gcube.accounting.datamodel.SingleUsageRecord; @@ -49,15 +51,15 @@ public abstract class AggregationScheduler { } @SuppressWarnings({ "rawtypes", "unchecked" }) - protected Class getAggregatedUsageRecordClass(String usageRecordName) throws ClassNotFoundException { + protected Class getAggregatedUsageRecordClass(String usageRecordType) throws ClassNotFoundException { Class clz; String aggregatedURFullyQualifiedName; try { - Package aggregatedPackage = org.gcube.accounting.aggregation.ServiceUsageRecord.class.getPackage(); - aggregatedURFullyQualifiedName = String.format("%s.%s", aggregatedPackage.getName(), usageRecordName); + Package aggregatedPackage = AggregatedServiceUsageRecord.class.getPackage(); + aggregatedURFullyQualifiedName = String.format("%s.Aggregated%s", aggregatedPackage.getName(), usageRecordType); clz = (Class) Class.forName(aggregatedURFullyQualifiedName); } catch (ClassNotFoundException e) { - logger.error("Unable To find the Aggregation Class for {}", usageRecordName); + logger.error("Unable To find the Aggregation Class for {}", usageRecordType); throw e; } return clz; @@ -65,8 +67,8 @@ public abstract class AggregationScheduler { @SuppressWarnings("rawtypes") protected AggregatedUsageRecord instantiateAggregatedUsageRecord(UsageRecord usageRecord) throws Exception{ - String usageRecordName = usageRecord.getClass().getSimpleName(); - Class clz = getAggregatedUsageRecordClass(usageRecordName); + String usageRecordType = usageRecord.getUsageRecordType(); + Class clz = getAggregatedUsageRecordClass(usageRecordType); Class[] argTypes = { usageRecord.getClass() }; Constructor constructor = clz.getDeclaredConstructor(argTypes); Object[] arguments = {usageRecord}; @@ -75,15 +77,15 @@ public abstract class AggregationScheduler { @SuppressWarnings({ "rawtypes", "unchecked" }) - protected Class getAggregattionStrategyUsageRecordClass(String usageRecordName) throws ClassNotFoundException { + protected Class getAggregattionStrategyUsageRecordClass(String usageRecordType) throws ClassNotFoundException { Class clz; String aggregationStrategyName; try { - Package aggregationStrategyPackage = org.gcube.accounting.aggregation.strategy.ServiceUsageRecordAggregationStrategy.class.getPackage(); - aggregationStrategyName = String.format("%s.%s%s", aggregationStrategyPackage.getName(), usageRecordName, AggregationStrategy.class.getSimpleName()); + Package aggregationStrategyPackage = ServiceUsageRecordAggregationStrategy.class.getPackage(); + aggregationStrategyName = String.format("%s.%s%s", aggregationStrategyPackage.getName(), usageRecordType, AggregationStrategy.class.getSimpleName()); clz = (Class) Class.forName(aggregationStrategyName); } catch (Exception e) { - logger.error("Unable To find the Aggregation Strategy Class for {}", usageRecordName); + logger.error("Unable To find the Aggregation Strategy Class for {}", usageRecordType); throw e; } return clz; @@ -91,8 +93,8 @@ public abstract class AggregationScheduler { @SuppressWarnings("rawtypes") protected AggregationStrategy instantiateAggregationStrategy(AggregatedUsageRecord aggregatedUsageRecord) throws Exception{ - String usageRecordName = aggregatedUsageRecord.getClass().getSimpleName(); - Class clz = getAggregattionStrategyUsageRecordClass(usageRecordName); + String usageRecordType = aggregatedUsageRecord.getUsageRecordType(); + Class clz = getAggregattionStrategyUsageRecordClass(usageRecordType); Class[] argTypes = { aggregatedUsageRecord.getClass() }; Constructor constructor = clz.getDeclaredConstructor(argTypes); Object[] arguments = {aggregatedUsageRecord}; @@ -102,12 +104,12 @@ public abstract class AggregationScheduler { @SuppressWarnings({ "rawtypes", "unchecked" }) protected void madeAggregation(UsageRecord usageRecord){ - String usageRecordName = usageRecord.getClass().getSimpleName(); + String usageRecordType = usageRecord.getUsageRecordType(); List aggregationStrategies; - if(this.records.containsKey(usageRecordName)){ - aggregationStrategies = this.records.get(usageRecordName); + if(this.records.containsKey(usageRecordType)){ + aggregationStrategies = this.records.get(usageRecordType); boolean found = false; for(AggregationStrategy aggregationStrategy : aggregationStrategies){ try { @@ -123,7 +125,7 @@ public abstract class AggregationScheduler { } }else{ aggregationStrategies = new ArrayList(); - this.records.put(usageRecordName, aggregationStrategies); + this.records.put(usageRecordType, aggregationStrategies); } @@ -139,7 +141,7 @@ public abstract class AggregationScheduler { // org.gcube.accounting.datamodel.aggregation package aggregatedUsageRecord = instantiateAggregatedUsageRecord(usageRecord); } catch (Exception e) { - logger.error("Unable to Istantiate the Aggregation Class for {}. The Record will be persisted as is (Better than nothing).", usageRecordName); + logger.error("Unable to Istantiate the Aggregation Class for {}. The Record will be persisted as is (Better than nothing).", usageRecordType); unaggregableRecords.add(usageRecord); totalBufferedRecords++; return; @@ -152,7 +154,7 @@ public abstract class AggregationScheduler { aggregationStrategies.add(aggregationStrategy); totalBufferedRecords++; } catch (Exception e) { - logger.error("Unable to Istantiate the Aggregation Strategy Class for {}. The Record will be persisted as is (Better than nothing).", usageRecordName); + logger.error("Unable to Istantiate the Aggregation Strategy Class for {}. The Record will be persisted as is (Better than nothing).", usageRecordType); unaggregableRecords.add(usageRecord); } diff --git a/src/main/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategy.java b/src/main/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategy.java index 1ba5a85..14964bd 100644 --- a/src/main/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategy.java +++ b/src/main/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategy.java @@ -3,36 +3,37 @@ */ package org.gcube.accounting.aggregation.strategy; -import org.gcube.accounting.aggregation.ServiceUsageRecord; +import org.gcube.accounting.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.AggregationStrategy; +import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class ServiceUsageRecordAggregationStrategy extends AggregationStrategy{ +public class ServiceUsageRecordAggregationStrategy extends AggregationStrategy{ /** * @param serviceUsageRecord */ - public ServiceUsageRecordAggregationStrategy(ServiceUsageRecord serviceUsageRecord) { + public ServiceUsageRecordAggregationStrategy(AggregatedServiceUsageRecord serviceUsageRecord) { super(serviceUsageRecord); - this.aggregationField.add(ServiceUsageRecord.CALLER_HOST); - this.aggregationField.add(ServiceUsageRecord.HOST); - this.aggregationField.add(ServiceUsageRecord.SERVICE_CLASS); - this.aggregationField.add(ServiceUsageRecord.SERVICE_NAME); - this.aggregationField.add(ServiceUsageRecord.CALLED_METHOD); + this.aggregationField.add(AggregatedServiceUsageRecord.CALLER_HOST); + this.aggregationField.add(AggregatedServiceUsageRecord.HOST); + this.aggregationField.add(AggregatedServiceUsageRecord.SERVICE_CLASS); + this.aggregationField.add(AggregatedServiceUsageRecord.SERVICE_NAME); + this.aggregationField.add(AggregatedServiceUsageRecord.CALLED_METHOD); } - protected long durationWeightedAverage(ServiceUsageRecord record){ + protected long durationWeightedAverage(AggregatedServiceUsageRecord record){ long tDuration = t.getDuration() * t.getOperationCount(); long recordDuration = record.getDuration() * record.getOperationCount(); long totalOperationCount = t.getOperationCount() + record.getOperationCount(); return (tDuration + recordDuration) / totalOperationCount; } - protected ServiceUsageRecord reallyAggregate(ServiceUsageRecord record) + protected AggregatedServiceUsageRecord reallyAggregate(AggregatedServiceUsageRecord record) throws NotAggregatableRecordsExceptions { try { diff --git a/src/main/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategy.java b/src/main/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategy.java index 41fdd31..a810b3e 100644 --- a/src/main/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategy.java +++ b/src/main/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategy.java @@ -3,30 +3,31 @@ */ package org.gcube.accounting.aggregation.strategy; -import org.gcube.accounting.aggregation.StorageUsageRecord; +import org.gcube.accounting.aggregation.AggregatedStorageUsageRecord; import org.gcube.accounting.datamodel.AggregationStrategy; +import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class StorageUsageRecordAggregationStrategy extends AggregationStrategy{ +public class StorageUsageRecordAggregationStrategy extends AggregationStrategy{ /** * @param serviceUsageRecord */ - public StorageUsageRecordAggregationStrategy(StorageUsageRecord storageUsageRecord) { + public StorageUsageRecordAggregationStrategy(AggregatedStorageUsageRecord storageUsageRecord) { super(storageUsageRecord); - this.aggregationField.add(StorageUsageRecord.RESOURCE_OWNER); - this.aggregationField.add(StorageUsageRecord.RESOURCE_SCOPE); - this.aggregationField.add(StorageUsageRecord.RESOURCE_URI); - this.aggregationField.add(StorageUsageRecord.PROVIDER_URI); - this.aggregationField.add(StorageUsageRecord.OPERATION_TYPE); - this.aggregationField.add(StorageUsageRecord.DATA_TYPE); + this.aggregationField.add(AggregatedStorageUsageRecord.RESOURCE_OWNER); + this.aggregationField.add(AggregatedStorageUsageRecord.RESOURCE_SCOPE); + this.aggregationField.add(AggregatedStorageUsageRecord.RESOURCE_URI); + this.aggregationField.add(AggregatedStorageUsageRecord.PROVIDER_URI); + this.aggregationField.add(AggregatedStorageUsageRecord.OPERATION_TYPE); + this.aggregationField.add(AggregatedStorageUsageRecord.DATA_TYPE); } - protected StorageUsageRecord reallyAggregate(StorageUsageRecord record) + protected AggregatedStorageUsageRecord reallyAggregate(AggregatedStorageUsageRecord record) throws NotAggregatableRecordsExceptions { try { diff --git a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java index 05fc0ac..ffdfd10 100644 --- a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java @@ -205,7 +205,7 @@ public abstract class BasicUsageRecord implements UsageRecord, Serializable { public BasicUsageRecord(){ init(); this.resourceProperties.put(ID, UUID.randomUUID().toString()); - this.resourceProperties.put(USAGE_RECORD_TYPE, this.getClass().getSimpleName()); + this.setUsageRecordType(); Calendar calendar = Calendar.getInstance(); this.resourceProperties.put(CREATION_TIME, calendar.getTimeInMillis()); } @@ -215,6 +215,20 @@ public abstract class BasicUsageRecord implements UsageRecord, Serializable { setResourceProperties(properties); } + /** + * {@inheritDoc} + */ + @Override + public String getUsageRecordType() { + return (String) this.resourceProperties.get(USAGE_RECORD_TYPE); + } + + protected abstract String giveMeUsageRecordType(); + + protected void setUsageRecordType(){ + this.resourceProperties.put(USAGE_RECORD_TYPE, this.giveMeUsageRecordType()); + } + /** * {@inheritDoc} */ @@ -496,7 +510,7 @@ public abstract class BasicUsageRecord implements UsageRecord, Serializable { Class utilityClass = org.gcube.accounting.datamodel.usagerecords.JobUsageRecord.class; if(aggregated){ - utilityClass = org.gcube.accounting.aggregation.JobUsageRecord.class; + utilityClass = org.gcube.accounting.aggregation.AggregatedJobUsageRecord.class; } String classCanonicalName = utilityClass.getCanonicalName(); diff --git a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java index f68787b..abe7597 100644 --- a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java @@ -437,6 +437,15 @@ public class RawUsageRecord extends BasicUsageRecord implements SingleUsageRecor logger.error("Unable to Set {}", FULLY_QUALIFIED_CONSUMER_ID); } } + + /** + * {@inheritDoc} + */ + @Override + protected String giveMeUsageRecordType() { + // This implementation is just a placeholder + return this.getClass().getSimpleName(); + } } diff --git a/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java index 2cc9f86..1fd373b 100644 --- a/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java @@ -18,6 +18,12 @@ public interface UsageRecord extends Comparable { */ public Set getRequiredFields(); + /** + * Return the Usage Record Type + * @return {#UsageRecord} Type + */ + public String getUsageRecordType(); + /** * Return the unique id for this {#UsageRecord} * @return {#UsageRecord} Unique ID diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/JobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractJobUsageRecord.java similarity index 91% rename from src/main/java/org/gcube/accounting/datamodel/basetypes/JobUsageRecord.java rename to src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractJobUsageRecord.java index 0f8feec..3157969 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractJobUsageRecord.java @@ -29,9 +29,9 @@ import org.slf4j.LoggerFactory; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public abstract class JobUsageRecord extends BasicUsageRecord { +public abstract class AbstractJobUsageRecord extends BasicUsageRecord { - private static Logger logger = LoggerFactory.getLogger(JobUsageRecord.class); + private static Logger logger = LoggerFactory.getLogger(AbstractJobUsageRecord.class); /** * Generated Serial Version UID @@ -80,14 +80,24 @@ public abstract class JobUsageRecord extends BasicUsageRecord { } - public JobUsageRecord(){ + public AbstractJobUsageRecord(){ super(); } - public JobUsageRecord(Map properties) throws InvalidValueException{ + public AbstractJobUsageRecord(Map properties) throws InvalidValueException{ super(properties); } + private static final String ABSTRACT_TO_REPLACE = "Abstract"; + + /** + * {@inheritDoc} + */ + @Override + protected String giveMeUsageRecordType() { + return AbstractJobUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); + } + /** * @return the Job Id */ diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/PortletUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractPortletUsageRecord.java similarity index 87% rename from src/main/java/org/gcube/accounting/datamodel/basetypes/PortletUsageRecord.java rename to src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractPortletUsageRecord.java index 14251dc..8a3ffc8 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractPortletUsageRecord.java @@ -25,7 +25,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public abstract class PortletUsageRecord extends BasicUsageRecord { +public abstract class AbstractPortletUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID @@ -55,14 +55,24 @@ public abstract class PortletUsageRecord extends BasicUsageRecord { @NotEmptyIfNotNull public static final String MESSAGE = "message"; - public PortletUsageRecord(){ + public AbstractPortletUsageRecord(){ super(); } - public PortletUsageRecord(Map properties) throws InvalidValueException { + public AbstractPortletUsageRecord(Map properties) throws InvalidValueException { super(properties); } + private static final String ABSTRACT_TO_REPLACE = "Abstract"; + + /** + * {@inheritDoc} + */ + @Override + protected String giveMeUsageRecordType() { + return AbstractPortletUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); + } + /* * * Use {@link #getConsumerId()} instead * @return the Consumer ID diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractServiceUsageRecord.java similarity index 85% rename from src/main/java/org/gcube/accounting/datamodel/basetypes/ServiceUsageRecord.java rename to src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractServiceUsageRecord.java index 190e13a..2ca6bfd 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractServiceUsageRecord.java @@ -16,7 +16,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public abstract class ServiceUsageRecord extends BasicUsageRecord { +public abstract class AbstractServiceUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID @@ -59,13 +59,23 @@ public abstract class ServiceUsageRecord extends BasicUsageRecord { @RequiredField @ValidLong public static final String DURATION = "duration"; - public ServiceUsageRecord(){ + public AbstractServiceUsageRecord(){ super(); } - public ServiceUsageRecord(Map properties) throws InvalidValueException { + public AbstractServiceUsageRecord(Map properties) throws InvalidValueException { super(properties); } + + private static final String ABSTRACT_TO_REPLACE = "Abstract"; + + /** + * {@inheritDoc} + */ + @Override + protected String giveMeUsageRecordType() { + return AbstractServiceUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); + } public String getCallerHost() { return (String) this.resourceProperties.get(CALLER_HOST); diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/StorageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageUsageRecord.java similarity index 92% rename from src/main/java/org/gcube/accounting/datamodel/basetypes/StorageUsageRecord.java rename to src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageUsageRecord.java index 6437339..c8f0eae 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/StorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageUsageRecord.java @@ -21,7 +21,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public abstract class StorageUsageRecord extends BasicUsageRecord { +public abstract class AbstractStorageUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID @@ -103,13 +103,23 @@ public abstract class StorageUsageRecord extends BasicUsageRecord { @NotEmptyIfNotNull public static final String QUALIFIER = "qualifier"; - public StorageUsageRecord() { + public AbstractStorageUsageRecord() { super(); } - public StorageUsageRecord(Map properties) throws InvalidValueException { + public AbstractStorageUsageRecord(Map properties) throws InvalidValueException { super(properties); } + + private static final String ABSTRACT_TO_REPLACE = "Abstract"; + + /** + * {@inheritDoc} + */ + @Override + protected String giveMeUsageRecordType() { + return AbstractStorageUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); + } /** * Return the identity id of the storage resource owner diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/TaskUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractTaskUsageRecord.java similarity index 93% rename from src/main/java/org/gcube/accounting/datamodel/basetypes/TaskUsageRecord.java rename to src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractTaskUsageRecord.java index fce1001..53c8399 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/TaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractTaskUsageRecord.java @@ -20,7 +20,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public abstract class TaskUsageRecord extends BasicUsageRecord { +public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID @@ -66,13 +66,23 @@ public abstract class TaskUsageRecord extends BasicUsageRecord { @ValidInteger public static final String PROCESSORS = "processors"; - public TaskUsageRecord(){ + public AbstractTaskUsageRecord(){ super(); } - public TaskUsageRecord(Map properties) throws InvalidValueException { + public AbstractTaskUsageRecord(Map properties) throws InvalidValueException { super(properties); } + + private static final String ABSTRACT_TO_REPLACE = "Abstract"; + + /** + * {@inheritDoc} + */ + @Override + protected String giveMeUsageRecordType() { + return AbstractTaskUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); + } /** * @return the Job Id diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/TestUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/TestUsageRecord.java index c9ff477..0639436 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/TestUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/TestUsageRecord.java @@ -132,8 +132,8 @@ public class TestUsageRecord { usageRecord.setResourceURI(new URI(TEST_RESOURCE_URI)); usageRecord.setProviderURI(new URI(TEST_PROVIDER_URI)); - usageRecord.setOperationType(StorageUsageRecord.OperationType.READ); - usageRecord.setDataType(StorageUsageRecord.DataType.STORAGE); + usageRecord.setOperationType(AbstractStorageUsageRecord.OperationType.READ); + usageRecord.setDataType(AbstractStorageUsageRecord.DataType.STORAGE); usageRecord.setDataVolume(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME)); diff --git a/src/main/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecord.java index ef525c3..d8c8875 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecord.java @@ -4,9 +4,10 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.SingleUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -public class JobUsageRecord extends org.gcube.accounting.datamodel.basetypes.JobUsageRecord implements SingleUsageRecord { +public class JobUsageRecord extends AbstractJobUsageRecord implements SingleUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/usagerecords/PortletUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/usagerecords/PortletUsageRecord.java index 6004a34..a999baf 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/PortletUsageRecord.java @@ -4,9 +4,10 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.SingleUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractPortletUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetypes.PortletUsageRecord implements SingleUsageRecord { +public class PortletUsageRecord extends AbstractPortletUsageRecord implements SingleUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecord.java index 0d1c047..bf310b8 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecord.java @@ -4,9 +4,10 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.SingleUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord implements SingleUsageRecord { +public class ServiceUsageRecord extends AbstractServiceUsageRecord implements SingleUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecord.java index 34c80b2..79c23dc 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecord.java @@ -4,9 +4,10 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.SingleUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetypes.StorageUsageRecord implements SingleUsageRecord { +public class StorageUsageRecord extends AbstractStorageUsageRecord implements SingleUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecord.java index f915f7c..f9822ae 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecord.java @@ -4,9 +4,10 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.SingleUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord; import org.gcube.accounting.exception.InvalidValueException; -public class TaskUsageRecord extends org.gcube.accounting.datamodel.basetypes.TaskUsageRecord implements SingleUsageRecord { +public class TaskUsageRecord extends AbstractTaskUsageRecord implements SingleUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidator.java index d89f1d5..a92a4ea 100644 --- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidator.java +++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidator.java @@ -3,7 +3,7 @@ package org.gcube.accounting.datamodel.validations.validators; import java.io.Serializable; import org.gcube.accounting.datamodel.UsageRecord; -import org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.DataType; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType; import org.gcube.accounting.datamodel.decorators.FieldAction; import org.gcube.accounting.exception.InvalidValueException; diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationTypeValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationTypeValidator.java index 03748fc..d2df98f 100644 --- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationTypeValidator.java +++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationTypeValidator.java @@ -4,7 +4,7 @@ import java.io.Serializable; import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.UsageRecord.OperationResult; -import org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.OperationType; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType; import org.gcube.accounting.datamodel.decorators.FieldAction; import org.gcube.accounting.exception.InvalidValueException; diff --git a/src/test/java/org/gcube/accounting/aggregation/ServiceUsageRecordTest.java b/src/test/java/org/gcube/accounting/aggregation/ServiceUsageRecordTest.java index fe9e0d5..0f7a53b 100644 --- a/src/test/java/org/gcube/accounting/aggregation/ServiceUsageRecordTest.java +++ b/src/test/java/org/gcube/accounting/aggregation/ServiceUsageRecordTest.java @@ -24,12 +24,12 @@ public class ServiceUsageRecordTest { public void testRequiredFields() throws InvalidValueException { org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); - ServiceUsageRecord aggregatedServiceUsageRecord = new ServiceUsageRecord(serviceUsageRecord); + AggregatedServiceUsageRecord aggregatedServiceUsageRecord = new AggregatedServiceUsageRecord(serviceUsageRecord); Set expectedRequiredFields = org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest.getExpectedRequiredFields(); - expectedRequiredFields.add(ServiceUsageRecord.DURATION); - expectedRequiredFields.add(ServiceUsageRecord.MAX_INVOCATION_TIME); - expectedRequiredFields.add(ServiceUsageRecord.MIN_INVOCATION_TIME); + expectedRequiredFields.add(AggregatedServiceUsageRecord.DURATION); + expectedRequiredFields.add(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME); + expectedRequiredFields.add(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME); logger.debug("Expected Required Fields : {}", expectedRequiredFields); diff --git a/src/test/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategyTest.java b/src/test/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategyTest.java index 87351f5..ec0b241 100644 --- a/src/test/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategyTest.java +++ b/src/test/java/org/gcube/accounting/aggregation/strategy/ServiceUsageRecordAggregationStrategyTest.java @@ -3,6 +3,7 @@ */ package org.gcube.accounting.aggregation.strategy; +import org.gcube.accounting.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.aggregation.strategy.ServiceUsageRecordAggregationStrategy; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; @@ -31,8 +32,7 @@ public class ServiceUsageRecordAggregationStrategyTest { serviceUsageRecord.validate(); logger.debug("ServiceUsageRecord : {}", serviceUsageRecord); - org.gcube.accounting.aggregation.ServiceUsageRecord aggregated = - new org.gcube.accounting.aggregation.ServiceUsageRecord(serviceUsageRecord); + AggregatedServiceUsageRecord aggregated = new AggregatedServiceUsageRecord(serviceUsageRecord); logger.debug("ServiceUsageRecord Converted to Aggregated: {}", aggregated); aggregated.validate(); @@ -61,6 +61,7 @@ public class ServiceUsageRecordAggregationStrategyTest { Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME)); + Assert.assertTrue(aggregated.getUsageRecordType().compareTo(ServiceUsageRecord.class.getSimpleName())==0); } @@ -71,8 +72,7 @@ public class ServiceUsageRecordAggregationStrategyTest { serviceUsageRecord.validate(); logger.debug("ServiceUsageRecord : {}", serviceUsageRecord); - org.gcube.accounting.aggregation.ServiceUsageRecord aggregated = - new org.gcube.accounting.aggregation.ServiceUsageRecord(serviceUsageRecord); + AggregatedServiceUsageRecord aggregated = new AggregatedServiceUsageRecord(serviceUsageRecord); logger.debug("ServiceUsageRecord Converted to Aggregated: {}", aggregated); aggregated.validate(); @@ -80,8 +80,7 @@ public class ServiceUsageRecordAggregationStrategyTest { serviceUsageRecord2.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE); serviceUsageRecord2.validate(); logger.debug("ServiceUsageRecord 2 : {}", serviceUsageRecord2); - org.gcube.accounting.aggregation.ServiceUsageRecord converted = - new org.gcube.accounting.aggregation.ServiceUsageRecord(serviceUsageRecord2); + AggregatedServiceUsageRecord converted = new AggregatedServiceUsageRecord(serviceUsageRecord2); logger.debug("ServiceUsageRecord 2 Converted to Aggregated: {}", converted); converted.validate(); @@ -105,6 +104,8 @@ public class ServiceUsageRecordAggregationStrategyTest { Assert.assertTrue(aggregated.getMinInvocationTime() == firstduration); } Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME)); + + Assert.assertTrue(aggregated.getUsageRecordType().compareTo(ServiceUsageRecord.class.getSimpleName())==0); } protected long durationWeightedAverage(int numberA, long durationA, int numberB, long durationB){ @@ -119,8 +120,7 @@ public class ServiceUsageRecordAggregationStrategyTest { serviceUsageRecord.validate(); logger.debug("ServiceUsageRecord : {}", serviceUsageRecord); - org.gcube.accounting.aggregation.ServiceUsageRecord aggregated = - new org.gcube.accounting.aggregation.ServiceUsageRecord(serviceUsageRecord); + AggregatedServiceUsageRecord aggregated = new AggregatedServiceUsageRecord(serviceUsageRecord); logger.debug("ServiceUsageRecord Converted to Aggregated: {}", aggregated); aggregated.validate(); @@ -161,6 +161,8 @@ public class ServiceUsageRecordAggregationStrategyTest { Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME)); } + Assert.assertTrue(aggregated.getUsageRecordType().compareTo(ServiceUsageRecord.class.getSimpleName())==0); + logger.debug("Resulting Aggregated ServiceUsageRecord: {}", aggregated); } diff --git a/src/test/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategyTest.java b/src/test/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategyTest.java index 01d2099..8cb2815 100644 --- a/src/test/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategyTest.java +++ b/src/test/java/org/gcube/accounting/aggregation/strategy/StorageUsageRecordAggregationStrategyTest.java @@ -30,8 +30,8 @@ public class StorageUsageRecordAggregationStrategyTest { storageUsageRecord.validate(); logger.debug("StorageUsageRecord : {}", storageUsageRecord); - org.gcube.accounting.aggregation.StorageUsageRecord aggregated = - new org.gcube.accounting.aggregation.StorageUsageRecord(storageUsageRecord); + org.gcube.accounting.aggregation.AggregatedStorageUsageRecord aggregated = + new org.gcube.accounting.aggregation.AggregatedStorageUsageRecord(storageUsageRecord); logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated); aggregated.validate(); @@ -60,8 +60,8 @@ public class StorageUsageRecordAggregationStrategyTest { storageUsageRecord.validate(); logger.debug("StorageUsageRecord : {}", storageUsageRecord); - org.gcube.accounting.aggregation.StorageUsageRecord aggregated = - new org.gcube.accounting.aggregation.StorageUsageRecord(storageUsageRecord); + org.gcube.accounting.aggregation.AggregatedStorageUsageRecord aggregated = + new org.gcube.accounting.aggregation.AggregatedStorageUsageRecord(storageUsageRecord); logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated); aggregated.validate(); @@ -69,8 +69,8 @@ public class StorageUsageRecordAggregationStrategyTest { storageUsageRecord2.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE); storageUsageRecord2.validate(); logger.debug("StorageUsageRecord 2 : {}", storageUsageRecord2); - org.gcube.accounting.aggregation.StorageUsageRecord converted = - new org.gcube.accounting.aggregation.StorageUsageRecord(storageUsageRecord2); + org.gcube.accounting.aggregation.AggregatedStorageUsageRecord converted = + new org.gcube.accounting.aggregation.AggregatedStorageUsageRecord(storageUsageRecord2); logger.debug("StorageUsageRecord Converted to Aggregated: {}", converted); converted.validate(); @@ -97,8 +97,8 @@ public class StorageUsageRecordAggregationStrategyTest { storageUsageRecord.validate(); logger.debug("StorageUsageRecord : {}", storageUsageRecord); - org.gcube.accounting.aggregation.StorageUsageRecord aggregated = - new org.gcube.accounting.aggregation.StorageUsageRecord(storageUsageRecord); + org.gcube.accounting.aggregation.AggregatedStorageUsageRecord aggregated = + new org.gcube.accounting.aggregation.AggregatedStorageUsageRecord(storageUsageRecord); logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated); aggregated.validate(); diff --git a/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordTest.java index de81725..54b2a7c 100644 --- a/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordTest.java @@ -28,12 +28,12 @@ public class ServiceUsageRecordTest { expectedRequiredFields.add(BasicUsageRecordUtility.USAGE_RECORD_TYPE); expectedRequiredFields.add(BasicUsageRecord.SCOPE); expectedRequiredFields.add(BasicUsageRecord.OPERATION_RESULT); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord.CALLER_HOST); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord.HOST); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord.SERVICE_CLASS); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord.SERVICE_NAME); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord.CALLED_METHOD); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.ServiceUsageRecord.DURATION); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord.CALLER_HOST); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord.HOST); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord.SERVICE_CLASS); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord.SERVICE_NAME); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord.CALLED_METHOD); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord.DURATION); return expectedRequiredFields; } diff --git a/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordTest.java index 4abac64..076e137 100644 --- a/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordTest.java @@ -28,13 +28,13 @@ public class StorageUsageRecordTest { expectedRequiredFields.add(BasicUsageRecordUtility.USAGE_RECORD_TYPE); expectedRequiredFields.add(BasicUsageRecord.SCOPE); expectedRequiredFields.add(BasicUsageRecord.OPERATION_RESULT); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.RESOURCE_OWNER); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.RESOURCE_SCOPE); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.RESOURCE_URI); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.PROVIDER_URI); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.OPERATION_TYPE); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.DATA_TYPE); - expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.StorageUsageRecord.DATA_VOLUME); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.RESOURCE_OWNER); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.RESOURCE_SCOPE); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.RESOURCE_URI); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.PROVIDER_URI); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OPERATION_TYPE); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DATA_TYPE); + expectedRequiredFields.add(org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DATA_VOLUME); return expectedRequiredFields; }