From 987f94b8968b676b2d1f903d6c11f7d2819adba3 Mon Sep 17 00:00:00 2001 From: Alessandro Pieve Date: Thu, 11 May 2017 14:38:38 +0000 Subject: [PATCH] version 3.0 Insert jackson to convert model. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@148471 82a268e6-3cf1-43bd-a215-b396298e98cf --- .project | 23 ++++++ pom.xml | 2 +- .../datamodel/AggregatedUsageRecord.java | 3 +- .../datamodel/BasicUsageRecord.java | 23 +++++- .../aggregation/AggregatedJobUsageRecord.java | 37 ++++++++- .../AggregatedPortletUsageRecord.java | 73 +++++++++++++---- .../AggregatedServiceUsageRecord.java | 47 ++++++++++- .../AggregatedStorageStatusRecord.java | 29 +++++++ .../AggregatedStorageUsageRecord.java | 28 +++++++ .../AggregatedTaskUsageRecord.java | 10 +++ .../basetypes/AbstractJobUsageRecord.java | 19 ++++- .../basetypes/AbstractPortletUsageRecord.java | 10 ++- .../basetypes/AbstractServiceUsageRecord.java | 28 +++++-- .../AbstractStorageStatusRecord.java | 24 +++++- .../basetypes/AbstractStorageUsageRecord.java | 20 ++++- .../basetypes/AbstractTaskUsageRecord.java | 35 ++++++-- .../usagerecords/JobUsageRecord.java | 3 + .../usagerecords/PortletUsageRecord.java | 3 + .../usagerecords/ServiceUsageRecord.java | 3 + .../usagerecords/StorageStatusRecord.java | 3 + .../usagerecords/StorageUsageRecord.java | 3 + .../usagerecords/TaskUsageRecord.java | 3 + .../annotations/ValidDataTypeVolume.java | 19 +++++ .../validators/ValidDataTypeValidator.java | 1 + .../ValidDataTypeValidatorVolume.java | 64 +++++++++++++++ .../persistence/AccountingPersistence.java | 2 + .../AccountingPersistenceFactory.java | 2 + .../AggregatedJobUsageRecordTest.java | 1 + .../AggregatedServiceUsageRecordTest.java | 1 + .../AggregatedStorageStatusRecordTest.java | 1 - .../AggregatedStorageUsageRecordTest.java | 1 + .../documentstore/persistence/MyTest.java | 65 +++++++++++++++ .../java/org/gcube/testutility/MyTest.java | 62 ++++++++------ .../org/gcube/testutility/ScopedTest.java | 82 +++++++++++++++++-- .../gcube/testutility/TestUsageRecord.java | 9 +- src/test/resources/token.properties | 4 + 36 files changed, 662 insertions(+), 81 deletions(-) create mode 100644 .project create mode 100644 src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidDataTypeVolume.java create mode 100644 src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidatorVolume.java create mode 100644 src/test/java/org/gcube/documentstore/persistence/MyTest.java create mode 100644 src/test/resources/token.properties diff --git a/.project b/.project new file mode 100644 index 0000000..1ecc090 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + accounting-lib-trunk_ultimo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pom.xml b/pom.xml index fe127a2..e0428e4 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.accounting accounting-lib - 2.4.1-SNAPSHOT + 3.0.0-SNAPSHOT Accounting Library Accounting Library jar diff --git a/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java index 354b127..5b490dd 100644 --- a/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java @@ -11,9 +11,10 @@ import org.gcube.documentstore.records.implementation.validations.annotations.Va /** * @author Luca Frosini (ISTI - CNR) */ + public interface AggregatedUsageRecord, U extends UsageRecord> extends AggregatedRecord { - @ValidBoolean + @ValidBoolean public static final String AGGREGATED = AggregatedRecord.AGGREGATED; @ValidInteger diff --git a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java index 70d8f0b..42ac38c 100644 --- a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java @@ -22,12 +22,16 @@ import org.gcube.documentstore.records.implementation.validations.annotations.No import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * @author Luca Frosini (ISTI - CNR) * */ -public abstract class BasicUsageRecord extends AbstractRecord implements UsageRecord { +@JsonTypeName(value="UsageRecord") +public class BasicUsageRecord extends AbstractRecord implements UsageRecord { /** * Generated Serial Version UID @@ -78,7 +82,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe try { this.setScope(getScopeFromToken()); } catch(Exception e) { - logger.warn("Unable to automatically set the scope using scope provider. The record will not be valid if the scope will not be explicitly set."); + logger.warn("Unable to automaticcally set the scope using scope provider. The record will not be valid if the scope will not be explicitly set."); } } @@ -103,6 +107,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe /** * {@inheritDoc} */ + @JsonIgnore @Override public String getConsumerId() { return (String) this.resourceProperties.get(CONSUMER_ID); @@ -111,15 +116,26 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe /** * {@inheritDoc} */ + @JsonIgnore @Override public void setConsumerId(String consumerId) throws InvalidValueException { setResourceProperty(CONSUMER_ID, consumerId); } + + + @Override + @JsonIgnore + protected String giveMeRecordType() { + return BasicUsageRecord.class.getSimpleName(); + } + + /** * {@inheritDoc} */ + @JsonIgnore @Override public String getScope() { return (String) this.resourceProperties.get(SCOPE); @@ -128,6 +144,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe /** * {@inheritDoc} */ + @JsonIgnore @Override public void setScope(String scope) throws InvalidValueException { setResourceProperty(SCOPE, scope); @@ -136,6 +153,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe /** * {@inheritDoc} */ + @JsonIgnore @Override public OperationResult getOperationResult(){ try { @@ -150,6 +168,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe * {@inheritDoc} * @throws InvalidValueException */ + @JsonIgnore @Override public void setOperationResult(OperationResult operationResult) throws InvalidValueException { setResourceProperty(OPERATION_RESULT, operationResult); diff --git a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecord.java index dd136dd..b4bc914 100644 --- a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecord.java @@ -17,10 +17,14 @@ import org.gcube.documentstore.records.implementation.AggregatedField; import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="JobUsageRecord") public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements AggregatedUsageRecord { @@ -43,7 +47,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements super(properties); } - // TODO + // TODO public AggregatedJobUsageRecord(JobUsageRecord record) throws InvalidValueException{ //throw new UnsupportedOperationException(); super(record.getResourceProperties()); @@ -57,28 +61,34 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements this.setEndTime(creationTime); } + @JsonIgnore @Override public int getOperationCount() { return super.getOperationCount(); } + @JsonIgnore @Override public void setOperationCount(int operationCount) throws InvalidValueException { super.setOperationCount(operationCount); } + @JsonIgnore public long getMaxInvocationTime() { return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME); } + @JsonIgnore public void setMaxInvocationTime(long maxInvocationTime) throws InvalidValueException { super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime); } + @JsonIgnore public long getMinInvocationTime() { return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME); } + @JsonIgnore public void setMinInvocationTime(long minInvocationTime) throws InvalidValueException { setResourceProperty(MIN_INVOCATION_TIME, minInvocationTime); } @@ -86,6 +96,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getStartTime() { return super.getStartTimeAsCalendar(); @@ -94,6 +105,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements /** * {@inheritDoc} */ + @JsonIgnore @Override public void setStartTime(Calendar startTime) throws InvalidValueException { super.setStartTime(startTime); @@ -102,6 +114,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getEndTime() { return super.getEndTimeAsCalendar(); @@ -110,11 +123,28 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements /** * {@inheritDoc} */ + @JsonIgnore @Override public void setEndTime(Calendar endTime) throws InvalidValueException { super.setEndTime(endTime); } + + //Introduce for to serialize Java Object + @JsonIgnore + @Override + public void setAggregate(Boolean aggregate) throws InvalidValueException { + super.setAggregate(aggregate); + } + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public Boolean getAggregate() { + return super.getAggregate(); + } + //End Introduce for to serialize Java Object protected long durationWeightedAverage(AggregatedJobUsageRecord record) throws InvalidValueException{ long thisDuration = this.getDuration() * this.getOperationCount(); @@ -127,6 +157,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedJobUsageRecord aggregate(AggregatedJobUsageRecord record) throws NotAggregatableRecordsExceptions { try { @@ -156,6 +187,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedJobUsageRecord aggregate(JobUsageRecord record) throws NotAggregatableRecordsExceptions { try { @@ -193,8 +225,9 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements /** * {@inheritDoc} - */ + */ @Override + @JsonIgnore public Class getAggregable() { return JobUsageRecord.class; } diff --git a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedPortletUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedPortletUsageRecord.java index eb88d1a..745d941 100644 --- a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedPortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedPortletUsageRecord.java @@ -14,10 +14,14 @@ import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.records.aggregation.AggregationUtility; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="PortletUsageRecord") public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord implements AggregatedUsageRecord { @@ -36,14 +40,24 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp // TODO public AggregatedPortletUsageRecord(PortletUsageRecord portletUsageRecord) throws InvalidValueException { - throw new UnsupportedOperationException(); + //TEST AGGREGATE + super(portletUsageRecord.getResourceProperties()); + this.setOperationCount(1); + Calendar creationTime = portletUsageRecord.getCreationTime(); + this.setCreationTime(Calendar.getInstance()); + this.setStartTime(creationTime); + this.setEndTime(creationTime); + //END TEST comment a throw + //throw new UnsupportedOperationException(); } + @JsonIgnore @Override public int getOperationCount() { return super.getOperationCount(); } + @JsonIgnore @Override public void setOperationCount(int operationCount) throws InvalidValueException { super.setOperationCount(operationCount); @@ -52,6 +66,7 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getStartTime() { return super.getStartTimeAsCalendar(); @@ -60,6 +75,7 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public void setStartTime(Calendar startTime) throws InvalidValueException { super.setStartTime(startTime); @@ -68,6 +84,7 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getEndTime() { return super.getEndTimeAsCalendar(); @@ -76,36 +93,59 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public void setEndTime(Calendar endTime) throws InvalidValueException { super.setEndTime(endTime); } + //Introduce for to serialize Java Object + @JsonIgnore + @Override + public void setAggregate(Boolean aggregate) throws InvalidValueException { + super.setAggregate(aggregate); + } /** * {@inheritDoc} */ + @JsonIgnore @Override - public AggregatedPortletUsageRecord aggregate( - AggregatedPortletUsageRecord record) - throws NotAggregatableRecordsExceptions { - try { - /* TODO - AggregationUtility aggregationUtility = new AggregationUtility(this); - aggregationUtility.aggregate(record); - } catch(NotAggregatableRecordsExceptions e){ - throw e; */ - } catch(Exception ex){ - throw new NotAggregatableRecordsExceptions(ex); - } - //return this; - - throw new UnsupportedOperationException(); + public Boolean getAggregate() { + return super.getAggregate(); } + //End Introduce for to serialize Java Object /** * {@inheritDoc} */ @Override + @JsonIgnore + public AggregatedPortletUsageRecord aggregate(AggregatedPortletUsageRecord record) + throws NotAggregatableRecordsExceptions { + try { + /* TODO*/ + AggregationUtility aggregationUtility = new AggregationUtility(this); + + aggregationUtility.aggregate(record); + } catch(NotAggregatableRecordsExceptions e){ + throw e; + } catch(Exception ex){ + throw new NotAggregatableRecordsExceptions(ex); + } + return this; + + //throw new UnsupportedOperationException(); + } + + + + + + /** + * {@inheritDoc} + */ + @Override + @JsonIgnore public AggregatedPortletUsageRecord aggregate(PortletUsageRecord record) throws NotAggregatableRecordsExceptions { try { @@ -141,6 +181,7 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp * {@inheritDoc} */ @Override + @JsonIgnore public Class getAggregable() { return PortletUsageRecord.class; } diff --git a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecord.java index 36b6eec..3fd69ad 100644 --- a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecord.java @@ -17,10 +17,14 @@ import org.gcube.documentstore.records.implementation.AggregatedField; import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="ServiceUsageRecord") public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord implements AggregatedUsageRecord { /** @@ -28,6 +32,8 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp */ private static final long serialVersionUID = 6387584974618335623L; + + @AggregatedField public static final String DURATION = AbstractServiceUsageRecord.DURATION; @@ -56,28 +62,35 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp this.setEndTime(creationTime); } + @JsonIgnore @Override public int getOperationCount() { return super.getOperationCount(); } + @JsonIgnore @Override public void setOperationCount(int operationCount) throws InvalidValueException { super.setOperationCount(operationCount); } + @JsonIgnore public long getMaxInvocationTime() { return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME); } - + + @JsonIgnore public void setMaxInvocationTime(long maxInvocationTime) throws InvalidValueException { super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime); } + + + @JsonIgnore public long getMinInvocationTime() { return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME); } - + @JsonIgnore public void setMinInvocationTime(long minInvocationTime) throws InvalidValueException { setResourceProperty(MIN_INVOCATION_TIME, minInvocationTime); } @@ -85,6 +98,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getStartTime() { return super.getStartTimeAsCalendar(); @@ -93,6 +107,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public void setStartTime(Calendar startTime) throws InvalidValueException { super.setStartTime(startTime); @@ -101,18 +116,37 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getEndTime() { return super.getEndTimeAsCalendar(); } - + /** * {@inheritDoc} */ + @JsonIgnore @Override public void setEndTime(Calendar endTime) throws InvalidValueException { super.setEndTime(endTime); } + + //Introduce for to serialize Java Object + @JsonIgnore + @Override + public void setAggregate(Boolean aggregate) throws InvalidValueException { + super.setAggregate(aggregate); + } + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public Boolean getAggregate() { + return super.getAggregate(); + } + //End Introduce for to serialize Java Object + protected long durationWeightedAverage(AggregatedServiceUsageRecord record){ long thisDuration = this.getDuration() * this.getOperationCount(); @@ -125,6 +159,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedServiceUsageRecord aggregate(AggregatedServiceUsageRecord record) throws NotAggregatableRecordsExceptions { try { @@ -160,6 +195,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedServiceUsageRecord aggregate(ServiceUsageRecord record) throws NotAggregatableRecordsExceptions { try { @@ -174,6 +210,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp /** * {@inheritDoc} */ + @Override public boolean isAggregable(AggregatedServiceUsageRecord record) throws NotAggregatableRecordsExceptions { @@ -184,7 +221,8 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp /** * {@inheritDoc} */ - @Override + + @Override public boolean isAggregable(ServiceUsageRecord record) throws NotAggregatableRecordsExceptions { try { @@ -200,6 +238,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp * {@inheritDoc} */ @Override + @JsonIgnore public Class getAggregable() { return ServiceUsageRecord.class; } diff --git a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecord.java b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecord.java index 43cc934..bf756a4 100644 --- a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecord.java @@ -15,10 +15,14 @@ import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.records.aggregation.AggregationUtility; import org.gcube.documentstore.records.implementation.AggregatedField; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * This Class is for library internal use only * @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it */ +@JsonTypeName(value="StorageStatusRecord") public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord implements AggregatedUsageRecord { /** @@ -50,11 +54,13 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i this.setEndTime(creationTime); } + @JsonIgnore @Override public int getOperationCount() { return super.getOperationCount(); } + @JsonIgnore @Override public void setOperationCount(int operationCount) throws InvalidValueException { super.setOperationCount(operationCount); @@ -63,6 +69,7 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getStartTime() { return super.getStartTimeAsCalendar(); @@ -71,6 +78,7 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i /** * {@inheritDoc} */ + @JsonIgnore @Override public void setStartTime(Calendar startTime) throws InvalidValueException { super.setStartTime(startTime); @@ -79,6 +87,7 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getEndTime() { return super.getEndTimeAsCalendar(); @@ -87,15 +96,33 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i /** * {@inheritDoc} */ + @JsonIgnore @Override public void setEndTime(Calendar endTime) throws InvalidValueException { super.setEndTime(endTime); } + //Introduce for to serialize Java Object + @JsonIgnore + @Override + public void setAggregate(Boolean aggregate) throws InvalidValueException { + super.setAggregate(aggregate); + } + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public Boolean getAggregate() { + return super.getAggregate(); + } + //End Introduce for to serialize Java Object + /** * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedStorageStatusRecord aggregate( AggregatedStorageStatusRecord record) throws NotAggregatableRecordsExceptions { @@ -117,6 +144,7 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedStorageStatusRecord aggregate(StorageStatusRecord record) throws NotAggregatableRecordsExceptions { try { @@ -157,6 +185,7 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i * {@inheritDoc} */ @Override + @JsonIgnore public Class getAggregable() { return StorageStatusRecord.class; } diff --git a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java index 808d689..a9993d0 100644 --- a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java @@ -15,10 +15,14 @@ import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.records.aggregation.AggregationUtility; import org.gcube.documentstore.records.implementation.AggregatedField; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="StorageUsageRecord") public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord implements AggregatedUsageRecord { /** @@ -47,11 +51,13 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp this.setEndTime(creationTime); } + @JsonIgnore @Override public int getOperationCount() { return super.getOperationCount(); } + @JsonIgnore @Override public void setOperationCount(int operationCount) throws InvalidValueException { super.setOperationCount(operationCount); @@ -60,6 +66,7 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getStartTime() { return super.getStartTimeAsCalendar(); @@ -76,6 +83,7 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getEndTime() { return super.getEndTimeAsCalendar(); @@ -84,15 +92,33 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp /** * {@inheritDoc} */ + @JsonIgnore @Override public void setEndTime(Calendar endTime) throws InvalidValueException { super.setEndTime(endTime); } + //Introduce for to serialize Java Object + @JsonIgnore + @Override + public void setAggregate(Boolean aggregate) throws InvalidValueException { + super.setAggregate(aggregate); + } + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public Boolean getAggregate() { + return super.getAggregate(); + } + //End Introduce for to serialize Java Object + /** * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedStorageUsageRecord aggregate( AggregatedStorageUsageRecord record) throws NotAggregatableRecordsExceptions { @@ -112,6 +138,7 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp * {@inheritDoc} */ @Override + @JsonIgnore public AggregatedStorageUsageRecord aggregate(StorageUsageRecord record) throws NotAggregatableRecordsExceptions { try { @@ -152,6 +179,7 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp * {@inheritDoc} */ @Override + @JsonIgnore public Class getAggregable() { return StorageUsageRecord.class; } diff --git a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedTaskUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedTaskUsageRecord.java index 5113631..cf9f90c 100644 --- a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedTaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedTaskUsageRecord.java @@ -14,10 +14,14 @@ import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.records.aggregation.AggregationUtility; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="AggregatedTaskUsageRecord") public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implements AggregatedUsageRecord { /** @@ -38,11 +42,13 @@ public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implement throw new UnsupportedOperationException(); } + @JsonIgnore @Override public int getOperationCount() { return super.getOperationCount(); } + @JsonIgnore @Override public void setOperationCount(int operationCount) throws InvalidValueException { super.setOperationCount(operationCount); @@ -51,6 +57,7 @@ public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implement /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getStartTime() { return super.getStartTimeAsCalendar(); @@ -59,6 +66,7 @@ public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implement /** * {@inheritDoc} */ + @JsonIgnore @Override public void setStartTime(Calendar startTime) throws InvalidValueException { super.setStartTime(startTime); @@ -67,6 +75,7 @@ public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implement /** * {@inheritDoc} */ + @JsonIgnore @Override public Calendar getEndTime() { return super.getEndTimeAsCalendar(); @@ -75,6 +84,7 @@ public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implement /** * {@inheritDoc} */ + @JsonIgnore @Override public void setEndTime(Calendar endTime) throws InvalidValueException { super.setEndTime(endTime); diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractJobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractJobUsageRecord.java index 9c328fd..21434a9 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractJobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractJobUsageRecord.java @@ -16,6 +16,8 @@ import org.gcube.documentstore.records.implementation.validations.annotations.No import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Luca Frosini (ISTI - CNR) * @@ -75,6 +77,7 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord { /** * @return the Job Id */ + @JsonIgnore public String getJobId() { return (String) this.resourceProperties.get(JOB_ID); } @@ -83,40 +86,48 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord { * @param jobId Job Id * @throws InvalidValueException if fails */ + @JsonIgnore public void setJobId(String jobId) throws InvalidValueException { setResourceProperty(JOB_ID, jobId); } - + @JsonIgnore public String getJobQualifier() { return (String) this.resourceProperties.get(JOB_QUALIFIER); } - + + @JsonIgnore public void setJobQualifier(String jobQualifier) throws InvalidValueException { setResourceProperty(JOB_QUALIFIER, jobQualifier); } + @JsonIgnore public String getJobName() { return (String) this.resourceProperties.get(JOB_NAME); } + @JsonIgnore public void setJobName(String jobName) throws InvalidValueException { setResourceProperty(JOB_NAME, jobName); } + @JsonIgnore public Calendar getJobStartTime() { long millis = (Long) this.resourceProperties.get(JOB_START_TIME); return timestampToCalendar(millis); } + @JsonIgnore public void setJobStartTime(Calendar jobStartTime) throws InvalidValueException { setResourceProperty(JOB_START_TIME, jobStartTime.getTimeInMillis()); } + @JsonIgnore public Calendar getJobEndTime() { long millis = (Long) this.resourceProperties.get(JOB_END_TIME); return timestampToCalendar(millis); } - + + @JsonIgnore public void setJobEndTime(Calendar jobEndTime) throws InvalidValueException { setResourceProperty(JOB_END_TIME, jobEndTime.getTimeInMillis()); } @@ -134,6 +145,7 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord { } } + @JsonIgnore public long getDuration() throws InvalidValueException { Long wallDuration = (Long) this.resourceProperties.get(DURATION); if(wallDuration == null){ @@ -145,6 +157,7 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord { } return wallDuration; } + @JsonIgnore public void setDuration(Long duration) throws InvalidValueException { setResourceProperty(DURATION, duration); } diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractPortletUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractPortletUsageRecord.java index 154594e..5e25b5e 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractPortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractPortletUsageRecord.java @@ -14,6 +14,8 @@ import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Luca Frosini (ISTI - CNR) * @@ -52,26 +54,32 @@ public abstract class AbstractPortletUsageRecord extends BasicUsageRecord { return AbstractPortletUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); } + @JsonIgnore public String getPortletId() { return (String) this.resourceProperties.get(PORTLET_ID); } - + + @JsonIgnore public void setPortletId(String portletId) throws InvalidValueException { setResourceProperty(PORTLET_ID, portletId); } + @JsonIgnore public String getOperationId() { return (String) this.resourceProperties.get(OPERATION_ID); } + @JsonIgnore public void setOperationId(String operationId) throws InvalidValueException { setResourceProperty(OPERATION_ID, operationId); } + @JsonIgnore public String getMessage() { return (String) this.resourceProperties.get(MESSAGE); } + @JsonIgnore public void setMessage(String message) throws InvalidValueException { setResourceProperty(MESSAGE, message); } diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractServiceUsageRecord.java index 9d12d6a..3ba1f4b 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractServiceUsageRecord.java @@ -12,11 +12,13 @@ import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Luca Frosini (ISTI - CNR) - * */ -public abstract class AbstractServiceUsageRecord extends BasicUsageRecord { + +public class AbstractServiceUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID @@ -26,6 +28,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord { /** * KEY for : hostname:port of the Hosting Node made the service call */ + @RequiredField @NotEmpty public static final String CALLER_HOST = "callerHost"; @@ -91,63 +94,76 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord { /** * {@inheritDoc} */ + @JsonIgnore @Override protected String giveMeRecordType() { return AbstractServiceUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); + } + @JsonIgnore public String getCallerHost() { return (String) this.resourceProperties.get(CALLER_HOST); } + @JsonIgnore public void setCallerHost(String callerHost) throws InvalidValueException { setResourceProperty(CALLER_HOST, callerHost); } + @JsonIgnore public String getHost() { return (String) this.resourceProperties.get(HOST); } + @JsonIgnore public void setHost(String host) throws InvalidValueException { setResourceProperty(HOST, host); } + @JsonIgnore public String getServiceClass() { return (String) this.resourceProperties.get(SERVICE_CLASS); } + @JsonIgnore public void setServiceClass(String serviceClass) throws InvalidValueException { setResourceProperty(SERVICE_CLASS, serviceClass); } + @JsonIgnore public String getServiceName() { return (String) this.resourceProperties.get(SERVICE_NAME); } - + @JsonIgnore public void setServiceName(String serviceName) throws InvalidValueException { setResourceProperty(SERVICE_NAME, serviceName); } + + @JsonIgnore public String getCalledMethod() { return (String) this.resourceProperties.get(CALLED_METHOD); } - + @JsonIgnore public void setCalledMethod(String calledMethod) throws InvalidValueException { setResourceProperty(CALLED_METHOD, calledMethod); } + @JsonIgnore public Long getDuration() { return (Long) this.resourceProperties.get(DURATION); } - + @JsonIgnore public void setDuration(Long duration) throws InvalidValueException { setResourceProperty(DURATION, duration); } - /*Add a new field*/ + @JsonIgnore public String getCallerQualifier() { return (String) this.resourceProperties.get(CALLERQUALIFIER); } + @JsonIgnore public void setCallerQualifier(String callerQualifier) throws InvalidValueException { setResourceProperty(CALLERQUALIFIER, callerQualifier); } diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageStatusRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageStatusRecord.java index acf00a7..3a23088 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageStatusRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageStatusRecord.java @@ -9,13 +9,15 @@ import java.util.Map; import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.validations.annotations.FixDataVolumeSign; -import org.gcube.accounting.datamodel.validations.annotations.ValidDataType; +import org.gcube.accounting.datamodel.validations.annotations.ValidDataTypeVolume; import org.gcube.accounting.datamodel.validations.annotations.ValidURI; import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it * @@ -42,7 +44,7 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord { * The value is a controlled dictionary by * {@link #StorageStatusRecord.DataType} */ - @RequiredField @ValidDataType + @RequiredField @ValidDataTypeVolume public static final String DATA_TYPE = "dataType"; /** @@ -94,58 +96,72 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord { return AbstractStorageStatusRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); } + @JsonIgnore public long getDataVolume() { return (Long) this.resourceProperties.get(DATA_VOLUME); } - + + @JsonIgnore public void setDataVolume(long dataVolume) throws InvalidValueException { setResourceProperty(DATA_VOLUME, dataVolume); } + @JsonIgnore public DataType getDataType() { return (DataType) this.resourceProperties.get(DATA_TYPE); } + @JsonIgnore public void setDataType(DataType dataType) throws InvalidValueException { setResourceProperty(DATA_TYPE, dataType); } + @JsonIgnore public long getDataCount() { return (Long) this.resourceProperties.get(DATA_COUNT); } + @JsonIgnore public void setDataCount(long dataCount) throws InvalidValueException { setResourceProperty(DATA_COUNT, dataCount); } + @JsonIgnore public String getDataServiceClass() { return (String) this.resourceProperties.get(DATA_SERVICECLASS); } + @JsonIgnore public void setDataServiceClass(String dataServiceClass) throws InvalidValueException { setResourceProperty(DATA_SERVICECLASS, dataServiceClass); } + @JsonIgnore public String getDataServiceName() { return (String) this.resourceProperties.get(DATA_SERVICENAME); } + @JsonIgnore public void setDataServiceName(String dataServiceName) throws InvalidValueException { setResourceProperty(DATA_SERVICENAME, dataServiceName); } + @JsonIgnore public String getDataServiceId() { return (String) this.resourceProperties.get(DATA_SERVICEID); } + @JsonIgnore public void setDataServiceId(String dataServiceId) throws InvalidValueException { setResourceProperty(DATA_SERVICEID, dataServiceId); } + @JsonIgnore public URI getProviderId() { return (URI) this.resourceProperties.get(PROVIDER_ID); } - + + @JsonIgnore public void setProviderId(URI provideId) throws InvalidValueException { setResourceProperty(PROVIDER_ID, provideId); } diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageUsageRecord.java index 2eb46e4..56a39f7 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractStorageUsageRecord.java @@ -18,6 +18,8 @@ import org.gcube.documentstore.records.implementation.validations.annotations.No import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Luca Frosini (ISTI - CNR) * @@ -116,6 +118,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord { * Return the identity id of the storage resource owner * @return the identity id of the accounting owner */ + @JsonIgnore public String getResourceOwner() { return (String) this.resourceProperties.get(RESOURCE_OWNER); } @@ -125,6 +128,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord { * @param owner the identity id of the storage resource owner * @throws InvalidValueException */ + @JsonIgnore public void setResourceOwner(String owner) throws InvalidValueException { setResourceProperty(RESOURCE_OWNER, owner); } @@ -132,6 +136,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord { * Return the scope of the storage resource * @return The scope id of the storage resource */ + @JsonIgnore public String getResourceScope() { return (String) this.resourceProperties.get(RESOURCE_SCOPE); } @@ -141,54 +146,67 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord { * @param scope the scope of the storage resource * @throws InvalidValueException */ + @JsonIgnore public void setResourceScope(String scope) throws InvalidValueException { setResourceProperty(RESOURCE_SCOPE, scope); } + @JsonIgnore public URI getProviderURI() { return (URI) this.resourceProperties.get(PROVIDER_URI); } + @JsonIgnore public void setProviderURI(URI providerURI) throws InvalidValueException { setResourceProperty(PROVIDER_URI, providerURI); } + @JsonIgnore public URI getResourceURI() { return (URI) this.resourceProperties.get(RESOURCE_URI); } + @JsonIgnore public void setResourceURI(URI resourceURI) throws InvalidValueException { setResourceProperty(RESOURCE_URI, resourceURI); } + @JsonIgnore public OperationType getOperationType() { return (OperationType) this.resourceProperties.get(OPERATION_TYPE); } - + + @JsonIgnore public void setOperationType(OperationType operationType) throws InvalidValueException { setResourceProperty(OPERATION_TYPE, operationType); } + @JsonIgnore public DataType getDataType() { return (DataType) this.resourceProperties.get(DATA_TYPE); } + @JsonIgnore public void setDataType(DataType dataType) throws InvalidValueException { setResourceProperty(DATA_TYPE, dataType); } + @JsonIgnore public long getDataVolume() { return (Long) this.resourceProperties.get(DATA_VOLUME); } + @JsonIgnore public void setDataVolume(long dataVolume) throws InvalidValueException { setResourceProperty(DATA_VOLUME, dataVolume); } + @JsonIgnore public String getQualifier() { return (String) this.resourceProperties.get(QUALIFIER); } + @JsonIgnore public void setQualifier(String qualifier) throws InvalidValueException { setResourceProperty(QUALIFIER, qualifier); } diff --git a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractTaskUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractTaskUsageRecord.java index 9ab1cc1..9b72dc9 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractTaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetypes/AbstractTaskUsageRecord.java @@ -16,10 +16,13 @@ import org.gcube.documentstore.records.implementation.validations.annotations.No import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Luca Frosini (ISTI - CNR) * */ + public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { /** @@ -27,7 +30,8 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { */ private static final long serialVersionUID = -2208425042550641240L; - @RequiredField @NotEmpty + + @RequiredField @NotEmpty public static final String TASK_ID = "taskId"; @NotEmptyIfNotNull public static final String REF_JOB_ID = "refJobId"; @@ -37,9 +41,9 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { @NotEmptyIfNotNull public static final String REF_HOSTING_NODE_ID = "refHostingNodeId"; - @ValidLong + @ValidLong @RequiredField public static final String TASK_START_TIME = "taskStartTime"; - @ValidLong + @ValidLong @RequiredField public static final String TASK_END_TIME = "taskEndTime"; @RequiredField @ComputedField(action=CalculateTaskWallDurationAction.class) @ValidLong @@ -69,6 +73,7 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { /** * @return the Task Id */ + @JsonIgnore public String getTaskId() { return (String) this.resourceProperties.get(TASK_ID); } @@ -77,6 +82,7 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { * @param taskId Task Id * @throws InvalidValueException if fails */ + @JsonIgnore public void setTaskId(String taskId) throws InvalidValueException { setResourceProperty(TASK_ID, taskId); } @@ -84,6 +90,7 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { /** * @return the Referenced Job Id */ + @JsonIgnore public String getRefJobId() { return (String) this.resourceProperties.get(REF_JOB_ID); } @@ -92,40 +99,49 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { * @param refJobId Referenced Job Id * @throws InvalidValueException if fails */ + @JsonIgnore public void setRefJobId(String refJobId) throws InvalidValueException { setResourceProperty(REF_JOB_ID, refJobId); } + @JsonIgnore public String getHost() { return (String) this.resourceProperties.get(HOST); } + @JsonIgnore public void setHost(String host) throws InvalidValueException { setResourceProperty(HOST, host); } + @JsonIgnore public String getRefHostingNodeId() { return (String) this.resourceProperties.get(REF_HOSTING_NODE_ID); } + @JsonIgnore public void setRefHostingNodeId(String refHostingNodeId) throws InvalidValueException { setResourceProperty(REF_HOSTING_NODE_ID, refHostingNodeId); } - + + @JsonIgnore public Calendar getTaskStartTime() { long millis = (Long) this.resourceProperties.get(TASK_START_TIME); return timestampToCalendar(millis); } - + + @JsonIgnore public void setTaskStartTime(Calendar startTime) throws InvalidValueException { setResourceProperty(TASK_START_TIME, startTime.getTimeInMillis()); } + @JsonIgnore public Calendar getTaskEndTime() { long millis = (Long) this.resourceProperties.get(TASK_END_TIME); return timestampToCalendar(millis); } + @JsonIgnore public void setTaskEndTime(Calendar endTime) throws InvalidValueException { setResourceProperty(TASK_END_TIME, endTime.getTimeInMillis()); } @@ -142,6 +158,7 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { } } + @JsonIgnore public long getWallDuration() throws InvalidValueException { Long wallDuration = (Long) this.resourceProperties.get(WALL_DURATION); if(wallDuration == null){ @@ -154,11 +171,19 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord { return wallDuration; } + @JsonIgnore + public void setWallDuration(Long duration) throws InvalidValueException { + setResourceProperty(WALL_DURATION, duration); + } + @SuppressWarnings("unchecked") + @JsonIgnore public Map getInputParameters(){ return (HashMap) getResourceProperty(INPUT_PARAMETERS); } + + @JsonIgnore public void setInputParameters(HashMap inputParameters) throws InvalidValueException{ setResourceProperty(INPUT_PARAMETERS, inputParameters); } 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 5b591df..a947c90 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecord.java @@ -6,9 +6,12 @@ import java.util.Map; import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord; import org.gcube.documentstore.exception.InvalidValueException; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="NotAggregateJobUsageRecord") public class JobUsageRecord extends AbstractJobUsageRecord { /** 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 7044f1a..c7b1be8 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/PortletUsageRecord.java @@ -6,9 +6,12 @@ import java.util.Map; import org.gcube.accounting.datamodel.basetypes.AbstractPortletUsageRecord; import org.gcube.documentstore.exception.InvalidValueException; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="NotAggregatePortletUsageRecord") public class PortletUsageRecord extends AbstractPortletUsageRecord { /** 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 dd62bad..4ff1be6 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecord.java @@ -6,9 +6,12 @@ import java.util.Map; import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord; import org.gcube.documentstore.exception.InvalidValueException; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="NotAggregateServiceUsageRecord") public class ServiceUsageRecord extends AbstractServiceUsageRecord { /** diff --git a/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageStatusRecord.java b/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageStatusRecord.java index 9cfa7d4..5f3a033 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageStatusRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageStatusRecord.java @@ -5,10 +5,13 @@ import java.util.Map; import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord; import org.gcube.documentstore.exception.InvalidValueException; + +import com.fasterxml.jackson.annotation.JsonTypeName; /** * @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it * */ +@JsonTypeName(value="NotAggregateStorageStatusRecord") public class StorageStatusRecord extends AbstractStorageStatusRecord { /** 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 fe2cc0c..9fc0c23 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecord.java @@ -6,9 +6,12 @@ import java.util.Map; import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord; import org.gcube.documentstore.exception.InvalidValueException; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="NotAggregateStorageUsageRecord") public class StorageUsageRecord extends AbstractStorageUsageRecord { /** 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 aa8f626..8b79ec6 100644 --- a/src/main/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecord.java @@ -6,9 +6,12 @@ import java.util.Map; import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord; import org.gcube.documentstore.exception.InvalidValueException; +import com.fasterxml.jackson.annotation.JsonTypeName; + /** * @author Luca Frosini (ISTI - CNR) */ +@JsonTypeName(value="TaskUsageRecord") public class TaskUsageRecord extends AbstractTaskUsageRecord { /** diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidDataTypeVolume.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidDataTypeVolume.java new file mode 100644 index 0000000..961a2e7 --- /dev/null +++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidDataTypeVolume.java @@ -0,0 +1,19 @@ +package org.gcube.accounting.datamodel.validations.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.gcube.accounting.datamodel.validations.validators.ValidDataTypeValidatorVolume; +import org.gcube.documentstore.records.implementation.FieldDecorator; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@FieldDecorator(action=ValidDataTypeValidatorVolume.class) +public @interface ValidDataTypeVolume { + +} 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 a1dc986..81438a4 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,6 +3,7 @@ package org.gcube.accounting.datamodel.validations.validators; import java.io.Serializable; import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType; + import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.implementation.FieldAction; diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidatorVolume.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidatorVolume.java new file mode 100644 index 0000000..9516497 --- /dev/null +++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidDataTypeValidatorVolume.java @@ -0,0 +1,64 @@ +package org.gcube.accounting.datamodel.validations.validators; + +import java.io.Serializable; + +import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord.DataType; +import org.gcube.documentstore.exception.InvalidValueException; +import org.gcube.documentstore.records.Record; +import org.gcube.documentstore.records.implementation.FieldAction; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class ValidDataTypeValidatorVolume implements FieldAction { + + private static final String ERROR = String.format("Not Instance of %s", DataType.class.getSimpleName()); + + /** + * {@inheritDoc} + */ + @SuppressWarnings("rawtypes") + @Override + public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException { + if(value instanceof DataType){ + return value; + } + + try { + if(value instanceof String){ + try{ + DataType dataType = DataType.valueOf((String) value); + if(dataType !=null){ + return dataType; + } + } catch(Exception e){ + // Trying another way + } + + try{ + Integer integer = Integer.getInteger((String) value); + if(integer!=null){ + value = integer; + } + } catch(Exception e){ + // Trying another way + } + } + + if(value instanceof Integer){ + return DataType.values()[(Integer) value]; + } + + if(value instanceof Enum){ + return DataType.values()[((Enum) value).ordinal()]; + } + + }catch(Exception e){ + throw new InvalidValueException(ERROR, e); + } + + throw new InvalidValueException(ERROR); + } + + +} diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java index ab53ac0..f47cc9c 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java @@ -50,4 +50,6 @@ public class AccountingPersistence { getAccountingPersistence().close(); } + + } diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java index b8bec27..4eea85a 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java @@ -24,6 +24,7 @@ public class AccountingPersistenceFactory { public static void initAccountingPackages(){ PersistenceBackendFactory.addRecordPackage(ServiceUsageRecord.class.getPackage()); PersistenceBackendFactory.addRecordPackage(AggregatedServiceUsageRecord.class.getPackage()); + } static { @@ -48,6 +49,7 @@ public class AccountingPersistenceFactory { PersistenceBackendFactory.flushAll(timeout, timeUnit); } + public static void shutDown(long timeout, TimeUnit timeUnit){ //flush all and shutdown connection and thread PersistenceBackendFactory.flushAll(timeout, timeUnit); diff --git a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecordTest.java index 5db0c49..3f461aa 100644 --- a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecordTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedJobUsageRecordTest.java @@ -5,6 +5,7 @@ package org.gcube.accounting.datamodel.aggregation; import java.util.Set; +import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecordTest; import org.gcube.documentstore.exception.InvalidValueException; diff --git a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecordTest.java index 6d04dfb..5d309e5 100644 --- a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecordTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedServiceUsageRecordTest.java @@ -5,6 +5,7 @@ package org.gcube.accounting.datamodel.aggregation; import java.util.Set; +import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest; import org.gcube.documentstore.exception.InvalidValueException; diff --git a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecordTest.java index 76617ac..91b91f0 100644 --- a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecordTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageStatusRecordTest.java @@ -5,7 +5,6 @@ package org.gcube.accounting.datamodel.aggregation; import java.util.Set; - import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord; import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecordTest; import org.gcube.documentstore.exception.InvalidValueException; diff --git a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecordTest.java index c1e400f..700b218 100644 --- a/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecordTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecordTest.java @@ -5,6 +5,7 @@ package org.gcube.accounting.datamodel.aggregation; import java.util.Set; +import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecordTest; import org.gcube.documentstore.exception.InvalidValueException; diff --git a/src/test/java/org/gcube/documentstore/persistence/MyTest.java b/src/test/java/org/gcube/documentstore/persistence/MyTest.java new file mode 100644 index 0000000..26fdfb9 --- /dev/null +++ b/src/test/java/org/gcube/documentstore/persistence/MyTest.java @@ -0,0 +1,65 @@ +package org.gcube.documentstore.persistence; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import org.gcube.accounting.datamodel.BasicUsageRecord; +import org.gcube.accounting.datamodel.UsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; +import org.gcube.documentstore.records.DSMapper; +import org.gcube.documentstore.records.Record; +import org.gcube.documentstore.records.RecordUtility; +import org.gcube.documentstore.records.implementation.AbstractRecord; +import org.gcube.testutility.ScopedTest; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MyTest extends ScopedTest { + + private static Logger logger = LoggerFactory.getLogger(MyTest.class); + + @Test + public void test() throws Exception{ + File f = new File("test.log"); + + DSMapper.registerSubtypes(Record.class); + DSMapper.registerSubtypes(AbstractRecord.class); + DSMapper.registerSubtypes(UsageRecord.class); + DSMapper.registerSubtypes(BasicUsageRecord.class); + DSMapper.registerSubtypes(AbstractServiceUsageRecord.class); + DSMapper.registerSubtypes(ServiceUsageRecord.class); + + /* + Record record = TestUsageRecord.createTestServiceUsageRecord(); + + FallbackPersistenceBackend fallbackPersistenceBackend = new FallbackPersistenceBackend(f); + + fallbackPersistenceBackend.reallyAccount(record); + */ + /* + try(BufferedReader br = new BufferedReader(new FileReader(f))) { + for(String line; (line = br.readLine()) != null; ) { + try { + Record record = RecordUtility.getRecord(ServiceUsageRecord.class, line); + logger.debug(record.toString()); + } catch(Exception e){ + logger.error("Was not possible parse line {} to obtain a valid Record. Going to writing back this line as string fallback file.", line, e); + + } + } + } catch (FileNotFoundException e) { + logger.error("File non trovato", e); + } catch (IOException e) { + logger.error("IOException", e); + } + */ + } + + +} diff --git a/src/test/java/org/gcube/testutility/MyTest.java b/src/test/java/org/gcube/testutility/MyTest.java index 39634d3..c6a1936 100644 --- a/src/test/java/org/gcube/testutility/MyTest.java +++ b/src/test/java/org/gcube/testutility/MyTest.java @@ -1,28 +1,29 @@ package org.gcube.testutility; + import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.TimeUnit; -import org.gcube.accounting.datamodel.BasicUsageRecord; -import org.gcube.accounting.datamodel.UsageRecord; -import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.persistence.AccountingPersistence; import org.gcube.accounting.persistence.AccountingPersistenceFactory; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; - +import org.gcube.documentstore.records.DSMapper; import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.RecordUtility; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + + public class MyTest { private static final Logger logger = LoggerFactory.getLogger(MyTest.class); @@ -35,39 +36,31 @@ public class MyTest { } @Test - public void test() throws Exception{ + public void testFull() throws Exception{ + - - AccountingPersistence apq= AccountingPersistenceFactory.getPersistence(); - //Record record=TestUsageRecord.createTestServiceUsageRecord(); - //Record record2=TestUsageRecord.createTestServiceUsageRecord(); - - - Record record=TestUsageRecord.createTestStorageVolumeUsageRecord(); - + //Record record=TestUsageRecord.createTestServiceUsageRecord();//ok verificato + //Record record=TestUsageRecord.createTestStorageUsageRecord();//ok verificato + //Record record=TestUsageRecord.createTestStorageVolumeUsageRecord();//ok verificato + //Record record=TestUsageRecord.createTestPortletUsageRecord();//ok verificato + Record record=TestUsageRecord.createTestTaskUsageRecord();//ok verificato + //Record record=TestUsageRecord.createTestJobUsageRecord();//ok logger.debug("----record:{}",record); apq.account(record); - //apq.account(record); - //apq.account(record2); - Thread.sleep(3000); - - apq.flush(3000, TimeUnit.MILLISECONDS); - + Thread.sleep(1500); + apq.flush(1500, TimeUnit.MILLISECONDS); logger.debug("end flush"); - - File elaborationFile = new File("/home/pieve/_gcube_devNext.fallback.log"); - try(BufferedReader br = new BufferedReader(new FileReader(elaborationFile))) { for(String line; (line = br.readLine()) != null; ) { try { //Record r =DSMapper.unmarshal(Record.class, line); Record r = RecordUtility.getRecord( line); - logger.debug("{}", r); + logger.debug("--record:{}", r); } catch(Exception e){ logger.error("Was not possible parse line {} to obtain a valid Record. Going to writing back this line as string fallback file.", line, e); @@ -76,14 +69,31 @@ public class MyTest { } } catch (FileNotFoundException e) { logger.error("File non trovato", e); - } catch (IOException e) { - logger.error("IOException", e); + } catch (IOException ei) { + logger.error("IOException", ei); } + } + + + + @Test + public void testSingle() throws Exception{ + + Record record=TestUsageRecord.createTestServiceUsageRecord(); + logger.debug("----init record:{}",record.toString()); + String test=DSMapper.marshal(record); + logger.debug("----marshal single record:{}",test); + + Record r =DSMapper.unmarshal(Record.class, test); + logger.debug("----unmarshal single record:{}",r.toString()); } + + + } diff --git a/src/test/java/org/gcube/testutility/ScopedTest.java b/src/test/java/org/gcube/testutility/ScopedTest.java index ac1e38d..662a840 100644 --- a/src/test/java/org/gcube/testutility/ScopedTest.java +++ b/src/test/java/org/gcube/testutility/ScopedTest.java @@ -3,21 +3,91 @@ */ package org.gcube.testutility; -//import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.gcube.common.authorization.client.Constants; +import org.gcube.common.authorization.client.exceptions.ObjectNotFound; +import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.junit.Before; +import org.gcube.common.scope.api.ScopeProvider; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) * */ public class ScopedTest { + + + + + private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class); + + protected static final String PROPERTIES_FILENAME = "token.properties"; + + private static final String GCUBE_DEVNEXT_VARNAME = "GCUBE_DEVNEXT"; + public static final String GCUBE_DEVNEXT; + + private static final String GCUBE_DEVNEXT_NEXTNEXT_VARNAME = "GCUBE_DEVNEXT_NEXTNEXT"; + public static final String GCUBE_DEVNEXT_NEXTNEXT; + + public static final String GCUBE_DEVSEC_VARNAME = "GCUBE_DEVSEC"; + public static final String GCUBE_DEVSEC; + + public static final String GCUBE_DEVSEC_DEVVRE_VARNAME = "GCUBE_DEVSEC_DEVVRE"; + public static final String GCUBE_DEVSEC_DEVVRE; + + public static final String DEFAULT_TEST_SCOPE; + public static final String ALTERNATIVE_TEST_SCOPE; + + static { + Properties properties = new Properties(); + InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME); - @Before - public void before() throws Exception{ - SecurityTokenProvider.instance.reset(); + try { + // load the properties file + properties.load(input); + } catch (IOException e) { + throw new RuntimeException(e); + } + + GCUBE_DEVNEXT = properties.getProperty(GCUBE_DEVNEXT_VARNAME); + GCUBE_DEVNEXT_NEXTNEXT = properties.getProperty(GCUBE_DEVNEXT_NEXTNEXT_VARNAME); - SecurityTokenProvider.instance.set(""); + GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME); + GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME); + + DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT; + ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC; + } + + public static String getCurrentScope(String token) throws ObjectNotFound, Exception{ + AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); + String context = authorizationEntry.getContext(); + logger.info("Context of token {} is {}", token, context); + return context; + } + + + public static void setContext(String token) throws ObjectNotFound, Exception{ + SecurityTokenProvider.instance.set(token); + ScopeProvider.instance.set(getCurrentScope(token)); + } + + @BeforeClass + public static void beforeClass() throws Exception{ + setContext(DEFAULT_TEST_SCOPE); + } + + @AfterClass + public static void afterClass() throws Exception{ + SecurityTokenProvider.instance.reset(); + ScopeProvider.instance.reset(); } } diff --git a/src/test/java/org/gcube/testutility/TestUsageRecord.java b/src/test/java/org/gcube/testutility/TestUsageRecord.java index 63d38f8..3717071 100644 --- a/src/test/java/org/gcube/testutility/TestUsageRecord.java +++ b/src/test/java/org/gcube/testutility/TestUsageRecord.java @@ -86,7 +86,6 @@ public class TestUsageRecord { try { usageRecord.setConsumerId(TEST_CONSUMER_ID); usageRecord.setOperationResult(TEST_OPERATION_RESULT); - usageRecord.setCallerHost(TEST_CALLER_HOST); usageRecord.setHost(TEST_HOST); usageRecord.setCallerQualifier(TEST_CALLER_QUALIFIER); @@ -183,6 +182,7 @@ public class TestUsageRecord { usageRecord.setJobId(TEST_JOB_ID); usageRecord.setJobName(TEST_JOB_NAME); + usageRecord.setJobQualifier("212505"); Calendar startTime = Calendar.getInstance(); Calendar endTime = Calendar.getInstance(); endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION); @@ -209,7 +209,7 @@ public class TestUsageRecord { usageRecord.setOperationResult(TEST_OPERATION_RESULT); usageRecord.setTaskId(TEST_TASK_ID); - usageRecord.setTaskId(TEST_JOB_ID); + //usageRecord.setTaskId(TEST_JOB_ID); usageRecord.setHost(TEST_HOST); usageRecord.setRefHostingNodeId(UUID.randomUUID().toString()); @@ -222,10 +222,14 @@ public class TestUsageRecord { usageRecord.setTaskStartTime(startTime); usageRecord.setTaskEndTime(endTime); + usageRecord.setResourceProperty("finalState", "DONE") ; + usageRecord.setResourceProperty("ESEMpio", "PLUTO") ; + HashMap inputParameters = new HashMap<>(); inputParameters.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE); inputParameters.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME); + HashMap parameter = new HashMap<>(); parameter.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE); parameter.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME); @@ -233,6 +237,7 @@ public class TestUsageRecord { inputParameters.put(TEST_NESTED_MAP, parameter); usageRecord.setInputParameters(inputParameters); + } catch (InvalidValueException e) { logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e); diff --git a/src/test/resources/token.properties b/src/test/resources/token.properties new file mode 100644 index 0000000..418380c --- /dev/null +++ b/src/test/resources/token.properties @@ -0,0 +1,4 @@ +GCUBE_DEVNEXT= +GCUBE_DEVNEXT_NEXTNEXT= +GCUBE_DEVSEC= +GCUBE_DEVSEC_DEVVRE=