142 lines
4.2 KiB
Java
142 lines
4.2 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.accounting.datamodel.implementations;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import org.gcube.accounting.datamodel.RawUsageRecord;
|
|
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
|
import org.gcube.accounting.datamodel.annotations.NotEmpty;
|
|
import org.gcube.accounting.datamodel.annotations.Required;
|
|
import org.gcube.accounting.datamodel.annotations.ValidInteger;
|
|
import org.gcube.accounting.datamodel.annotations.ValidLong;
|
|
import org.gcube.accounting.exception.InvalidValueException;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
*
|
|
*/
|
|
public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord {
|
|
|
|
/**
|
|
* Generated Serial Version UID
|
|
*/
|
|
private static final long serialVersionUID = -8648691183939346858L;
|
|
|
|
public static enum JobStatus {
|
|
completed, failed
|
|
};
|
|
|
|
@Required @NotEmpty
|
|
public static final String JOB_ID = "jobId";
|
|
@Required @NotEmpty
|
|
public static final String JOB_QUALIFIER = "jobQualifier";
|
|
@Required @NotEmpty
|
|
public static final String JOB_NAME = "jobName";
|
|
@Required @ValidLong
|
|
public static final String JOB_START_TIME = "jobStartTime";
|
|
@Required @ValidLong
|
|
public static final String JOB_END_TIME = "jobEndTime";
|
|
@NotEmpty
|
|
protected static final String JOB_STATUS = "jobStatus";
|
|
@ValidInteger
|
|
public static final String VMS_USED = "vmsUsed";
|
|
@ValidLong
|
|
protected static final String WALL_DURATION = "wallDuration";
|
|
|
|
public JobUsageRecord(){
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @return the Job Id
|
|
*/
|
|
public String getJobId() {
|
|
return (String) this.resourceSpecificProperties.get(JOB_ID);
|
|
}
|
|
|
|
/**
|
|
* @param jobId Job Id
|
|
* @throws InvalidValueException if fails
|
|
*/
|
|
public void setJobId(String jobId) throws InvalidValueException {
|
|
setResourceSpecificProperty(JOB_ID, jobId);
|
|
}
|
|
|
|
public String getJobQualifier() {
|
|
return (String) this.resourceSpecificProperties.get(JOB_QUALIFIER);
|
|
}
|
|
|
|
public void setJobQualifier(String jobQualifier) throws InvalidValueException {
|
|
setResourceSpecificProperty(JOB_QUALIFIER, jobQualifier);
|
|
}
|
|
|
|
public String getJobName() {
|
|
return (String) this.resourceSpecificProperties.get(JOB_NAME);
|
|
}
|
|
|
|
public void setJobName(String jobName) throws InvalidValueException {
|
|
setResourceSpecificProperty(JOB_NAME, jobName);
|
|
}
|
|
|
|
public Calendar getJobStartTime() {
|
|
long millis = (Long) this.resourceSpecificProperties.get(JOB_START_TIME);
|
|
return timestampStringToCalendar(millis);
|
|
}
|
|
|
|
public void setJobStartTime(Calendar jobStartTime) throws InvalidValueException {
|
|
setResourceSpecificProperty(JOB_START_TIME, jobStartTime.getTimeInMillis());
|
|
|
|
}
|
|
|
|
public Calendar getJobEndTime() {
|
|
long millis = (Long) this.resourceSpecificProperties.get(JOB_END_TIME);
|
|
return timestampStringToCalendar(millis);
|
|
}
|
|
|
|
public void setJobEndTime(Calendar jobEndTime) throws InvalidValueException {
|
|
setResourceSpecificProperty(JOB_END_TIME, jobEndTime.getTimeInMillis());
|
|
|
|
}
|
|
|
|
@Deprecated
|
|
public JobStatus getJobStatus() {
|
|
return JobStatus.values()[((OperationResult) this.resourceSpecificProperties.get(OPERATION_RESULT)).ordinal()];
|
|
}
|
|
|
|
@Deprecated
|
|
public void setJobStatus(JobStatus jobStatus) throws InvalidValueException {
|
|
setResourceSpecificProperty(OPERATION_RESULT, OperationResult.values()[jobStatus.ordinal()]);
|
|
}
|
|
|
|
public int getVmsUsed() {
|
|
return (Integer) this.resourceSpecificProperties.get(VMS_USED);
|
|
}
|
|
|
|
public void setVmsUsed(int vmsUsed) throws InvalidValueException {
|
|
setResourceSpecificProperty(VMS_USED, vmsUsed);
|
|
}
|
|
|
|
protected void calculateWallDuration() throws InvalidValueException {
|
|
try {
|
|
long endTime = (Long) this.resourceSpecificProperties.get(JOB_END_TIME);
|
|
long startTime = (Long) this.resourceSpecificProperties.get(JOB_START_TIME);
|
|
long wallDuration = endTime - startTime;
|
|
setResourceSpecificProperty(WALL_DURATION, wallDuration);
|
|
}catch(Exception e){
|
|
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
|
|
START_TIME, END_TIME), e.getCause());
|
|
}
|
|
}
|
|
|
|
public long getWallDuration() throws InvalidValueException {
|
|
Long wallDuration = (Long) this.resourceSpecificProperties.get(WALL_DURATION);
|
|
if(wallDuration == null){
|
|
calculateWallDuration();
|
|
}
|
|
return wallDuration;
|
|
}
|
|
|
|
}
|