Fixed jackson serialization

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@153094 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-09-14 12:21:23 +00:00
parent 8e592a4f0f
commit dff433de7c
28 changed files with 196 additions and 1082 deletions

View File

@ -9,12 +9,15 @@ import java.util.Map;
import org.gcube.accounting.datamodel.AggregatedUsageRecord; import org.gcube.accounting.datamodel.AggregatedUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord; import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.aggregation.AggregationUtility; import org.gcube.documentstore.records.aggregation.AggregationUtility;
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; import com.fasterxml.jackson.annotation.JsonTypeName;
/** /**
@ -29,19 +32,14 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
*/ */
private static final long serialVersionUID = -3376423316219914682L; private static final long serialVersionUID = -3376423316219914682L;
/* @AggregatedField
/ *add a field max e min invocation* / public static final String DURATION = AbstractServiceUsageRecord.DURATION;
@RequiredField @ValidLong @AggregatedField @RequiredField @ValidLong @AggregatedField
public static final String MAX_INVOCATION_TIME = "maxInvocationTime"; public static final String MAX_INVOCATION_TIME = "maxInvocationTime";
@RequiredField @ValidLong @AggregatedField @RequiredField @ValidLong @AggregatedField
public static final String MIN_INVOCATION_TIME = "minInvocationTime"; public static final String MIN_INVOCATION_TIME = "minInvocationTime";
@RequiredField @ValidLong @AggregatedField
public static final String JOB_START_TIME = "jobStartTime";
@RequiredField @ValidLong @AggregatedField
public static final String JOB_END_TIME = "jobEndTime";
*/
public AggregatedJobUsageRecord(){ public AggregatedJobUsageRecord(){
super(); super();
} }
@ -52,58 +50,46 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
// TODO // TODO
public AggregatedJobUsageRecord(JobUsageRecord record) throws InvalidValueException{ public AggregatedJobUsageRecord(JobUsageRecord record) throws InvalidValueException{
//throw new UnsupportedOperationException();
super(record.getResourceProperties()); super(record.getResourceProperties());
this.setOperationCount(1); this.setOperationCount(1);
/*
long duration = record.getDuration(); long duration = record.getDuration();
this.setMinInvocationTime(duration); this.setMinInvocationTime(duration);
this.setMaxInvocationTime(duration); this.setMaxInvocationTime(duration);
*/
Calendar creationTime = record.getCreationTime(); Calendar creationTime = record.getCreationTime();
this.setCreationTime(Calendar.getInstance()); this.setCreationTime(Calendar.getInstance());
this.setStartTime(creationTime); this.setStartTime(creationTime);
this.setEndTime(creationTime); this.setEndTime(creationTime);
} }
@JsonIgnore
@Override @Override
public int getOperationCount() { public int getOperationCount() {
return super.getOperationCount(); return super.getOperationCount();
} }
@JsonIgnore
@Override @Override
public void setOperationCount(int operationCount) throws InvalidValueException { public void setOperationCount(int operationCount) throws InvalidValueException {
super.setOperationCount(operationCount); super.setOperationCount(operationCount);
} }
/*
@JsonIgnore
public long getMaxInvocationTime() { public long getMaxInvocationTime() {
return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME); return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME);
} }
@JsonIgnore
public void setMaxInvocationTime(long maxInvocationTime) throws InvalidValueException { public void setMaxInvocationTime(long maxInvocationTime) throws InvalidValueException {
super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime); super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime);
} }
@JsonIgnore
public long getMinInvocationTime() { public long getMinInvocationTime() {
return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME); return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME);
} }
@JsonIgnore
public void setMinInvocationTime(long minInvocationTime) throws InvalidValueException { public void setMinInvocationTime(long minInvocationTime) throws InvalidValueException {
setResourceProperty(MIN_INVOCATION_TIME, minInvocationTime); setResourceProperty(MIN_INVOCATION_TIME, minInvocationTime);
} }
*/
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getStartTime() { public Calendar getStartTime() {
return super.getStartTimeAsCalendar(); return super.getStartTimeAsCalendar();
@ -112,7 +98,6 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setStartTime(Calendar startTime) throws InvalidValueException { public void setStartTime(Calendar startTime) throws InvalidValueException {
super.setStartTime(startTime); super.setStartTime(startTime);
@ -121,7 +106,6 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getEndTime() { public Calendar getEndTime() {
return super.getEndTimeAsCalendar(); return super.getEndTimeAsCalendar();
@ -130,51 +114,50 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setEndTime(Calendar endTime) throws InvalidValueException { public void setEndTime(Calendar endTime) throws InvalidValueException {
super.setEndTime(endTime); super.setEndTime(endTime);
} }
//Introduced to serialize Java Object
@JsonIgnore
@Override @Override
public void setAggregate(Boolean aggregate) throws InvalidValueException { public void setAggregated(Boolean aggregate) throws InvalidValueException {
super.setAggregate(aggregate); super.setAggregated(aggregate);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Boolean getAggregate() { public Boolean isAggregated() {
return super.getAggregate(); return super.isAggregated();
} }
//End Introduced to serialize Java Object
/*
protected long durationWeightedAverage(AggregatedJobUsageRecord record) throws InvalidValueException{ protected long durationWeightedAverage(AggregatedJobUsageRecord record) throws InvalidValueException{
long thisDuration = this.getDuration() * this.getOperationCount(); long thisDuration = this.getDuration() * this.getOperationCount();
long recordDuration = record.getDuration() * record.getOperationCount(); long recordDuration = record.getDuration() * record.getOperationCount();
long totalOperationCount = this.getOperationCount() + record.getOperationCount(); long totalOperationCount = this.getOperationCount() + record.getOperationCount();
return (thisDuration + recordDuration) / totalOperationCount; return (thisDuration + recordDuration) / totalOperationCount;
} }
*/
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedJobUsageRecord aggregate(AggregatedJobUsageRecord record) public AggregatedJobUsageRecord aggregate(AggregatedJobUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
throw new NotAggregatableRecordsExceptions();
/*
try { try {
/*
* It is also checked in aggregationUtility.aggregate(record)
* but has to be also checked before modifying values
*/
if(!isAggregable(record)){
throw new NotAggregatableRecordsExceptions("The Record provided as argument has different values for field wich must be common to be aggregatable");
}
AggregationUtility<AggregatedJobUsageRecord> aggregationUtility = new AggregationUtility<AggregatedJobUsageRecord>(this); AggregationUtility<AggregatedJobUsageRecord> aggregationUtility = new AggregationUtility<AggregatedJobUsageRecord>(this);
setDuration(durationWeightedAverage(record)); setDuration(durationWeightedAverage(record));
long max = record.getMaxInvocationTime(); long max = record.getMaxInvocationTime();
if(max > this.getMaxInvocationTime()){ if(max > this.getMaxInvocationTime()){
this.setMaxInvocationTime(max); this.setMaxInvocationTime(max);
@ -184,21 +167,25 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
if(min < this.getMinInvocationTime()){ if(min < this.getMinInvocationTime()){
this.setMinInvocationTime(min); this.setMinInvocationTime(min);
} }
// This statement is at the end because the aggregate method
// sum operation counts. If this statement is moved at the
// beginning the weighted average is not calculated correctly
aggregationUtility.aggregate(record); aggregationUtility.aggregate(record);
} catch(NotAggregatableRecordsExceptions e){ } catch(NotAggregatableRecordsExceptions e){
throw e; throw e;
} catch(Exception ex){ } catch(Exception ex){
throw new NotAggregatableRecordsExceptions(ex); throw new NotAggregatableRecordsExceptions(ex);
} }
return this; return this;
*/
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedJobUsageRecord aggregate(JobUsageRecord record) public AggregatedJobUsageRecord aggregate(JobUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
try { try {
@ -238,13 +225,9 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public Class<JobUsageRecord> getAggregable() { public Class<JobUsageRecord> getAggregable() {
return JobUsageRecord.class; return JobUsageRecord.class;
} }
@Override
protected void cleanExtraFields(){
return;
}
} }

View File

@ -14,7 +14,6 @@ import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.aggregation.AggregationUtility; import org.gcube.documentstore.records.aggregation.AggregationUtility;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
/** /**
@ -51,13 +50,17 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp
//throw new UnsupportedOperationException(); //throw new UnsupportedOperationException();
} }
@JsonIgnore /**
* {@inheritDoc}
*/
@Override @Override
public int getOperationCount() { public int getOperationCount() {
return super.getOperationCount(); return super.getOperationCount();
} }
@JsonIgnore /**
* {@inheritDoc}
*/
@Override @Override
public void setOperationCount(int operationCount) throws InvalidValueException { public void setOperationCount(int operationCount) throws InvalidValueException {
super.setOperationCount(operationCount); super.setOperationCount(operationCount);
@ -66,7 +69,6 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getStartTime() { public Calendar getStartTime() {
return super.getStartTimeAsCalendar(); return super.getStartTimeAsCalendar();
@ -75,7 +77,6 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setStartTime(Calendar startTime) throws InvalidValueException { public void setStartTime(Calendar startTime) throws InvalidValueException {
super.setStartTime(startTime); super.setStartTime(startTime);
@ -84,7 +85,6 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getEndTime() { public Calendar getEndTime() {
return super.getEndTimeAsCalendar(); return super.getEndTimeAsCalendar();
@ -93,33 +93,31 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setEndTime(Calendar endTime) throws InvalidValueException { public void setEndTime(Calendar endTime) throws InvalidValueException {
super.setEndTime(endTime); super.setEndTime(endTime);
} }
//Introduce for to serialize Java Object
@JsonIgnore
@Override
public void setAggregate(Boolean aggregate) throws InvalidValueException {
super.setAggregate(aggregate);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Boolean getAggregate() { public void setAggregated(Boolean aggregate) throws InvalidValueException {
return super.getAggregate(); super.setAggregated(aggregate);
}
/**
* {@inheritDoc}
*/
@Override
public Boolean isAggregated() {
return super.isAggregated();
} }
//End Introduce for to serialize Java Object
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedPortletUsageRecord aggregate(AggregatedPortletUsageRecord record) public AggregatedPortletUsageRecord aggregate(AggregatedPortletUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
try { try {
@ -137,15 +135,10 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp
//throw new UnsupportedOperationException(); //throw new UnsupportedOperationException();
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedPortletUsageRecord aggregate(PortletUsageRecord record) public AggregatedPortletUsageRecord aggregate(PortletUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
try { try {
@ -176,12 +169,10 @@ public class AggregatedPortletUsageRecord extends AbstractPortletUsageRecord imp
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public Class<PortletUsageRecord> getAggregable() { public Class<PortletUsageRecord> getAggregable() {
return PortletUsageRecord.class; return PortletUsageRecord.class;
} }

View File

@ -17,7 +17,6 @@ import org.gcube.documentstore.records.implementation.AggregatedField;
import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
/** /**
@ -32,8 +31,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
*/ */
private static final long serialVersionUID = 6387584974618335623L; private static final long serialVersionUID = 6387584974618335623L;
@AggregatedField @AggregatedField
public static final String DURATION = AbstractServiceUsageRecord.DURATION; public static final String DURATION = AbstractServiceUsageRecord.DURATION;
@ -62,35 +59,28 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
this.setEndTime(creationTime); this.setEndTime(creationTime);
} }
@JsonIgnore
@Override @Override
public int getOperationCount() { public int getOperationCount() {
return super.getOperationCount(); return super.getOperationCount();
} }
@JsonIgnore
@Override @Override
public void setOperationCount(int operationCount) throws InvalidValueException { public void setOperationCount(int operationCount) throws InvalidValueException {
super.setOperationCount(operationCount); super.setOperationCount(operationCount);
} }
@JsonIgnore
public long getMaxInvocationTime() { public long getMaxInvocationTime() {
return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME); return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME);
} }
@JsonIgnore
public void setMaxInvocationTime(long maxInvocationTime) throws InvalidValueException { public void setMaxInvocationTime(long maxInvocationTime) throws InvalidValueException {
super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime); super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime);
} }
@JsonIgnore
public long getMinInvocationTime() { public long getMinInvocationTime() {
return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME); return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME);
} }
@JsonIgnore
public void setMinInvocationTime(long minInvocationTime) throws InvalidValueException { public void setMinInvocationTime(long minInvocationTime) throws InvalidValueException {
setResourceProperty(MIN_INVOCATION_TIME, minInvocationTime); setResourceProperty(MIN_INVOCATION_TIME, minInvocationTime);
} }
@ -98,7 +88,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getStartTime() { public Calendar getStartTime() {
return super.getStartTimeAsCalendar(); return super.getStartTimeAsCalendar();
@ -107,7 +96,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setStartTime(Calendar startTime) throws InvalidValueException { public void setStartTime(Calendar startTime) throws InvalidValueException {
super.setStartTime(startTime); super.setStartTime(startTime);
@ -116,7 +104,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getEndTime() { public Calendar getEndTime() {
return super.getEndTimeAsCalendar(); return super.getEndTimeAsCalendar();
@ -125,27 +112,26 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setEndTime(Calendar endTime) throws InvalidValueException { public void setEndTime(Calendar endTime) throws InvalidValueException {
super.setEndTime(endTime); super.setEndTime(endTime);
} }
//Introduce for to serialize Java Object
@JsonIgnore
@Override
public void setAggregate(Boolean aggregate) throws InvalidValueException {
super.setAggregate(aggregate);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Boolean getAggregate() { public void setAggregated(Boolean aggregate) throws InvalidValueException {
return super.getAggregate(); super.setAggregated(aggregate);
}
/**
* {@inheritDoc}
*/
@Override
public Boolean isAggregated() {
return super.isAggregated();
} }
//End Introduce for to serialize Java Object
protected long durationWeightedAverage(AggregatedServiceUsageRecord record){ protected long durationWeightedAverage(AggregatedServiceUsageRecord record){
@ -159,7 +145,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedServiceUsageRecord aggregate(AggregatedServiceUsageRecord record) public AggregatedServiceUsageRecord aggregate(AggregatedServiceUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
try { try {
@ -203,7 +188,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedServiceUsageRecord aggregate(ServiceUsageRecord record) public AggregatedServiceUsageRecord aggregate(ServiceUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
try { try {
@ -218,7 +202,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isAggregable(AggregatedServiceUsageRecord record) public boolean isAggregable(AggregatedServiceUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
@ -229,7 +212,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isAggregable(ServiceUsageRecord record) public boolean isAggregable(ServiceUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
@ -246,7 +228,6 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public Class<ServiceUsageRecord> getAggregable() { public Class<ServiceUsageRecord> getAggregable() {
return ServiceUsageRecord.class; return ServiceUsageRecord.class;
} }

View File

@ -15,7 +15,6 @@ import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.aggregation.AggregationUtility; import org.gcube.documentstore.records.aggregation.AggregationUtility;
import org.gcube.documentstore.records.implementation.AggregatedField; import org.gcube.documentstore.records.implementation.AggregatedField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
/** /**
@ -54,13 +53,11 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
this.setEndTime(creationTime); this.setEndTime(creationTime);
} }
@JsonIgnore
@Override @Override
public int getOperationCount() { public int getOperationCount() {
return super.getOperationCount(); return super.getOperationCount();
} }
@JsonIgnore
@Override @Override
public void setOperationCount(int operationCount) throws InvalidValueException { public void setOperationCount(int operationCount) throws InvalidValueException {
super.setOperationCount(operationCount); super.setOperationCount(operationCount);
@ -69,7 +66,6 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getStartTime() { public Calendar getStartTime() {
return super.getStartTimeAsCalendar(); return super.getStartTimeAsCalendar();
@ -78,7 +74,6 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setStartTime(Calendar startTime) throws InvalidValueException { public void setStartTime(Calendar startTime) throws InvalidValueException {
super.setStartTime(startTime); super.setStartTime(startTime);
@ -87,7 +82,6 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getEndTime() { public Calendar getEndTime() {
return super.getEndTimeAsCalendar(); return super.getEndTimeAsCalendar();
@ -96,33 +90,28 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setEndTime(Calendar endTime) throws InvalidValueException { public void setEndTime(Calendar endTime) throws InvalidValueException {
super.setEndTime(endTime); super.setEndTime(endTime);
} }
//Introduce for to serialize Java Object
@JsonIgnore
@Override @Override
public void setAggregate(Boolean aggregate) throws InvalidValueException { public void setAggregated(Boolean aggregate) throws InvalidValueException {
super.setAggregate(aggregate); super.setAggregated(aggregate);
}
/**
* {@inheritDoc}
*/
@Override
public Boolean isAggregated() {
return super.isAggregated();
} }
/**
* {@inheritDoc}
*/
@JsonIgnore
@Override
public Boolean getAggregate() {
return super.getAggregate();
}
//End Introduce for to serialize Java Object
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedStorageStatusRecord aggregate( public AggregatedStorageStatusRecord aggregate(
AggregatedStorageStatusRecord record) AggregatedStorageStatusRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
@ -144,7 +133,6 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedStorageStatusRecord aggregate(StorageStatusRecord record) public AggregatedStorageStatusRecord aggregate(StorageStatusRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
try { try {
@ -185,7 +173,6 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public Class<StorageStatusRecord> getAggregable() { public Class<StorageStatusRecord> getAggregable() {
return StorageStatusRecord.class; return StorageStatusRecord.class;
} }

View File

@ -15,14 +15,13 @@ import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.aggregation.AggregationUtility; import org.gcube.documentstore.records.aggregation.AggregationUtility;
import org.gcube.documentstore.records.implementation.AggregatedField; import org.gcube.documentstore.records.implementation.AggregatedField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
/** /**
* This Class is for library internal use only * This Class is for library internal use only
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
@JsonTypeName(value="AggregatedStorageUsageRecord") @JsonTypeName(value="StorageUsageRecord")
public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord implements AggregatedUsageRecord<AggregatedStorageUsageRecord, StorageUsageRecord> { public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord implements AggregatedUsageRecord<AggregatedStorageUsageRecord, StorageUsageRecord> {
/** /**
@ -51,13 +50,11 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp
this.setEndTime(creationTime); this.setEndTime(creationTime);
} }
@JsonIgnore
@Override @Override
public int getOperationCount() { public int getOperationCount() {
return super.getOperationCount(); return super.getOperationCount();
} }
@JsonIgnore
@Override @Override
public void setOperationCount(int operationCount) throws InvalidValueException { public void setOperationCount(int operationCount) throws InvalidValueException {
super.setOperationCount(operationCount); super.setOperationCount(operationCount);
@ -66,7 +63,6 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getStartTime() { public Calendar getStartTime() {
return super.getStartTimeAsCalendar(); return super.getStartTimeAsCalendar();
@ -83,7 +79,6 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Calendar getEndTime() { public Calendar getEndTime() {
return super.getEndTimeAsCalendar(); return super.getEndTimeAsCalendar();
@ -92,33 +87,27 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setEndTime(Calendar endTime) throws InvalidValueException { public void setEndTime(Calendar endTime) throws InvalidValueException {
super.setEndTime(endTime); super.setEndTime(endTime);
} }
//Introduce for to serialize Java Object
@JsonIgnore
@Override @Override
public void setAggregate(Boolean aggregate) throws InvalidValueException { public void setAggregated(Boolean aggregate) throws InvalidValueException {
super.setAggregate(aggregate); super.setAggregated(aggregate);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public Boolean getAggregate() { public Boolean isAggregated() {
return super.getAggregate(); return super.isAggregated();
} }
//End Introduce for to serialize Java Object
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedStorageUsageRecord aggregate( public AggregatedStorageUsageRecord aggregate(
AggregatedStorageUsageRecord record) AggregatedStorageUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
@ -138,7 +127,6 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public AggregatedStorageUsageRecord aggregate(StorageUsageRecord record) public AggregatedStorageUsageRecord aggregate(StorageUsageRecord record)
throws NotAggregatableRecordsExceptions { throws NotAggregatableRecordsExceptions {
try { try {
@ -179,7 +167,6 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@JsonIgnore
public Class<StorageUsageRecord> getAggregable() { public Class<StorageUsageRecord> getAggregable() {
return StorageUsageRecord.class; return StorageUsageRecord.class;
} }

View File

@ -1,148 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.aggregation;
import java.io.Serializable;
import java.util.Calendar;
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.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<AggregatedTaskUsageRecord, TaskUsageRecord> {
/**
* Generated Serial version UID
*/
private static final long serialVersionUID = 7445526162102677455L;
public AggregatedTaskUsageRecord(){
super();
}
public AggregatedTaskUsageRecord(Map<String, ? extends Serializable> properties) throws InvalidValueException{
super(properties);
}
// TODO
public AggregatedTaskUsageRecord(TaskUsageRecord taskUsageRecord) throws InvalidValueException{
throw new UnsupportedOperationException();
}
@JsonIgnore
@Override
public int getOperationCount() {
return super.getOperationCount();
}
@JsonIgnore
@Override
public void setOperationCount(int operationCount) throws InvalidValueException {
super.setOperationCount(operationCount);
}
/**
* {@inheritDoc}
*/
@JsonIgnore
@Override
public Calendar getStartTime() {
return super.getStartTimeAsCalendar();
}
/**
* {@inheritDoc}
*/
@JsonIgnore
@Override
public void setStartTime(Calendar startTime) throws InvalidValueException {
super.setStartTime(startTime);
}
/**
* {@inheritDoc}
*/
@JsonIgnore
@Override
public Calendar getEndTime() {
return super.getEndTimeAsCalendar();
}
/**
* {@inheritDoc}
*/
@JsonIgnore
@Override
public void setEndTime(Calendar endTime) throws InvalidValueException {
super.setEndTime(endTime);
}
/**
* {@inheritDoc}
*/
@Override
public AggregatedTaskUsageRecord aggregate(AggregatedTaskUsageRecord record)
throws NotAggregatableRecordsExceptions {
throw new NotAggregatableRecordsExceptions();
}
/**
* {@inheritDoc}
*/
@Override
public AggregatedTaskUsageRecord aggregate(TaskUsageRecord record)
throws NotAggregatableRecordsExceptions {
try {
return aggregate(new AggregatedTaskUsageRecord(record));
} catch(NotAggregatableRecordsExceptions e){
throw e;
} catch(Exception ex){
throw new NotAggregatableRecordsExceptions(ex);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAggregable(AggregatedTaskUsageRecord record) throws NotAggregatableRecordsExceptions {
AggregationUtility<AggregatedTaskUsageRecord> aggregationUtility = new AggregationUtility<AggregatedTaskUsageRecord>(this);
return aggregationUtility.isAggregable(record);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAggregable(TaskUsageRecord record) throws NotAggregatableRecordsExceptions {
try {
return isAggregable(new AggregatedTaskUsageRecord(record));
} catch(NotAggregatableRecordsExceptions e){
throw e;
} catch(Exception ex){
throw new NotAggregatableRecordsExceptions(ex);
}
}
/**
* {@inheritDoc}
*/
@Override
public Class<TaskUsageRecord> getAggregable() {
return TaskUsageRecord.class;
}
}

View File

@ -1,16 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(action=MoveToJobWallDurationAction.class)
public @interface MoveToJobWallDuration { }

View File

@ -1,19 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
public class MoveToJobWallDurationAction implements FieldAction {
@Override
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
return null; //Returning null the initial key is removed from Record
}
}

View File

@ -1,22 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(action=MoveToTaskEndTimeAction.class)
public @interface MoveToTaskEndTime {
}

View File

@ -1,30 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
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 MoveToTaskEndTimeAction implements FieldAction {
/**
* {@inheritDoc}
*/
@Override
public Serializable validate(String key,
Serializable value, Record record)
throws InvalidValueException {
record.setResourceProperty(AbstractTaskUsageRecord.TASK_END_TIME, value);
return null; //Returning null the initial key is removed from Record
}
}

View File

@ -1,22 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(action=MoveToTaskStartTimeAction.class)
public @interface MoveToTaskStartTime {
}

View File

@ -1,30 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
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 MoveToTaskStartTimeAction implements FieldAction {
/**
* {@inheritDoc}
*/
@Override
public Serializable validate(String key,
Serializable value, Record record)
throws InvalidValueException {
record.setResourceProperty(AbstractTaskUsageRecord.TASK_START_TIME, value);
return null; //Returning null the initial key is removed from Record
}
}

View File

@ -1,16 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(action=MoveToTaskWallDurationAction.class)
public @interface MoveToTaskWallDuration { }

View File

@ -1,19 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
public class MoveToTaskWallDurationAction implements FieldAction {
@Override
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
return null; //Returning null the initial key is removed from Record
}
}

View File

@ -4,23 +4,16 @@
package org.gcube.accounting.datamodel.basetypes; package org.gcube.accounting.datamodel.basetypes;
import java.io.Serializable; import java.io.Serializable;
import java.util.Calendar;
import java.util.Map; import java.util.Map;
import java.util.SortedSet;
import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.ComputedField;
import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*
*/ */
public abstract class AbstractJobUsageRecord extends BasicUsageRecord { public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
@ -29,22 +22,46 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
*/ */
private static final long serialVersionUID = -8648691183939346858L; private static final long serialVersionUID = -8648691183939346858L;
/**
* KEY for : hostname:port of the Hosting Node receiving the service call
*/
@RequiredField @NotEmpty @RequiredField @NotEmpty
public static final String JOB_ID = "jobId"; public static final String HOST = "host";
@NotEmptyIfNotNull
public static final String JOB_NAME = "jobName";
@NotEmptyIfNotNull
public static final String JOB_QUALIFIER = "jobQualifier";
/**
* KEY for : Duration
*/
@RequiredField @ValidLong @RequiredField @ValidLong
public static final String JOB_START_TIME = "jobStartTime";
@RequiredField @ValidLong
public static final String JOB_END_TIME = "jobEndTime";
@RequiredField @ComputedField(action=CalculateJobWallDurationAction.class) @ValidLong
public static final String DURATION = "duration"; public static final String DURATION = "duration";
/**
* KEY for : Service Class
*/
@RequiredField @NotEmpty
public static final String SERVICE_CLASS = "serviceClass";
/**
* KEY for : Service Class
*/
@RequiredField @NotEmpty
public static final String SERVICE_NAME = "serviceName";
/**
* KEY for : Job Name
*/
@RequiredField
public static final String JOB_NAME = "jobName";
/**
* KEY for : callerQualifier
*
*/
@RequiredField @NotEmpty
public static final String CALLER_QUALIFIER = "callerQualifier";
public AbstractJobUsageRecord(){ public AbstractJobUsageRecord(){
super(); super();
} }
@ -60,101 +77,52 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
return AbstractJobUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); return AbstractJobUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
} }
@Override
public SortedSet<String> getQuerableKeys()
throws Exception {
SortedSet<String> properties = super.getQuerableKeys();
properties.remove(JOB_START_TIME);
properties.remove(JOB_END_TIME);
return properties;
}
/**
* @return the Job Id
*/
@JsonIgnore
public String getJobId() {
return (String) this.resourceProperties.get(JOB_ID);
}
/**
* @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() { public String getJobName() {
return (String) this.resourceProperties.get(JOB_NAME); return (String) this.resourceProperties.get(JOB_NAME);
} }
@JsonIgnore
public void setJobName(String jobName) throws InvalidValueException { public void setJobName(String jobName) throws InvalidValueException {
setResourceProperty(JOB_NAME, jobName); setResourceProperty(JOB_NAME, jobName);
} }
@JsonIgnore public String getHost() {
public Calendar getJobStartTime() { return (String) this.resourceProperties.get(HOST);
long millis = (Long) this.resourceProperties.get(JOB_START_TIME);
return timestampToCalendar(millis);
} }
@JsonIgnore public void setHost(String host) throws InvalidValueException {
public void setJobStartTime(Calendar jobStartTime) throws InvalidValueException { setResourceProperty(HOST, host);
setResourceProperty(JOB_START_TIME, jobStartTime.getTimeInMillis());
} }
@JsonIgnore public String getServiceClass() {
public Calendar getJobEndTime() { return (String) this.resourceProperties.get(SERVICE_CLASS);
long millis = (Long) this.resourceProperties.get(JOB_END_TIME);
return timestampToCalendar(millis);
} }
@JsonIgnore public void setServiceClass(String serviceClass) throws InvalidValueException {
public void setJobEndTime(Calendar jobEndTime) throws InvalidValueException { setResourceProperty(SERVICE_CLASS, serviceClass);
setResourceProperty(JOB_END_TIME, jobEndTime.getTimeInMillis());
} }
protected long calculateDuration() throws InvalidValueException { public String getServiceName() {
try { return (String) this.resourceProperties.get(SERVICE_NAME);
long endTime = (Long) this.resourceProperties.get(JOB_END_TIME);
long startTime = (Long) this.resourceProperties.get(JOB_START_TIME);
long wallDuration = endTime - startTime;
setResourceProperty(AbstractJobUsageRecord.DURATION, wallDuration);
return wallDuration;
}catch(Exception e){
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
JOB_START_TIME, JOB_END_TIME), e);
}
} }
@JsonIgnore public void setServiceName(String serviceName) throws InvalidValueException {
public long getDuration() throws InvalidValueException { setResourceProperty(SERVICE_NAME, serviceName);
Long duration = (Long) this.resourceProperties.get(DURATION);
if(duration == null){
try {
duration = calculateDuration();
} catch(InvalidValueException e){
throw e;
} }
public Long getDuration() {
return (Long) this.resourceProperties.get(DURATION);
} }
return duration;
}
@JsonIgnore
public void setDuration(Long duration) throws InvalidValueException { public void setDuration(Long duration) throws InvalidValueException {
setResourceProperty(DURATION, duration); setResourceProperty(DURATION, duration);
} }
public String getCallerQualifier() {
return (String) this.resourceProperties.get(CALLER_QUALIFIER);
}
public void setCallerQualifier(String callerQualifier) throws InvalidValueException {
setResourceProperty(CALLER_QUALIFIER, callerQualifier);
}
} }

View File

@ -12,11 +12,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.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*
*/ */
public abstract class AbstractPortletUsageRecord extends BasicUsageRecord { public abstract class AbstractPortletUsageRecord extends BasicUsageRecord {
@ -50,33 +47,28 @@ public abstract class AbstractPortletUsageRecord extends BasicUsageRecord {
return AbstractPortletUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); return AbstractPortletUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
} }
@JsonIgnore
public String getPortletId() { public String getPortletId() {
return (String) this.resourceProperties.get(PORTLET_ID); return (String) this.resourceProperties.get(PORTLET_ID);
} }
@JsonIgnore
public void setPortletId(String portletId) throws InvalidValueException { public void setPortletId(String portletId) throws InvalidValueException {
setResourceProperty(PORTLET_ID, portletId); setResourceProperty(PORTLET_ID, portletId);
} }
@JsonIgnore
public String getOperationId() { public String getOperationId() {
return (String) this.resourceProperties.get(OPERATION_ID); return (String) this.resourceProperties.get(OPERATION_ID);
} }
@JsonIgnore
public void setOperationId(String operationId) throws InvalidValueException { public void setOperationId(String operationId) throws InvalidValueException {
setResourceProperty(OPERATION_ID, operationId); setResourceProperty(OPERATION_ID, operationId);
} }
@JsonIgnore
public String getMessage() { public String getMessage() {
return (String) this.resourceProperties.get(MESSAGE); return (String) this.resourceProperties.get(MESSAGE);
} }
@JsonIgnore
public void setMessage(String message) throws InvalidValueException { public void setMessage(String message) throws InvalidValueException {
setResourceProperty(MESSAGE, message); setResourceProperty(MESSAGE, message);
} }
} }

View File

@ -12,12 +12,9 @@ import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
public abstract class AbstractServiceUsageRecord extends BasicUsageRecord { public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
/** /**
@ -64,18 +61,26 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
/** /**
* KEY for : callerQualifier * KEY for : callerQualifier
*
*/ */
@RequiredField @NotEmpty @RequiredField @NotEmpty
public static final String CALLER_QUALIFIER = "callerQualifier"; public static final String CALLER_QUALIFIER = "callerQualifier";
protected static final String UNKNOWN = "UNKNOWN";
public AbstractServiceUsageRecord(){ public AbstractServiceUsageRecord(){
super(); super();
try{
// Need to fix old ServiceUsageRecords which does not have such a field
setResourceProperty(CALLER_QUALIFIER, UNKNOWN);
}catch (Exception e) {
throw new RuntimeException("Unable to set " + CALLER_QUALIFIER + " to " + UNKNOWN);
}
} }
public AbstractServiceUsageRecord(Map<String, ? extends Serializable> properties) throws InvalidValueException { public AbstractServiceUsageRecord(Map<String, ? extends Serializable> properties) throws InvalidValueException {
super(properties); super(properties);
// Need to fix old ServiceUsageRecords which does not have such a field
setResourceProperty(CALLER_QUALIFIER, UNKNOWN);
} }
private static final String ABSTRACT_TO_REPLACE = "Abstract"; private static final String ABSTRACT_TO_REPLACE = "Abstract";
@ -86,72 +91,60 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
} }
@JsonIgnore
public String getCallerHost() { public String getCallerHost() {
return (String) this.resourceProperties.get(CALLER_HOST); return (String) this.resourceProperties.get(CALLER_HOST);
} }
@JsonIgnore
public void setCallerHost(String callerHost) throws InvalidValueException { public void setCallerHost(String callerHost) throws InvalidValueException {
setResourceProperty(CALLER_HOST, callerHost); setResourceProperty(CALLER_HOST, callerHost);
} }
@JsonIgnore
public String getHost() { public String getHost() {
return (String) this.resourceProperties.get(HOST); return (String) this.resourceProperties.get(HOST);
} }
@JsonIgnore
public void setHost(String host) throws InvalidValueException { public void setHost(String host) throws InvalidValueException {
setResourceProperty(HOST, host); setResourceProperty(HOST, host);
} }
@JsonIgnore
public String getServiceClass() { public String getServiceClass() {
return (String) this.resourceProperties.get(SERVICE_CLASS); return (String) this.resourceProperties.get(SERVICE_CLASS);
} }
@JsonIgnore
public void setServiceClass(String serviceClass) throws InvalidValueException { public void setServiceClass(String serviceClass) throws InvalidValueException {
setResourceProperty(SERVICE_CLASS, serviceClass); setResourceProperty(SERVICE_CLASS, serviceClass);
} }
@JsonIgnore
public String getServiceName() { public String getServiceName() {
return (String) this.resourceProperties.get(SERVICE_NAME); return (String) this.resourceProperties.get(SERVICE_NAME);
} }
@JsonIgnore
public void setServiceName(String serviceName) throws InvalidValueException { public void setServiceName(String serviceName) throws InvalidValueException {
setResourceProperty(SERVICE_NAME, serviceName); setResourceProperty(SERVICE_NAME, serviceName);
} }
@JsonIgnore
public String getCalledMethod() { public String getCalledMethod() {
return (String) this.resourceProperties.get(CALLED_METHOD); return (String) this.resourceProperties.get(CALLED_METHOD);
} }
@JsonIgnore
public void setCalledMethod(String calledMethod) throws InvalidValueException { public void setCalledMethod(String calledMethod) throws InvalidValueException {
setResourceProperty(CALLED_METHOD, calledMethod); setResourceProperty(CALLED_METHOD, calledMethod);
} }
@JsonIgnore
public Long getDuration() { public Long getDuration() {
return (Long) this.resourceProperties.get(DURATION); return (Long) this.resourceProperties.get(DURATION);
} }
@JsonIgnore
public void setDuration(Long duration) throws InvalidValueException { public void setDuration(Long duration) throws InvalidValueException {
setResourceProperty(DURATION, duration); setResourceProperty(DURATION, duration);
} }
@JsonIgnore
public String getCallerQualifier() { public String getCallerQualifier() {
return (String) this.resourceProperties.get(CALLER_QUALIFIER); return (String) this.resourceProperties.get(CALLER_QUALIFIER);
} }
@JsonIgnore
public void setCallerQualifier(String callerQualifier) throws InvalidValueException { public void setCallerQualifier(String callerQualifier) throws InvalidValueException {
setResourceProperty(CALLER_QUALIFIER, callerQualifier); setResourceProperty(CALLER_QUALIFIER, callerQualifier);
} }
} }

View File

@ -16,11 +16,9 @@ import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; 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 * @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it
* * @author Luca Frosini (ISTI - CNR)
*/ */
public abstract class AbstractStorageStatusRecord extends BasicUsageRecord { public abstract class AbstractStorageStatusRecord extends BasicUsageRecord {
@ -93,72 +91,58 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord {
return AbstractStorageStatusRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, ""); return AbstractStorageStatusRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
} }
@JsonIgnore
public long getDataVolume() { public long getDataVolume() {
return (Long) this.resourceProperties.get(DATA_VOLUME); return (Long) this.resourceProperties.get(DATA_VOLUME);
} }
@JsonIgnore
public void setDataVolume(long dataVolume) throws InvalidValueException { public void setDataVolume(long dataVolume) throws InvalidValueException {
setResourceProperty(DATA_VOLUME, dataVolume); setResourceProperty(DATA_VOLUME, dataVolume);
} }
@JsonIgnore
public DataType getDataType() { public DataType getDataType() {
return (DataType) this.resourceProperties.get(DATA_TYPE); return (DataType) this.resourceProperties.get(DATA_TYPE);
} }
@JsonIgnore
public void setDataType(DataType dataType) throws InvalidValueException { public void setDataType(DataType dataType) throws InvalidValueException {
setResourceProperty(DATA_TYPE, dataType); setResourceProperty(DATA_TYPE, dataType);
} }
@JsonIgnore
public long getDataCount() { public long getDataCount() {
return (Long) this.resourceProperties.get(DATA_COUNT); return (Long) this.resourceProperties.get(DATA_COUNT);
} }
@JsonIgnore
public void setDataCount(long dataCount) throws InvalidValueException { public void setDataCount(long dataCount) throws InvalidValueException {
setResourceProperty(DATA_COUNT, dataCount); setResourceProperty(DATA_COUNT, dataCount);
} }
@JsonIgnore
public String getDataServiceClass() { public String getDataServiceClass() {
return (String) this.resourceProperties.get(DATA_SERVICECLASS); return (String) this.resourceProperties.get(DATA_SERVICECLASS);
} }
@JsonIgnore
public void setDataServiceClass(String dataServiceClass) throws InvalidValueException { public void setDataServiceClass(String dataServiceClass) throws InvalidValueException {
setResourceProperty(DATA_SERVICECLASS, dataServiceClass); setResourceProperty(DATA_SERVICECLASS, dataServiceClass);
} }
@JsonIgnore
public String getDataServiceName() { public String getDataServiceName() {
return (String) this.resourceProperties.get(DATA_SERVICENAME); return (String) this.resourceProperties.get(DATA_SERVICENAME);
} }
@JsonIgnore
public void setDataServiceName(String dataServiceName) throws InvalidValueException { public void setDataServiceName(String dataServiceName) throws InvalidValueException {
setResourceProperty(DATA_SERVICENAME, dataServiceName); setResourceProperty(DATA_SERVICENAME, dataServiceName);
} }
@JsonIgnore
public String getDataServiceId() { public String getDataServiceId() {
return (String) this.resourceProperties.get(DATA_SERVICEID); return (String) this.resourceProperties.get(DATA_SERVICEID);
} }
@JsonIgnore
public void setDataServiceId(String dataServiceId) throws InvalidValueException { public void setDataServiceId(String dataServiceId) throws InvalidValueException {
setResourceProperty(DATA_SERVICEID, dataServiceId); setResourceProperty(DATA_SERVICEID, dataServiceId);
} }
@JsonIgnore
public URI getProviderId() { public URI getProviderId() {
return (URI) this.resourceProperties.get(PROVIDER_ID); return (URI) this.resourceProperties.get(PROVIDER_ID);
} }
@JsonIgnore
public void setProviderId(URI provideId) throws InvalidValueException { public void setProviderId(URI provideId) throws InvalidValueException {
setResourceProperty(PROVIDER_ID, provideId); setResourceProperty(PROVIDER_ID, provideId);
} }

View File

@ -18,11 +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.NotEmptyIfNotNull;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*
*/ */
public abstract class AbstractStorageUsageRecord extends BasicUsageRecord { public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
@ -115,7 +112,6 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
* Return the identity id of the storage resource owner * Return the identity id of the storage resource owner
* @return the identity id of the accounting owner * @return the identity id of the accounting owner
*/ */
@JsonIgnore
public String getResourceOwner() { public String getResourceOwner() {
return (String) this.resourceProperties.get(RESOURCE_OWNER); return (String) this.resourceProperties.get(RESOURCE_OWNER);
} }
@ -125,7 +121,6 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
* @param owner the identity id of the storage resource owner * @param owner the identity id of the storage resource owner
* @throws InvalidValueException * @throws InvalidValueException
*/ */
@JsonIgnore
public void setResourceOwner(String owner) throws InvalidValueException { public void setResourceOwner(String owner) throws InvalidValueException {
setResourceProperty(RESOURCE_OWNER, owner); setResourceProperty(RESOURCE_OWNER, owner);
} }
@ -133,7 +128,6 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
* Return the scope of the storage resource * Return the scope of the storage resource
* @return The scope id of the storage resource * @return The scope id of the storage resource
*/ */
@JsonIgnore
public String getResourceScope() { public String getResourceScope() {
return (String) this.resourceProperties.get(RESOURCE_SCOPE); return (String) this.resourceProperties.get(RESOURCE_SCOPE);
} }
@ -143,67 +137,54 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
* @param scope the scope of the storage resource * @param scope the scope of the storage resource
* @throws InvalidValueException * @throws InvalidValueException
*/ */
@JsonIgnore
public void setResourceScope(String scope) throws InvalidValueException { public void setResourceScope(String scope) throws InvalidValueException {
setResourceProperty(RESOURCE_SCOPE, scope); setResourceProperty(RESOURCE_SCOPE, scope);
} }
@JsonIgnore
public URI getProviderURI() { public URI getProviderURI() {
return (URI) this.resourceProperties.get(PROVIDER_URI); return (URI) this.resourceProperties.get(PROVIDER_URI);
} }
@JsonIgnore
public void setProviderURI(URI providerURI) throws InvalidValueException { public void setProviderURI(URI providerURI) throws InvalidValueException {
setResourceProperty(PROVIDER_URI, providerURI); setResourceProperty(PROVIDER_URI, providerURI);
} }
@JsonIgnore
public URI getResourceURI() { public URI getResourceURI() {
return (URI) this.resourceProperties.get(RESOURCE_URI); return (URI) this.resourceProperties.get(RESOURCE_URI);
} }
@JsonIgnore
public void setResourceURI(URI resourceURI) throws InvalidValueException { public void setResourceURI(URI resourceURI) throws InvalidValueException {
setResourceProperty(RESOURCE_URI, resourceURI); setResourceProperty(RESOURCE_URI, resourceURI);
} }
@JsonIgnore
public OperationType getOperationType() { public OperationType getOperationType() {
return (OperationType) this.resourceProperties.get(OPERATION_TYPE); return (OperationType) this.resourceProperties.get(OPERATION_TYPE);
} }
@JsonIgnore
public void setOperationType(OperationType operationType) throws InvalidValueException { public void setOperationType(OperationType operationType) throws InvalidValueException {
setResourceProperty(OPERATION_TYPE, operationType); setResourceProperty(OPERATION_TYPE, operationType);
} }
@JsonIgnore
public DataType getDataType() { public DataType getDataType() {
return (DataType) this.resourceProperties.get(DATA_TYPE); return (DataType) this.resourceProperties.get(DATA_TYPE);
} }
@JsonIgnore
public void setDataType(DataType dataType) throws InvalidValueException { public void setDataType(DataType dataType) throws InvalidValueException {
setResourceProperty(DATA_TYPE, dataType); setResourceProperty(DATA_TYPE, dataType);
} }
@JsonIgnore
public long getDataVolume() { public long getDataVolume() {
return (Long) this.resourceProperties.get(DATA_VOLUME); return (Long) this.resourceProperties.get(DATA_VOLUME);
} }
@JsonIgnore
public void setDataVolume(long dataVolume) throws InvalidValueException { public void setDataVolume(long dataVolume) throws InvalidValueException {
setResourceProperty(DATA_VOLUME, dataVolume); setResourceProperty(DATA_VOLUME, dataVolume);
} }
@JsonIgnore
public String getQualifier() { public String getQualifier() {
return (String) this.resourceProperties.get(QUALIFIER); return (String) this.resourceProperties.get(QUALIFIER);
} }
@JsonIgnore
public void setQualifier(String qualifier) throws InvalidValueException { public void setQualifier(String qualifier) throws InvalidValueException {
setResourceProperty(QUALIFIER, qualifier); setResourceProperty(QUALIFIER, qualifier);
} }
@ -217,4 +198,5 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
setResourceProperty(CALLERQUALIFIER, callerQualifier); setResourceProperty(CALLERQUALIFIER, callerQualifier);
} }
*/ */
} }

View File

@ -1,191 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.basetypes;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Map;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.ComputedField;
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 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 {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -2208425042550641240L;
@RequiredField @NotEmpty
public static final String TASK_ID = "taskId";
@NotEmptyIfNotNull
public static final String REF_JOB_ID = "refJobId";
@NotEmptyIfNotNull
public static final String HOST = "host";
@NotEmptyIfNotNull
public static final String REF_HOSTING_NODE_ID = "refHostingNodeId";
@ValidLong @RequiredField
public static final String TASK_START_TIME = "taskStartTime";
@ValidLong @RequiredField
public static final String TASK_END_TIME = "taskEndTime";
@RequiredField @ComputedField(action=CalculateTaskWallDurationAction.class) @ValidLong
public static final String WALL_DURATION = "wallDuration";
/*
@NotEmptyIfNotNull
public static final String INPUT_PARAMETERS = "inputParameters";
*/
public AbstractTaskUsageRecord(){
super();
}
public AbstractTaskUsageRecord(Map<String, ? extends Serializable> properties) throws InvalidValueException {
super(properties);
}
private static final String ABSTRACT_TO_REPLACE = "Abstract";
@Override
public String getRecordType() {
return AbstractTaskUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
}
/**
* @return the Task Id
*/
@JsonIgnore
public String getTaskId() {
return (String) this.resourceProperties.get(TASK_ID);
}
/**
* @param taskId Task Id
* @throws InvalidValueException if fails
*/
@JsonIgnore
public void setTaskId(String taskId) throws InvalidValueException {
setResourceProperty(TASK_ID, taskId);
}
/**
* @return the Referenced Job Id
*/
@JsonIgnore
public String getRefJobId() {
return (String) this.resourceProperties.get(REF_JOB_ID);
}
/**
* @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());
}
protected long calculateWallDuration() throws InvalidValueException {
try {
long endTime = (Long) this.resourceProperties.get(TASK_END_TIME);
long startTime = (Long) this.resourceProperties.get(TASK_START_TIME);
long wallDuration = endTime - startTime;
return wallDuration;
}catch(Exception e){
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
TASK_START_TIME, TASK_END_TIME), e);
}
}
@JsonIgnore
public long getWallDuration() throws InvalidValueException {
Long wallDuration = (Long) this.resourceProperties.get(WALL_DURATION);
if(wallDuration == null){
try {
wallDuration = calculateWallDuration();
} catch(InvalidValueException e){
throw e;
}
}
return wallDuration;
}
@JsonIgnore
public void setWallDuration(Long duration) throws InvalidValueException {
setResourceProperty(WALL_DURATION, duration);
}
/*
@SuppressWarnings("unchecked")
//@JsonIgnore
public Map<String, Serializable> getInputParameters(){
return (HashMap<String, Serializable>) getResourceProperty(INPUT_PARAMETERS);
}
//@JsonIgnore
@JsonProperty(value=INPUT_PARAMETERS)
public void setInputParameters(HashMap<String, Serializable> inputParameters) throws InvalidValueException{
setResourceProperty(INPUT_PARAMETERS, inputParameters);
}
*/
}

View File

@ -1,33 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.basetypes;
import java.io.Serializable;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class CalculateJobWallDurationAction implements FieldAction {
private static final Logger logger = LoggerFactory.getLogger(CalculateJobWallDurationAction.class);
@Override
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
try {
long wallDuration = ((AbstractJobUsageRecord) record).calculateDuration();
if(key.compareTo(AbstractJobUsageRecord.DURATION)==0){
logger.warn("{} is automatically computed using {} and {}. This invocation has the only effect of recalculating the value. Any provided value is ignored.",
AbstractJobUsageRecord.DURATION, AbstractJobUsageRecord.JOB_START_TIME, AbstractJobUsageRecord.JOB_END_TIME);
value = wallDuration;
}
}catch(InvalidValueException e){ }
return value;
}
}

View File

@ -1,35 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.basetypes;
import java.io.Serializable;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class CalculateTaskWallDurationAction implements FieldAction {
private static final Logger logger = LoggerFactory.getLogger(CalculateTaskWallDurationAction.class);
@Override
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
try {
long wallDuration = ((AbstractTaskUsageRecord) record).calculateWallDuration();
if(key.compareTo(AbstractTaskUsageRecord.WALL_DURATION)==0){
logger.warn("{} is automatically computed using {} and {}. This invocation has the only effect of recalculating the value. Any provided value is ignored.",
AbstractTaskUsageRecord.WALL_DURATION, AbstractTaskUsageRecord.TASK_START_TIME, AbstractTaskUsageRecord.TASK_END_TIME);
value = wallDuration;
}else{
record.setResourceProperty(AbstractTaskUsageRecord.WALL_DURATION, wallDuration);
}
}catch(InvalidValueException e){ }
return value;
}
}

View File

@ -1,29 +0,0 @@
package org.gcube.accounting.datamodel.usagerecords;
import java.io.Serializable;
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="SingleTaskUsageRecord")
public class TaskUsageRecord extends AbstractTaskUsageRecord {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 5053135599013854281L;
public TaskUsageRecord(){
super();
}
public TaskUsageRecord(Map<String, ? extends Serializable> properties) throws InvalidValueException {
super(properties);
}
}

View File

@ -5,7 +5,6 @@ package org.gcube.accounting.datamodel.aggregation;
import java.util.Set; import java.util.Set;
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecordTest; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecordTest;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
@ -38,10 +37,8 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
AggregatedJobUsageRecord aggregatedJobUsageRecord = new AggregatedJobUsageRecord(jobUsageRecord); AggregatedJobUsageRecord aggregatedJobUsageRecord = new AggregatedJobUsageRecord(jobUsageRecord);
Set<String> expectedRequiredFields = JobUsageRecordTest.getExpectedRequiredFields(); Set<String> expectedRequiredFields = JobUsageRecordTest.getExpectedRequiredFields();
/*
expectedRequiredFields.add(AggregatedJobUsageRecord.MAX_INVOCATION_TIME); expectedRequiredFields.add(AggregatedJobUsageRecord.MAX_INVOCATION_TIME);
expectedRequiredFields.add(AggregatedJobUsageRecord.MIN_INVOCATION_TIME); expectedRequiredFields.add(AggregatedJobUsageRecord.MIN_INVOCATION_TIME);
*/
expectedRequiredFields.addAll(AggregatedUsageRecordTest.getExpectedRequiredFields()); expectedRequiredFields.addAll(AggregatedUsageRecordTest.getExpectedRequiredFields());
@ -57,7 +54,7 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
} }
@Test(expected=NotAggregatableRecordsExceptions.class) @Test
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions { public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
SecurityTokenProvider.instance.reset(); SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset(); ScopeProvider.instance.reset();
@ -65,7 +62,10 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord(); JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
Assert.assertTrue(jobUsageRecord.getScope()==null); Assert.assertTrue(jobUsageRecord.getScope()==null);
jobUsageRecord.setScope(TestUsageRecord.TEST_SCOPE); jobUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
jobUsageRecord.setJobQualifier("TEST QUALIFIER JOB USAGE RECORD 1");
jobUsageRecord.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
jobUsageRecord.validate(); jobUsageRecord.validate();
AggregatedJobUsageRecord aggregated = new AggregatedJobUsageRecord(jobUsageRecord); AggregatedJobUsageRecord aggregated = new AggregatedJobUsageRecord(jobUsageRecord);
logger.debug("jobUsageRecord Converted to Aggregated: {}", aggregated); logger.debug("jobUsageRecord Converted to Aggregated: {}", aggregated);
@ -79,15 +79,30 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
jobUsageRecord2.validate(); jobUsageRecord2.validate();
logger.debug("JobUsageRecord 2 : {}", jobUsageRecord2); logger.debug("JobUsageRecord 2 : {}", jobUsageRecord2);
long firstDuration = jobUsageRecord.getDuration();
long secondDuration = jobUsageRecord2.getDuration();
aggregated.aggregate(jobUsageRecord2); aggregated.aggregate(jobUsageRecord2);
/* logger.debug("Resulting Aggregated ServiceUsageRecord: {}", aggregated);
logger.debug("jobUsageRecord2 Converted to Aggregated: {}", aggregated);
aggregated.validate(); aggregated.validate();
logger.debug("jobUsageRecord2 Converted to Aggregated post validate: {}", aggregated);
*/ Assert.assertTrue(aggregated.getDuration() == ((firstDuration + secondDuration)/2));
Assert.assertTrue(aggregated.getOperationCount() == 2);
if(firstDuration >= secondDuration){
Assert.assertTrue(aggregated.getMaxInvocationTime() == firstDuration);
Assert.assertTrue(aggregated.getMinInvocationTime() == secondDuration);
}else{
Assert.assertTrue(aggregated.getMaxInvocationTime() == secondDuration);
Assert.assertTrue(aggregated.getMinInvocationTime() == firstDuration);
} }
/* Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME));
Assert.assertTrue(aggregated.getRecordType().compareTo(JobUsageRecord.class.getSimpleName())==0);
}
@Test @Test
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions { public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
SecurityTokenProvider.instance.reset(); SecurityTokenProvider.instance.reset();
@ -168,26 +183,26 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
long minInvocationTime = aggregated.getMinInvocationTime(); long minInvocationTime = aggregated.getMinInvocationTime();
long maxInvocationTime = aggregated.getMaxInvocationTime(); long maxInvocationTime = aggregated.getMaxInvocationTime();
long oldDuration = aggregated.getDuration(); long oldDuration = aggregated.getDuration();
long surDuration = jur.getDuration(); long jurDuration = jur.getDuration();
aggregated.aggregate(jur); aggregated.aggregate(jur);
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated); logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
aggregated.validate(); aggregated.validate();
long avgDuration = durationWeightedAverage(i-1, oldDuration, 1, surDuration); long avgDuration = durationWeightedAverage(i-1, oldDuration, 1, jurDuration);
Assert.assertTrue(aggregated.getDuration() == (avgDuration)); Assert.assertTrue(aggregated.getDuration() == (avgDuration));
Assert.assertTrue(aggregated.getOperationCount() == i); Assert.assertTrue(aggregated.getOperationCount() == i);
if(minInvocationTime >= surDuration){ if(minInvocationTime >= jurDuration){
Assert.assertTrue(aggregated.getMinInvocationTime() == surDuration); Assert.assertTrue(aggregated.getMinInvocationTime() == jurDuration);
}else{ }else{
Assert.assertTrue(aggregated.getMinInvocationTime() == minInvocationTime); Assert.assertTrue(aggregated.getMinInvocationTime() == minInvocationTime);
} }
if(maxInvocationTime >= surDuration){ if(maxInvocationTime >= jurDuration){
Assert.assertTrue(aggregated.getMaxInvocationTime() == maxInvocationTime); Assert.assertTrue(aggregated.getMaxInvocationTime() == maxInvocationTime);
}else{ }else{
Assert.assertTrue(aggregated.getMaxInvocationTime() == surDuration); Assert.assertTrue(aggregated.getMaxInvocationTime() == jurDuration);
} }
Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME)); Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME));
@ -197,5 +212,6 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated); logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
} }
*/
} }

View File

@ -34,10 +34,13 @@ public class JobUsageRecordTest extends ScopedTest {
expectedRequiredFields.add(UsageRecord.CREATION_TIME); expectedRequiredFields.add(UsageRecord.CREATION_TIME);
expectedRequiredFields.add(UsageRecord.SCOPE); expectedRequiredFields.add(UsageRecord.SCOPE);
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT); expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_ID); expectedRequiredFields.add(AbstractJobUsageRecord.HOST);
expectedRequiredFields.add(AbstractJobUsageRecord.DURATION); expectedRequiredFields.add(AbstractJobUsageRecord.DURATION);
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_END_TIME); expectedRequiredFields.add(AbstractJobUsageRecord.SERVICE_CLASS);
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_START_TIME); expectedRequiredFields.add(AbstractJobUsageRecord.SERVICE_NAME);
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_NAME);
expectedRequiredFields.add(AbstractJobUsageRecord.CALLER_QUALIFIER);
return expectedRequiredFields; return expectedRequiredFields;
} }

View File

@ -1,74 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.usagerecords;
import java.util.HashSet;
import java.util.Set;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.testutility.ScopedTest;
import org.gcube.testutility.TestUsageRecord;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class TaskUsageRecordTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(TaskUsageRecordTest.class);
public static Set<String> getExpectedRequiredFields(){
Set<String> expectedRequiredFields = new HashSet<String>();
expectedRequiredFields.add(Record.ID);
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
expectedRequiredFields.add(UsageRecord.SCOPE);
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_ID);
expectedRequiredFields.add(AbstractTaskUsageRecord.WALL_DURATION);
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_START_TIME);
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_END_TIME);
return expectedRequiredFields;
}
@Test(expected=InvalidValueException.class)
public void scopeNotSetValidationError() throws InvalidValueException {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
usageRecord.validate();
logger.debug("{}", usageRecord);
}
@Test
public void testRequiredFields() throws InvalidValueException{
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
Assert.assertTrue(usageRecord.getScope()==null);
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
Set<String> expectedRequiredFields = getExpectedRequiredFields();
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
Set<String> gotRequiredFields = usageRecord.getRequiredFields();
logger.debug("Got Required Fields : {}", gotRequiredFields);
Assert.assertTrue(expectedRequiredFields.containsAll(gotRequiredFields));
Assert.assertTrue(gotRequiredFields.containsAll(expectedRequiredFields));
usageRecord.validate();
logger.debug("{}", usageRecord);
}
}

View File

@ -3,22 +3,18 @@
*/ */
package org.gcube.testutility; package org.gcube.testutility;
import java.io.Serializable;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult; import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord; import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord; import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord; import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord;
import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord; import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.accounting.persistence.AccountingPersistenceFactory; import org.gcube.accounting.persistence.AccountingPersistenceFactory;
import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.InvalidValueException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -50,12 +46,6 @@ public class TestUsageRecord {
public final static String TEST_JOB_ID = UUID.randomUUID().toString(); public final static String TEST_JOB_ID = UUID.randomUUID().toString();
public final static String TEST_JOB_NAME = "TestJobName"; public final static String TEST_JOB_NAME = "TestJobName";
public final static int TEST_VMS_USED = 2;
public final static String TEST_JOB_QUALIFIER = "TestJobQualifier";
public final static long HALF_DURATION = 10 * 60 * 1000; // 10 min
public final static String TEST_TASK_ID = UUID.randomUUID().toString();
public final static String TEST_NESTED_MAP = "TestNestedMap";
public final static String TEST_PORTLET_ID = "TestPortlet"; public final static String TEST_PORTLET_ID = "TestPortlet";
public final static String TEST_PORTLET_OPERATION_ID = "TestPortletOperationID"; public final static String TEST_PORTLET_OPERATION_ID = "TestPortletOperationID";
@ -179,65 +169,12 @@ public class TestUsageRecord {
try { try {
usageRecord.setConsumerId(TEST_CONSUMER_ID); usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_OPERATION_RESULT); usageRecord.setOperationResult(TEST_OPERATION_RESULT);
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);
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
usageRecord.setJobStartTime(startTime);
usageRecord.setJobEndTime(endTime);
} catch (InvalidValueException e) {
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
}
return usageRecord;
}
/**
* @return
*/
public static TaskUsageRecord createTestTaskUsageRecord() {
TaskUsageRecord usageRecord = new TaskUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setTaskId(TEST_TASK_ID);
//usageRecord.setTaskId(TEST_JOB_ID);
usageRecord.setHost(TEST_HOST); usageRecord.setHost(TEST_HOST);
usageRecord.setCallerQualifier(TEST_CALLER_QUALIFIER);
usageRecord.setRefHostingNodeId(UUID.randomUUID().toString()); usageRecord.setServiceClass(TEST_SERVICE_CLASS);
usageRecord.setServiceName(TEST_SERVICE_NAME);
Calendar startTime = Calendar.getInstance(); usageRecord.setJobName(TEST_JOB_NAME);
Calendar endTime = Calendar.getInstance(); usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION));
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
usageRecord.setTaskStartTime(startTime);
usageRecord.setTaskEndTime(endTime);
usageRecord.setResourceProperty("finalState", "DONE") ;
usageRecord.setResourceProperty("ESEMpio", "PLUTO") ;
HashMap<String, Serializable> inputParameters = new HashMap<>();
inputParameters.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
inputParameters.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME);
HashMap<String, Serializable> parameter = new HashMap<>();
parameter.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
parameter.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME);
inputParameters.put(TEST_NESTED_MAP, parameter);
//usageRecord.setInputParameters(inputParameters);
} catch (InvalidValueException e) { } catch (InvalidValueException e) {
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e); logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
@ -246,7 +183,6 @@ public class TestUsageRecord {
return usageRecord; return usageRecord;
} }
/** /**
* @return * @return
*/ */
@ -257,11 +193,6 @@ public class TestUsageRecord {
usageRecord.setConsumerId(TEST_CONSUMER_ID); usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_OPERATION_RESULT); usageRecord.setOperationResult(TEST_OPERATION_RESULT);
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
usageRecord.setPortletId(TEST_PORTLET_ID); usageRecord.setPortletId(TEST_PORTLET_ID);
usageRecord.setOperationId(TEST_PORTLET_OPERATION_ID); usageRecord.setOperationId(TEST_PORTLET_OPERATION_ID);
usageRecord.setMessage(TEST_PORTLET_MESSAGE); usageRecord.setMessage(TEST_PORTLET_MESSAGE);