Revisited models. Refined jackson support refs #9617
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@152713 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a94a3b9621
commit
8e592a4f0f
|
@ -2,6 +2,10 @@
|
||||||
<!DOCTYPE xml>
|
<!DOCTYPE xml>
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
<Changeset component="org.gcube.accounting.accounting-lib.3-0-0" date="${buildDate}">
|
<Changeset component="org.gcube.accounting.accounting-lib.3-0-0" date="${buildDate}">
|
||||||
|
<Change>Refined Jackson support #9617</Change>
|
||||||
|
<Change>Revisited models</Change>
|
||||||
|
</Changeset>
|
||||||
|
<Changeset component="org.gcube.accounting.accounting-lib.3-0-0" date="2017-06-07">
|
||||||
<Change>Added Jackson support on Usage Record model to allow to use it for marshalling and unmarshalling</Change>
|
<Change>Added Jackson support on Usage Record model to allow to use it for marshalling and unmarshalling</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.accounting.accounting-lib.2-4-1" date="2017-05-02">
|
<Changeset component="org.gcube.accounting.accounting-lib.2-4-1" date="2017-05-02">
|
||||||
|
|
3
pom.xml
3
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-lib</artifactId>
|
<artifactId>accounting-lib</artifactId>
|
||||||
<version>3.0.0-SNAPSHOT</version>
|
<version>3.1.0-SNAPSHOT</version>
|
||||||
<name>Accounting Library</name>
|
<name>Accounting Library</name>
|
||||||
<description>Accounting Library</description>
|
<description>Accounting Library</description>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@ -56,7 +56,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.data.publishing</groupId>
|
<groupId>org.gcube.data.publishing</groupId>
|
||||||
<artifactId>document-store-lib</artifactId>
|
<artifactId>document-store-lib</artifactId>
|
||||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources.discovery</groupId>
|
<groupId>org.gcube.resources.discovery</groupId>
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToRecordType;
|
|
||||||
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
|
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
|
||||||
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
|
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
|
||||||
import org.gcube.common.authorization.client.Constants;
|
import org.gcube.common.authorization.client.Constants;
|
||||||
|
@ -15,7 +14,6 @@ import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.documentstore.exception.InvalidValueException;
|
import org.gcube.documentstore.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.Record;
|
|
||||||
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
||||||
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;
|
||||||
|
@ -23,15 +21,11 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@JsonTypeName(value="UsageRecord")
|
public abstract class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
||||||
public class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generated Serial Version UID
|
* Generated Serial Version UID
|
||||||
|
@ -40,26 +34,22 @@ public class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(BasicUsageRecord.class);
|
private static Logger logger = LoggerFactory.getLogger(BasicUsageRecord.class);
|
||||||
|
|
||||||
/**
|
@RequiredField
|
||||||
* Moved to {@link Record#RECORD_TYPE}. This filed should not be set
|
@NotEmpty
|
||||||
* explicitly because it is automatically calculated
|
|
||||||
*/
|
|
||||||
@Deprecated @MoveToRecordType
|
|
||||||
public static final String USAGE_RECORD_TYPE = "usageRecordType";
|
|
||||||
|
|
||||||
@RequiredField @NotEmpty
|
|
||||||
public static final String CONSUMER_ID = UsageRecord.CONSUMER_ID;
|
public static final String CONSUMER_ID = UsageRecord.CONSUMER_ID;
|
||||||
|
|
||||||
@RequiredField @NotEmpty
|
@RequiredField
|
||||||
|
@NotEmpty
|
||||||
public static final String SCOPE = UsageRecord.SCOPE;
|
public static final String SCOPE = UsageRecord.SCOPE;
|
||||||
|
|
||||||
@RequiredField @ValidOperationResult
|
@RequiredField
|
||||||
|
@ValidOperationResult
|
||||||
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
|
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
|
||||||
|
|
||||||
public static String getScopeFromToken(){
|
public static String getContextFromToken() {
|
||||||
|
|
||||||
String scope =ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
if (scope==null){
|
if (scope == null) {
|
||||||
String token = SecurityTokenProvider.instance.get();
|
String token = SecurityTokenProvider.instance.get();
|
||||||
|
|
||||||
AuthorizationEntry authorizationEntry;
|
AuthorizationEntry authorizationEntry;
|
||||||
|
@ -80,13 +70,14 @@ public class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
||||||
super.init();
|
super.init();
|
||||||
// Backward compatibility
|
// Backward compatibility
|
||||||
try {
|
try {
|
||||||
this.setScope(getScopeFromToken());
|
this.setScope(getContextFromToken());
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
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.");
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicUsageRecord(){
|
public BasicUsageRecord() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +86,7 @@ public class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<String> getQuerableKeys()
|
public SortedSet<String> getQuerableKeys() throws Exception {
|
||||||
throws Exception {
|
|
||||||
SortedSet<String> properties = super.getQuerableKeys();
|
SortedSet<String> properties = super.getQuerableKeys();
|
||||||
|
|
||||||
properties.remove(UsageRecord.SCOPE);
|
properties.remove(UsageRecord.SCOPE);
|
||||||
|
@ -122,16 +112,12 @@ public class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
||||||
setResourceProperty(CONSUMER_ID, consumerId);
|
setResourceProperty(CONSUMER_ID, consumerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
protected String giveMeRecordType() {
|
public String getRecordType() {
|
||||||
return BasicUsageRecord.class.getSimpleName();
|
return BasicUsageRecord.class.getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -155,10 +141,10 @@ public class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@Override
|
@Override
|
||||||
public OperationResult getOperationResult(){
|
public OperationResult getOperationResult() {
|
||||||
try {
|
try {
|
||||||
return (OperationResult) new ValidOperationResultValidator().
|
return (OperationResult) new ValidOperationResultValidator().validate(OPERATION_RESULT,
|
||||||
validate(OPERATION_RESULT, this.resourceProperties.get(OPERATION_RESULT), null);
|
this.resourceProperties.get(OPERATION_RESULT), null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -166,6 +152,7 @@ public class BasicUsageRecord extends AbstractRecord implements UsageRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
* @throws InvalidValueException
|
* @throws InvalidValueException
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
|
|
@ -13,9 +13,6 @@ 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.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
|
@ -27,18 +24,24 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
@JsonTypeName(value="JobUsageRecord")
|
@JsonTypeName(value="JobUsageRecord")
|
||||||
public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements AggregatedUsageRecord<AggregatedJobUsageRecord, JobUsageRecord> {
|
public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements AggregatedUsageRecord<AggregatedJobUsageRecord, JobUsageRecord> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generated Serial Version UID
|
* Generated Serial Version UID
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -3376423316219914682L;
|
private static final long serialVersionUID = -3376423316219914682L;
|
||||||
/*add a field max e min invocation*/
|
|
||||||
|
/*
|
||||||
|
/ *add a field max e min invocation* /
|
||||||
@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,9 +55,11 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
|
||||||
//throw new UnsupportedOperationException();
|
//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);
|
||||||
|
@ -73,6 +78,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
|
||||||
super.setOperationCount(operationCount);
|
super.setOperationCount(operationCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public long getMaxInvocationTime() {
|
public long getMaxInvocationTime() {
|
||||||
return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME);
|
return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME);
|
||||||
|
@ -92,6 +98,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
|
||||||
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}
|
||||||
|
@ -130,7 +137,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Introduce for to serialize Java Object
|
//Introduced to serialize Java Object
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@Override
|
@Override
|
||||||
public void setAggregate(Boolean aggregate) throws InvalidValueException {
|
public void setAggregate(Boolean aggregate) throws InvalidValueException {
|
||||||
|
@ -144,14 +151,16 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
|
||||||
public Boolean getAggregate() {
|
public Boolean getAggregate() {
|
||||||
return super.getAggregate();
|
return super.getAggregate();
|
||||||
}
|
}
|
||||||
//End Introduce for to serialize Java Object
|
//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}
|
||||||
|
@ -160,6 +169,8 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public AggregatedJobUsageRecord aggregate(AggregatedJobUsageRecord record)
|
public AggregatedJobUsageRecord aggregate(AggregatedJobUsageRecord record)
|
||||||
throws NotAggregatableRecordsExceptions {
|
throws NotAggregatableRecordsExceptions {
|
||||||
|
throw new NotAggregatableRecordsExceptions();
|
||||||
|
/*
|
||||||
try {
|
try {
|
||||||
|
|
||||||
AggregationUtility<AggregatedJobUsageRecord> aggregationUtility = new AggregationUtility<AggregatedJobUsageRecord>(this);
|
AggregationUtility<AggregatedJobUsageRecord> aggregationUtility = new AggregationUtility<AggregatedJobUsageRecord>(this);
|
||||||
|
@ -180,7 +191,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
|
||||||
throw new NotAggregatableRecordsExceptions(ex);
|
throw new NotAggregatableRecordsExceptions(ex);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
//throw new UnsupportedOperationException();
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -163,6 +163,14 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
|
||||||
public AggregatedServiceUsageRecord aggregate(AggregatedServiceUsageRecord record)
|
public AggregatedServiceUsageRecord aggregate(AggregatedServiceUsageRecord record)
|
||||||
throws NotAggregatableRecordsExceptions {
|
throws 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<AggregatedServiceUsageRecord> aggregationUtility = new AggregationUtility<AggregatedServiceUsageRecord>(this);
|
AggregationUtility<AggregatedServiceUsageRecord> aggregationUtility = new AggregationUtility<AggregatedServiceUsageRecord>(this);
|
||||||
|
|
||||||
setDuration(durationWeightedAverage(record));
|
setDuration(durationWeightedAverage(record));
|
||||||
|
|
|
@ -22,7 +22,7 @@ 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="StorageUsageRecord")
|
@JsonTypeName(value="AggregatedStorageUsageRecord")
|
||||||
public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord implements AggregatedUsageRecord<AggregatedStorageUsageRecord, StorageUsageRecord> {
|
public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord implements AggregatedUsageRecord<AggregatedStorageUsageRecord, StorageUsageRecord> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -96,18 +96,7 @@ public class AggregatedTaskUsageRecord extends AbstractTaskUsageRecord implement
|
||||||
@Override
|
@Override
|
||||||
public AggregatedTaskUsageRecord aggregate(AggregatedTaskUsageRecord record)
|
public AggregatedTaskUsageRecord aggregate(AggregatedTaskUsageRecord record)
|
||||||
throws NotAggregatableRecordsExceptions {
|
throws NotAggregatableRecordsExceptions {
|
||||||
try {
|
throw new NotAggregatableRecordsExceptions();
|
||||||
/* TODO
|
|
||||||
AggregationUtility<AggregatedTaskUsageRecord> aggregationUtility = new AggregationUtility<AggregatedTaskUsageRecord>(this);
|
|
||||||
aggregationUtility.aggregate(record);
|
|
||||||
} catch(NotAggregatableRecordsExceptions e){
|
|
||||||
throw e; */
|
|
||||||
} catch(Exception ex){
|
|
||||||
throw new NotAggregatableRecordsExceptions(ex);
|
|
||||||
}
|
|
||||||
//return this;
|
|
||||||
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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=MoveToRecordTypeAction.class)
|
|
||||||
public @interface MoveToRecordType { }
|
|
|
@ -1,22 +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 MoveToRecordTypeAction implements FieldAction {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
|
|
||||||
if(value instanceof String && value!= null && !((String) value).isEmpty()){
|
|
||||||
record.setResourceProperty(Record.RECORD_TYPE, value);
|
|
||||||
}
|
|
||||||
return null; //Returning null the initial key is removed from Record
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -55,11 +55,8 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected String giveMeRecordType() {
|
public String getRecordType() {
|
||||||
return AbstractJobUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
return AbstractJobUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,10 +64,8 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
||||||
public SortedSet<String> getQuerableKeys()
|
public SortedSet<String> getQuerableKeys()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
SortedSet<String> properties = super.getQuerableKeys();
|
SortedSet<String> properties = super.getQuerableKeys();
|
||||||
|
|
||||||
properties.remove(JOB_START_TIME);
|
properties.remove(JOB_START_TIME);
|
||||||
properties.remove(JOB_END_TIME);
|
properties.remove(JOB_END_TIME);
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +127,7 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
||||||
setResourceProperty(JOB_END_TIME, jobEndTime.getTimeInMillis());
|
setResourceProperty(JOB_END_TIME, jobEndTime.getTimeInMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long calculateWallDuration() throws InvalidValueException {
|
protected long calculateDuration() throws InvalidValueException {
|
||||||
try {
|
try {
|
||||||
long endTime = (Long) this.resourceProperties.get(JOB_END_TIME);
|
long endTime = (Long) this.resourceProperties.get(JOB_END_TIME);
|
||||||
long startTime = (Long) this.resourceProperties.get(JOB_START_TIME);
|
long startTime = (Long) this.resourceProperties.get(JOB_START_TIME);
|
||||||
|
@ -147,15 +142,15 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public long getDuration() throws InvalidValueException {
|
public long getDuration() throws InvalidValueException {
|
||||||
Long wallDuration = (Long) this.resourceProperties.get(DURATION);
|
Long duration = (Long) this.resourceProperties.get(DURATION);
|
||||||
if(wallDuration == null){
|
if(duration == null){
|
||||||
try {
|
try {
|
||||||
wallDuration = calculateWallDuration();
|
duration = calculateDuration();
|
||||||
} catch(InvalidValueException e){
|
} catch(InvalidValueException e){
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return wallDuration;
|
return duration;
|
||||||
}
|
}
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public void setDuration(Long duration) throws InvalidValueException {
|
public void setDuration(Long duration) throws InvalidValueException {
|
||||||
|
|
|
@ -7,8 +7,6 @@ import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToConsumerId;
|
|
||||||
import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
|
|
||||||
import org.gcube.documentstore.exception.InvalidValueException;
|
import org.gcube.documentstore.exception.InvalidValueException;
|
||||||
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;
|
||||||
|
@ -27,8 +25,9 @@ public abstract class AbstractPortletUsageRecord extends BasicUsageRecord {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 8339324883678974869L;
|
private static final long serialVersionUID = 8339324883678974869L;
|
||||||
|
|
||||||
@DeprecatedWarning @MoveToConsumerId
|
//@DeprecatedWarning @MoveToConsumerId
|
||||||
protected static final String USER_ID = "userId";
|
//protected static final String USER_ID = "userId";
|
||||||
|
|
||||||
@RequiredField @NotEmpty
|
@RequiredField @NotEmpty
|
||||||
public static final String PORTLET_ID = "portletId";
|
public static final String PORTLET_ID = "portletId";
|
||||||
@RequiredField @NotEmpty
|
@RequiredField @NotEmpty
|
||||||
|
@ -46,11 +45,8 @@ public abstract class AbstractPortletUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected String giveMeRecordType() {
|
public String getRecordType() {
|
||||||
return AbstractPortletUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
return AbstractPortletUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class AbstractServiceUsageRecord extends BasicUsageRecord {
|
public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generated Serial Version UID
|
* Generated Serial Version UID
|
||||||
|
@ -67,19 +67,8 @@ public class AbstractServiceUsageRecord extends BasicUsageRecord {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@RequiredField @NotEmpty
|
@RequiredField @NotEmpty
|
||||||
public static final String CALLERQUALIFIER = "callerQualifier";
|
public static final String CALLER_QUALIFIER = "callerQualifier";
|
||||||
/*for remove querable key
|
|
||||||
@Override
|
|
||||||
public SortedSet<String> getQuerableKeys()
|
|
||||||
throws Exception {
|
|
||||||
SortedSet<String> properties = super.getQuerableKeys();
|
|
||||||
|
|
||||||
//properties.remove(CALLERQUALIFIER);
|
|
||||||
|
|
||||||
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
***/
|
|
||||||
|
|
||||||
public AbstractServiceUsageRecord(){
|
public AbstractServiceUsageRecord(){
|
||||||
super();
|
super();
|
||||||
|
@ -91,12 +80,8 @@ public class AbstractServiceUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@JsonIgnore
|
|
||||||
@Override
|
@Override
|
||||||
protected String giveMeRecordType() {
|
public String getRecordType() {
|
||||||
return AbstractServiceUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
return AbstractServiceUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,7 +125,6 @@ public class AbstractServiceUsageRecord extends BasicUsageRecord {
|
||||||
setResourceProperty(SERVICE_NAME, serviceName);
|
setResourceProperty(SERVICE_NAME, serviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public String getCalledMethod() {
|
public String getCalledMethod() {
|
||||||
return (String) this.resourceProperties.get(CALLED_METHOD);
|
return (String) this.resourceProperties.get(CALLED_METHOD);
|
||||||
|
@ -161,11 +145,12 @@ public class AbstractServiceUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public String getCallerQualifier() {
|
public String getCallerQualifier() {
|
||||||
return (String) this.resourceProperties.get(CALLERQUALIFIER);
|
return (String) this.resourceProperties.get(CALLER_QUALIFIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public void setCallerQualifier(String callerQualifier) throws InvalidValueException {
|
public void setCallerQualifier(String callerQualifier) throws InvalidValueException {
|
||||||
setResourceProperty(CALLERQUALIFIER, callerQualifier);
|
setResourceProperty(CALLER_QUALIFIER, callerQualifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -88,11 +88,8 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected String giveMeRecordType() {
|
public String getRecordType() {
|
||||||
return AbstractStorageStatusRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
return AbstractStorageStatusRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,11 +106,8 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected String giveMeRecordType() {
|
public String getRecordType() {
|
||||||
return AbstractStorageUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
return AbstractStorageUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ package org.gcube.accounting.datamodel.basetypes;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
|
@ -49,8 +48,10 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
||||||
@RequiredField @ComputedField(action=CalculateTaskWallDurationAction.class) @ValidLong
|
@RequiredField @ComputedField(action=CalculateTaskWallDurationAction.class) @ValidLong
|
||||||
public static final String WALL_DURATION = "wallDuration";
|
public static final String WALL_DURATION = "wallDuration";
|
||||||
|
|
||||||
|
/*
|
||||||
@NotEmptyIfNotNull
|
@NotEmptyIfNotNull
|
||||||
public static final String INPUT_PARAMETERS = "inputParameters";
|
public static final String INPUT_PARAMETERS = "inputParameters";
|
||||||
|
*/
|
||||||
|
|
||||||
public AbstractTaskUsageRecord(){
|
public AbstractTaskUsageRecord(){
|
||||||
super();
|
super();
|
||||||
|
@ -62,11 +63,8 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
private static final String ABSTRACT_TO_REPLACE = "Abstract";
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected String giveMeRecordType() {
|
public String getRecordType() {
|
||||||
return AbstractTaskUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
return AbstractTaskUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,16 +174,18 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
||||||
setResourceProperty(WALL_DURATION, duration);
|
setResourceProperty(WALL_DURATION, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@JsonIgnore
|
//@JsonIgnore
|
||||||
public Map<String, Serializable> getInputParameters(){
|
public Map<String, Serializable> getInputParameters(){
|
||||||
return (HashMap<String, Serializable>) getResourceProperty(INPUT_PARAMETERS);
|
return (HashMap<String, Serializable>) getResourceProperty(INPUT_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
//@JsonIgnore
|
||||||
|
@JsonProperty(value=INPUT_PARAMETERS)
|
||||||
public void setInputParameters(HashMap<String, Serializable> inputParameters) throws InvalidValueException{
|
public void setInputParameters(HashMap<String, Serializable> inputParameters) throws InvalidValueException{
|
||||||
setResourceProperty(INPUT_PARAMETERS, inputParameters);
|
setResourceProperty(INPUT_PARAMETERS, inputParameters);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class CalculateJobWallDurationAction implements FieldAction {
|
||||||
@Override
|
@Override
|
||||||
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
|
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
|
||||||
try {
|
try {
|
||||||
long wallDuration = ((AbstractJobUsageRecord) record).calculateWallDuration();
|
long wallDuration = ((AbstractJobUsageRecord) record).calculateDuration();
|
||||||
if(key.compareTo(AbstractJobUsageRecord.DURATION)==0){
|
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.",
|
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);
|
AbstractJobUsageRecord.DURATION, AbstractJobUsageRecord.JOB_START_TIME, AbstractJobUsageRecord.JOB_END_TIME);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@JsonTypeName(value="NotAggregateJobUsageRecord")
|
@JsonTypeName(value="SingleJobUsageRecord")
|
||||||
public class JobUsageRecord extends AbstractJobUsageRecord {
|
public class JobUsageRecord extends AbstractJobUsageRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@JsonTypeName(value="NotAggregatePortletUsageRecord")
|
@JsonTypeName(value="SinglePortletUsageRecord")
|
||||||
public class PortletUsageRecord extends AbstractPortletUsageRecord {
|
public class PortletUsageRecord extends AbstractPortletUsageRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@JsonTypeName(value="NotAggregateServiceUsageRecord")
|
@JsonTypeName(value="SingleServiceUsageRecord")
|
||||||
public class ServiceUsageRecord extends AbstractServiceUsageRecord {
|
public class ServiceUsageRecord extends AbstractServiceUsageRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
* @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it
|
* @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@JsonTypeName(value="NotAggregateStorageStatusRecord")
|
@JsonTypeName(value="SingleStorageStatusRecord")
|
||||||
public class StorageStatusRecord extends AbstractStorageStatusRecord {
|
public class StorageStatusRecord extends AbstractStorageStatusRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@JsonTypeName(value="NotAggregateStorageUsageRecord")
|
@JsonTypeName(value="SingleStorageUsageRecord")
|
||||||
public class StorageUsageRecord extends AbstractStorageUsageRecord {
|
public class StorageUsageRecord extends AbstractStorageUsageRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@JsonTypeName(value="TaskUsageRecord")
|
@JsonTypeName(value="SingleTaskUsageRecord")
|
||||||
public class TaskUsageRecord extends AbstractTaskUsageRecord {
|
public class TaskUsageRecord extends AbstractTaskUsageRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,14 +15,14 @@ import org.gcube.documentstore.records.Record;
|
||||||
*/
|
*/
|
||||||
public class AccountingPersistence {
|
public class AccountingPersistence {
|
||||||
|
|
||||||
protected String scope;
|
protected String context;
|
||||||
|
|
||||||
protected AccountingPersistence(String scope){
|
protected AccountingPersistence(String context){
|
||||||
this.scope = scope;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PersistenceBackend getAccountingPersistence(){
|
private PersistenceBackend getAccountingPersistence(){
|
||||||
return PersistenceBackendFactory.getPersistenceBackend(this.scope);
|
return PersistenceBackendFactory.getPersistenceBackend(this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,14 +42,27 @@ public class AccountingPersistence {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void flush() throws Exception {
|
||||||
|
getAccountingPersistence().flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used {@link AccountingPersistence#flush() instead}
|
||||||
|
* @param timeout
|
||||||
|
* @param timeUnit
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public void flush(long timeout, TimeUnit timeUnit) throws Exception {
|
public void flush(long timeout, TimeUnit timeUnit) throws Exception {
|
||||||
getAccountingPersistence().flush(timeout, timeUnit);
|
this.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws Exception{
|
public void close() throws Exception{
|
||||||
getAccountingPersistence().close();
|
getAccountingPersistence().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConnectionActive() throws Exception {
|
||||||
|
return getAccountingPersistence().isConnectionActive();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
|
||||||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
||||||
if(serviceEndpoints.size()>1){
|
if(serviceEndpoints.size()>1){
|
||||||
String scope = BasicUsageRecord.getScopeFromToken();
|
String scope = BasicUsageRecord.getContextFromToken();
|
||||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
|
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
|
||||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope));
|
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope));
|
||||||
serviceEndpoints = client.submit(query);
|
serviceEndpoints = client.submit(query);
|
||||||
|
|
|
@ -37,22 +37,41 @@ public class AccountingPersistenceFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static AccountingPersistence getPersistence() {
|
public synchronized static AccountingPersistence getPersistence() {
|
||||||
String scope = BasicUsageRecord.getScopeFromToken();
|
String context = BasicUsageRecord.getContextFromToken();
|
||||||
AccountingPersistence accountingPersistence = persistences.get(scope);
|
AccountingPersistence accountingPersistence = persistences.get(context);
|
||||||
if(accountingPersistence==null){
|
if(accountingPersistence==null){
|
||||||
accountingPersistence = new AccountingPersistence(scope);
|
accountingPersistence = new AccountingPersistence(context);
|
||||||
}
|
}
|
||||||
return accountingPersistence;
|
return accountingPersistence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void flushAll(long timeout, TimeUnit timeUnit){
|
public static void flushAll(){
|
||||||
PersistenceBackendFactory.flushAll(timeout, timeUnit);
|
PersistenceBackendFactory.flushAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@link AccountingPersistenceFactory#flushAll() instead}
|
||||||
|
* @param timeout
|
||||||
|
* @param timeUnit
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void flushAll(long timeout, TimeUnit timeUnit){
|
||||||
|
AccountingPersistenceFactory.flushAll();
|
||||||
|
}
|
||||||
|
|
||||||
public static void shutDown(long timeout, TimeUnit timeUnit){
|
public static void shutDown(){
|
||||||
//flush all and shutdown connection and thread
|
//flush all and shutdown connection and thread
|
||||||
PersistenceBackendFactory.flushAll(timeout, timeUnit);
|
PersistenceBackendFactory.flushAll();
|
||||||
PersistenceBackendFactory.shutdown();
|
PersistenceBackendFactory.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@link AccountingPersistenceFactory#shutDown() instead}
|
||||||
|
* @param timeout
|
||||||
|
* @param timeUnit
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void shutDown(long timeout, TimeUnit timeUnit){
|
||||||
|
AccountingPersistenceFactory.shutDown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package org.gcube.accounting.datamodel;
|
package org.gcube.accounting.datamodel;
|
||||||
|
|
||||||
import org.gcube.documentstore.exception.InvalidValueException;
|
import org.gcube.documentstore.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.RecordUtility;
|
|
||||||
import org.gcube.testutility.TestUsageRecord;
|
import org.gcube.testutility.TestUsageRecord;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -21,7 +20,7 @@ public class UsageRecordTest {
|
||||||
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
||||||
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
@Test
|
@Test
|
||||||
public void testCompareToEqualsObject() throws Exception {
|
public void testCompareToEqualsObject() throws Exception {
|
||||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
|
@ -50,6 +49,7 @@ public class UsageRecordTest {
|
||||||
Assert.assertEquals(1, usageRecord.compareTo(ur));
|
Assert.assertEquals(1, usageRecord.compareTo(ur));
|
||||||
Assert.assertEquals(1, ur.compareTo(usageRecord));
|
Assert.assertEquals(1, ur.compareTo(usageRecord));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompareToDifferentFromCreation() throws Exception {
|
public void testCompareToDifferentFromCreation() throws Exception {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
|
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.scope.api.ScopeProvider;
|
||||||
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.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -26,6 +28,9 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException {
|
public void testRequiredFields() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
|
|
||||||
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);
|
||||||
|
@ -33,8 +38,10 @@ 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());
|
||||||
|
|
||||||
|
@ -50,8 +57,11 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected=NotAggregatableRecordsExceptions.class)
|
||||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
|
|
||||||
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);
|
||||||
|
@ -62,47 +72,27 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
|
||||||
aggregated.validate();
|
aggregated.validate();
|
||||||
logger.debug("jobUsageRecord Converted to Aggregated post validate: {}", aggregated);
|
logger.debug("jobUsageRecord Converted to Aggregated post validate: {}", aggregated);
|
||||||
|
|
||||||
|
|
||||||
JobUsageRecord jobUsageRecord2 = TestUsageRecord.createTestJobUsageRecord();
|
JobUsageRecord jobUsageRecord2 = TestUsageRecord.createTestJobUsageRecord();
|
||||||
Assert.assertTrue(jobUsageRecord2.getScope()==null);
|
Assert.assertTrue(jobUsageRecord2.getScope()==null);
|
||||||
jobUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
jobUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
||||||
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("jobUsageRecord2 Converted to Aggregated: {}", aggregated);
|
logger.debug("jobUsageRecord2 Converted to Aggregated: {}", aggregated);
|
||||||
aggregated.validate();
|
aggregated.validate();
|
||||||
logger.debug("jobUsageRecord2 Converted to Aggregated post validate: {}", aggregated);
|
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();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
|
|
||||||
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);
|
||||||
|
@ -130,9 +120,11 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
|
||||||
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
|
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
|
||||||
aggregated.validate();
|
aggregated.validate();
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(aggregated.getDuration() == ((firstduration + secondDuration)/2));
|
Assert.assertTrue(aggregated.getDuration() == ((firstduration + secondDuration)/2));
|
||||||
Assert.assertTrue(aggregated.getOperationCount() == 2);
|
Assert.assertTrue(aggregated.getOperationCount() == 2);
|
||||||
|
|
||||||
|
|
||||||
if(firstduration >= secondDuration){
|
if(firstduration >= secondDuration){
|
||||||
Assert.assertTrue(aggregated.getMaxInvocationTime() == firstduration);
|
Assert.assertTrue(aggregated.getMaxInvocationTime() == firstduration);
|
||||||
Assert.assertTrue(aggregated.getMinInvocationTime() == secondDuration);
|
Assert.assertTrue(aggregated.getMinInvocationTime() == secondDuration);
|
||||||
|
@ -151,6 +143,9 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
|
|
||||||
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);
|
||||||
|
@ -164,18 +159,18 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
for(int i=2; i<1002; i++){
|
for(int i=2; i<1002; i++){
|
||||||
|
|
||||||
JobUsageRecord sur = TestUsageRecord.createTestJobUsageRecord();
|
JobUsageRecord jur = TestUsageRecord.createTestJobUsageRecord();
|
||||||
sur.setScope(TestUsageRecord.TEST_SCOPE);
|
jur.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
sur.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
jur.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||||
sur.validate();
|
jur.validate();
|
||||||
logger.debug("Cycle JobUsageRecord {}: {}", i, sur);
|
logger.debug("Cycle JobUsageRecord {}: {}", i, jur);
|
||||||
|
|
||||||
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 = sur.getDuration();
|
long surDuration = jur.getDuration();
|
||||||
|
|
||||||
aggregated.aggregate(sur);
|
aggregated.aggregate(jur);
|
||||||
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
|
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
|
||||||
aggregated.validate();
|
aggregated.validate();
|
||||||
|
|
||||||
|
@ -202,5 +197,5 @@ public class AggregatedJobUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
|
logger.debug("Resulting Aggregated JobUsageRecord: {}", aggregated);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest;
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest;
|
||||||
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -27,6 +29,8 @@ public class AggregatedServiceUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException {
|
public void testRequiredFields() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -53,6 +57,8 @@ public class AggregatedServiceUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -98,6 +104,8 @@ public class AggregatedServiceUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -146,6 +154,8 @@ public class AggregatedServiceUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord;
|
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecordTest;
|
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecordTest;
|
||||||
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -26,6 +28,8 @@ public class AggregatedStorageStatusRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException {
|
public void testRequiredFields() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -48,6 +52,8 @@ public class AggregatedStorageStatusRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -83,6 +89,8 @@ public class AggregatedStorageStatusRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageStatusRecord storageStatusUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
StorageStatusRecord storageStatusUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||||
Assert.assertTrue(storageStatusUsageRecord.getScope()==null);
|
Assert.assertTrue(storageStatusUsageRecord.getScope()==null);
|
||||||
storageStatusUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageStatusUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -121,6 +129,8 @@ public class AggregatedStorageStatusRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecordTest;
|
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecordTest;
|
||||||
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -27,6 +29,8 @@ public class AggregatedStorageUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException {
|
public void testRequiredFields() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -49,6 +53,8 @@ public class AggregatedStorageUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -81,6 +87,8 @@ public class AggregatedStorageUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -115,6 +123,8 @@ public class AggregatedStorageUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
|
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
|
||||||
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -30,7 +32,6 @@ public class JobUsageRecordTest extends ScopedTest {
|
||||||
expectedRequiredFields.add(Record.ID);
|
expectedRequiredFields.add(Record.ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
||||||
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
|
|
||||||
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.JOB_ID);
|
||||||
|
@ -42,6 +43,8 @@ public class JobUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test(expected=InvalidValueException.class)
|
@Test(expected=InvalidValueException.class)
|
||||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||||
usageRecord.validate();
|
usageRecord.validate();
|
||||||
logger.debug("{}", usageRecord);
|
logger.debug("{}", usageRecord);
|
||||||
|
@ -49,6 +52,8 @@ public class JobUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException{
|
public void testRequiredFields() throws InvalidValueException{
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||||
Assert.assertTrue(usageRecord.getScope()==null);
|
Assert.assertTrue(usageRecord.getScope()==null);
|
||||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
|
@ -7,9 +7,15 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
|
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
||||||
|
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.exception.InvalidValueException;
|
||||||
|
import org.gcube.documentstore.records.DSMapper;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
|
import org.gcube.documentstore.records.RecordUtility;
|
||||||
|
import org.gcube.documentstore.records.aggregation.AggregationScheduler;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
import org.gcube.testutility.TestUsageRecord;
|
import org.gcube.testutility.TestUsageRecord;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -19,7 +25,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ServiceUsageRecordTest extends ScopedTest {
|
public class ServiceUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
|
@ -30,7 +35,6 @@ public class ServiceUsageRecordTest extends ScopedTest {
|
||||||
expectedRequiredFields.add(Record.ID);
|
expectedRequiredFields.add(Record.ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
||||||
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
|
|
||||||
expectedRequiredFields.add(UsageRecord.SCOPE);
|
expectedRequiredFields.add(UsageRecord.SCOPE);
|
||||||
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
||||||
expectedRequiredFields.add(AbstractServiceUsageRecord.CALLER_HOST);
|
expectedRequiredFields.add(AbstractServiceUsageRecord.CALLER_HOST);
|
||||||
|
@ -39,11 +43,14 @@ public class ServiceUsageRecordTest extends ScopedTest {
|
||||||
expectedRequiredFields.add(AbstractServiceUsageRecord.SERVICE_NAME);
|
expectedRequiredFields.add(AbstractServiceUsageRecord.SERVICE_NAME);
|
||||||
expectedRequiredFields.add(AbstractServiceUsageRecord.CALLED_METHOD);
|
expectedRequiredFields.add(AbstractServiceUsageRecord.CALLED_METHOD);
|
||||||
expectedRequiredFields.add(AbstractServiceUsageRecord.DURATION);
|
expectedRequiredFields.add(AbstractServiceUsageRecord.DURATION);
|
||||||
|
expectedRequiredFields.add(AbstractServiceUsageRecord.CALLER_QUALIFIER);
|
||||||
return expectedRequiredFields;
|
return expectedRequiredFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=InvalidValueException.class)
|
@Test(expected=InvalidValueException.class)
|
||||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
usageRecord.validate();
|
usageRecord.validate();
|
||||||
logger.debug("{}", usageRecord);
|
logger.debug("{}", usageRecord);
|
||||||
|
@ -51,6 +58,8 @@ public class ServiceUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException{
|
public void testRequiredFields() throws InvalidValueException{
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
Assert.assertTrue(usageRecord.getScope()==null);
|
Assert.assertTrue(usageRecord.getScope()==null);
|
||||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
@ -68,4 +77,38 @@ public class ServiceUsageRecordTest extends ScopedTest {
|
||||||
logger.debug("{}", usageRecord);
|
logger.debug("{}", usageRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMarshalling() throws Exception {
|
||||||
|
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
|
AggregatedServiceUsageRecord aggregatedUsageRecord = (AggregatedServiceUsageRecord) AggregationScheduler.getAggregatedRecord(usageRecord);
|
||||||
|
logger.debug(DSMapper.marshal(aggregatedUsageRecord));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeserialization() throws Exception{
|
||||||
|
RecordUtility.addRecordPackage(ServiceUsageRecord.class.getPackage());
|
||||||
|
RecordUtility.addRecordPackage(AggregatedServiceUsageRecord.class.getPackage());
|
||||||
|
|
||||||
|
String singleUsageRecordString = "{"
|
||||||
|
+ "\"creationTime\":1498081970156,"
|
||||||
|
+ "\"serviceClass\":\"InformationSystem\","
|
||||||
|
+ "\"callerHost\":\"146.48.123.84\","
|
||||||
|
+ "\"callerQualifier\":\"TOKEN\","
|
||||||
|
+ "\"recordType\":\"ServiceUsageRecord\","
|
||||||
|
+ "\"consumerId\":\"luca.frosini\","
|
||||||
|
+ "\"aggregated\":true,"
|
||||||
|
+ "\"serviceName\":\"resource-registry\","
|
||||||
|
+ "\"duration\":692,"
|
||||||
|
+ "\"scope\":\"/gcube/devNext/NextNext\","
|
||||||
|
+ "\"host\":\"resourceregistry1-d-d4s.d4science.org:80\","
|
||||||
|
+ "\"id\":\"1ca35f57-75b7-48f4-84b1-ac3dae2f58ab\","
|
||||||
|
+ "\"calledMethod\":\"/er/resource/957d40f4-44b5-4e7e-be7d-76bba44e751f\","
|
||||||
|
+ "\"operationResult\":\"SUCCESS\""
|
||||||
|
+ "}";
|
||||||
|
UsageRecord usageRecord = DSMapper.unmarshal(UsageRecord.class, singleUsageRecordString);
|
||||||
|
AggregatedServiceUsageRecord aggregatedServiceUsageRecord = new AggregatedServiceUsageRecord(usageRecord.getResourceProperties());
|
||||||
|
logger.debug("{}", usageRecord);
|
||||||
|
logger.debug("{}", aggregatedServiceUsageRecord);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
||||||
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -30,7 +32,6 @@ public class StorageStatusRecordTest extends ScopedTest {
|
||||||
expectedRequiredFields.add(Record.ID);
|
expectedRequiredFields.add(Record.ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
||||||
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
|
|
||||||
expectedRequiredFields.add(UsageRecord.SCOPE);
|
expectedRequiredFields.add(UsageRecord.SCOPE);
|
||||||
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
||||||
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_VOLUME);
|
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_VOLUME);
|
||||||
|
@ -46,6 +47,8 @@ public class StorageStatusRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test(expected=InvalidValueException.class)
|
@Test(expected=InvalidValueException.class)
|
||||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||||
usageRecord.validate();
|
usageRecord.validate();
|
||||||
logger.debug("{}", usageRecord);
|
logger.debug("{}", usageRecord);
|
||||||
|
@ -53,6 +56,8 @@ public class StorageStatusRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException{
|
public void testRequiredFields() throws InvalidValueException{
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||||
Assert.assertTrue(usageRecord.getScope()==null);
|
Assert.assertTrue(usageRecord.getScope()==null);
|
||||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||||
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -30,7 +32,6 @@ public class StorageUsageRecordTest extends ScopedTest {
|
||||||
expectedRequiredFields.add(Record.ID);
|
expectedRequiredFields.add(Record.ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
||||||
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
|
|
||||||
expectedRequiredFields.add(UsageRecord.SCOPE);
|
expectedRequiredFields.add(UsageRecord.SCOPE);
|
||||||
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
||||||
expectedRequiredFields.add(AbstractStorageUsageRecord.RESOURCE_OWNER);
|
expectedRequiredFields.add(AbstractStorageUsageRecord.RESOURCE_OWNER);
|
||||||
|
@ -46,6 +47,8 @@ public class StorageUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test(expected=InvalidValueException.class)
|
@Test(expected=InvalidValueException.class)
|
||||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||||
usageRecord.validate();
|
usageRecord.validate();
|
||||||
logger.debug("{}", usageRecord);
|
logger.debug("{}", usageRecord);
|
||||||
|
@ -53,6 +56,8 @@ public class StorageUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException{
|
public void testRequiredFields() throws InvalidValueException{
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||||
Assert.assertTrue(usageRecord.getScope()==null);
|
Assert.assertTrue(usageRecord.getScope()==null);
|
||||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
|
@ -30,16 +32,19 @@ public class TaskUsageRecordTest extends ScopedTest {
|
||||||
expectedRequiredFields.add(Record.ID);
|
expectedRequiredFields.add(Record.ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
||||||
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
||||||
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
|
|
||||||
expectedRequiredFields.add(UsageRecord.SCOPE);
|
expectedRequiredFields.add(UsageRecord.SCOPE);
|
||||||
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
||||||
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_ID);
|
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_ID);
|
||||||
expectedRequiredFields.add(AbstractTaskUsageRecord.WALL_DURATION);
|
expectedRequiredFields.add(AbstractTaskUsageRecord.WALL_DURATION);
|
||||||
|
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_START_TIME);
|
||||||
|
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_END_TIME);
|
||||||
return expectedRequiredFields;
|
return expectedRequiredFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=InvalidValueException.class)
|
@Test(expected=InvalidValueException.class)
|
||||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
|
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
|
||||||
usageRecord.validate();
|
usageRecord.validate();
|
||||||
logger.debug("{}", usageRecord);
|
logger.debug("{}", usageRecord);
|
||||||
|
@ -47,6 +52,8 @@ public class TaskUsageRecordTest extends ScopedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredFields() throws InvalidValueException{
|
public void testRequiredFields() throws InvalidValueException{
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
|
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
|
||||||
Assert.assertTrue(usageRecord.getScope()==null);
|
Assert.assertTrue(usageRecord.getScope()==null);
|
||||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||||
|
|
|
@ -7,35 +7,24 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||||
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.Record;
|
||||||
import org.gcube.documentstore.records.RecordUtility;
|
import org.gcube.documentstore.records.RecordUtility;
|
||||||
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
|
||||||
import org.gcube.testutility.ScopedTest;
|
import org.gcube.testutility.ScopedTest;
|
||||||
import org.gcube.testutility.TestUsageRecord;
|
import org.gcube.testutility.TestUsageRecord;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class MyTest extends ScopedTest {
|
public class FalbackTest extends ScopedTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(MyTest.class);
|
private static Logger logger = LoggerFactory.getLogger(FalbackTest.class);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception{
|
public void test() throws Exception{
|
||||||
File f = new File("test.log");
|
File f = new File("test.log");
|
||||||
|
|
||||||
DSMapper.registerSubtypes(Record.class);
|
AccountingPersistenceFactory.getPersistence();
|
||||||
DSMapper.registerSubtypes(AbstractRecord.class);
|
|
||||||
DSMapper.registerSubtypes(UsageRecord.class);
|
|
||||||
DSMapper.registerSubtypes(BasicUsageRecord.class);
|
|
||||||
DSMapper.registerSubtypes(AbstractServiceUsageRecord.class);
|
|
||||||
DSMapper.registerSubtypes(ServiceUsageRecord.class);
|
|
||||||
|
|
||||||
Record record = TestUsageRecord.createTestServiceUsageRecord();
|
Record record = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
FallbackPersistenceBackend fallbackPersistenceBackend = new FallbackPersistenceBackend(f);
|
FallbackPersistenceBackend fallbackPersistenceBackend = new FallbackPersistenceBackend(f);
|
|
@ -1,97 +0,0 @@
|
||||||
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.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
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.Test;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class MyTest {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MyTest.class);
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void beforeClass() throws Exception{
|
|
||||||
SecurityTokenProvider.instance.set("36501a0d-a205-4bf1-87ad-4c7185faa0d6-98187548");
|
|
||||||
ScopeProvider.instance.set("/gcube/devNext");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFull() throws Exception{
|
|
||||||
|
|
||||||
|
|
||||||
AccountingPersistence apq= AccountingPersistenceFactory.getPersistence();
|
|
||||||
|
|
||||||
//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);
|
|
||||||
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("--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);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
logger.error("File non trovato", 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());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -23,9 +23,6 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
public class ScopedTest {
|
public class ScopedTest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class);
|
private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class);
|
||||||
|
|
||||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||||
|
|
|
@ -236,7 +236,7 @@ public class TestUsageRecord {
|
||||||
|
|
||||||
inputParameters.put(TEST_NESTED_MAP, parameter);
|
inputParameters.put(TEST_NESTED_MAP, parameter);
|
||||||
|
|
||||||
usageRecord.setInputParameters(inputParameters);
|
//usageRecord.setInputParameters(inputParameters);
|
||||||
|
|
||||||
|
|
||||||
} catch (InvalidValueException e) {
|
} catch (InvalidValueException e) {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{"recordType":"SingleTaskUsageRecord","ESEMpio":"PLUTO","creationTime":1503928807106,"refHostingNodeId":"4f96f787-44b4-46f7-9d85-359e57313840","consumerId":"name.surname","wallDuration":1200000,"taskStartTime":1503928207106,"scope":"/gcube/devNext","host":"localhost","id":"ab97bb13-ca9a-4b01-bd4c-564da3f27759","taskId":"6776f112-4f62-4d13-ad33-d0cab5a98c76","finalState":"DONE","operationResult":"SUCCESS","taskEndTime":1503929407106}
|
|
@ -1,4 +0,0 @@
|
||||||
GCUBE_DEVNEXT=
|
|
||||||
GCUBE_DEVNEXT_NEXTNEXT=
|
|
||||||
GCUBE_DEVSEC=
|
|
||||||
GCUBE_DEVSEC_DEVVRE=
|
|
Loading…
Reference in New Issue