Fixing startup bug and javadoc errors
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@111665 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
10019c27ab
commit
bd00ebddf8
|
@ -1,10 +0,0 @@
|
|||
|
||||
CREATE TABLE IF NOT EXISTS `pluginInstanceEvolution` (
|
||||
`id` INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
`uuid` VARCHAR(36) NOT NULL,
|
||||
`pluginName` VARCHAR(255) NOT NULL,
|
||||
`timestamp` BIGINT NOT NULL,
|
||||
`state` INT NOT NULL
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
2
pom.xml
2
pom.xml
|
@ -107,7 +107,6 @@
|
|||
<directory>${distroDirectory}</directory>
|
||||
<includes>
|
||||
<include>gcube-app.xml</include>
|
||||
<include>db.sql</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
|
@ -119,6 +118,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<warName>smart-executor</warName>
|
||||
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
|
||||
|
|
|
@ -139,7 +139,7 @@ public class ExecutorImpl implements Executor {
|
|||
/**
|
||||
* Create the Service Endpoint using information related to discovered
|
||||
* available plugins and their own discoverd capabilities
|
||||
* @return
|
||||
* @return the created {@link ServiceEndpoint}
|
||||
*/
|
||||
protected static ServiceEndpoint createServiceEndpoint(){
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
package org.gcube.vremanagement.executor.persistence;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
|
@ -11,6 +10,7 @@ import java.sql.DriverManager;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||
|
@ -19,7 +19,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class JDBCPersistenceConnector extends PersistenceConnector {
|
||||
|
||||
|
@ -35,15 +34,18 @@ public class JDBCPersistenceConnector extends PersistenceConnector {
|
|||
public static final String username = "username";
|
||||
public static final String password = "password";
|
||||
public static final String dbName = "executor";
|
||||
public static final String queriesFilePath = "distro/db.sql";
|
||||
|
||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE = "pluginInstanceEvolution";
|
||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE = "PluginInstanceEvolution";
|
||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_ID_FIELD = "id";
|
||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD = "uuid";
|
||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_PLUGIN_NAME_FIELD = "pluginName";
|
||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD = "timestamp";
|
||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD = "state";
|
||||
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* @throws Exception if fails
|
||||
*/
|
||||
public JDBCPersistenceConnector() throws Exception {
|
||||
|
||||
try {
|
||||
|
@ -65,7 +67,29 @@ public class JDBCPersistenceConnector extends PersistenceConnector {
|
|||
}
|
||||
|
||||
try {
|
||||
runScript(queriesFilePath);
|
||||
connection.setAutoCommit(false); // transaction block start
|
||||
|
||||
String createTable = String.format(
|
||||
"CREATE TABLE IF NOT EXISTS `%s` ("
|
||||
+ "`%s` INT PRIMARY KEY AUTO_INCREMENT NOT NULL,"
|
||||
+ "`%s` VARCHAR(36) NOT NULL,"
|
||||
+ "`%s` VARCHAR(255) NOT NULL,"
|
||||
+ "`%s` BIGINT NOT NULL,"
|
||||
+ "`%s` INT NOT NULL);",
|
||||
PLUGIN_INSTANCE_EVOLUTION_TABLE,
|
||||
PLUGIN_INSTANCE_EVOLUTION_TABLE_ID_FIELD,
|
||||
PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD,
|
||||
PLUGIN_INSTANCE_EVOLUTION_TABLE_PLUGIN_NAME_FIELD,
|
||||
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD,
|
||||
PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD);
|
||||
|
||||
logger.info(String.format("Creating %s Table : %s.",
|
||||
PLUGIN_INSTANCE_EVOLUTION_TABLE, createTable));
|
||||
|
||||
Statement createTableStatement = connection.createStatement();
|
||||
createTableStatement.execute(createTable);
|
||||
connection.commit(); //transaction block end
|
||||
|
||||
}catch (Exception e){
|
||||
logger.error("Error while creating DB", e);
|
||||
throw e;
|
||||
|
@ -73,15 +97,8 @@ public class JDBCPersistenceConnector extends PersistenceConnector {
|
|||
|
||||
}
|
||||
|
||||
protected void runScript(String queriesFilePath) throws Exception {
|
||||
SQLiteScriptRunner scriptRunner = new SQLiteScriptRunner(connection, false, true);
|
||||
FileReader fileReader = new FileReader(queriesFilePath);
|
||||
scriptRunner.runScript(fileReader);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the connection
|
||||
* @return the connection to the DB
|
||||
*/
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
package org.gcube.vremanagement.executor.persistence;
|
||||
|
||||
/*
|
||||
* Slightly modified version of the com.ibatis.common.jdbc.ScriptRunner class
|
||||
* from the iBATIS Apache project. Only removed dependency on Resource class
|
||||
* and a constructor
|
||||
*/
|
||||
/*
|
||||
* Copyright 2004 Clinton Begin
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Tool to run database scripts
|
||||
*/
|
||||
public class SQLiteScriptRunner {
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static Logger logger = LoggerFactory.getLogger(SQLiteScriptRunner.class);
|
||||
|
||||
private static final String DEFAULT_DELIMITER = ";";
|
||||
|
||||
private Connection connection;
|
||||
|
||||
private boolean stopOnError;
|
||||
private boolean autoCommit;
|
||||
|
||||
private String delimiter = DEFAULT_DELIMITER;
|
||||
private boolean fullLineDelimiter = false;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public SQLiteScriptRunner(Connection connection, boolean autoCommit,
|
||||
boolean stopOnError) {
|
||||
this.connection = connection;
|
||||
this.autoCommit = autoCommit;
|
||||
this.stopOnError = stopOnError;
|
||||
}
|
||||
|
||||
public void setDelimiter(String delimiter, boolean fullLineDelimiter) {
|
||||
this.delimiter = delimiter;
|
||||
this.fullLineDelimiter = fullLineDelimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an SQL script (read in using the Reader parameter)
|
||||
*
|
||||
* @param reader
|
||||
* - the source of the script
|
||||
*/
|
||||
public void runScript(Reader reader) throws IOException, SQLException {
|
||||
try {
|
||||
boolean originalAutoCommit = connection.getAutoCommit();
|
||||
try {
|
||||
if (originalAutoCommit != this.autoCommit) {
|
||||
connection.setAutoCommit(this.autoCommit);
|
||||
}
|
||||
runScript(connection, reader);
|
||||
} finally {
|
||||
connection.setAutoCommit(originalAutoCommit);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error running script. Cause: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an SQL script (read in using the Reader parameter) using the
|
||||
* connection passed in
|
||||
*
|
||||
* @param conn
|
||||
* - the connection to use for the script
|
||||
* @param reader
|
||||
* - the source of the script
|
||||
* @throws SQLException
|
||||
* if any SQL errors occur
|
||||
* @throws IOException
|
||||
* if there is an error reading from the Reader
|
||||
*/
|
||||
private void runScript(Connection conn, Reader reader) throws IOException,
|
||||
SQLException {
|
||||
StringBuffer command = null;
|
||||
try {
|
||||
LineNumberReader lineReader = new LineNumberReader(reader);
|
||||
String line = null;
|
||||
while ((line = lineReader.readLine()) != null) {
|
||||
if (command == null) {
|
||||
command = new StringBuffer();
|
||||
}
|
||||
String trimmedLine = line.trim();
|
||||
if (trimmedLine.startsWith("--")) {
|
||||
logger.debug(trimmedLine);
|
||||
} else if (trimmedLine.length() < 1
|
||||
|| trimmedLine.startsWith("//")) {
|
||||
// Do nothing
|
||||
} else if (trimmedLine.length() < 1
|
||||
|| trimmedLine.startsWith("--")) {
|
||||
// Do nothing
|
||||
} else if (!fullLineDelimiter
|
||||
&& trimmedLine.endsWith(getDelimiter())
|
||||
|| fullLineDelimiter
|
||||
&& trimmedLine.equals(getDelimiter())) {
|
||||
command.append(line.substring(0, line
|
||||
.lastIndexOf(getDelimiter())));
|
||||
command.append(" ");
|
||||
Statement statement = conn.createStatement();
|
||||
|
||||
logger.debug(command.toString());
|
||||
|
||||
try {
|
||||
statement.execute(command.toString());
|
||||
} catch (SQLException e) {
|
||||
e.fillInStackTrace();
|
||||
logger.error("Error executing: " + command, e);
|
||||
if(stopOnError){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
command = null;
|
||||
try {
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
// Ignore to workaround a bug in Jakarta DBCP
|
||||
}
|
||||
Thread.yield();
|
||||
} else {
|
||||
command.append(line);
|
||||
command.append(" ");
|
||||
}
|
||||
}
|
||||
if (!autoCommit) {
|
||||
conn.commit();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.fillInStackTrace();
|
||||
logger.error("Error executing: " + command, e);
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
e.fillInStackTrace();
|
||||
logger.error("Error executing: " + command, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private String getDelimiter() {
|
||||
return delimiter;
|
||||
}
|
||||
|
||||
}
|
|
@ -33,7 +33,7 @@ public class PluginManager {
|
|||
private Map<String, PluginDeclaration> availablePlugins;
|
||||
|
||||
/**
|
||||
* Get the singleton instance of {@link #PPluginManager}.
|
||||
* Get the singleton instance of {@link #PluginManager}.
|
||||
* The first time this function is invoked the instance is null
|
||||
* so it is created. Otherwise the already created instance is returned
|
||||
* @return singleton instance of {@link #PluginManager}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
CREATE TABLE IF NOT EXISTS `pluginInstanceEvolution` (
|
||||
`id` INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
`uuid` VARCHAR(36) NOT NULL,
|
||||
`pluginName` VARCHAR(255) NOT NULL,
|
||||
`timestamp` BIGINT NOT NULL,
|
||||
`state` INT NOT NULL
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<listener>
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.pluginmanager;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -12,6 +9,7 @@ import org.acme.HelloWorldPluginDeclaration;
|
|||
import org.gcube.vremanagement.executor.persistence.JDBCPersistence;
|
||||
import org.gcube.vremanagement.executor.persistence.JDBCPersistenceConnector;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||
import org.gcube.vremanagement.executor.pluginmanager.PluginThread;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
|
Loading…
Reference in New Issue