refs #200: Create accouting-lib library

https://support.d4science.org/issues/200
Updating Javadoc and fixing model

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115583 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-06-26 10:21:28 +00:00
parent 99f823c9bb
commit 091e0d27d4
5 changed files with 97 additions and 18 deletions

View File

@ -95,12 +95,14 @@ public class TestUsageRecord {
usageRecord.setResourceOwner(TEST_RESOUCE_OWNER);
usageRecord.setResourceScope(TEST_RESOUCE_SCOPE);
usageRecord.setObjectURI(new URI(TEST_OBJECT_URI));
usageRecord.setResourceURI(new URI(TEST_OBJECT_URI));
usageRecord.setOperationType(OperationType.READ);
//usageRecord.setDataType();
usageRecord.setDataType(StorageUsageRecord.STORAGE_DATA_TYPE);
usageRecord.setDataVolume(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME));
usageRecord.setQualifier("image/png");
usageRecord.setCallerIP("192.168.0.1");
usageRecord.setResourceProperty(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);

View File

@ -28,7 +28,7 @@ public class StorageUsageRecord extends org.gcube.accounting.datamodel.implement
@RequiredField @ValidLong @AggregatedField
public static final String DATA_VOLUME = "dataVolume";
/**
* Indicate The Number of Aggregated Operation
* KEY for : Indicate The Number of Aggregated Operation
*/
@RequiredField @ValidInteger @AggregatedField
public static final String OPERATION_COUNT = "operationCount";

View File

@ -20,8 +20,8 @@ public class StorageUsageRecordAggregationStrategy extends AggregationStrategy<S
super(storageUsageRecord);
this.aggregationField.add(StorageUsageRecord.RESOURCE_OWNER);
this.aggregationField.add(StorageUsageRecord.RESOURCE_SCOPE);
this.aggregationField.add(StorageUsageRecord.RESOURCE_URI);
this.aggregationField.add(StorageUsageRecord.OPERATION_TYPE);
this.aggregationField.add(StorageUsageRecord.OBJECT_URI);
this.aggregationField.add(StorageUsageRecord.DATA_TYPE);
}

View File

@ -26,32 +26,37 @@ public class ServiceUsageRecord extends BasicUsageRecord implements SingleUsageR
private static final long serialVersionUID = -4214891294699473587L;
/**
*
* KEY for : IP address that originated the service call
*/
@ValidIP
public static final String CALLER_IP = "callerIP";
/**
*
* KEY for : hostname:port of the Hosting Node
*/
@RequiredField @NotEmpty
public static final String REF_HOST = "refHost";
/**
*
* KEY for : Hosting Node ID
*/
@RequiredField @NotEmpty
public static final String REF_VM = "refVM";
/**
*
* KEY for : Service Class
*/
@RequiredField @NotEmpty
public static final String SERVICE_CLASS = "serviceClass";
/**
*
* KEY for : Service Name
*/
@RequiredField @NotEmpty
public static final String SERVICE_NAME = "serviceName";
/**
*
* KEY for : Service Name
*/
@RequiredField @ValidLong
public static final String DURATION = "duration";

View File

@ -4,18 +4,27 @@
package org.gcube.accounting.datamodel.implementations;
import java.io.Serializable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.URI;
import java.util.Map;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.SingleUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
import org.gcube.accounting.datamodel.validations.annotations.ValidIP;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationType;
import org.gcube.accounting.datamodel.validations.annotations.ValidURI;
import org.gcube.accounting.datamodel.validations.validators.ValidURIValidator;
import org.gcube.accounting.exception.InvalidValueException;
/**
@ -34,10 +43,31 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
}
/**
*
* Predefined DATA TYPE
*/
public static final String STORAGE_DATA_TYPE = "STORAGE";
/**
* Predefined DATA TYPE
*/
public static final String TREE_DATA_TYPE = "TREE";
/**
* Predefined DATA TYPE
*/
public static final String GEO_DATA_TYPE = "GEO";
/**
* Predefined DATA TYPE
*/
public static final String DATABASE_DATA_TYPE = "DATABASE";
/**
* KEY for : The Owner of the stored Resource
*/
@RequiredField @NotEmpty
public static final String RESOURCE_OWNER = "resourceOwner";
/**
* KEY for : The Scope where the Resource was stored
*/
@RequiredField @NotEmpty
public static final String RESOURCE_SCOPE = "resourceScope";
@ -45,10 +75,44 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
@NotEmptyIfNotNull
public static final String PROVIDER_ID = "providerId";
*/
@RequiredField @NotEmptyIfNotNull @ValidURI
public static final String OBJECT_URI = "objectURI";
@DeprecatedWarning @MoveToResourceURI
protected static final String OBJECT_URI = "objectURI";
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToResourceURIAction.class)
protected @interface MoveToResourceURI { }
protected class MoveToResourceURIAction implements FieldAction {
@Override
public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
ValidURIValidator neinnv = new ValidURIValidator();
value = neinnv.validate(key, value, usageRecord);
((StorageUsageRecord) usageRecord).setResourceURI((URI) value);
return value;
}
}
/**
* KEY for : The URI of the Stored Resource
*/
@RequiredField @ValidURI //@NotEmptyIfNotNull
public static final String RESOURCE_URI = "resourceURI";
/**
* KEY for : The operation performed over the stored resource.
* The value is a controlled dictionary by
* {@link #StorageUsageRecord.OperationType}
*/
@RequiredField @ValidOperationType
public static final String OPERATION_TYPE = "operationType";
/**
* KEY for : type of data accessed.
* Even this field is not a controlled dictionary some type are defined
* i.e. STORAGE, TREE, GEO, DATABASE.
* Check the constant on this class:
* {@link #STORAGE_DATA_TYPE}, {@link #TREE_DATA_TYPE},
* {@link #GEO_DATA_TYPE}, {@link #DATABASE_DATA_TYPE}
*/
@RequiredField @NotEmpty
public static final String DATA_TYPE = "dataType";
@ -58,11 +122,19 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
@RequiredField @ValidLong
public static final String DATA_VOLUME = "dataVolume";
@NotEmpty
/**
* KEY for : Qualifies the data in terms of data (e.g. MIME type for the
* Storage, domain for a database)
*/
@NotEmptyIfNotNull
public static final String QUALIFIER = "qualifier";
/**
* KEY for : IP address that originated the service call
*/
@ValidIP
public static final String CALLER_IP = "callerIP";
public StorageUsageRecord(){
super();
}
@ -114,12 +186,12 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
}
*/
public URI getObjectURI() {
return (URI) this.resourceProperties.get(OBJECT_URI);
public URI getResourceURI() {
return (URI) this.resourceProperties.get(RESOURCE_URI);
}
public void setObjectURI(URI objectURI) throws InvalidValueException {
setResourceProperty(OBJECT_URI, objectURI);
public void setResourceURI(URI resourceURI) throws InvalidValueException {
setResourceProperty(RESOURCE_URI, resourceURI);
}
public OperationType getOperationType() {