Lucio Lelii 2017-09-28 09:44:51 +00:00
parent 56ab89ca45
commit cd43b8f199
6 changed files with 45 additions and 17 deletions

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -27,4 +27,7 @@
<Changeset component="org.gcube.data-access.species-products-discovery.3-0-0" date="2017-02-09">
<Change>service moved to smartgears</Change>
</Changeset>
<Changeset component="org.gcube.data-access.species-products-discovery.3-0-1" date="2017-02-09">
<Change>changed for the new JobUsageRecord</Change>
</Changeset>
</ReleaseNotes>

12
pom.xml
View File

@ -3,10 +3,16 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.data.spd</groupId>
<artifactId>species-products-discovery</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>species product discovery</name>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
@ -221,10 +227,6 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -7,8 +7,11 @@ 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.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data.spd.model.service.types.JobStatus;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,33 +37,45 @@ public abstract class SpeciesJob implements Runnable {
public abstract boolean isResubmitPermitted();
private ApplicationContext ctx = ContextProvider.get();
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{
log.debug("running job with id {}",this.getId());
execute();
log.debug("job with id {} executed",this.getId());
}catch(Exception e){
log.error("unexpected exception in job, setting status to FAILED",e);
log.error("unexpected exception in job with id {}, setting status to FAILED",this.getId(),e);
this.setStatus(JobStatus.FAILED);
}
generateAccounting();
}
private final void generateAccounting(){
AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence();
JobUsageRecord jobUsageRecord = new JobUsageRecord();
try{
Caller caller = AuthorizationProvider.instance.get();
String consumerId = caller!= null ?
caller.getClient().getId() : "UNKNOWN";
String qualifier = caller!= null ?
caller.getTokenQualifier() : "UNKNOWN";
jobUsageRecord.setConsumerId(AuthorizationProvider.instance.get().getClient().getId());
jobUsageRecord.setConsumerId(consumerId);
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());
jobUsageRecord.setDuration(this.getEndDate().getTime().getTime()-this.getStartDate().getTime().getTime());
jobUsageRecord.setServiceName(ctx.configuration().name());
jobUsageRecord.setServiceClass(ctx.configuration().serviceClass());
jobUsageRecord.setHost(ctx.container().configuration().hostname());
jobUsageRecord.setCallerQualifier(qualifier);
persistence.account(jobUsageRecord);
log.info("Job {} accounted successfully",getId());

View File

@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
public class PluginManager{
private static Logger log = LoggerFactory.getLogger(PluginManager.class);
private static final Logger log = LoggerFactory.getLogger(PluginManager.class);
private static final int CACHE_ENTRIES_PER_PLUGIN =500;
private static final String RESOURCE_CATEGORY ="BiodiversityRepository";
@ -199,7 +199,7 @@ public class PluginManager{
if (pluginDescriptions==null) continue;
log.trace("plugins in Pluginmanager are "+plugins.keySet());
log.trace("plugins in Pluginmanager are {} ",plugins.keySet().toString());
addRemotePlugins(pluginDescriptions, endpointId);
}
@ -292,7 +292,7 @@ public class PluginManager{
}
retrievePlugins(runtimeResourcePerPlugin);
retrieveRemotePlugins();
//TODO : reintroduce it to discovery twin services // retrieveRemotePlugins();
}

View File

@ -27,7 +27,9 @@ public abstract class RetryCall<T, E extends Throwable>{
int retry = 0;
do {
try{
return execute();
T result = execute();
if (result != null)
return result;
}catch (ExternalRepositoryException e) {
logger.warn("error on external repository, "+(retry<retries?" ":"not ")+"retrying",e);
retry++;