git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/branches/data-access/species-products-discovery/3.0@144393 82a268e6-3cf1-43bd-a215-b396298e98cf
parent
9e57374771
commit
b613a26119
@ -0,0 +1,80 @@
|
||||
package org.gcube.data.spd.executor.jobs;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.gcube.data.spd.model.service.types.JobStatus;
|
||||
|
||||
public class SerializableSpeciesJob extends SpeciesJob implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private JobStatus status;
|
||||
private String id;
|
||||
private int completedEntries;
|
||||
private Calendar startDate;
|
||||
private Calendar endDate;
|
||||
|
||||
public SerializableSpeciesJob(JobStatus status, String id,
|
||||
int completedEntries, Calendar startDate, Calendar endDate) {
|
||||
super();
|
||||
this.status = status!=JobStatus.COMPLETED?JobStatus.FAILED:JobStatus.COMPLETED;
|
||||
this.id = id;
|
||||
this.completedEntries = completedEntries;
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() {}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isResubmitPermitted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public JobStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(JobStatus status) {
|
||||
this.status= status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateInput(String input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCompletedEntries() {
|
||||
return completedEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Calendar getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Calendar getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +1,72 @@
|
||||
package org.gcube.data.spd.executor.jobs;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.data.spd.model.service.types.JobStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public interface SpeciesJob extends Serializable, Runnable {
|
||||
public abstract class SpeciesJob implements Runnable {
|
||||
|
||||
public JobStatus getStatus() ;
|
||||
|
||||
public void setStatus(JobStatus status) ;
|
||||
private static Logger log = LoggerFactory.getLogger(SpeciesJob.class);
|
||||
|
||||
public abstract JobStatus getStatus() ;
|
||||
|
||||
public abstract void setStatus(JobStatus status) ;
|
||||
|
||||
public abstract String getId();
|
||||
|
||||
public abstract boolean validateInput(String input);
|
||||
|
||||
public abstract int getCompletedEntries();
|
||||
|
||||
public abstract Calendar getStartDate();
|
||||
|
||||
public abstract Calendar getEndDate();
|
||||
|
||||
public abstract void execute();
|
||||
|
||||
public abstract boolean isResubmitPermitted();
|
||||
|
||||
public final void run(){
|
||||
if (getStatus()!=JobStatus.PENDING && !isResubmitPermitted()){
|
||||
log.warn("the job with id {} cannot be resubmitted",getId());
|
||||
throw new IllegalStateException("this job cannot be resubmitted");
|
||||
}
|
||||
try{
|
||||
execute();
|
||||
}catch(Exception e){
|
||||
log.error("unexpected exception in job, setting status to FAILED",e);
|
||||
this.setStatus(JobStatus.FAILED);
|
||||
}
|
||||
generateAccounting();
|
||||
}
|
||||
|
||||
public String getId();
|
||||
|
||||
public boolean validateInput(String input);
|
||||
|
||||
public int getCompletedEntries();
|
||||
|
||||
public Calendar getStartDate();
|
||||
|
||||
public Calendar getEndDate();
|
||||
private final void generateAccounting(){
|
||||
AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence();
|
||||
JobUsageRecord jobUsageRecord = new JobUsageRecord();
|
||||
try{
|
||||
|
||||
jobUsageRecord.setConsumerId(AuthorizationProvider.instance.get().getClient().getId());
|
||||
jobUsageRecord.setScope(ScopeProvider.instance.get());
|
||||
jobUsageRecord.setJobName(this.getClass().getSimpleName());
|
||||
jobUsageRecord.setOperationResult(getStatus()==JobStatus.COMPLETED?OperationResult.SUCCESS:OperationResult.FAILED);
|
||||
jobUsageRecord.setJobId(this.getId());
|
||||
jobUsageRecord.setJobStartTime(this.getStartDate());
|
||||
jobUsageRecord.setJobEndTime(this.getEndDate());
|
||||
|
||||
persistence.account(jobUsageRecord);
|
||||
log.info("Job {} accounted successfully",getId());
|
||||
}catch(Exception ex){
|
||||
log.warn("invalid record passed to accounting ",ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package org.gcube.data.spd.executor.jobs;
|
||||
|
||||
public interface URLJob extends SpeciesJob {
|
||||
public abstract class URLJob extends SpeciesJob {
|
||||
|
||||
public String getResultURL() ;
|
||||
public abstract String getResultURL() ;
|
||||
|
||||
public String getErrorURL() ;
|
||||
public abstract String getErrorURL() ;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue