refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Implementing library git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115272 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e43bfe1843
commit
c0038b9efb
6
pom.xml
6
pom.xml
|
@ -67,6 +67,12 @@
|
|||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -20,9 +20,10 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.AggregatedField;
|
||||
import org.gcube.accounting.datamodel.decorators.ComputedField;
|
||||
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToAggregatedUsageRecordId;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
||||
|
@ -83,8 +84,10 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
/** resource-specific properties */
|
||||
protected Map<String, Serializable> resourceProperties;
|
||||
|
||||
protected Map<String, List<ValidatorAction>> validation;
|
||||
protected Map<String, List<FieldAction>> validation;
|
||||
protected Set<String> requiredFields;
|
||||
protected Set<String> aggregatedFields;
|
||||
protected Set<String> computedFields;
|
||||
|
||||
protected void initializeValidation() {
|
||||
logger.debug("Initializing Field Validators");
|
||||
|
@ -96,12 +99,12 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
} catch (Exception e) {
|
||||
continue;
|
||||
}
|
||||
List<ValidatorAction> fieldValidators = new ArrayList<ValidatorAction>();
|
||||
List<FieldAction> fieldValidators = new ArrayList<FieldAction>();
|
||||
validation.put(keyString, fieldValidators);
|
||||
for (Annotation annotation : field.getAnnotations()){
|
||||
if (annotation.annotationType().isAnnotationPresent(ValidatorField.class)){
|
||||
Class<? extends ValidatorAction> managedClass = ((ValidatorField)annotation.annotationType().getAnnotation(ValidatorField.class)).managed();
|
||||
ValidatorAction validator;
|
||||
if (annotation.annotationType().isAnnotationPresent(FieldDecorator.class)){
|
||||
Class<? extends FieldAction> managedClass = ((FieldDecorator)annotation.annotationType().getAnnotation(FieldDecorator.class)).managed();
|
||||
FieldAction validator;
|
||||
try {
|
||||
validator = managedClass.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
|
@ -109,9 +112,15 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
}
|
||||
fieldValidators.add(validator);
|
||||
}
|
||||
if(annotation.getClass().isAssignableFrom(RequiredField.class)){
|
||||
if(annotation.annotationType().isAssignableFrom(RequiredField.class)){
|
||||
requiredFields.add(keyString);
|
||||
}
|
||||
if(annotation.annotationType().isAssignableFrom(AggregatedField.class)){
|
||||
aggregatedFields.add(keyString);
|
||||
}
|
||||
if(annotation.annotationType().isAssignableFrom(ComputedField.class)){
|
||||
computedFields.add(keyString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +129,7 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
* Initialize variable
|
||||
*/
|
||||
private void init() {
|
||||
this.validation = new HashMap<String, List<ValidatorAction>>();
|
||||
this.validation = new HashMap<String, List<FieldAction>>();
|
||||
this.requiredFields = new HashSet<String>();
|
||||
initializeValidation();
|
||||
}
|
||||
|
@ -456,10 +465,14 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
throw new InvalidValueException("The key of property to set cannot be null");
|
||||
}
|
||||
Serializable checkedValue = serializable;
|
||||
List<ValidatorAction> fieldValidators = validation.get(key);
|
||||
List<FieldAction> fieldValidators = validation.get(key);
|
||||
if(fieldValidators!=null){
|
||||
for(ValidatorAction fieldValidator : fieldValidators){
|
||||
for(FieldAction fieldValidator : fieldValidators){
|
||||
checkedValue = fieldValidator.validate(key, checkedValue, this);
|
||||
/*
|
||||
* Check here if the key is for a ComputedField or for an
|
||||
* AggregatedField
|
||||
*/
|
||||
}
|
||||
}
|
||||
return checkedValue;
|
||||
|
@ -589,7 +602,10 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
*/
|
||||
public static UsageRecord getUsageRecord(Map<String, Serializable> usageRecordMap) throws Exception {
|
||||
String className = (String) usageRecordMap.get(USAGE_RECORD_TYPE);
|
||||
boolean aggregated = (Boolean) usageRecordMap.get(AGGREGATED);
|
||||
boolean aggregated = false;
|
||||
try {
|
||||
aggregated = (Boolean) usageRecordMap.get(AGGREGATED);
|
||||
}catch(Exception e){}
|
||||
|
||||
Class<? extends UsageRecord> clz = getClass(className, aggregated);
|
||||
logger.debug("Trying to instantiate {}", clz.getClass().getSimpleName());
|
||||
|
@ -599,7 +615,11 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
Constructor<? extends UsageRecord> usageRecordConstructor = clz.getDeclaredConstructor(usageRecordArgTypes);
|
||||
Object[] usageRecordArguments = {usageRecordMap};
|
||||
|
||||
return usageRecordConstructor.newInstance(usageRecordArguments);
|
||||
UsageRecord usageRecord = usageRecordConstructor.newInstance(usageRecordArguments);
|
||||
|
||||
logger.debug("Created Usage Record : {}", usageRecord);
|
||||
|
||||
return usageRecord;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.gcube.accounting.exception.InvalidValueException;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*/
|
||||
public interface ValidatorAction {
|
||||
public interface FieldAction {
|
||||
|
||||
/**
|
||||
* Validate (and eventually convert) the value of the property identified by
|
|
@ -16,8 +16,8 @@ import java.lang.annotation.Target;
|
|||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
public @interface ValidatorField {
|
||||
public @interface FieldDecorator {
|
||||
|
||||
Class<? extends ValidatorAction> managed();
|
||||
Class<? extends FieldAction> managed();
|
||||
}
|
||||
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.DeprecatedWarningValidator;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.DeprecatedWarningAction;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=DeprecatedWarningValidator.class)
|
||||
@FieldDecorator(managed=DeprecatedWarningAction.class)
|
||||
public @interface DeprecatedWarning {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToAggregatedUsageRecordIdValidator;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToAggregatedUsageRecordIdAction;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=MoveToAggregatedUsageRecordIdValidator.class)
|
||||
@FieldDecorator(managed=MoveToAggregatedUsageRecordIdAction.class)
|
||||
public @interface MoveToAggregatedUsageRecordId {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToOperationResultValidator;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToOperationResultAction;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=MoveToOperationResultValidator.class)
|
||||
@FieldDecorator(managed=MoveToOperationResultAction.class)
|
||||
public @interface MoveToOperationResult {
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.datamodel.deprecationmanagement.validators;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -15,9 +15,9 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class DeprecatedWarningValidator implements ValidatorAction {
|
||||
public class DeprecatedWarningAction implements FieldAction {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DeprecatedWarningValidator.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(DeprecatedWarningAction.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.datamodel.deprecationmanagement.validators;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
|
@ -14,7 +14,7 @@ import org.gcube.accounting.exception.InvalidValueException;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class MoveToAggregatedUsageRecordIdValidator implements ValidatorAction {
|
||||
public class MoveToAggregatedUsageRecordIdAction implements FieldAction {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
|
@ -7,7 +7,7 @@ import java.io.Serializable;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
|
@ -15,7 +15,7 @@ import org.gcube.accounting.exception.InvalidValueException;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class MoveToOperationResultValidator implements ValidatorAction {
|
||||
public class MoveToOperationResultAction implements FieldAction {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
|
@ -4,12 +4,19 @@
|
|||
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.util.Calendar;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ComputedField;
|
||||
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.MoveToOperationResult;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
||||
|
@ -39,9 +46,9 @@ public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord
|
|||
public static final String JOB_QUALIFIER = "jobQualifier";
|
||||
@RequiredField @NotEmpty
|
||||
public static final String JOB_NAME = "jobName";
|
||||
@RequiredField @ValidLong
|
||||
@RequiredField @ValidLong @CalculateWallDuration
|
||||
public static final String JOB_START_TIME = "jobStartTime";
|
||||
@RequiredField @ValidLong
|
||||
@RequiredField @ValidLong @CalculateWallDuration
|
||||
public static final String JOB_END_TIME = "jobEndTime";
|
||||
|
||||
@ValidOperationResult @MoveToOperationResult
|
||||
|
@ -49,9 +56,41 @@ public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord
|
|||
|
||||
@ValidInteger
|
||||
public static final String VMS_USED = "vmsUsed";
|
||||
@ComputedField @ValidLong
|
||||
@ComputedField @ValidLong @CalculateWallDuration
|
||||
protected static final String WALL_DURATION = "wallDuration";
|
||||
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@FieldDecorator(managed=CalculateWallDurationAction.class)
|
||||
protected @interface CalculateWallDuration {
|
||||
|
||||
}
|
||||
|
||||
protected class CalculateWallDurationAction implements FieldAction {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
|
||||
try {
|
||||
long wallDuration = calculateWallDuration();
|
||||
if(key.compareTo(WALL_DURATION)==0){
|
||||
value = wallDuration;
|
||||
}
|
||||
}catch(InvalidValueException e){
|
||||
if(key.compareTo(WALL_DURATION)==0){
|
||||
throw new InvalidValueException(String.format("Unable to set %s. %s and %s MUST be set before.", WALL_DURATION,
|
||||
JOB_START_TIME, JOB_END_TIME));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public JobUsageRecord(){
|
||||
super();
|
||||
}
|
||||
|
@ -129,22 +168,25 @@ public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord
|
|||
setResourceProperty(VMS_USED, vmsUsed);
|
||||
}
|
||||
|
||||
protected void calculateWallDuration() throws InvalidValueException {
|
||||
protected long calculateWallDuration() throws InvalidValueException {
|
||||
try {
|
||||
long endTime = (Long) this.resourceProperties.get(JOB_END_TIME);
|
||||
long startTime = (Long) this.resourceProperties.get(JOB_START_TIME);
|
||||
long wallDuration = endTime - startTime;
|
||||
setResourceProperty(WALL_DURATION, wallDuration);
|
||||
return wallDuration;
|
||||
}catch(Exception e){
|
||||
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
|
||||
START_TIME, END_TIME), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public long getWallDuration() throws InvalidValueException {
|
||||
public long getWallDuration() {
|
||||
Long wallDuration = (Long) this.resourceProperties.get(WALL_DURATION);
|
||||
if(wallDuration == null){
|
||||
calculateWallDuration();
|
||||
try {
|
||||
wallDuration = calculateWallDuration();
|
||||
} catch(Exception e){}
|
||||
}
|
||||
return wallDuration;
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ public class ServiceUsageRecord extends RawUsageRecord implements SingleUsageRec
|
|||
protected static final String INVOCATION_COUNT = "invocationCount";
|
||||
@ValidInteger @AggregatedField
|
||||
protected static final String AVERAGE_INVOCATION_COUNT = "averageInvocationTime";
|
||||
@NotEmpty
|
||||
@RequiredField @NotEmpty
|
||||
public static final String SERVICE_CLASS = "serviceClass";
|
||||
@NotEmpty
|
||||
@RequiredField @NotEmpty
|
||||
public static final String SERVICE_NAME = "serviceName";
|
||||
|
||||
public ServiceUsageRecord(){
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.NotEmptyValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=NotEmptyValidator.class)
|
||||
@FieldDecorator(managed=NotEmptyValidator.class)
|
||||
public @interface NotEmpty {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=NotEmptyIfNotNullValidator.class)
|
||||
@FieldDecorator(managed=NotEmptyIfNotNullValidator.class)
|
||||
public @interface NotEmptyIfNotNull {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.NotNullValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=NotNullValidator.class)
|
||||
@FieldDecorator(managed=NotNullValidator.class)
|
||||
public @interface NotNull {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidIPValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=ValidIPValidator.class)
|
||||
@FieldDecorator(managed=ValidIPValidator.class)
|
||||
public @interface ValidIP {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidIntegerValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=ValidIntegerValidator.class)
|
||||
@FieldDecorator(managed=ValidIntegerValidator.class)
|
||||
public @interface ValidInteger {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidLongValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=ValidLongValidator.class)
|
||||
@FieldDecorator(managed=ValidLongValidator.class)
|
||||
public @interface ValidLong {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=ValidOperationResultValidator.class)
|
||||
@FieldDecorator(managed=ValidOperationResultValidator.class)
|
||||
public @interface ValidOperationResult {
|
||||
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import java.io.Serializable;
|
|||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
public class NotEmptyValidator implements ValidatorAction{
|
||||
public class NotEmptyValidator implements FieldAction{
|
||||
|
||||
private static final String ERROR = "Is Empty";
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ package org.gcube.accounting.datamodel.validations.validators;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
public class NotNullValidator implements ValidatorAction {
|
||||
public class NotNullValidator implements FieldAction {
|
||||
|
||||
private static final String ERROR = "Is Null";
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ValidIPValidator implements ValidatorAction{
|
||||
public class ValidIPValidator implements FieldAction{
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ValidIPValidator.class);
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ package org.gcube.accounting.datamodel.validations.validators;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
|
||||
public class ValidIntegerValidator implements ValidatorAction {
|
||||
public class ValidIntegerValidator implements FieldAction {
|
||||
|
||||
private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName());
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ package org.gcube.accounting.datamodel.validations.validators;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
|
||||
public class ValidLongValidator implements ValidatorAction {
|
||||
public class ValidLongValidator implements FieldAction {
|
||||
|
||||
private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName());
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ import java.io.Serializable;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
public class ValidOperationResultValidator implements ValidatorAction {
|
||||
public class ValidOperationResultValidator implements FieldAction {
|
||||
|
||||
private static final String ERROR = String.format("Not Instance of %s", OperationResult.class.getSimpleName());
|
||||
|
||||
|
|
|
@ -87,29 +87,35 @@ public abstract class Persistence {
|
|||
}
|
||||
}
|
||||
|
||||
public static UsageRecord createTestRawUsageRecord(){
|
||||
UsageRecord usageRecord = new ServiceUsageRecord();
|
||||
public static UsageRecord createTestUsageRecord(){
|
||||
ServiceUsageRecord serviceUsageRecord = new ServiceUsageRecord();
|
||||
try {
|
||||
usageRecord.setCreatorId("accounting");
|
||||
usageRecord.setConsumerId("accounting");
|
||||
serviceUsageRecord.setCreatorId("accounting");
|
||||
serviceUsageRecord.setConsumerId("accounting");
|
||||
|
||||
usageRecord.setResourceScope("/gcube/devsec");
|
||||
serviceUsageRecord.setResourceScope("/gcube/devsec");
|
||||
|
||||
Calendar creatingTime = new GregorianCalendar();
|
||||
//Calendar startTime = new GregorianCalendar();
|
||||
//Calendar endTime = new GregorianCalendar();
|
||||
|
||||
usageRecord.setCreationTime(creatingTime);
|
||||
serviceUsageRecord.setCreationTime(creatingTime);
|
||||
//usageRecord.setStartTime(startTime);
|
||||
//usageRecord.setEndTime(endTime);
|
||||
|
||||
usageRecord.setResourceProperty("ConnectionTest", "Test");
|
||||
serviceUsageRecord.setResourceProperty("ConnectionTest", "Test");
|
||||
|
||||
serviceUsageRecord.setServiceClass("Accounting");
|
||||
serviceUsageRecord.setServiceName("Accounting-Lib");
|
||||
serviceUsageRecord.setRefHost("localhost");
|
||||
serviceUsageRecord.setRefVM("local");
|
||||
serviceUsageRecord.setCallerScope("/gcube/devsec");
|
||||
|
||||
} catch (InvalidValueException e1) {
|
||||
|
||||
}
|
||||
|
||||
return usageRecord;
|
||||
return serviceUsageRecord;
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,7 +152,7 @@ public abstract class Persistence {
|
|||
*/
|
||||
public void connect() throws Exception {
|
||||
prepareConnection();
|
||||
this.account(createTestRawUsageRecord());
|
||||
this.account(createTestUsageRecord());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ public class RawUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToSameObject(){
|
||||
UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
UsageRecord ur = usageRecord;
|
||||
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
||||
|
@ -23,7 +23,7 @@ public class RawUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToEqualsObject() throws Exception {
|
||||
UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
UsageRecord ur = RawUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
|
||||
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
||||
|
@ -31,7 +31,7 @@ public class RawUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToComparedAddedProperty() throws Exception {
|
||||
UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
UsageRecord ur = RawUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
|
||||
for(int i=1; i<31; i++){
|
||||
ur.setResourceProperty(Integer.toString(i), i);
|
||||
|
@ -42,7 +42,7 @@ public class RawUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToDifferentForAddedProperties() throws Exception {
|
||||
UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
UsageRecord ur = RawUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
|
||||
usageRecord.setResourceProperty(Integer.toString(1), 2);
|
||||
ur.setResourceProperty(Integer.toString(2), 2);
|
||||
|
@ -52,8 +52,8 @@ public class RawUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToDifferentFromCreation() throws Exception {
|
||||
UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord ur = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
UsageRecord ur = Persistence.createTestUsageRecord();
|
||||
Assert.assertEquals(1, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(1, ur.compareTo(usageRecord));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CouchDBPersistenceTest {
|
|||
|
||||
@Test
|
||||
public void TestJsonNodeUsageRecordConversions() throws Exception {
|
||||
UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
logger.debug("UsageRecord : {}", usageRecord.toString());
|
||||
JsonNode node = CouchDBPersistence.usageRecordToJsonNode(usageRecord);
|
||||
logger.debug("Node : {}", node.toString());
|
||||
|
|
|
@ -33,7 +33,7 @@ public class PersistenceTest {
|
|||
int quantity = 3000;
|
||||
Calendar startTestTime = new GregorianCalendar();
|
||||
for(int i=0; i< quantity; i++){
|
||||
UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
|
||||
UsageRecord usageRecord = Persistence.createTestUsageRecord();
|
||||
persistence.account(usageRecord);
|
||||
}
|
||||
Calendar stopTestTime = new GregorianCalendar();
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="org.gcube" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue