refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Fixing validators git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115165 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8f4642f0ae
commit
7203fafe17
|
@ -18,7 +18,7 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.accounting.datamodel.validators.NotEmptyIfNotNull;
|
||||
import org.gcube.accounting.datamodel.validators.ValidTime;
|
||||
import org.gcube.accounting.datamodel.validators.ValidLong;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.FieldValidator;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
@ -40,11 +40,11 @@ public class RawUsageRecord implements UsageRecord, Serializable {
|
|||
public static final String CREATOR_ID = "creatorId";
|
||||
@NotEmpty
|
||||
public static final String CONSUMER_ID = "consumerId";
|
||||
@ValidTime
|
||||
@ValidLong
|
||||
public static final String CREATION_TIME = "creationTime";
|
||||
@ValidTime
|
||||
@ValidLong
|
||||
public static final String START_TIME = "startTime";
|
||||
@ValidTime
|
||||
@ValidLong
|
||||
public static final String END_TIME = "endTime";
|
||||
@NotEmpty
|
||||
public static final String RESOURCE_TYPE = "resourceType";
|
||||
|
|
|
@ -6,7 +6,8 @@ package org.gcube.accounting.datamodel.implementations;
|
|||
import java.util.Calendar;
|
||||
|
||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validators.ValidTime;
|
||||
import org.gcube.accounting.datamodel.validators.ValidInteger;
|
||||
import org.gcube.accounting.datamodel.validators.ValidLong;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -31,15 +32,15 @@ public class JobUsageRecord extends RawUsageRecord {
|
|||
public static final String JOB_QUALIFIER = "jobQualifier";
|
||||
@NotEmpty
|
||||
public static final String JOB_NAME = "jobName";
|
||||
@ValidTime
|
||||
@ValidLong
|
||||
public static final String JOB_START_TIME = "jobStartTime";
|
||||
@ValidTime
|
||||
@ValidLong
|
||||
public static final String JOB_END_TIME = "jobEndTime";
|
||||
@NotEmpty
|
||||
public static final String JOB_STATUS = "jobStatus";
|
||||
|
||||
@ValidInteger
|
||||
public static final String VMS_USED = "vmsUsed";
|
||||
|
||||
@ValidLong
|
||||
public static final String WALL_DURATION = "wallDuration";
|
||||
|
||||
public JobUsageRecord(){
|
||||
|
|
|
@ -20,7 +20,6 @@ public class PortletUsageRecord extends RawUsageRecord {
|
|||
|
||||
@NotEmpty
|
||||
public static final String USER_ID = "userId";
|
||||
|
||||
@NotEmpty
|
||||
public static final String OPERATION_ID = "operationId";
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ package org.gcube.accounting.datamodel.implementations;
|
|||
|
||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validators.ValidIP;
|
||||
import org.gcube.accounting.datamodel.validators.ValidInteger;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -30,8 +31,10 @@ public class ServiceUsageRecord extends RawUsageRecord {
|
|||
@NotEmpty
|
||||
public static final String DOMAIN = "domain";
|
||||
//@Aggregated
|
||||
@ValidInteger
|
||||
public static final String INVOCATION_COUNT = "invocationCount";
|
||||
//@Aggregated
|
||||
@ValidInteger
|
||||
public static final String AVERAGE_INVOCATION_COUNT = "averageInvocationTime";
|
||||
@NotEmpty
|
||||
public static final String SERVICE_CLASS = "serviceClass";
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
package org.gcube.accounting.datamodel.implementations;
|
||||
|
||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validators.ValidInteger;
|
||||
import org.gcube.accounting.datamodel.validators.ValidLong;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -24,9 +26,9 @@ public class StorageStatusUsageRecord extends RawUsageRecord {
|
|||
public static final String QUALIFIER = "qualifier";
|
||||
@NotEmpty
|
||||
public static final String DATA_TYPE = "dataType";
|
||||
|
||||
@ValidLong
|
||||
public static final String DATA_VOLUME = "dataVolume";
|
||||
|
||||
@ValidInteger
|
||||
public static final String DATA_COUNT = "dataCount";
|
||||
|
||||
public StorageStatusUsageRecord(){
|
||||
|
@ -57,19 +59,19 @@ public class StorageStatusUsageRecord extends RawUsageRecord {
|
|||
setResourceSpecificProperty(DATA_TYPE, dataType);
|
||||
}
|
||||
|
||||
public String getDataVolume() {
|
||||
return (String) this.resourceSpecificProperties.get(DATA_VOLUME);
|
||||
public long getDataVolume() {
|
||||
return (Long) this.resourceSpecificProperties.get(DATA_VOLUME);
|
||||
}
|
||||
|
||||
public void setDataVolume(String dataVolume) throws InvalidValueException {
|
||||
public void setDataVolume(long dataVolume) throws InvalidValueException {
|
||||
setResourceSpecificProperty(DATA_VOLUME, dataVolume);
|
||||
}
|
||||
|
||||
public String getDataCount() {
|
||||
return (String) this.resourceSpecificProperties.get(DATA_COUNT);
|
||||
public int getDataCount() {
|
||||
return (Integer) this.resourceSpecificProperties.get(DATA_COUNT);
|
||||
}
|
||||
|
||||
public void setDataCount(String dataCount) throws InvalidValueException {
|
||||
public void setDataCount(int dataCount) throws InvalidValueException {
|
||||
setResourceSpecificProperty(DATA_COUNT, dataCount);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ package org.gcube.accounting.datamodel.implementations;
|
|||
import java.util.Calendar;
|
||||
|
||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validators.ValidTime;
|
||||
import org.gcube.accounting.datamodel.validators.ValidInteger;
|
||||
import org.gcube.accounting.datamodel.validators.ValidLong;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -33,27 +34,27 @@ public class TaskUsageRecord extends RawUsageRecord {
|
|||
public static final String REF_VM = "refVM";
|
||||
@NotEmpty
|
||||
public static final String DOMAIN = "domain";
|
||||
@ValidTime
|
||||
@ValidLong
|
||||
public static final String USAGE_START_TIME = "usageStartTime";
|
||||
@ValidTime
|
||||
@ValidLong
|
||||
public static final String USAGE_END_TIME = "usageEndTime";
|
||||
@NotEmpty
|
||||
public static final String USAGE_PHASE = "usagePhase";
|
||||
|
||||
@ValidInteger
|
||||
public static final String INPUT_FILES_NUMBER = "inputFilesNumber";
|
||||
|
||||
@ValidLong
|
||||
public static final String INPUT_FILES_SIZE = "inputFilesSize";
|
||||
|
||||
@ValidInteger
|
||||
public static final String OUTPUT_FILES_NUMBER = "outputFilesNumber";
|
||||
|
||||
@ValidLong
|
||||
public static final String OUTPUT_FILES_SIZE = "outputFilesSize";
|
||||
|
||||
@ValidLong
|
||||
public static final String OVERALL_NETWORK_IN = "overallNetworkIn";
|
||||
|
||||
@ValidLong
|
||||
public static final String OVERALL_NETWORK_OUT = "overallNetworkOut";
|
||||
|
||||
@ValidInteger
|
||||
public static final String CORES = "cores";
|
||||
|
||||
@ValidInteger
|
||||
public static final String PROCESSORS = "processors";
|
||||
|
||||
|
||||
|
|
|
@ -3,17 +3,16 @@ package org.gcube.accounting.datamodel.validators;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.common.validator.annotations.FieldValidator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ValidIPValidator implements FieldValidator<ValidTime>{
|
||||
public class ValidIPValidator implements FieldValidator<ValidLong>{
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ValidIPValidator.class);
|
||||
|
||||
public Class<ValidTime> annotation() {
|
||||
return ValidTime.class;
|
||||
public Class<ValidLong> annotation() {
|
||||
return ValidLong.class;
|
||||
}
|
||||
|
||||
private static Pattern IPV4_PATTERN = null;
|
||||
|
@ -51,7 +50,7 @@ public class ValidIPValidator implements FieldValidator<ValidTime>{
|
|||
}
|
||||
|
||||
public String getErrorSuffix() {
|
||||
return String.format("not instace of %s", UsageRecord.class.getSimpleName());
|
||||
return "not valid IP Address";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.accounting.datamodel.validators;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.common.validator.annotations.ValidityChecker;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidityChecker(managed=ValidIntegerValidator.class)
|
||||
public @interface ValidInteger {
|
||||
|
||||
}
|
|
@ -3,21 +3,21 @@ package org.gcube.accounting.datamodel.validators;
|
|||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.common.validator.annotations.FieldValidator;
|
||||
|
||||
public class ValidTimeValidator implements FieldValidator<ValidTime>{
|
||||
public class ValidIntegerValidator implements FieldValidator<ValidLong>{
|
||||
|
||||
public Class<ValidTime> annotation() {
|
||||
return ValidTime.class;
|
||||
public Class<ValidLong> annotation() {
|
||||
return ValidLong.class;
|
||||
}
|
||||
|
||||
public boolean isValid(Object toValidate) {
|
||||
if(toValidate instanceof Long){
|
||||
if(toValidate instanceof Integer){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getErrorSuffix() {
|
||||
return String.format("not instace of %s", UsageRecord.class.getSimpleName());
|
||||
return String.format("not instace of %s", Integer.class.getSimpleName());
|
||||
}
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ import org.gcube.common.validator.annotations.ValidityChecker;
|
|||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidityChecker(managed=ValidTimeValidator.class)
|
||||
public @interface ValidTime {
|
||||
@ValidityChecker(managed=ValidLongValidator.class)
|
||||
public @interface ValidLong {
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.accounting.datamodel.validators;
|
||||
|
||||
import org.gcube.common.validator.annotations.FieldValidator;
|
||||
|
||||
public class ValidLongValidator implements FieldValidator<ValidLong>{
|
||||
|
||||
public Class<ValidLong> annotation() {
|
||||
return ValidLong.class;
|
||||
}
|
||||
|
||||
public boolean isValid(Object toValidate) {
|
||||
if(toValidate instanceof Long){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getErrorSuffix() {
|
||||
return String.format("not instace of %s", Long.class.getSimpleName());
|
||||
}
|
||||
|
||||
}
|
|
@ -13,14 +13,14 @@ public class ValidTimeValidatorTest {
|
|||
|
||||
@Test
|
||||
public void testPrimitiveLong(){
|
||||
ValidTimeValidator validTimeValidator = new ValidTimeValidator();
|
||||
ValidLongValidator validTimeValidator = new ValidLongValidator();
|
||||
long myLong = 4;
|
||||
validTimeValidator.isValid(myLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassLong(){
|
||||
ValidTimeValidator validTimeValidator = new ValidTimeValidator();
|
||||
ValidLongValidator validTimeValidator = new ValidLongValidator();
|
||||
Long myLong = new Long(4);
|
||||
validTimeValidator.isValid(myLong);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue