Commit 62382a93 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added connection pooling on core, added ObsCore uytpe and ucd on XML model,...

Added connection pooling on core, added ObsCore uytpe and ucd on XML model, added ObsCore optional columns
parent 60551cea
......@@ -13,15 +13,23 @@
<netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>8.5.19</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1104-jdbc41</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
......@@ -45,6 +53,14 @@
<show>public</show>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -38,6 +38,11 @@ public class Column extends ChildEntity<Table> {
public final static String ARRAYSIZE_KEY = "arraysize";
public final static String INDEXED_KEY = "indexed";
public final static String PRIMARY_KEY = "primary_key";
public final static String PRINCIPAL_KEY = "principal";
public final static String STD_KEY = "std";
public final static String UTYPE_KEY = "utype";
public final static String UCD_KEY = "ucd";
public final static String UNIT_KEY = "unit";
private static final long serialVersionUID = 9175956487892235521L;
private static final Logger LOG = LoggerFactory.getLogger(Column.class);
......
......@@ -22,10 +22,8 @@
*/
package it.inaf.ia2.tsm;
import it.inaf.ia2.tsm.datalayer.Credentials;
import it.inaf.ia2.tsm.datalayer.DatabaseType;
import it.inaf.ia2.tsm.datalayer.DBWrapper;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
......@@ -33,7 +31,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -47,36 +44,6 @@ public class TSMUtil {
private static final Logger LOG = LoggerFactory.getLogger(TSMUtil.class);
public static DataSource createDataSource(Credentials credentials) {
switch (credentials.getDatabaseType()) {
case MYSQL:
MysqlDataSource myds = new MysqlDataSource();
myds.setServerName(credentials.getHostname());
myds.setPortNumber(credentials.getPort());
myds.setUser(credentials.getUsername());
myds.setPassword(credentials.getPassword());
return myds;
case POSTGRES:
PGPoolingDataSource pgds = new PGPoolingDataSource();
pgds.setServerName(credentials.getHostname());
pgds.setPortNumber(credentials.getPort());
pgds.setUser(credentials.getUsername());
pgds.setPassword(credentials.getPassword());
pgds.setDatabaseName(credentials.getDatabase());
return pgds;
default:
throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
}
}
protected static List<String> sortStringsList(List<String> list) {
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list;
......@@ -236,11 +203,6 @@ public class TSMUtil {
return null;
}
// private static void setTSColumnDescription(Table table, String columnName, String description) {
// Column column = table.getChild(columnName);
// column.setDescription(description);
// column.setStd(true);
// }
public static String getNaturalLangueName(TapSchemaEntity entity) {
if (entity instanceof Schema) {
return "schema";
......
......@@ -56,7 +56,6 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
public static final String KEY_COLUMNS_TABLE = "key_columns";
public static final String DESCRIPTION_KEY = "description";
public static final String STD_KEY = "std";
private static final long serialVersionUID = 1678083091602571256L;
......@@ -458,7 +457,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
// Adding TAP_SCHEMA into TAP_SCHEMA
addEntireSchema(tapSchemaName);
fillColumnDescriptionsAndStd(tapSchemaModel, tapSchemaName);
fillColumnProperties(tapSchemaModel, tapSchemaName);
if (obscore) {
SchemaModel ivoaSchemaModel = getIvoaSchemaModel();
......@@ -680,11 +679,22 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
return visibleKeys;
}
private Integer getIntAsBool(Boolean value) {
if (value == null) {
return null;
}
return value ? 1 : 0;
}
/**
* Fill descriptions of the TAP_SCHEMA schema entities for a given
* SchemaModel (TAP_SCHEMA or ivoa).
*/
private void fillColumnDescriptionsAndStd(SchemaModel schemaModel, String schemaName) {
private void fillColumnProperties(SchemaModel schemaModel, String schemaName) {
// check only on std, but valid also for principal (it depends on TS version)
boolean useIntegerAsBool = getTapSchemaModel().get(COLUMNS_TABLE).get(Column.STD_KEY).getJavaType() == Integer.class;
Schema schema = getChild(schemaName);
schema.setValue(DESCRIPTION_KEY, schemaModel.getDescription());
for (TableModel tableModel : schemaModel.getTables().values()) {
......@@ -693,14 +703,19 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
for (PropertyModel propertyModel : tableModel.getProperties().values()) {
Column column = table.getChild(propertyModel.getName());
column.setValue(DESCRIPTION_KEY, propertyModel.getDescription());
if (propertyModel.isStandard()) {
column.setValue(STD_KEY, 1);
}
column.setValue(Column.UCD_KEY, propertyModel.getUcd());
column.setValue(Column.UNIT_KEY, propertyModel.getUnit());
column.setValue(Column.UTYPE_KEY, propertyModel.getUtype());
Object compatibleStd = useIntegerAsBool ? getIntAsBool(propertyModel.isStandard()) : propertyModel.isStandard();
Object compatiblePrincipal = useIntegerAsBool ? getIntAsBool(propertyModel.isPrincipal()) : propertyModel.isPrincipal();
column.setValue(Column.STD_KEY, compatibleStd);
column.setValue(Column.PRINCIPAL_KEY, compatiblePrincipal);
}
}
}
private void fillColumnDescriptionsAndStd(SchemaModel schemaModel) {
fillColumnDescriptionsAndStd(schemaModel, schemaModel.getName());
fillColumnProperties(schemaModel, schemaModel.getName());
}
}
......@@ -22,10 +22,8 @@
*/
package it.inaf.ia2.tsm.datalayer;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.io.Serializable;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
/**
* Serializable wrapper for a DataSource.
......@@ -48,32 +46,32 @@ public class DataSourceWrapper implements Serializable {
public DataSource getDataSource() {
if (dataSource == null) {
String driverClassName, url;
switch (credentials.getDatabaseType()) {
case MYSQL:
MysqlDataSource myds = new MysqlDataSource();
myds.setServerName(credentials.getHostname());
myds.setPortNumber(credentials.getPort());
myds.setUser(credentials.getUsername());
myds.setPassword(credentials.getPassword());
return myds;
driverClassName = "com.mysql.jdbc.Driver";
url = String.format("jdbc:mysql://%s:%s", credentials.getHostname(), credentials.getPort());
break;
case POSTGRES:
PGPoolingDataSource pgds = new PGPoolingDataSource();
pgds.setServerName(credentials.getHostname());
pgds.setPortNumber(credentials.getPort());
pgds.setUser(credentials.getUsername());
pgds.setPassword(credentials.getPassword());
pgds.setDatabaseName(credentials.getDatabase());
return pgds;
driverClassName = "org.postgresql.Driver";
url = String.format("jdbc:postgresql://%s:%s/%s",
credentials.getHostname(), credentials.getPort(), credentials.getDatabase());
break;
default:
throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
}
org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource();
ds.setDriverClassName(driverClassName);
ds.setUrl(url);
ds.setUsername(credentials.getUsername());
ds.setPassword(credentials.getPassword());
ds.setInitialSize(5);
ds.setMaxActive(10);
ds.setMaxIdle(5);
ds.setMinIdle(2);
dataSource = ds;
}
return dataSource;
}
......
......@@ -40,14 +40,21 @@ public class PropertyModel implements Serializable {
private boolean updatable;
private boolean nullable;
private boolean standard;
private boolean mandatory;
private String defaultValueString;
private String loaderKey;
private String description;
private String ucd;
private String utype;
private String unit;
private boolean principal;
public PropertyModel() {
// default values
updatable = true;
nullable = true;
// Currently this is used only for ObsCore
mandatory = true;
}
@XmlElement(name = "name")
......@@ -104,6 +111,15 @@ public class PropertyModel implements Serializable {
this.standard = standard;
}
@XmlElement(name = "mandatory", defaultValue = "true")
public boolean isMandatory() {
return mandatory;
}
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}
@XmlElement(name = "default-value")
public String getDefaultValueString() {
return defaultValueString;
......@@ -131,6 +147,42 @@ public class PropertyModel implements Serializable {
this.description = description;
}
@XmlElement(name = "ucd")
public String getUcd() {
return ucd;
}
public void setUcd(String ucd) {
this.ucd = ucd;
}
@XmlElement(name = "utype")
public String getUtype() {
return utype;
}
public void setUtype(String utype) {
this.utype = utype;
}
@XmlElement(name = "unit")
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
@XmlElement(name = "principal", defaultValue = "false")
public boolean isPrincipal() {
return principal;
}
public void setPrincipal(boolean principal) {
this.principal = principal;
}
@XmlTransient
public Object getDefaultValue() {
if (defaultValueString == null) {
......
......@@ -103,7 +103,11 @@ public class SchemaModels {
tableModel = new TableModel(tableXmlModel);
}
for (PropertyModel property : tableXmlModel.getAdd()) {
tableModel.getProperties().put(property.getName(), property);
if (tableModel.getProperties().get(property.getName()) == null) {
// Add property only if it didn't exist in child structure
// this allows to override properties in children
tableModel.getProperties().put(property.getName(), property);
}
}
model.getTables().put(tableName, tableModel);
}
......
......@@ -71,5 +71,17 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<pgsql>text</pgsql>
<java>java.lang.String</java>
</type>
<type>
<adql>TIMESTAMP</adql>
<mysql>TIMESTAMP</mysql>
<pgsql>timestamp</pgsql>
<java>java.lang.String</java>
</type>
<type>
<adql>REGION</adql>
<mysql>VARCHAR</mysql>
<pgsql>character varying</pgsql>
<java>java.lang.String</java>
</type>
</sql_type_mapping>
package it.inaf.ia2.tap.tasman;
import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.webapp.WebAppContext;
/**
......@@ -10,11 +14,29 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class Main {
private static final int DEFAULT_PORT = 8080;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
Server server = new Server(2500);
int port = DEFAULT_PORT;
if (args.length == 1) {
try {
port = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
System.err.println("First argument must be a port number");
}
}
final int serverPort = port;
// Suppress log verbosity
((StdErrLog) Log.getRootLogger()).setLevel(StdErrLog.LEVEL_WARN);
Server server = new Server(serverPort);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
......@@ -22,17 +44,26 @@ public class Main {
webapp.setWar(warFile.getAbsolutePath());
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=477705
//https://docs.jboss.org/weld/reference/latest/en-US/html/environments.html#_jetty
// https://docs.jboss.org/weld/reference/latest/en-US/html/environments.html#_jetty
webapp.prependServerClass("-org.eclipse.jetty.server.handler.ContextHandler");
webapp.prependServerClass("-org.eclipse.jetty.servlet.FilterHolder");
webapp.prependServerClass("-org.eclipse.jetty.servlet.ServletContextHandler");
webapp.prependServerClass("-org.eclipse.jetty.servlet.ServletHolder");
webapp.addEventListener(new ServletContextListener() {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("TASMAN initialized. Visit http://localhost:" + serverPort);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
});
server.setHandler(webapp);
server.start();
server.dumpStdErr();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
server.join();
......
......@@ -111,6 +111,13 @@
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>tasman-core</artifactId>
<version>1.2.0</version>
<exclusions>
<!-- exclusion due to tomcat-jdbc dependency conflicting with Jetty -->
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ari.ucidy</groupId>
......
......@@ -97,5 +97,36 @@
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet>
<servlet-name>REST</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>it.inaf.ia2.tsm.webapp it.inaf.ia2.tsm.webapp.env</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>REST</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>welcomeServlets</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>redirectWelcome</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
${enable.jetty.config.start} -->
</web-app>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment