Skip to content

Commit

Permalink
server: add BIONETDB_HOME parameter to web.xml and INSTALLATION.DIR t…
Browse files Browse the repository at this point in the history
…o pom.xml
  • Loading branch information
imedina committed Mar 12, 2018
1 parent 50c6637 commit 0d81b1b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 58 deletions.
4 changes: 2 additions & 2 deletions bionetdb-core/src/main/resources/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
logLevel: null
logFile: null

## You can define more than one database, you can pass the database id to BioNetDBManager.
## More than one database can be defined, you can pass the database id to BioNetDBManager.
## If not passed the default database will always be the first one.
databases:
- id: "${BIONETDB.DB.DATABASE}"
Expand All @@ -11,4 +11,4 @@ databases:
port: "${BIONETDB.DB.PORT}"
user: "${BIONETDB.DB.USER}"
password: "${BIONETDB.DB.PASSWORD}"
options: null
options: null ## map containing specific database options
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
import com.google.common.base.Splitter;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.opencb.bionetdb.core.BioNetDBManager;
import org.opencb.bionetdb.core.api.NetworkDBAdaptor;
import org.opencb.bionetdb.core.config.BioNetDBConfiguration;
Expand All @@ -18,13 +19,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Created by imedina on 01/10/15.
Expand Down Expand Up @@ -73,45 +76,17 @@ public class GenericRestWSServer {
protected static NetworkDBAdaptor networkDBAdaptor;
protected static Map<String, BioNetDBManager> bioNetDBManagers;

protected static AtomicBoolean initialized;

private static final int LIMIT_DEFAULT = 1000;
private static final int LIMIT_MAX = 5000;
private static final int DEFAULT_LIMIT = 2000;
private static final int MAX_LIMIT = 5000;

static {
logger = LoggerFactory.getLogger("org.opencb.cellbase.server.ws.GenericRestWSServer");
logger.info("Static block, creating Neo4JNetworkDBAdaptor");
try {
if (System.getenv("BIONETDB_HOME") != null) {
logger.info("Loading configuration from '{}'", System.getenv("BIONETDB_HOME") + "/configuration.yml");
bioNetDBConfiguration = BioNetDBConfiguration
.load(new FileInputStream(new File(System.getenv("BIONETDB_HOME") + "/configuration.yml")));
} else {
logger.info("Loading configuration from '{}'",
BioNetDBConfiguration.class.getClassLoader().getResourceAsStream("configuration.yml").toString());
bioNetDBConfiguration = BioNetDBConfiguration
.load(BioNetDBConfiguration.class.getClassLoader().getResourceAsStream("configuration.yml"));
}
initialized = new AtomicBoolean(false);

// networkDBAdaptor = new Neo4JNetworkDBAdaptor("test1", bioNetDBConfiguration);
// } catch (BioNetDBException e) {
// e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

// Init the manager map with the managers, this will allow methods to query the right database
bioNetDBManagers = new HashMap<>();
if (bioNetDBConfiguration != null && bioNetDBConfiguration.getDatabases().size() > 0) {
try {
for (DatabaseConfiguration databaseConfiguration : bioNetDBConfiguration.getDatabases()) {
BioNetDBManager bioNetDBManager = new BioNetDBManager(databaseConfiguration.getId(), bioNetDBConfiguration);
bioNetDBManagers.put(databaseConfiguration.getId(), bioNetDBManager);
}
} catch (BioNetDBException e) {
e.printStackTrace();
}
}
logger = LoggerFactory.getLogger("org.opencb.bionetdb.server.rest.GenericRestWSServer");

jsonObjectMapper = new ObjectMapper();
jsonObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
Expand All @@ -126,18 +101,65 @@ public GenericRestWSServer(@PathParam("apiVersion") String apiVersion, @Context
this.uriInfo = uriInfo;
this.httpServletRequest = hsr;

logger.debug("Executing GenericRestWSServer constructor with no Species");
init();
}

protected void init() throws VersionException {
private void init() throws VersionException {
// This must be only executed once, this method loads the configuration and create the BioNetDBManagers
if (initialized.compareAndSet(false, true)) {
initBioNetDBObjects();
}

query = new Query();
queryOptions = new QueryOptions();

parseQueryParams();

startTime = System.currentTimeMillis();
}

/**
* This method loads the configuration and create the BioNetDB mangers, must be called once.
*/
private void initBioNetDBObjects() {
try {
if (System.getenv("BIONETDB_HOME") != null) {
logger.info("Loading configuration from '{}'", System.getenv("BIONETDB_HOME") + "/configuration.yml");
bioNetDBConfiguration = BioNetDBConfiguration
.load(new FileInputStream(new File(System.getenv("BIONETDB_HOME") + "/configuration.yml")));
} else {
// We read 'BIONETDB_HOME' parameter from the web.xml file
ServletContext context = httpServletRequest.getServletContext();
String bionetdbHome = context.getInitParameter("BIONETDB_HOME");
if (StringUtils.isNotEmpty(bionetdbHome)) {
logger.info("Loading configuration from '{}'", bionetdbHome + "/configuration.yml");
bioNetDBConfiguration = BioNetDBConfiguration
.load(new FileInputStream(new File(bionetdbHome + "/configuration.yml")));
} else {
logger.info("Loading configuration from '{}'",
BioNetDBConfiguration.class.getClassLoader().getResourceAsStream("configuration.yml").toString());
bioNetDBConfiguration = BioNetDBConfiguration
.load(BioNetDBConfiguration.class.getClassLoader().getResourceAsStream("configuration.yml"));
}
}
} catch (IOException e) {
e.printStackTrace();
}

// Init the manager map with the managers, this will allow methods to query the right database
bioNetDBManagers = new HashMap<>();
if (bioNetDBConfiguration != null && bioNetDBConfiguration.getDatabases().size() > 0) {
try {
for (DatabaseConfiguration databaseConfiguration : bioNetDBConfiguration.getDatabases()) {
BioNetDBManager bioNetDBManager = new BioNetDBManager(databaseConfiguration.getId(), bioNetDBConfiguration);
bioNetDBManagers.put(databaseConfiguration.getId(), bioNetDBManager);
}
} catch (BioNetDBException e) {
e.printStackTrace();
}
}
}

private void parseQueryParams() throws VersionException {
// If by any reason 'apiVersion' is null we try to read it from the URI path, if not present an Exception is thrown
if (this.apiVersion == null) {
Expand Down
29 changes: 7 additions & 22 deletions bionetdb-server/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml apiVersion="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 OpenCB
~
Expand All @@ -18,10 +18,15 @@
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
xsi:schemaLocation="http://jBIONETDB_HOMEava.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<display-name>BioNetDB Server</display-name>

<context-param>
<param-name>BIONETDB_HOME</param-name>
<param-value>${BIONETDB.INSTALLATION.DIR}</param-value>
</context-param>

<servlet>
<servlet-name>BioNetDBServer</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
Expand All @@ -31,11 +36,6 @@
<param-value>io.swagger.jaxrs.listing;org.opencb.bionetdb.server.rest;com.jersey.jaxb;com.fasterxml.jackson.jaxrs.json</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>BIONETDB_HOME</param-name>
<param-value>~/appl/bionetdb/build</param-value>
Expand All @@ -59,21 +59,6 @@
<url-pattern>*</url-pattern>
</filter-mapping>

<!--swagger-->
<!--<servlet>-->
<!--<servlet-name>JerseyJaxrsConfig</servlet-name>-->
<!--<servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>-->

<!--<init-param>-->
<!--<param-name>api.apiVersion</param-name>-->
<!--<param-value>1.0.0</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>swagger.api.basepath</param-name>-->
<!--<param-value>/cellbase/webservices/rest</param-value>-->
<!--</init-param>-->
<!--<load-on-startup>2</load-on-startup>-->
<!--</servlet>-->

<servlet>
<servlet-name>Jersey2Config</servlet-name>
Expand Down
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@
<groupId>org.opencb.biodata</groupId>
<artifactId>biodata-models</artifactId>
<version>${biodata.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-lite</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opencb.commons</groupId>
Expand Down Expand Up @@ -200,7 +210,10 @@
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<BIONETDB.INSTALLATION.DIR>/opt/bionetdb</BIONETDB.INSTALLATION.DIR>

<BIONETDB.DB.DATABASE>scerevisiae</BIONETDB.DB.DATABASE>
<BIONETDB.DB.SPECIES>scerevisiae</BIONETDB.DB.SPECIES>
<BIONETDB.DB.HOST>localhost</BIONETDB.DB.HOST>
<BIONETDB.DB.PORT>7687</BIONETDB.DB.PORT>
<BIONETDB.DB.USER>neo4j</BIONETDB.DB.USER>
Expand Down

0 comments on commit 0d81b1b

Please sign in to comment.