Improving Model
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@122578 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1a48e45faa
commit
9050adfdd1
|
@ -8,13 +8,11 @@ import java.util.Calendar;
|
||||||
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.MoveToOperationResult;
|
|
||||||
import org.gcube.documentstore.exception.InvalidValueException;
|
import org.gcube.documentstore.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.AggregatedRecord;
|
|
||||||
import org.gcube.documentstore.records.implementation.ComputedField;
|
import org.gcube.documentstore.records.implementation.ComputedField;
|
||||||
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;
|
||||||
import org.gcube.documentstore.records.implementation.validations.annotations.ValidInteger;
|
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull;
|
||||||
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
|
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,21 +28,19 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
@RequiredField @NotEmpty
|
@RequiredField @NotEmpty
|
||||||
public static final String JOB_ID = "jobId";
|
public static final String JOB_ID = "jobId";
|
||||||
@RequiredField @NotEmpty
|
|
||||||
public static final String JOB_QUALIFIER = "jobQualifier";
|
|
||||||
@RequiredField @NotEmpty
|
|
||||||
public static final String JOB_NAME = "jobName";
|
|
||||||
@RequiredField @ValidLong @CalculateWallDuration
|
|
||||||
public static final String JOB_START_TIME = "jobStartTime";
|
|
||||||
@RequiredField @ValidLong @CalculateWallDuration
|
|
||||||
public static final String JOB_END_TIME = "jobEndTime";
|
|
||||||
@MoveToOperationResult @Deprecated
|
|
||||||
protected static final String JOB_STATUS = "jobStatus";
|
|
||||||
@ValidInteger
|
|
||||||
public static final String VMS_USED = "vmsUsed";
|
|
||||||
|
|
||||||
@ComputedField @ValidLong @CalculateWallDuration
|
@NotEmptyIfNotNull
|
||||||
protected static final String WALL_DURATION = "wallDuration";
|
public static final String JOB_NAME = "jobName";
|
||||||
|
@NotEmptyIfNotNull
|
||||||
|
public static final String JOB_QUALIFIER = "jobQualifier";
|
||||||
|
|
||||||
|
@RequiredField @ValidLong @CalculateJobWallDuration
|
||||||
|
public static final String JOB_START_TIME = "jobStartTime";
|
||||||
|
@RequiredField @ValidLong @CalculateJobWallDuration
|
||||||
|
public static final String JOB_END_TIME = "jobEndTime";
|
||||||
|
@RequiredField @ValidLong @CalculateJobWallDuration @ComputedField
|
||||||
|
protected static final String WALL_DURATION = "_wallDuration";
|
||||||
|
|
||||||
|
|
||||||
public AbstractJobUsageRecord(){
|
public AbstractJobUsageRecord(){
|
||||||
super();
|
super();
|
||||||
|
@ -112,14 +108,6 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
||||||
public void setJobEndTime(Calendar jobEndTime) throws InvalidValueException {
|
public void setJobEndTime(Calendar jobEndTime) throws InvalidValueException {
|
||||||
setResourceProperty(JOB_END_TIME, jobEndTime.getTimeInMillis());
|
setResourceProperty(JOB_END_TIME, jobEndTime.getTimeInMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVmsUsed() {
|
|
||||||
return (Integer) this.resourceProperties.get(VMS_USED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVmsUsed(int vmsUsed) throws InvalidValueException {
|
|
||||||
setResourceProperty(VMS_USED, vmsUsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected long calculateWallDuration() throws InvalidValueException {
|
protected long calculateWallDuration() throws InvalidValueException {
|
||||||
try {
|
try {
|
||||||
|
@ -129,7 +117,7 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
||||||
return wallDuration;
|
return wallDuration;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
|
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
|
||||||
AggregatedRecord.START_TIME, AggregatedRecord.END_TIME), e);
|
JOB_START_TIME, JOB_END_TIME), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,11 @@ import java.util.Calendar;
|
||||||
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.MoveToOperationResult;
|
|
||||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToTaskEndTime;
|
|
||||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToTaskStartTime;
|
|
||||||
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.ComputedField;
|
||||||
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;
|
||||||
import org.gcube.documentstore.records.implementation.validations.annotations.ValidInteger;
|
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull;
|
||||||
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
|
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,45 +26,26 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -2208425042550641240L;
|
private static final long serialVersionUID = -2208425042550641240L;
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
public static final String TASK_ID = "taskId";
|
||||||
|
@NotEmptyIfNotNull
|
||||||
|
public static final String REF_JOB_ID = "refJobId";
|
||||||
|
|
||||||
@RequiredField @NotEmpty
|
@RequiredField @NotEmpty
|
||||||
public static final String JOB_ID = "jobId";
|
public static final String HOST = "host";
|
||||||
@RequiredField @NotEmpty
|
@NotEmptyIfNotNull
|
||||||
public static final String REF_HOST = "refHost";
|
public static final String REF_HOSTING_NODE = "refHostingNode";
|
||||||
@RequiredField @NotEmpty
|
|
||||||
public static final String REF_VM = "refVM";
|
|
||||||
|
|
||||||
@Deprecated @NotEmpty @DeprecatedWarning
|
@RequiredField @ValidLong @CalculateTaskWallDuration
|
||||||
protected static final String DOMAIN = "domain";
|
|
||||||
|
|
||||||
@Deprecated @DeprecatedWarning @MoveToTaskStartTime
|
|
||||||
protected static final String USAGE_START_TIME = "usageStartTime";
|
|
||||||
@Deprecated @DeprecatedWarning @MoveToTaskEndTime
|
|
||||||
protected static final String USAGE_END_TIME = "usageEndTime";
|
|
||||||
|
|
||||||
@Deprecated @MoveToOperationResult @DeprecatedWarning
|
|
||||||
protected static final String USAGE_PHASE = "usagePhase";
|
|
||||||
|
|
||||||
@RequiredField @ValidLong
|
|
||||||
public static final String TASK_START_TIME = "taskStartTime";
|
public static final String TASK_START_TIME = "taskStartTime";
|
||||||
@RequiredField @ValidLong
|
@RequiredField @ValidLong @CalculateTaskWallDuration
|
||||||
public static final String TASK_END_TIME = "taskEndTime";
|
public static final String TASK_END_TIME = "taskEndTime";
|
||||||
|
|
||||||
@Deprecated @ValidInteger @DeprecatedWarning
|
@RequiredField @ValidLong @CalculateTaskWallDuration @ComputedField
|
||||||
protected static final String INPUT_FILES_NUMBER = "inputFilesNumber";
|
protected static final String WALL_DURATION = "wallDuration";
|
||||||
@Deprecated @ValidLong @DeprecatedWarning
|
|
||||||
protected static final String INPUT_FILES_SIZE = "inputFilesSize";
|
@RequiredField //@ValidMap
|
||||||
@Deprecated @ValidInteger @DeprecatedWarning
|
public static final String INPUT_PARAMETERS = "inputParameters";
|
||||||
protected static final String OUTPUT_FILES_NUMBER = "outputFilesNumber";
|
|
||||||
@Deprecated @ValidLong @DeprecatedWarning
|
|
||||||
protected static final String OUTPUT_FILES_SIZE = "outputFilesSize";
|
|
||||||
@Deprecated @ValidLong @DeprecatedWarning
|
|
||||||
protected static final String OVERALL_NETWORK_IN = "overallNetworkIn";
|
|
||||||
@Deprecated @ValidLong @DeprecatedWarning
|
|
||||||
protected static final String OVERALL_NETWORK_OUT = "overallNetworkOut";
|
|
||||||
@Deprecated @ValidInteger @DeprecatedWarning
|
|
||||||
protected static final String CORES = "cores";
|
|
||||||
@Deprecated @ValidInteger @DeprecatedWarning
|
|
||||||
protected static final String PROCESSORS = "processors";
|
|
||||||
|
|
||||||
public AbstractTaskUsageRecord(){
|
public AbstractTaskUsageRecord(){
|
||||||
super();
|
super();
|
||||||
|
@ -88,57 +66,51 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the Job Id
|
* @return the Task Id
|
||||||
*/
|
*/
|
||||||
public String getJobId() {
|
public String getTaskId() {
|
||||||
return (String) this.resourceProperties.get(JOB_ID);
|
return (String) this.resourceProperties.get(TASK_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param jobId Job Id
|
* @param taskId Task Id
|
||||||
* @throws InvalidValueException if fails
|
* @throws InvalidValueException if fails
|
||||||
*/
|
*/
|
||||||
public void setJobId(String jobId) throws InvalidValueException {
|
public void setTaskId(String taskId) throws InvalidValueException {
|
||||||
setResourceProperty(JOB_ID, jobId);
|
setResourceProperty(TASK_ID, taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRefHost() {
|
/**
|
||||||
return (String) this.resourceProperties.get(REF_HOST);
|
* @return the Referenced Job Id
|
||||||
|
*/
|
||||||
|
public String getRefJobId() {
|
||||||
|
return (String) this.resourceProperties.get(REF_JOB_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRefHost(String refHost) throws InvalidValueException {
|
/**
|
||||||
setResourceProperty(REF_HOST, refHost);
|
* @param refJobId Referenced Job Id
|
||||||
}
|
* @throws InvalidValueException if fails
|
||||||
|
*/
|
||||||
public String getRefVM() {
|
public void setRefJobId(String refJobId) throws InvalidValueException {
|
||||||
return (String) this.resourceProperties.get(REF_VM);
|
setResourceProperty(REF_JOB_ID, refJobId);
|
||||||
}
|
|
||||||
|
|
||||||
public void setRefVM(String refVM) throws InvalidValueException {
|
|
||||||
setResourceProperty(REF_VM, refVM);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Calendar getUsageStartTime() {
|
|
||||||
long millis = (Long) this.resourceProperties.get(USAGE_START_TIME);
|
|
||||||
return timestampToCalendar(millis);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setUsageStartTime(Calendar usageStartTime) throws InvalidValueException {
|
|
||||||
setResourceProperty(USAGE_START_TIME, usageStartTime.getTimeInMillis());
|
|
||||||
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public Calendar getUsageEndTime() {
|
|
||||||
long millis = (Long) this.resourceProperties.get(USAGE_END_TIME);
|
|
||||||
return timestampToCalendar(millis);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setUsageEndTime(Calendar usageEndTime) throws InvalidValueException {
|
|
||||||
setResourceProperty(USAGE_END_TIME, usageEndTime.getTimeInMillis());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return (String) this.resourceProperties.get(HOST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefHost(String host) throws InvalidValueException {
|
||||||
|
setResourceProperty(HOST, host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRefHostingNode() {
|
||||||
|
return (String) this.resourceProperties.get(REF_HOSTING_NODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefHostingNode(String refHostingNode) throws InvalidValueException {
|
||||||
|
setResourceProperty(REF_HOSTING_NODE, refHostingNode);
|
||||||
|
}
|
||||||
|
|
||||||
public Calendar getTaskStartTime() {
|
public Calendar getTaskStartTime() {
|
||||||
long millis = (Long) this.resourceProperties.get(TASK_START_TIME);
|
long millis = (Long) this.resourceProperties.get(TASK_START_TIME);
|
||||||
return timestampToCalendar(millis);
|
return timestampToCalendar(millis);
|
||||||
|
@ -156,82 +128,40 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
||||||
|
|
||||||
public void setTaskEndTime(Calendar endTime) throws InvalidValueException {
|
public void setTaskEndTime(Calendar endTime) throws InvalidValueException {
|
||||||
setResourceProperty(TASK_END_TIME, endTime.getTimeInMillis());
|
setResourceProperty(TASK_END_TIME, endTime.getTimeInMillis());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
protected long calculateWallDuration() throws InvalidValueException {
|
||||||
public USAGE_PHASE getUsagePhase() {
|
try {
|
||||||
return (USAGE_PHASE) this.resourceProperties.get(USAGE_PHASE);
|
long endTime = (Long) this.resourceProperties.get(TASK_END_TIME);
|
||||||
|
long startTime = (Long) this.resourceProperties.get(TASK_START_TIME);
|
||||||
|
long wallDuration = endTime - startTime;
|
||||||
|
return wallDuration;
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
|
||||||
|
TASK_START_TIME, TASK_END_TIME), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsagePhase(USAGE_PHASE usagePhase) throws InvalidValueException {
|
|
||||||
setResourceProperty(USAGE_PHASE, usagePhase);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Deprecated
|
public long getWallDuration() throws InvalidValueException {
|
||||||
public int getInputFilesNumber() {
|
Long wallDuration = (Long) this.resourceProperties.get(WALL_DURATION);
|
||||||
return (Integer) this.resourceProperties.get(INPUT_FILES_NUMBER);
|
if(wallDuration == null){
|
||||||
|
try {
|
||||||
|
wallDuration = calculateWallDuration();
|
||||||
|
} catch(InvalidValueException e){
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wallDuration;
|
||||||
}
|
}
|
||||||
@Deprecated
|
|
||||||
public void setInputFilesNumber(int inputFilesNumber) throws InvalidValueException {
|
@SuppressWarnings("unchecked")
|
||||||
setResourceProperty(INPUT_FILES_NUMBER, inputFilesNumber);
|
public Map<String, Object> getInputParameters(){
|
||||||
|
return (Map<String, Object>) getResourceProperty(INPUT_PARAMETERS);
|
||||||
}
|
}
|
||||||
@Deprecated
|
|
||||||
public long getInputFilesSize() {
|
@SuppressWarnings("unchecked")
|
||||||
return (Long) this.resourceProperties.get(INPUT_FILES_SIZE);
|
public void setInputParameters(Map<String, Object> inputParameters) throws InvalidValueException{
|
||||||
}
|
setResourceProperty(INPUT_PARAMETERS, (Comparable<? extends Serializable>) inputParameters);
|
||||||
@Deprecated
|
|
||||||
public void setInputFilesSize(long inputFilesSize) throws InvalidValueException {
|
|
||||||
setResourceProperty(INPUT_FILES_SIZE, inputFilesSize);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public int getOutputFilesNumber() {
|
|
||||||
return (Integer) this.resourceProperties.get(OUTPUT_FILES_NUMBER);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setOutputFilesNumber(int outputFilesNumber) throws InvalidValueException {
|
|
||||||
setResourceProperty(OUTPUT_FILES_NUMBER, outputFilesNumber);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public long getOutputFilesSize() {
|
|
||||||
return (Long) this.resourceProperties.get(OUTPUT_FILES_SIZE);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setOutputFilesSize(long outputFilesSize) throws InvalidValueException {
|
|
||||||
setResourceProperty(OUTPUT_FILES_SIZE, outputFilesSize);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public long getOverallNetworkIn() {
|
|
||||||
return (Long) this.resourceProperties.get(OVERALL_NETWORK_IN);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setOverallNetworkIn(long overallNetworkIn) throws InvalidValueException {
|
|
||||||
setResourceProperty(OVERALL_NETWORK_IN, overallNetworkIn);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public long getOverallNetworkOut() {
|
|
||||||
return (Long) this.resourceProperties.get(OVERALL_NETWORK_OUT);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setOverallNetworkOut(long overallNetworkOut) throws InvalidValueException {
|
|
||||||
setResourceProperty(OVERALL_NETWORK_OUT, overallNetworkOut);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public int getCores() {
|
|
||||||
return (Integer) this.resourceProperties.get(CORES);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setCores(int cores) throws InvalidValueException {
|
|
||||||
setResourceProperty(CORES, cores);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public int getProcessors() {
|
|
||||||
return (Integer) this.resourceProperties.get(PROCESSORS);
|
|
||||||
}
|
|
||||||
@Deprecated
|
|
||||||
public void setProcessors(int processors) throws InvalidValueException {
|
|
||||||
setResourceProperty(PROCESSORS, processors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,5 @@ import org.gcube.documentstore.records.implementation.FieldDecorator;
|
||||||
|
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@FieldDecorator(action=CalculateWallDurationAction.class)
|
@FieldDecorator(action=CalculateJobWallDurationAction.class)
|
||||||
public @interface CalculateWallDuration {}
|
public @interface CalculateJobWallDuration {}
|
|
@ -11,9 +11,9 @@ import org.gcube.documentstore.records.implementation.FieldAction;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class CalculateWallDurationAction implements FieldAction {
|
public class CalculateJobWallDurationAction implements FieldAction {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CalculateWallDurationAction.class);
|
private static final Logger logger = LoggerFactory.getLogger(CalculateJobWallDurationAction.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
|
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
|
|
@ -0,0 +1,16 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.datamodel.basetypes;
|
||||||
|
|
||||||
|
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=CalculateTaskWallDurationAction.class)
|
||||||
|
public @interface CalculateTaskWallDuration {}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.datamodel.basetypes;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.gcube.documentstore.exception.InvalidValueException;
|
||||||
|
import org.gcube.documentstore.records.Record;
|
||||||
|
import org.gcube.documentstore.records.implementation.FieldAction;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class CalculateTaskWallDurationAction implements FieldAction {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(CalculateTaskWallDurationAction.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
|
||||||
|
try {
|
||||||
|
long wallDuration = ((AbstractTaskUsageRecord) record).calculateWallDuration();
|
||||||
|
if(key.compareTo(AbstractTaskUsageRecord.WALL_DURATION)==0){
|
||||||
|
logger.warn("{} is automatically computed using {} and {}. This invocation has the only effect of recalculating the value. Any provided value is ignored.",
|
||||||
|
AbstractTaskUsageRecord.WALL_DURATION, AbstractTaskUsageRecord.TASK_START_TIME, AbstractTaskUsageRecord.TASK_END_TIME);
|
||||||
|
value = wallDuration;
|
||||||
|
}
|
||||||
|
}catch(InvalidValueException e){ }
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -196,7 +196,6 @@ public class TestUsageRecord {
|
||||||
usageRecord.setJobEndTime(endTime);
|
usageRecord.setJobEndTime(endTime);
|
||||||
|
|
||||||
usageRecord.setOperationResult(OperationResult.SUCCESS);
|
usageRecord.setOperationResult(OperationResult.SUCCESS);
|
||||||
usageRecord.setVmsUsed(TEST_VMS_USED);
|
|
||||||
|
|
||||||
} catch (InvalidValueException e) {
|
} catch (InvalidValueException e) {
|
||||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.gcube.accounting.datamodel.validations.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.validations.validators.ValidMapValidator;
|
||||||
|
import org.gcube.documentstore.records.implementation.FieldDecorator;
|
||||||
|
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@FieldDecorator(action=ValidMapValidator.class)
|
||||||
|
public @interface ValidMap {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.gcube.accounting.datamodel.validations.validators;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.documentstore.exception.InvalidValueException;
|
||||||
|
import org.gcube.documentstore.records.Record;
|
||||||
|
import org.gcube.documentstore.records.implementation.FieldAction;
|
||||||
|
|
||||||
|
public class ValidMapValidator implements FieldAction {
|
||||||
|
|
||||||
|
private static final String ERROR = String.format("This Map cannot be serilized properly");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(value instanceof Map){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new InvalidValueException(ERROR, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidValueException(ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue