git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application/perform-service@176515 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3b3e6bf616
commit
946e8a4639
199
pom.xml
199
pom.xml
|
@ -16,7 +16,7 @@
|
|||
<properties>
|
||||
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
|
||||
<jersey-version>2.13</jersey-version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -36,7 +36,7 @@
|
|||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -59,7 +59,11 @@
|
|||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-control-library</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
|
@ -73,27 +77,59 @@
|
|||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- weld -->
|
||||
<!-- <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId>
|
||||
<version>1.2</version> </dependency> <dependency> <groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet</artifactId> <version>${weld-version}</version>
|
||||
2.0.4 doesn't find implementations. 2.2.4 doesn't find CDI... </dependency> -->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.enterprise</groupId>
|
||||
<artifactId>cdi-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JERSEY -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
|
||||
<artifactId>jersey-container-servlet</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- WELD -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet</artifactId>
|
||||
<version>2.2.10.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss</groupId>
|
||||
<artifactId>jandex</artifactId>
|
||||
<version>1.2.2.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
@ -104,65 +140,88 @@
|
|||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.1-901.jdbc4</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
||||
<artifactId>jersey-test-framework-provider-simple</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
|
||||
|
||||
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!-- <plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<versionRange>[1.0,)</versionRange>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<execute />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin> -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<configuration>
|
||||
<complianceLevel>1.8</complianceLevel>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-control-library</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<versionRange>[1.0,)</versionRange>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<execute />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<configuration>
|
||||
<complianceLevel>1.8</complianceLevel>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-control-library</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</project>
|
|
@ -17,11 +17,11 @@ public class LocalConfiguration {
|
|||
|
||||
|
||||
public static final String MAPPING_DB_ENDPOINT_NAME="mapping-db.ep.name";
|
||||
public static final String MAPPING_DB_ENDPOINT_CATEGORY="mapping-db.ep.name";
|
||||
public static final String MAPPING_DB_ENDPOINT_CATEGORY="mapping-db.ep.category";
|
||||
|
||||
|
||||
public static final String PERFORMANCE_DB_ENDPOINT_NAME="performance-db.ep.name";
|
||||
public static final String PERFORMANCE_DB_ENDPOINT_CATEGORY="performance-db.ep.name";
|
||||
public static final String PERFORMANCE_DB_ENDPOINT_CATEGORY="performance-db.ep.category";
|
||||
|
||||
|
||||
public static final String IMPORTER_COMPUTATION_ID="dm.importer.computationid";
|
||||
|
|
|
@ -2,13 +2,43 @@ package org.gcube.application.perform.service;
|
|||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
|
||||
import org.gcube.application.perform.service.engine.Importer;
|
||||
import org.gcube.application.perform.service.engine.ImporterImpl;
|
||||
import org.gcube.application.perform.service.engine.MappingManager;
|
||||
import org.gcube.application.perform.service.engine.MappingManagerImpl;
|
||||
import org.gcube.application.perform.service.rest.Mappings;
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ApplicationPath(ServiceConstants.APPLICATION_PATH)
|
||||
public class PerformService {
|
||||
|
||||
@ApplicationPath(ServiceConstants.SERVICE_NAME)
|
||||
public class PerformService extends ResourceConfig{
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(PerformService.class);
|
||||
|
||||
|
||||
public PerformService() {
|
||||
super();
|
||||
super();
|
||||
|
||||
|
||||
AbstractBinder binder = new AbstractBinder() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(MappingManagerImpl.class).to(MappingManager.class);
|
||||
bind(ImporterImpl.class).to(Importer.class);
|
||||
|
||||
}
|
||||
};
|
||||
register(binder);
|
||||
registerClasses(Mappings.class);
|
||||
|
||||
// packages("org.gcube.application.perform.service.rest");
|
||||
register(MultiPartFeature.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.application.perform.service;
|
|||
|
||||
public interface ServiceConstants {
|
||||
|
||||
public static final String SERVICE_NAME="perform-service";
|
||||
public static final String APPLICATION_PATH="/gcube/service/";
|
||||
|
||||
public static interface Mappings{
|
||||
|
@ -13,6 +14,8 @@ public interface ServiceConstants {
|
|||
public static final String BATCH_TYPE_PARAMETER="type";
|
||||
|
||||
public static final String FARM_METHOD="farm";
|
||||
|
||||
public static final String AUTH="statistical.manager";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.application.perform.service.engine.model.InvalidRequestExceptio
|
|||
import org.gcube.application.perform.service.engine.model.anagraphic.Batch;
|
||||
import org.gcube.application.perform.service.engine.model.anagraphic.Farm;
|
||||
|
||||
|
||||
public interface MappingManager {
|
||||
|
||||
public Batch getBatch(DBQueryDescriptor desc) throws BeanNotFound, SQLException, InvalidRequestException, InternalException;
|
||||
|
|
|
@ -20,11 +20,11 @@ import org.slf4j.LoggerFactory;
|
|||
public class MappingManagerImpl implements MappingManager {
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(MappingManagerImpl.class);
|
||||
|
||||
|
||||
private static ISQueryDescriptor isQueryDescriptor=null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static synchronized ISQueryDescriptor getISQueryDescriptor() {
|
||||
if(isQueryDescriptor==null) {
|
||||
isQueryDescriptor=
|
||||
|
@ -34,43 +34,43 @@ public class MappingManagerImpl implements MappingManager {
|
|||
}
|
||||
return isQueryDescriptor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Batch getBatch(DBQueryDescriptor desc) throws SQLException, InternalException{
|
||||
DataBaseManager db=DataBaseManager.get(getISQueryDescriptor());
|
||||
Connection conn=db.getConnection();
|
||||
Query getQuery=Queries.GET_BATCH_BY_DESCRIPTIVE_KEY;
|
||||
PreparedStatement psSearch=getQuery.get(conn, desc);
|
||||
|
||||
|
||||
ResultSet rs=psSearch.executeQuery();
|
||||
|
||||
|
||||
if(rs.next())
|
||||
return Queries.rowToBatch(rs);
|
||||
|
||||
// ID NOT FOUND, TRY TO REGISTER IT
|
||||
|
||||
log.trace("Registering new Batch from condition {}",desc);
|
||||
PreparedStatement psInsert=Queries.INSERT_BATCH.get(conn, desc);
|
||||
|
||||
boolean inserted=psInsert.executeUpdate()==1;
|
||||
if(inserted) {
|
||||
conn.commit();
|
||||
log.trace("Committed Batch.");
|
||||
}
|
||||
rs=psSearch.executeQuery();
|
||||
|
||||
if(rs.next())
|
||||
return Queries.rowToBatch(rs);
|
||||
|
||||
// ID NOT FOUND, TRY TO REGISTER IT
|
||||
|
||||
log.trace("Registering new Batch from condition {}",desc);
|
||||
PreparedStatement psInsert=Queries.INSERT_BATCH.get(conn, desc);
|
||||
|
||||
boolean inserted=psInsert.executeUpdate()==1;
|
||||
if(inserted) {
|
||||
conn.commit();
|
||||
log.trace("Committed Batch.");
|
||||
}
|
||||
rs=psSearch.executeQuery();
|
||||
|
||||
if(rs.next())
|
||||
return Queries.rowToBatch(rs);
|
||||
else throw new BeanNotFound(String.format("Unable to find Bean with ",desc));
|
||||
|
||||
else throw new BeanNotFound(String.format("Unable to find Bean with ",desc));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Farm getFarm(DBQueryDescriptor desc) throws SQLException, InternalException{
|
||||
DataBaseManager db=DataBaseManager.get(getISQueryDescriptor());
|
||||
|
||||
|
||||
|
||||
|
||||
Connection conn=db.getConnection();
|
||||
PreparedStatement psGet=null;
|
||||
DBField IDField=DBField.Farm.fields.get(DBField.Farm.FARM_ID);
|
||||
|
@ -78,14 +78,14 @@ public class MappingManagerImpl implements MappingManager {
|
|||
psGet=Queries.GET_FARM_BY_ID.get(conn, desc);
|
||||
}
|
||||
|
||||
ResultSet rs=psGet.executeQuery();
|
||||
if(!rs.next())
|
||||
throw new BeanNotFound("Farm not found. Condition was "+desc);
|
||||
|
||||
return Queries.rowToFarm(rs);
|
||||
ResultSet rs=psGet.executeQuery();
|
||||
if(!rs.next())
|
||||
throw new BeanNotFound("Farm not found. Condition was "+desc);
|
||||
|
||||
return Queries.rowToFarm(rs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ import org.gcube.application.perform.service.engine.model.importer.ImportStatus;
|
|||
public class Queries {
|
||||
|
||||
public static final Query GET_BATCH_BY_DESCRIPTIVE_KEY= new Query("Select * from batches where farmid=? AND type=? AND name= ?",
|
||||
new DBField[] {});
|
||||
new DBField[] {DBField.Batch.fields.get(DBField.Batch.FARM_ID),
|
||||
DBField.Batch.fields.get(DBField.Batch.BATCH_TYPE),
|
||||
DBField.Batch.fields.get(DBField.Batch.BATCH_NAME)});
|
||||
|
||||
public static final Query INSERT_BATCH=new Query("INSERT INTO batches (id,uuid,farmid,type,name) VALUES (SELECT (max(id)+1 from batches),?,?,?,?) ON CONFLICT DO NOTHING",
|
||||
new DBField[] {});
|
||||
|
|
|
@ -6,13 +6,18 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.gcube.application.perform.service.AnagraphicTests;
|
||||
import org.gcube.application.perform.service.engine.model.DBField;
|
||||
import org.gcube.application.perform.service.engine.model.DBQueryDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.InvalidRequestException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class Query {
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(Query.class);
|
||||
|
||||
private final String query;
|
||||
private final ArrayList<DBField> psFields;
|
||||
|
||||
|
@ -36,6 +41,7 @@ public class Query {
|
|||
}
|
||||
|
||||
public PreparedStatement fill(PreparedStatement ps,DBQueryDescriptor desc) throws SQLException, InvalidRequestException{
|
||||
log.debug("Setting VALUES {} for Query {} ",desc,getQuery());
|
||||
ArrayList<DBField> fields=getPSFields();
|
||||
for(int i=0;i<fields.size();i++) {
|
||||
DBField field=fields.get(i);
|
||||
|
|
|
@ -18,10 +18,10 @@ public class DBField {
|
|||
|
||||
static {
|
||||
fields.put(BATCH_ID, new DBField(Types.BIGINT,BATCH_ID));
|
||||
fields.put(UUID, new DBField(Types.NVARCHAR,UUID));
|
||||
fields.put(UUID, new DBField(Types.VARCHAR,UUID));
|
||||
fields.put(FARM_ID, new DBField(Types.BIGINT,FARM_ID));
|
||||
fields.put(BATCH_TYPE, new DBField(Types.NVARCHAR,BATCH_TYPE));
|
||||
fields.put(BATCH_NAME, new DBField(Types.NVARCHAR,BATCH_NAME));
|
||||
fields.put(BATCH_TYPE, new DBField(Types.VARCHAR,BATCH_TYPE));
|
||||
fields.put(BATCH_NAME, new DBField(Types.VARCHAR,BATCH_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,14 @@ public class ISQueryDescriptor {
|
|||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ISQueryDescriptor [resourceName=" + resourceName + ", platformName=" + platformName + ", category="
|
||||
+ category + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
import org.gcube.application.perform.service.engine.model.DatabaseConnectionDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.ISQueryDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.InternalException;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
|
@ -19,8 +20,17 @@ public class ISUtils {
|
|||
|
||||
private static final Logger log= LoggerFactory.getLogger(ISUtils.class);
|
||||
|
||||
private static String fixedToken=null;
|
||||
|
||||
|
||||
public static DatabaseConnectionDescriptor queryForDatabase(ISQueryDescriptor desc) throws InternalException {
|
||||
|
||||
if(fixedToken!=null) {
|
||||
SecurityTokenProvider.instance.set(fixedToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
log.debug("Querying for Service Endpoints {} ",desc,ScopeUtils.getCurrentScope());
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
|
@ -32,7 +42,7 @@ public class ISUtils {
|
|||
query.addCondition("$resource/Profile/Platform/Name/text() eq '"+desc.getPlatformName()+"'");
|
||||
|
||||
if(desc.getResourceName()!=null)
|
||||
query.addCondition("$resource/Profile/Name/text() eq '"+desc.getCategory()+"'");
|
||||
query.addCondition("$resource/Profile/Name/text() eq '"+desc.getResourceName()+"'");
|
||||
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
|
@ -51,5 +61,8 @@ public class ISUtils {
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static final void setFixedToken(String toSet) {
|
||||
log.warn("SETTING FIXED TOKEN. THIS SHOULD HAPPEN ONLY IN DEBUG MODE.");
|
||||
fixedToken=toSet;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,6 @@ public class ScopeUtils {
|
|||
return SecurityTokenProvider.instance.get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,9 +10,12 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.gcube.application.perform.service.AnagraphicTests;
|
||||
import org.gcube.application.perform.service.PerformServiceManager;
|
||||
import org.gcube.application.perform.service.ServiceConstants;
|
||||
import org.gcube.application.perform.service.engine.MappingManager;
|
||||
|
@ -23,17 +26,22 @@ import org.gcube.application.perform.service.engine.model.InternalException;
|
|||
import org.gcube.application.perform.service.engine.model.InvalidRequestException;
|
||||
import org.gcube.application.perform.service.engine.model.anagraphic.Batch;
|
||||
import org.gcube.application.perform.service.engine.model.anagraphic.Farm;
|
||||
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@Path(ServiceConstants.Mappings.PATH)
|
||||
|
||||
@ManagedBy(PerformServiceManager.class)
|
||||
|
||||
@AuthorizationControl(allowed={"lucio.lelii"}, exception=MyAuthException.class)
|
||||
|
||||
public class Mappings {
|
||||
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(Mappings.class);
|
||||
|
||||
|
||||
@Inject
|
||||
private MappingManager mappings;
|
||||
|
||||
|
@ -45,10 +53,13 @@ public class Mappings {
|
|||
* @param farmid
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path(ServiceConstants.Mappings.BATCHES_METHOD)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@AuthorizationControl(allowed={ServiceConstants.Mappings.AUTH}, exception=MyAuthException.class)
|
||||
public Batch getBatch(@QueryParam(ServiceConstants.Mappings.BATCH_NAME_PARAMETER) String name,
|
||||
@QueryParam(ServiceConstants.Mappings.BATCH_TYPE_PARAMETER) String type,
|
||||
@QueryParam(ServiceConstants.Mappings.FARM_ID_PARAMETER) Long farmid) {
|
||||
|
@ -68,13 +79,20 @@ public class Mappings {
|
|||
try{
|
||||
return mappings.getBatch(desc);
|
||||
}catch(BeanNotFound e) {
|
||||
log.debug("Exception while getting Batch",e);
|
||||
throw new WebApplicationException("Unable to find Batch with condition "+desc,Response.Status.BAD_REQUEST);
|
||||
}catch(SQLException e) {
|
||||
log.debug("Exception while getting Batch",e);
|
||||
throw new WebApplicationException("Unexpected Exception occurred while dealing with database.", e,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (InvalidRequestException e) {
|
||||
log.debug("Exception while getting Batch",e);
|
||||
throw new WebApplicationException("Unable to search for Batch. ",e,Response.Status.BAD_REQUEST);
|
||||
} catch (InternalException e) {
|
||||
} catch (InternalException e) {
|
||||
log.warn("Unexpected Exception while getting Batch",e);
|
||||
throw new WebApplicationException("Unexpected Exception.", e,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}catch(Throwable t) {
|
||||
log.warn("Unexpected Exception while getting Batch",t);
|
||||
throw new WebApplicationException("Unexpected Exception.", t,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,18 +107,20 @@ public class Mappings {
|
|||
@GET
|
||||
@Path(ServiceConstants.Mappings.FARM_METHOD)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Farm getFarm(@QueryParam(ServiceConstants.Mappings.FARM_ID_PARAMETER) Long farmid,
|
||||
@QueryParam(ServiceConstants.Mappings.FARM_UUID_PARAMETER) String farmuuid){
|
||||
|
||||
@AuthorizationControl(allowed={ServiceConstants.Mappings.AUTH}, exception=MyAuthException.class)
|
||||
public Farm getFarm(@Context UriInfo info){
|
||||
|
||||
DBQueryDescriptor desc=null;
|
||||
|
||||
|
||||
try {
|
||||
InterfaceCommons.checkMandatory(farmid, ServiceConstants.Mappings.FARM_ID_PARAMETER);
|
||||
desc=new DBQueryDescriptor(Collections.singletonMap(DBField.Farm.fields.get(DBField.Farm.FARM_ID), farmid));
|
||||
String farmidString=info.getQueryParameters().getFirst(ServiceConstants.Mappings.FARM_ID_PARAMETER);
|
||||
InterfaceCommons.checkMandatory(farmidString, ServiceConstants.Mappings.FARM_ID_PARAMETER);
|
||||
desc=new DBQueryDescriptor(Collections.singletonMap(DBField.Farm.fields.get(DBField.Farm.FARM_ID), Long.parseLong(farmidString)));
|
||||
}catch(WebApplicationException e) {
|
||||
try {
|
||||
InterfaceCommons.checkMandatory(farmuuid, ServiceConstants.Mappings.FARM_UUID_PARAMETER);
|
||||
desc=new DBQueryDescriptor(Collections.singletonMap(DBField.Farm.fields.get(DBField.Farm.UUID), farmuuid));
|
||||
String farmUUID=info.getQueryParameters().getFirst(ServiceConstants.Mappings.FARM_UUID_PARAMETER);
|
||||
InterfaceCommons.checkMandatory(farmUUID, ServiceConstants.Mappings.FARM_UUID_PARAMETER);
|
||||
desc=new DBQueryDescriptor(Collections.singletonMap(DBField.Farm.fields.get(DBField.Farm.UUID), farmUUID));
|
||||
}catch(WebApplicationException e1) {
|
||||
throw new WebApplicationException("Specify either "+ServiceConstants.Mappings.FARM_UUID_PARAMETER+" or "+ServiceConstants.Mappings.FARM_ID_PARAMETER,Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
@ -109,13 +129,24 @@ public class Mappings {
|
|||
try{
|
||||
return mappings.getFarm(desc);
|
||||
}catch(BeanNotFound e) {
|
||||
log.debug("Exception while getting Farm",e);
|
||||
throw new WebApplicationException("Unable to find Farm with condition "+desc,Response.Status.BAD_REQUEST);
|
||||
}catch(SQLException e) {
|
||||
log.debug("Exception while getting Farm",e);
|
||||
throw new WebApplicationException("Unexpected Exception occurred while dealing with database.", e,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (InvalidRequestException e) {
|
||||
log.debug("Exception while getting Farm",e);
|
||||
throw new WebApplicationException("Unable to search for Farm. ",e,Response.Status.BAD_REQUEST);
|
||||
} catch (InternalException e) {
|
||||
log.warn("Unexpected Exception while getting Farm",e);
|
||||
throw new WebApplicationException("Unexpected Exception.", e,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}catch(NumberFormatException t) {
|
||||
throw new WebApplicationException("Invalid FarmID format "+desc,Response.Status.BAD_REQUEST);
|
||||
}catch(Throwable t) {
|
||||
log.warn("Unexpected Exception while getting Farm",t);
|
||||
throw new WebApplicationException("Unexpected Exception.", t,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.gcube.application.perform.service.rest;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
public class MyAuthException extends WebApplicationException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyAuthException(Throwable cause) {
|
||||
super(cause, Status.FORBIDDEN);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
db.pools.max_idle=5
|
||||
db.pools.max_total=50
|
||||
db.pools.min_total=3
|
||||
|
||||
mapping-db.ep.name=PF_DB
|
||||
mapping-db.ep.category=Database
|
||||
|
||||
performance-db.ep.name=PF_DB2
|
||||
performance-db.ep.category=PF_DB2
|
||||
|
||||
dm.importer.computationid=org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.PERFORMFISH_DATA_EXTRACTOR
|
|
@ -1,5 +1,23 @@
|
|||
<web-app>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>org.gcube.application.perform.service.PerformService</servlet-name>
|
||||
<servlet-class>org.glassfish.jersey.servlet.ServletContainer
|
||||
</servlet-class>
|
||||
<init-param>
|
||||
<param-name>javax.ws.rs.Application</param-name>
|
||||
<param-value>org.gcube.application.perform.service.PerformService</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>jersey.config.server.provider.classnames</param-name>
|
||||
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature
|
||||
</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>jersey.config.xml.formatOutput</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>org.gcube.application.perform.service.PerformService</servlet-name>
|
||||
<url-pattern>/gcube/service/*</url-pattern>
|
||||
|
|
|
@ -1,5 +1,68 @@
|
|||
package org.gcube.application.perform.service;
|
||||
|
||||
public class AnagraphicTests {
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.Application;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.application.perform.service.engine.utils.ISUtils;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AnagraphicTests extends JerseyTest{
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(AnagraphicTests.class);
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws MalformedURLException {
|
||||
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
|
||||
TokenSetter.set("/gcube/preprod/preVRE");
|
||||
ISUtils.setFixedToken(SecurityTokenProvider.instance.get());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Application configure() {
|
||||
|
||||
return new PerformService();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getBatch() {
|
||||
WebTarget target=
|
||||
// target(ServiceConstants.SERVICE_NAME).
|
||||
// path(ServiceConstants.APPLICATION_PATH).
|
||||
target(ServiceConstants.Mappings.PATH).
|
||||
path(ServiceConstants.Mappings.BATCHES_METHOD).
|
||||
queryParam(ServiceConstants.Mappings.BATCH_NAME_PARAMETER, "gino").
|
||||
queryParam(ServiceConstants.Mappings.BATCH_TYPE_PARAMETER, "pino").
|
||||
queryParam(ServiceConstants.Mappings.FARM_ID_PARAMETER, 1234);
|
||||
|
||||
System.out.println(target.getUri());
|
||||
Response resp=target.request().get();
|
||||
System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFarm() {
|
||||
WebTarget target=
|
||||
// target(ServiceConstants.SERVICE_NAME).
|
||||
// path(ServiceConstants.APPLICATION_PATH).
|
||||
target(ServiceConstants.Mappings.PATH).
|
||||
path(ServiceConstants.Mappings.FARM_METHOD).
|
||||
queryParam(ServiceConstants.Mappings.FARM_ID_PARAMETER, 12334).
|
||||
queryParam(ServiceConstants.Mappings.FARM_UUID_PARAMETER, "pino");
|
||||
|
||||
System.out.println(target.getUri());
|
||||
Response resp=target.request().get();
|
||||
System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package org.gcube.application.perform.service;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TokenSetter {
|
||||
|
||||
|
||||
private static Properties props=new Properties();
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(AnagraphicTests.class);
|
||||
|
||||
static{
|
||||
try {
|
||||
props.load(TokenSetter.class.getResourceAsStream("/tokens.properties"));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("YOU NEED TO SET TOKEN FILE IN CONFIGURATION");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void set(String scope){
|
||||
try{
|
||||
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
|
||||
SecurityTokenProvider.instance.set(props.getProperty(scope));
|
||||
}catch(Throwable e){
|
||||
log.warn("Unable to set token for scope "+scope,e);
|
||||
}
|
||||
ScopeProvider.instance.set(scope);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<configuration debug="true">
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- encoders are assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="debug">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
Loading…
Reference in New Issue