refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Creating more validators git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115157 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1022ab01c9
commit
84181f9655
|
@ -6,6 +6,7 @@ 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.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -20,21 +21,25 @@ public class JobUsageRecord extends RawUsageRecord {
|
|||
*/
|
||||
private static final long serialVersionUID = -8648691183939346858L;
|
||||
|
||||
public static enum JOB_STATUS {
|
||||
completed, failed
|
||||
};
|
||||
|
||||
@NotEmpty
|
||||
public static final String JOB_ID = "jobId";
|
||||
@NotEmpty
|
||||
public static final String JOB_QUALIFIER = "jobQualifier";
|
||||
@NotEmpty
|
||||
public static final String JOB_NAME = "jobName";
|
||||
@NotEmpty
|
||||
@ValidTime
|
||||
public static final String JOB_START_TIME = "jobStartTime";
|
||||
@NotEmpty
|
||||
@ValidTime
|
||||
public static final String JOB_END_TIME = "jobEndTime";
|
||||
@NotEmpty
|
||||
public static final String JOB_STATUS = "jobStatus";
|
||||
@NotEmpty
|
||||
|
||||
public static final String VMS_USED = "vmsUsed";
|
||||
@NotEmpty
|
||||
|
||||
public static final String WALL_DURATION = "wallDuration";
|
||||
|
||||
public JobUsageRecord(){
|
||||
|
@ -92,11 +97,11 @@ public class JobUsageRecord extends RawUsageRecord {
|
|||
|
||||
}
|
||||
|
||||
public String getJobStatus() {
|
||||
return (String) this.resourceSpecificProperties.get(JOB_STATUS);
|
||||
public JOB_STATUS getJobStatus() {
|
||||
return (JOB_STATUS) this.resourceSpecificProperties.get(JOB_STATUS);
|
||||
}
|
||||
|
||||
public void setJobStatus(String jobStatus) throws InvalidValueException {
|
||||
public void setJobStatus(JOB_STATUS jobStatus) throws InvalidValueException {
|
||||
setResourceSpecificProperty(JOB_STATUS, jobStatus);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package org.gcube.accounting.datamodel.implementations;
|
||||
|
||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validators.ValidIP;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -18,7 +19,7 @@ public class ServiceUsageRecord extends RawUsageRecord {
|
|||
*/
|
||||
private static final long serialVersionUID = -4214891294699473587L;
|
||||
|
||||
@NotEmpty
|
||||
@ValidIP
|
||||
public static final String CALLER_IP = "callerIP";
|
||||
@NotEmpty
|
||||
public static final String CALLER_SCOPE = "callerScope";
|
||||
|
@ -28,9 +29,9 @@ public class ServiceUsageRecord extends RawUsageRecord {
|
|||
public static final String REF_VM = "refVM";
|
||||
@NotEmpty
|
||||
public static final String DOMAIN = "domain";
|
||||
@NotEmpty
|
||||
//@Aggregated
|
||||
public static final String INVOCATION_COUNT = "invocationCount";
|
||||
@NotEmpty
|
||||
//@Aggregated
|
||||
public static final String AVERAGE_INVOCATION_COUNT = "averageInvocationTime";
|
||||
@NotEmpty
|
||||
public static final String SERVICE_CLASS = "serviceClass";
|
||||
|
|
|
@ -24,9 +24,9 @@ public class StorageStatusUsageRecord extends RawUsageRecord {
|
|||
public static final String QUALIFIER = "qualifier";
|
||||
@NotEmpty
|
||||
public static final String DATA_TYPE = "dataType";
|
||||
@NotEmpty
|
||||
|
||||
public static final String DATA_VOLUME = "dataVolume";
|
||||
@NotEmpty
|
||||
|
||||
public static final String DATA_COUNT = "dataCount";
|
||||
|
||||
public StorageStatusUsageRecord(){
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package org.gcube.accounting.datamodel.implementations;
|
||||
|
||||
import org.gcube.accounting.datamodel.validators.ValidIP;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -21,7 +22,7 @@ public class StorageUsageRecord extends StorageStatusUsageRecord {
|
|||
public static final String OBJECT_URI = "objectURI";
|
||||
@NotEmpty
|
||||
public static final String OPERATION_TYPE = "operationType";
|
||||
@NotEmpty
|
||||
@ValidIP
|
||||
public static final String CALLER_IP = "callerIP";
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ 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.exception.InvalidValueException;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
|
@ -32,27 +33,27 @@ public class TaskUsageRecord extends RawUsageRecord {
|
|||
public static final String REF_VM = "refVM";
|
||||
@NotEmpty
|
||||
public static final String DOMAIN = "domain";
|
||||
@NotEmpty
|
||||
@ValidTime
|
||||
public static final String USAGE_START_TIME = "usageStartTime";
|
||||
@NotEmpty
|
||||
@ValidTime
|
||||
public static final String USAGE_END_TIME = "usageEndTime";
|
||||
@NotEmpty
|
||||
public static final String USAGE_PHASE = "usagePhase";
|
||||
@NotEmpty
|
||||
|
||||
public static final String INPUT_FILES_NUMBER = "inputFilesNumber";
|
||||
@NotEmpty
|
||||
|
||||
public static final String INPUT_FILES_SIZE = "inputFilesSize";
|
||||
@NotEmpty
|
||||
|
||||
public static final String OUTPUT_FILES_NUMBER = "outputFilesNumber";
|
||||
@NotEmpty
|
||||
|
||||
public static final String OUTPUT_FILES_SIZE = "outputFilesSize";
|
||||
@NotEmpty
|
||||
|
||||
public static final String OVERALL_NETWORK_IN = "overallNetworkIn";
|
||||
@NotEmpty
|
||||
|
||||
public static final String OVERALL_NETWORK_OUT = "overallNetworkOut";
|
||||
@NotEmpty
|
||||
|
||||
public static final String CORES = "cores";
|
||||
@NotEmpty
|
||||
|
||||
public static final String PROCESSORS = "processors";
|
||||
|
||||
|
||||
|
|
|
@ -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=ValidIPValidator.class)
|
||||
public @interface ValidIP {
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.gcube.accounting.datamodel.validators;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.common.validator.annotations.FieldValidator;
|
||||
|
||||
public class ValidIPValidator implements FieldValidator<ValidTime>{
|
||||
|
||||
public Class<ValidTime> annotation() {
|
||||
return ValidTime.class;
|
||||
}
|
||||
|
||||
public boolean isValid(Object toValidate) {
|
||||
if(toValidate instanceof String){
|
||||
// TODO Validate it
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getErrorSuffix() {
|
||||
return String.format("not instace of %s", UsageRecord.class.getSimpleName());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue