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.MoveToScope;
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.PortletUsageRecord;
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.Retention;
@ -6,7 +6,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToOperationResultAction;
@Target(ElementType.FIELD)
@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;

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 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.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToOperationResult;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
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.FieldDecorator;
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.NotEmptyIfNotNull;
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";
/**
* Quantity of data in terms of KB
* KEY for : Quantity of data in terms of KB
*/
@RequiredField @ValidLong @FixDataVolumeSign
public static final String DATA_VOLUME = "dataVolume";

View File

@ -8,9 +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.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToOperationResult;
import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
@ -27,10 +29,6 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
*/
private static final long serialVersionUID = -2208425042550641240L;
public static enum USAGE_PHASE {
completed, failed
};
@RequiredField @NotEmpty
public static final String JOB_ID = "jobId";
@RequiredField @NotEmpty
@ -38,33 +36,38 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
@RequiredField @NotEmpty
public static final String REF_VM = "refVM";
@NotEmpty @DeprecatedWarning
@Deprecated @NotEmpty @DeprecatedWarning
protected static final String DOMAIN = "domain";
@RequiredField @ValidLong
public static final String USAGE_START_TIME = "usageStartTime";
@RequiredField @ValidLong
public static final String USAGE_END_TIME = "usageEndTime";
@Deprecated @DeprecatedWarning @MoveToTaskStartTime
protected static final String USAGE_START_TIME = "usageStartTime";
@Deprecated @DeprecatedWarning @MoveToTaskEndTime
protected static final String USAGE_END_TIME = "usageEndTime";
@MoveToOperationResult
@Deprecated @MoveToOperationResult @DeprecatedWarning
protected 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";
@RequiredField @ValidLong
public static final String TASK_START_TIME = "taskStartTime";
@RequiredField @ValidLong
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";
public AbstractTaskUsageRecord(){
super();
@ -124,27 +127,47 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
setResourceProperty(DOMAIN, domain);
}
*/
@Deprecated
public Calendar getUsageStartTime() {
long millis = (Long) this.resourceProperties.get(USAGE_START_TIME);
return timestampStringToCalendar(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 timestampStringToCalendar(millis);
}
@Deprecated
public void setUsageEndTime(Calendar usageEndTime) throws InvalidValueException {
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() {
return (USAGE_PHASE) this.resourceProperties.get(USAGE_PHASE);
@ -154,67 +177,68 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
setResourceProperty(USAGE_PHASE, usagePhase);
}
*/
@Deprecated
public int getInputFilesNumber() {
return (Integer) this.resourceProperties.get(INPUT_FILES_NUMBER);
}
@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);
}

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.Retention;
@ -6,7 +6,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.deprecationmanagement.validators.DeprecatedWarningAction;
@Target(ElementType.FIELD)
@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;
@ -24,7 +24,7 @@ public class DeprecatedWarningAction implements FieldAction {
*/
@Override
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());
return value;
}