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 org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToOperationResult;
|
||||
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.RequiredField;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -30,21 +28,19 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
|||
|
||||
@RequiredField @NotEmpty
|
||||
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
|
||||
protected static final String WALL_DURATION = "wallDuration";
|
||||
@NotEmptyIfNotNull
|
||||
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(){
|
||||
super();
|
||||
|
@ -113,14 +109,6 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
|||
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 {
|
||||
try {
|
||||
long endTime = (Long) this.resourceProperties.get(JOB_END_TIME);
|
||||
|
@ -129,7 +117,7 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
|
|||
return wallDuration;
|
||||
}catch(Exception e){
|
||||
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 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.records.implementation.ComputedField;
|
||||
import org.gcube.documentstore.records.implementation.RequiredField;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -29,45 +26,26 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
|||
*/
|
||||
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
|
||||
public static final String JOB_ID = "jobId";
|
||||
@RequiredField @NotEmpty
|
||||
public static final String REF_HOST = "refHost";
|
||||
@RequiredField @NotEmpty
|
||||
public static final String REF_VM = "refVM";
|
||||
public static final String HOST = "host";
|
||||
@NotEmptyIfNotNull
|
||||
public static final String REF_HOSTING_NODE = "refHostingNode";
|
||||
|
||||
@Deprecated @NotEmpty @DeprecatedWarning
|
||||
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
|
||||
@RequiredField @ValidLong @CalculateTaskWallDuration
|
||||
public static final String TASK_START_TIME = "taskStartTime";
|
||||
@RequiredField @ValidLong
|
||||
@RequiredField @ValidLong @CalculateTaskWallDuration
|
||||
public static final String TASK_END_TIME = "taskEndTime";
|
||||
|
||||
@Deprecated @ValidInteger @DeprecatedWarning
|
||||
protected static final String INPUT_FILES_NUMBER = "inputFilesNumber";
|
||||
@Deprecated @ValidLong @DeprecatedWarning
|
||||
protected static final String INPUT_FILES_SIZE = "inputFilesSize";
|
||||
@Deprecated @ValidInteger @DeprecatedWarning
|
||||
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";
|
||||
@RequiredField @ValidLong @CalculateTaskWallDuration @ComputedField
|
||||
protected static final String WALL_DURATION = "wallDuration";
|
||||
|
||||
@RequiredField //@ValidMap
|
||||
public static final String INPUT_PARAMETERS = "inputParameters";
|
||||
|
||||
public AbstractTaskUsageRecord(){
|
||||
super();
|
||||
|
@ -88,55 +66,49 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the Job Id
|
||||
* @return the Task Id
|
||||
*/
|
||||
public String getJobId() {
|
||||
return (String) this.resourceProperties.get(JOB_ID);
|
||||
public String getTaskId() {
|
||||
return (String) this.resourceProperties.get(TASK_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jobId Job Id
|
||||
* @param taskId Task Id
|
||||
* @throws InvalidValueException if fails
|
||||
*/
|
||||
public void setJobId(String jobId) throws InvalidValueException {
|
||||
setResourceProperty(JOB_ID, jobId);
|
||||
public void setTaskId(String taskId) throws InvalidValueException {
|
||||
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 void setRefJobId(String refJobId) throws InvalidValueException {
|
||||
setResourceProperty(REF_JOB_ID, refJobId);
|
||||
}
|
||||
|
||||
public String getRefVM() {
|
||||
return (String) this.resourceProperties.get(REF_VM);
|
||||
public String getHost() {
|
||||
return (String) this.resourceProperties.get(HOST);
|
||||
}
|
||||
|
||||
public void setRefVM(String refVM) throws InvalidValueException {
|
||||
setResourceProperty(REF_VM, refVM);
|
||||
public void setRefHost(String host) throws InvalidValueException {
|
||||
setResourceProperty(HOST, host);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Calendar getUsageStartTime() {
|
||||
long millis = (Long) this.resourceProperties.get(USAGE_START_TIME);
|
||||
return timestampToCalendar(millis);
|
||||
public String getRefHostingNode() {
|
||||
return (String) this.resourceProperties.get(REF_HOSTING_NODE);
|
||||
}
|
||||
@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 void setRefHostingNode(String refHostingNode) throws InvalidValueException {
|
||||
setResourceProperty(REF_HOSTING_NODE, refHostingNode);
|
||||
}
|
||||
|
||||
public Calendar getTaskStartTime() {
|
||||
|
@ -156,82 +128,40 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
|
|||
|
||||
public void setTaskEndTime(Calendar endTime) throws InvalidValueException {
|
||||
setResourceProperty(TASK_END_TIME, endTime.getTimeInMillis());
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public USAGE_PHASE getUsagePhase() {
|
||||
return (USAGE_PHASE) this.resourceProperties.get(USAGE_PHASE);
|
||||
protected long calculateWallDuration() throws InvalidValueException {
|
||||
try {
|
||||
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);
|
||||
public long getWallDuration() throws InvalidValueException {
|
||||
Long wallDuration = (Long) this.resourceProperties.get(WALL_DURATION);
|
||||
if(wallDuration == null){
|
||||
try {
|
||||
wallDuration = calculateWallDuration();
|
||||
} catch(InvalidValueException e){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return wallDuration;
|
||||
}
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public int getInputFilesNumber() {
|
||||
return (Integer) this.resourceProperties.get(INPUT_FILES_NUMBER);
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getInputParameters(){
|
||||
return (Map<String, Object>) getResourceProperty(INPUT_PARAMETERS);
|
||||
}
|
||||
@Deprecated
|
||||
public void setInputFilesNumber(int inputFilesNumber) throws InvalidValueException {
|
||||
setResourceProperty(INPUT_FILES_NUMBER, inputFilesNumber);
|
||||
}
|
||||
@Deprecated
|
||||
public long getInputFilesSize() {
|
||||
return (Long) this.resourceProperties.get(INPUT_FILES_SIZE);
|
||||
}
|
||||
@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);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setInputParameters(Map<String, Object> inputParameters) throws InvalidValueException{
|
||||
setResourceProperty(INPUT_PARAMETERS, (Comparable<? extends Serializable>) inputParameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ import org.gcube.documentstore.records.implementation.FieldDecorator;
|
|||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@FieldDecorator(action=CalculateWallDurationAction.class)
|
||||
public @interface CalculateWallDuration {}
|
||||
@FieldDecorator(action=CalculateJobWallDurationAction.class)
|
||||
public @interface CalculateJobWallDuration {}
|
|
@ -11,9 +11,9 @@ import org.gcube.documentstore.records.implementation.FieldAction;
|
|||
import org.slf4j.Logger;
|
||||
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
|
||||
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.setOperationResult(OperationResult.SUCCESS);
|
||||
usageRecord.setVmsUsed(TEST_VMS_USED);
|
||||
|
||||
} catch (InvalidValueException 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