Reorganizing internal decorators

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120528 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-12-01 13:37:23 +00:00
parent 94d6b5e4ce
commit 7d31661459
13 changed files with 185 additions and 59 deletions

View File

@ -12,7 +12,7 @@ import java.util.Map;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToCreationTime; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToCreationTime;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToScope; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToScope;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToUsageRecordType; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToUsageRecordType;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning; import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord; import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;

View File

@ -1,4 +1,4 @@
package org.gcube.accounting.datamodel.deprecationmanagement.annotations; package org.gcube.accounting.datamodel.backwardcompatibility;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -6,7 +6,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator; import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToOperationResultAction;
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -1,7 +1,7 @@
/** /**
* *
*/ */
package org.gcube.accounting.datamodel.deprecationmanagement.validators; package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable; import java.io.Serializable;

View File

@ -0,0 +1,22 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
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.decorators.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToTaskEndTimeAction.class)
public @interface MoveToTaskEndTime {
}

View File

@ -0,0 +1,30 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class MoveToTaskEndTimeAction implements FieldAction {
/**
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key,
Comparable<? extends Serializable> value, UsageRecord usageRecord)
throws InvalidValueException {
usageRecord.setResourceProperty(AbstractTaskUsageRecord.TASK_END_TIME, value);
return usageRecord.getResourceProperty(AbstractTaskUsageRecord.TASK_END_TIME);
}
}

View File

@ -0,0 +1,22 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
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.decorators.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToTaskStartTimeAction.class)
public @interface MoveToTaskStartTime {
}

View File

@ -0,0 +1,30 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class MoveToTaskStartTimeAction implements FieldAction {
/**
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key,
Comparable<? extends Serializable> value, UsageRecord usageRecord)
throws InvalidValueException {
usageRecord.setResourceProperty(AbstractTaskUsageRecord.TASK_START_TIME, value);
return usageRecord.getResourceProperty(AbstractTaskUsageRecord.TASK_START_TIME);
}
}

View File

@ -8,9 +8,9 @@ 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.decorators.ComputedField; import org.gcube.accounting.datamodel.decorators.ComputedField;
import org.gcube.accounting.datamodel.decorators.RequiredField; import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToOperationResult;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty; import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger; import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong; import org.gcube.accounting.datamodel.validations.annotations.ValidLong;

View File

@ -15,7 +15,7 @@ import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction; import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.datamodel.decorators.FieldDecorator; import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.decorators.RequiredField; import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning; import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty; import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull; import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator; import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;

View File

@ -91,7 +91,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
public static final String DATA_TYPE = "dataType"; public static final String DATA_TYPE = "dataType";
/** /**
* Quantity of data in terms of KB * KEY for : Quantity of data in terms of KB
*/ */
@RequiredField @ValidLong @FixDataVolumeSign @RequiredField @ValidLong @FixDataVolumeSign
public static final String DATA_VOLUME = "dataVolume"; public static final String DATA_VOLUME = "dataVolume";

View File

@ -8,9 +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.decorators.RequiredField; import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning; import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToOperationResult;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty; import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger; import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong; import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
@ -27,10 +29,6 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
*/ */
private static final long serialVersionUID = -2208425042550641240L; private static final long serialVersionUID = -2208425042550641240L;
public static enum USAGE_PHASE {
completed, failed
};
@RequiredField @NotEmpty @RequiredField @NotEmpty
public static final String JOB_ID = "jobId"; public static final String JOB_ID = "jobId";
@RequiredField @NotEmpty @RequiredField @NotEmpty
@ -38,33 +36,38 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
@RequiredField @NotEmpty @RequiredField @NotEmpty
public static final String REF_VM = "refVM"; public static final String REF_VM = "refVM";
@NotEmpty @DeprecatedWarning @Deprecated @NotEmpty @DeprecatedWarning
protected static final String DOMAIN = "domain"; protected static final String DOMAIN = "domain";
@RequiredField @ValidLong @Deprecated @DeprecatedWarning @MoveToTaskStartTime
public static final String USAGE_START_TIME = "usageStartTime"; protected static final String USAGE_START_TIME = "usageStartTime";
@RequiredField @ValidLong @Deprecated @DeprecatedWarning @MoveToTaskEndTime
public static final String USAGE_END_TIME = "usageEndTime"; protected static final String USAGE_END_TIME = "usageEndTime";
@MoveToOperationResult @Deprecated @MoveToOperationResult @DeprecatedWarning
protected static final String USAGE_PHASE = "usagePhase"; protected static final String USAGE_PHASE = "usagePhase";
@ValidInteger @RequiredField @ValidLong
public static final String INPUT_FILES_NUMBER = "inputFilesNumber"; public static final String TASK_START_TIME = "taskStartTime";
@ValidLong @RequiredField @ValidLong
public static final String INPUT_FILES_SIZE = "inputFilesSize"; public static final String TASK_END_TIME = "taskEndTime";
@ValidInteger
public static final String OUTPUT_FILES_NUMBER = "outputFilesNumber"; @Deprecated @ValidInteger @DeprecatedWarning
@ValidLong protected static final String INPUT_FILES_NUMBER = "inputFilesNumber";
public static final String OUTPUT_FILES_SIZE = "outputFilesSize"; @Deprecated @ValidLong @DeprecatedWarning
@ValidLong protected static final String INPUT_FILES_SIZE = "inputFilesSize";
public static final String OVERALL_NETWORK_IN = "overallNetworkIn"; @Deprecated @ValidInteger @DeprecatedWarning
@ValidLong protected static final String OUTPUT_FILES_NUMBER = "outputFilesNumber";
public static final String OVERALL_NETWORK_OUT = "overallNetworkOut"; @Deprecated @ValidLong @DeprecatedWarning
@ValidInteger protected static final String OUTPUT_FILES_SIZE = "outputFilesSize";
public static final String CORES = "cores"; @Deprecated @ValidLong @DeprecatedWarning
@ValidInteger protected static final String OVERALL_NETWORK_IN = "overallNetworkIn";
public static final String PROCESSORS = "processors"; @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();
@ -124,27 +127,47 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
setResourceProperty(DOMAIN, domain); setResourceProperty(DOMAIN, domain);
} }
*/ */
@Deprecated
public Calendar getUsageStartTime() { public Calendar getUsageStartTime() {
long millis = (Long) this.resourceProperties.get(USAGE_START_TIME); long millis = (Long) this.resourceProperties.get(USAGE_START_TIME);
return timestampStringToCalendar(millis); return timestampStringToCalendar(millis);
} }
@Deprecated
public void setUsageStartTime(Calendar usageStartTime) throws InvalidValueException { public void setUsageStartTime(Calendar usageStartTime) throws InvalidValueException {
setResourceProperty(USAGE_START_TIME, usageStartTime.getTimeInMillis()); setResourceProperty(USAGE_START_TIME, usageStartTime.getTimeInMillis());
} }
@Deprecated
public Calendar getUsageEndTime() { public Calendar getUsageEndTime() {
long millis = (Long) this.resourceProperties.get(USAGE_END_TIME); long millis = (Long) this.resourceProperties.get(USAGE_END_TIME);
return timestampStringToCalendar(millis); return timestampStringToCalendar(millis);
} }
@Deprecated
public void setUsageEndTime(Calendar usageEndTime) throws InvalidValueException { public void setUsageEndTime(Calendar usageEndTime) throws InvalidValueException {
setResourceProperty(USAGE_END_TIME, usageEndTime.getTimeInMillis()); setResourceProperty(USAGE_END_TIME, usageEndTime.getTimeInMillis());
} }
public Calendar getTaskStartTime() {
long millis = (Long) this.resourceProperties.get(TASK_START_TIME);
return timestampStringToCalendar(millis);
}
public void setTaskStartTime(Calendar startTime) throws InvalidValueException {
setResourceProperty(TASK_START_TIME, startTime.getTimeInMillis());
}
public Calendar getTaskEndTime() {
long millis = (Long) this.resourceProperties.get(TASK_END_TIME);
return timestampStringToCalendar(millis);
}
public void setTaskEndTime(Calendar endTime) throws InvalidValueException {
setResourceProperty(TASK_END_TIME, endTime.getTimeInMillis());
}
/* /*
public USAGE_PHASE getUsagePhase() { public USAGE_PHASE getUsagePhase() {
return (USAGE_PHASE) this.resourceProperties.get(USAGE_PHASE); return (USAGE_PHASE) this.resourceProperties.get(USAGE_PHASE);
@ -154,67 +177,68 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
setResourceProperty(USAGE_PHASE, usagePhase); setResourceProperty(USAGE_PHASE, usagePhase);
} }
*/ */
@Deprecated
public int getInputFilesNumber() { public int getInputFilesNumber() {
return (Integer) this.resourceProperties.get(INPUT_FILES_NUMBER); return (Integer) this.resourceProperties.get(INPUT_FILES_NUMBER);
} }
@Deprecated
public void setInputFilesNumber(int inputFilesNumber) throws InvalidValueException { public void setInputFilesNumber(int inputFilesNumber) throws InvalidValueException {
setResourceProperty(INPUT_FILES_NUMBER, inputFilesNumber); setResourceProperty(INPUT_FILES_NUMBER, inputFilesNumber);
} }
@Deprecated
public long getInputFilesSize() { public long getInputFilesSize() {
return (Long) this.resourceProperties.get(INPUT_FILES_SIZE); return (Long) this.resourceProperties.get(INPUT_FILES_SIZE);
} }
@Deprecated
public void setInputFilesSize(long inputFilesSize) throws InvalidValueException { public void setInputFilesSize(long inputFilesSize) throws InvalidValueException {
setResourceProperty(INPUT_FILES_SIZE, inputFilesSize); setResourceProperty(INPUT_FILES_SIZE, inputFilesSize);
} }
@Deprecated
public int getOutputFilesNumber() { public int getOutputFilesNumber() {
return (Integer) this.resourceProperties.get(OUTPUT_FILES_NUMBER); return (Integer) this.resourceProperties.get(OUTPUT_FILES_NUMBER);
} }
@Deprecated
public void setOutputFilesNumber(int outputFilesNumber) throws InvalidValueException { public void setOutputFilesNumber(int outputFilesNumber) throws InvalidValueException {
setResourceProperty(OUTPUT_FILES_NUMBER, outputFilesNumber); setResourceProperty(OUTPUT_FILES_NUMBER, outputFilesNumber);
} }
@Deprecated
public long getOutputFilesSize() { public long getOutputFilesSize() {
return (Long) this.resourceProperties.get(OUTPUT_FILES_SIZE); return (Long) this.resourceProperties.get(OUTPUT_FILES_SIZE);
} }
@Deprecated
public void setOutputFilesSize(long outputFilesSize) throws InvalidValueException { public void setOutputFilesSize(long outputFilesSize) throws InvalidValueException {
setResourceProperty(OUTPUT_FILES_SIZE, outputFilesSize); setResourceProperty(OUTPUT_FILES_SIZE, outputFilesSize);
} }
@Deprecated
public long getOverallNetworkIn() { public long getOverallNetworkIn() {
return (Long) this.resourceProperties.get(OVERALL_NETWORK_IN); return (Long) this.resourceProperties.get(OVERALL_NETWORK_IN);
} }
@Deprecated
public void setOverallNetworkIn(long overallNetworkIn) throws InvalidValueException { public void setOverallNetworkIn(long overallNetworkIn) throws InvalidValueException {
setResourceProperty(OVERALL_NETWORK_IN, overallNetworkIn); setResourceProperty(OVERALL_NETWORK_IN, overallNetworkIn);
} }
@Deprecated
public long getOverallNetworkOut() { public long getOverallNetworkOut() {
return (Long) this.resourceProperties.get(OVERALL_NETWORK_OUT); return (Long) this.resourceProperties.get(OVERALL_NETWORK_OUT);
} }
@Deprecated
public void setOverallNetworkOut(long overallNetworkOut) throws InvalidValueException { public void setOverallNetworkOut(long overallNetworkOut) throws InvalidValueException {
setResourceProperty(OVERALL_NETWORK_OUT, overallNetworkOut); setResourceProperty(OVERALL_NETWORK_OUT, overallNetworkOut);
} }
@Deprecated
public int getCores() { public int getCores() {
return (Integer) this.resourceProperties.get(CORES); return (Integer) this.resourceProperties.get(CORES);
} }
@Deprecated
public void setCores(int cores) throws InvalidValueException { public void setCores(int cores) throws InvalidValueException {
setResourceProperty(CORES, cores); setResourceProperty(CORES, cores);
} }
@Deprecated
public int getProcessors() { public int getProcessors() {
return (Integer) this.resourceProperties.get(PROCESSORS); return (Integer) this.resourceProperties.get(PROCESSORS);
} }
@Deprecated
public void setProcessors(int processors) throws InvalidValueException { public void setProcessors(int processors) throws InvalidValueException {
setResourceProperty(PROCESSORS, processors); setResourceProperty(PROCESSORS, processors);
} }

View File

@ -1,4 +1,4 @@
package org.gcube.accounting.datamodel.deprecationmanagement.annotations; package org.gcube.accounting.datamodel.deprecationmanagement;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -6,7 +6,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator; import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.deprecationmanagement.validators.DeprecatedWarningAction;
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -1,7 +1,7 @@
/** /**
* *
*/ */
package org.gcube.accounting.datamodel.deprecationmanagement.validators; package org.gcube.accounting.datamodel.deprecationmanagement;
import java.io.Serializable; import java.io.Serializable;
@ -24,7 +24,7 @@ public class DeprecatedWarningAction implements FieldAction {
*/ */
@Override @Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException { public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
logger.trace("The field {} is deprecated for {}. Anyway the field will be included in the document", logger.trace("The field {} is deprecated for {}. Anyway the field will be included in the SingleUsageRecord. The field can be lost during aggregation.",
key, usageRecord.getClass().getSimpleName()); key, usageRecord.getClass().getSimpleName());
return value; return value;
} }