diff --git a/.gitignore b/.gitignore index 4dd69fea..43afce4f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ velocity.log out/ err/ +workflow.out +workflow.err conf/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3740bfa1..d9e10b61 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 @@ -56,8 +56,8 @@ - maven-surefire-plugin - 3.5.1 + maven-surefire-plugin + 3.5.1 @@ -90,21 +90,39 @@ - log4j - log4j - 1.2.17 + ch.qos.logback + logback-classic + 1.5.18 + + + + org.slf4j + slf4j-api + 2.0.17 commons-configuration commons-configuration 1.9 + + + commons-logging + commons-logging + + + + + + org.slf4j + jcl-over-slf4j + 2.0.17 commons-io commons-io - 2.4 + 2.17.0 @@ -126,10 +144,10 @@ - org.junit.jupiter - junit-jupiter-api - 5.11.3 - test + org.junit.jupiter + junit-jupiter-api + 5.11.3 + test diff --git a/src/main/java/fr/insalyon/creatis/gasw/Gasw.java b/src/main/java/fr/insalyon/creatis/gasw/Gasw.java index 9477425d..cf0fa7c8 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/Gasw.java +++ b/src/main/java/fr/insalyon/creatis/gasw/Gasw.java @@ -35,17 +35,13 @@ import fr.insalyon.creatis.gasw.execution.ExecutorFactory; import fr.insalyon.creatis.gasw.execution.FailOver; import fr.insalyon.creatis.gasw.plugin.ExecutorPlugin; + import java.util.List; -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -/** - * - * @author Rafael Ferreira da Silva - */ public class Gasw { - - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(Gasw.class); private static Gasw instance; private GaswNotification notification; @@ -63,10 +59,7 @@ public synchronized static Gasw getInstance() throws GaswException { } private Gasw() throws GaswException { - try { - PropertyConfigurator.configure( - Gasw.class.getClassLoader().getResource("gaswLog4j.properties")); logger.info("Initializing GASW."); GaswConfiguration.getInstance().loadHibernate(); @@ -77,22 +70,10 @@ private Gasw() throws GaswException { } } - /** - * Sets the client which will receive notifications. - * - * @param client - */ public synchronized void setNotificationClient(Object client) { - notification.setClient(client); } - /** - * - * @param gaswInput - * @return - * @throws GaswException - */ public synchronized String submit(GaswInput gaswInput) throws GaswException { ExecutorPlugin executor = ExecutorFactory.getExecutor(gaswInput); @@ -100,27 +81,14 @@ public synchronized String submit(GaswInput gaswInput) throws GaswException { return executor.submit(); } - /** - * Gets the list of output objects of all finished jobs - * - * @return List of output objects of finished jobs. - */ public synchronized List getFinishedJobs() { return notification.getFinishedJobs(); } - /** - * The client informs GASW that it is waiting for new notifications. - */ public synchronized void waitForNotification() { notification.waitForNotification(); } - /** - * Terminates all GASW threads and close the connection with the database. - * - * @throws GaswException - */ public synchronized void terminate(boolean force) throws GaswException { notification.terminate(); diff --git a/src/main/java/fr/insalyon/creatis/gasw/GaswConfiguration.java b/src/main/java/fr/insalyon/creatis/gasw/GaswConfiguration.java index 3b084008..68f7442d 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/GaswConfiguration.java +++ b/src/main/java/fr/insalyon/creatis/gasw/GaswConfiguration.java @@ -42,7 +42,8 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.hibernate.SessionFactory; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; @@ -66,13 +67,9 @@ import net.xeoh.plugins.base.util.JSPFProperties; import net.xeoh.plugins.base.util.PluginManagerUtil; -/** - * - * @author Rafael Ferreira da Silva - */ public class GaswConfiguration { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(GaswConfiguration.class); private static final String configDir = "./conf"; private static final String configFile = "settings.conf"; private static GaswConfiguration instance; @@ -127,7 +124,6 @@ public class GaswConfiguration { private SessionFactory sessionFactory; public static GaswConfiguration getInstance() throws GaswException { - if (instance == null) { instance = new GaswConfiguration(); } @@ -231,7 +227,7 @@ private void loadConfigurationFile() throws GaswException { config.save(); } catch (ConfigurationException ex) { - logger.error(ex); + logger.error("Error:", ex); } } @@ -243,11 +239,6 @@ private String getRequiredString(PropertiesConfiguration config, String key) thr } } - /** - * Loads GASW plugins. - * - * @throws GaswException - */ private void loadPlugins() throws GaswException { final JSPFProperties props = new JSPFProperties(); @@ -274,19 +265,12 @@ private void loadPlugins() throws GaswException { private URI getAndLogPluginUri(String pluginPath, String pluginType) { URI pluginUri = new File(pluginPath).toURI(); - logger.info("Loading " + pluginType + " plugin from " + pluginPath - + " (loaded URI : " + pluginUri + ")"); + logger.info("Loading {} plugin from {} (loaded URI : {})", pluginType, pluginPath, pluginUri); return pluginUri; } - /** - * Loads Hibernate properties - * - * @throws GaswException - */ public void loadHibernate() throws GaswException { - - logger.info("Loading database plugin '" + dbPlugin.getName() + "'."); + logger.info("Loading database plugin '{}'.", dbPlugin.getName()); dbPlugin.load(); Configuration cfg = new Configuration(); @@ -325,10 +309,6 @@ public void loadHibernate() throws GaswException { sessionFactory = cfg.buildSessionFactory(serviceRegistry); } - /** - * - * @throws GaswException - */ private void loadSEEntryPoints() throws GaswException { try { logger.info("Loading SEs entry points."); @@ -353,10 +333,10 @@ private void loadSEEntryPoints() throws GaswException { service.getPath())); } catch (URISyntaxException ex) { - logger.warn("Unable to read end point from: " + s); + logger.warn("Unable to read end point from: {}", s); } catch (DAOException ex) { if (!ex.getMessage().contains("duplicate key value")) { - logger.warn("Unable to save end point: " + ex.getMessage()); + logger.warn("Unable to save end point: {}", ex.getMessage()); } } } @@ -369,20 +349,15 @@ private void loadSEEntryPoints() throws GaswException { throw new GaswException("Unable to load SEs entry points."); } } catch (InterruptedException ex) { - logger.error(ex); + logger.error("Error:", ex); throw new GaswException(ex); } catch (IOException ex) { - logger.error(ex); + logger.error("Error:", ex); throw new GaswException(ex); } } - /** - * Terminates all plugins. - * - * @throws GaswException - */ public void terminate(boolean force) throws GaswException { for (ExecutorPlugin executorPlugin : executorPlugins) { diff --git a/src/main/java/fr/insalyon/creatis/gasw/GaswNotification.java b/src/main/java/fr/insalyon/creatis/gasw/GaswNotification.java index 0e5ee2cd..58de1ef0 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/GaswNotification.java +++ b/src/main/java/fr/insalyon/creatis/gasw/GaswNotification.java @@ -39,15 +39,12 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -/** - * - * @author Rafael Silva - */ public class GaswNotification extends Thread { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(GaswNotification.class); private static GaswNotification instance; private Notification notification; private Object client; @@ -76,30 +73,19 @@ private GaswNotification() { * @param client */ public void setClient(Object client) { - this.client = client; notification = new Notification(); notification.start(); } - /** - * - * @param finishedJobs - */ public synchronized void addFinishedJob(GaswOutput finishedJob) { - this.finishedJobs.add(finishedJob); } - /** - * Gets the list of output objects of all finished jobs - * - * @return List of output objects of finished jobs. - */ public List getFinishedJobs() { - gettingOutputs = true; List outputsList = new ArrayList(); + synchronized (finishedJobs) { for (GaswOutput output : finishedJobs) { outputsList.add(output); @@ -110,9 +96,8 @@ public List getFinishedJobs() { return outputsList; } - public synchronized void addErrorJob(GaswOutput errorJob) { - if (errorJob.getStdErr()!=null) { + if (errorJob.getStdErr() != null) { String instanceId = errorJob.getJobID(); if (this.instanceErrorJobs.containsKey(instanceId)) { this.instanceErrorJobs.replace(instanceId,errorJob); @@ -122,9 +107,6 @@ public synchronized void addErrorJob(GaswOutput errorJob) { } } - /** - * Gets the GaswOutput for the last job in error for instanceId - */ public GaswOutput getGaswOutputFromLastFailedJob(String instanceId) { if (this.instanceErrorJobs.containsKey(instanceId)) { return this.instanceErrorJobs.get(instanceId); @@ -132,27 +114,16 @@ public GaswOutput getGaswOutputFromLastFailedJob(String instanceId) { return null; } - /** - * The client informs GASW that it is waiting for new notifications. - */ public void waitForNotification() { - gettingOutputs = false; } - /** - * Terminates the notification thread. - */ - public void terminate() { + public void terminate() { notification.terminate(); } - /** - * Notifies the client when tasks are finished. - */ private class Notification extends Thread { - private boolean stop = false; @Override @@ -169,9 +140,9 @@ public void run() { try { sleep(GaswConfiguration.getInstance().getDefaultSleeptime() / 2); } catch (GaswException ex) { - logger.error(ex); + logger.error("Error:", ex); } catch (InterruptedException ex) { - logger.error(ex); + logger.error("Error:", ex); } } } diff --git a/src/main/java/fr/insalyon/creatis/gasw/GaswUtil.java b/src/main/java/fr/insalyon/creatis/gasw/GaswUtil.java index f3cc236f..b822d6be 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/GaswUtil.java +++ b/src/main/java/fr/insalyon/creatis/gasw/GaswUtil.java @@ -37,7 +37,7 @@ import java.io.InputStreamReader; import java.util.regex.Pattern; -import org.apache.log4j.Logger; +import org.slf4j.Logger; public class GaswUtil { @@ -49,8 +49,7 @@ public static int sleep(Logger logger, String message, int index) if (index < times.length - 1) { index++; } - logger.warn(message + ". Next " - + "attempt in " + times[index] + " seconds."); + logger.warn("{}. Next attempt in {} seconds.", message, times[index]); Thread.sleep(times[index] * 1000); return index; } @@ -77,7 +76,6 @@ public static BufferedReader getBufferedReader(Process process) { } public static void closeProcess(Process process) throws IOException { - process.getOutputStream().close(); process.getInputStream().close(); process.getErrorStream().close(); diff --git a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/DataToReplicateData.java b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/DataToReplicateData.java index 5fd2149b..2faab0ce 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/DataToReplicateData.java +++ b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/DataToReplicateData.java @@ -37,19 +37,17 @@ import fr.insalyon.creatis.gasw.bean.DataToReplicate; import fr.insalyon.creatis.gasw.dao.DAOException; import fr.insalyon.creatis.gasw.dao.DataToReplicateDAO; + import java.util.List; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; -/** - * - * @author Rafael Silva - */ public class DataToReplicateData implements DataToReplicateDAO { - private static final Logger logger = Logger.getLogger(JobData.class); + private static final Logger logger = LoggerFactory.getLogger(DataToReplicate.class); private SessionFactory sessionFactory; public DataToReplicateData(SessionFactory sessionFactory) { @@ -66,7 +64,7 @@ public synchronized void add(DataToReplicate dataToReplicate) throws DAOExceptio session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while adding", ex); throw new DAOException(ex); } } @@ -80,7 +78,7 @@ public synchronized void update(DataToReplicate dataToReplicate) throws DAOExcep session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while updating", ex); throw new DAOException(ex); } } @@ -94,7 +92,7 @@ public synchronized void remove(DataToReplicate dataToReplicate) throws DAOExcep session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error whice removing", ex); throw new DAOException(ex); } } @@ -111,7 +109,7 @@ public synchronized List get() throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving", ex); throw new DAOException(ex); } } diff --git a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobData.java b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobData.java index 706bb7d5..06f66540 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobData.java +++ b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobData.java @@ -36,19 +36,17 @@ import fr.insalyon.creatis.gasw.dao.DAOException; import fr.insalyon.creatis.gasw.dao.JobDAO; import fr.insalyon.creatis.gasw.execution.GaswStatus; + import java.util.List; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; -/** - * - * @author Rafael Ferreira da Silva - */ public class JobData implements JobDAO { - private static final Logger logger = Logger.getLogger(JobData.class); + private static final Logger logger = LoggerFactory.getLogger(JobData.class); private SessionFactory sessionFactory; public JobData(SessionFactory sessionFactory) { @@ -63,7 +61,7 @@ public void add(Job job) throws DAOException { session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while adding", ex); throw new DAOException(ex); } } @@ -81,7 +79,7 @@ public void update(Job job) throws DAOException { session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while updateing", ex); throw new DAOException(ex); } } @@ -96,7 +94,7 @@ public void remove(Job job) throws DAOException { session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while removing", ex); throw new DAOException(ex); } } @@ -115,7 +113,7 @@ public Job getJobByID(String id) throws DAOException { return job; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving by ID", ex); throw new DAOException(ex); } } @@ -138,7 +136,7 @@ public List getActiveJobs() throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving actives jobs", ex); throw new DAOException(ex); } } @@ -155,7 +153,7 @@ public List getJobs(GaswStatus status) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving jobs", ex); throw new DAOException(ex); } } @@ -174,7 +172,7 @@ public long getNumberOfCompletedJobsByInvocationID(int invocationID) throws DAOE return completedJobs; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving completed jobs by invocation ID",ex); throw new DAOException(ex); } } @@ -198,7 +196,7 @@ public List getActiveJobsByInvocationID(int invocationID) throws DAOExcepti return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving actives jobs by invocation ID", ex); throw new DAOException(ex); } } @@ -220,7 +218,7 @@ public List getFailedJobsByInvocationID(int invocationID) throws DAOExcepti return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving failed jobs by invocation ID", ex); throw new DAOException(ex); } } @@ -242,7 +240,7 @@ public List getRunningByCommand(String command) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving running jobs by command", ex); throw new DAOException(ex); } } @@ -261,7 +259,7 @@ public List getCompletedByCommand(String command) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving completed jobs by command", ex); throw new DAOException(ex); } } @@ -279,7 +277,7 @@ public List getByParameters(String parameters) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving jobs by parameters", ex); throw new DAOException(ex); } } @@ -301,13 +299,13 @@ public List getFailedByCommand(String command) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving failed jobs by command", ex); throw new DAOException(ex); } } @Override - public List getJobsByCommand(String command) throws DAOException { + public List getJobsByCommand(String command) throws DAOException { try (Session session = sessionFactory.openSession()) { session.beginTransaction(); @@ -319,7 +317,7 @@ public List getJobsByCommand(String command) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving jobs by command", ex); throw new DAOException(ex); } } @@ -337,7 +335,7 @@ public List getInvocationsByCommand(String command) throws DAOException return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving invocations by command", ex); throw new DAOException(ex); } } @@ -355,7 +353,7 @@ public List getByFileName(String filename) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving jobs by filename", ex); throw new DAOException(ex); } } diff --git a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobMinorStatusData.java b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobMinorStatusData.java index b4682ff7..b1b4ece1 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobMinorStatusData.java +++ b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/JobMinorStatusData.java @@ -39,18 +39,15 @@ import fr.insalyon.creatis.gasw.dao.JobMinorStatusDAO; import fr.insalyon.creatis.gasw.execution.GaswMinorStatus; import java.util.List; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; -/** - * - * @author Rafael Ferreira da Silva - */ public class JobMinorStatusData implements JobMinorStatusDAO { - private static final Logger logger = Logger.getLogger(JobData.class); + private static final Logger logger = LoggerFactory.getLogger(JobMinorStatusData.class); private SessionFactory sessionFactory; public JobMinorStatusData(SessionFactory sessionFactory) { @@ -67,7 +64,7 @@ public void add(JobMinorStatus jobMinorStatus) throws DAOException { session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while adding", ex); throw new DAOException(ex); } } @@ -88,7 +85,7 @@ public List getCheckpoints(String jobID) throws DAOException { return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving checkpoints", ex); throw new DAOException(ex); } } @@ -112,7 +109,7 @@ public List getExecutionMinorStatus(String jobID) throws DAOExce return list; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving minorstatus", ex); throw new DAOException(ex); } } @@ -133,7 +130,7 @@ public long getDateDiff(String jobID, GaswMinorStatus start, return Math.abs(list.get(1).getDate().getTime() - list.get(0).getDate().getTime()); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving date diff", ex); throw new DAOException(ex); } } diff --git a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/NodeData.java b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/NodeData.java index 60003d72..d1898c81 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/NodeData.java +++ b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/NodeData.java @@ -37,18 +37,15 @@ import fr.insalyon.creatis.gasw.bean.Node; import fr.insalyon.creatis.gasw.dao.DAOException; import fr.insalyon.creatis.gasw.dao.NodeDAO; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; -/** - * - * @author Rafael Silva - */ public class NodeData implements NodeDAO { - private static final Logger logger = Logger.getLogger(JobData.class); + private static final Logger logger = LoggerFactory.getLogger(NodeData.class); private SessionFactory sessionFactory; public NodeData(SessionFactory sessionFactory) { @@ -65,7 +62,7 @@ public void add(Node node) throws DAOException { session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while adding", ex); throw new DAOException(ex); } } @@ -84,7 +81,7 @@ public Node getNodeBySiteAndNodeName(String site, String nodeName) throws DAOExc return node; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving", ex); throw new DAOException(ex); } } diff --git a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/SEEntryPointData.java b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/SEEntryPointData.java index ca38d3d4..32e17f35 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/SEEntryPointData.java +++ b/src/main/java/fr/insalyon/creatis/gasw/dao/hibernate/SEEntryPointData.java @@ -37,18 +37,15 @@ import fr.insalyon.creatis.gasw.bean.SEEntryPoint; import fr.insalyon.creatis.gasw.dao.DAOException; import fr.insalyon.creatis.gasw.dao.SEEntryPointsDAO; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; -/** - * - * @author Rafael Silva - */ public class SEEntryPointData implements SEEntryPointsDAO { - private static final Logger logger = Logger.getLogger(JobData.class); + private static final Logger logger = LoggerFactory.getLogger(SEEntryPointData.class); private SessionFactory sessionFactory; public SEEntryPointData(SessionFactory sessionFactory) { @@ -65,7 +62,7 @@ public synchronized void add(SEEntryPoint seEntryPoint) throws DAOException { session.getTransaction().commit(); } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while adding", ex); throw new DAOException(ex); } } @@ -83,7 +80,7 @@ public synchronized SEEntryPoint getByHostName(String hostname) throws DAOExcept return entryPoint; } catch (HibernateException ex) { - logger.error(ex); + logger.error("Error while retrieving", ex); throw new DAOException(ex); } } diff --git a/src/main/java/fr/insalyon/creatis/gasw/execution/FailOver.java b/src/main/java/fr/insalyon/creatis/gasw/execution/FailOver.java index 2ee7b043..a5d4508a 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/execution/FailOver.java +++ b/src/main/java/fr/insalyon/creatis/gasw/execution/FailOver.java @@ -52,21 +52,17 @@ import java.util.Date; import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -/** - * - * @author Rafael Silva - */ public class FailOver extends Thread { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(FailOver.class); private static FailOver instance; private volatile boolean stop = false; private DataToReplicateDAO dataToReplicateDAO; public synchronized static FailOver getInstance() { - if (instance == null) { instance = new FailOver(); instance.start(); @@ -75,7 +71,6 @@ public synchronized static FailOver getInstance() { } private FailOver() { - try { dataToReplicateDAO = DAOFactory.getDAOFactory().getDataToReplicateDAO(); } catch (DAOException ex) { @@ -85,7 +80,6 @@ private FailOver() { @Override public void run() { - try { while (!stop) { @@ -101,7 +95,7 @@ public void run() { data.setEventDate(new Date()); dataToReplicateDAO.update(data); } else { - logger.warn("Achieved data max attempts to reply '" + data.getUrl().getPath() + "'."); + logger.warn("Achieved data max attempts to reply '{}'.", data.getUrl().getPath()); dataToReplicateDAO.remove(data); } } @@ -113,17 +107,11 @@ public void run() { } catch (GaswException ex) { // do nothing } catch (InterruptedException ex) { - logger.error(ex); + logger.error("InterruptedException: ",ex); } } - /** - * - * @param uri - * @throws DAOException - */ public synchronized void addData(URI uri) { - try { String scheme = uri.getScheme(); if (scheme == null || (!scheme.equalsIgnoreCase("file") @@ -132,35 +120,20 @@ public synchronized void addData(URI uri) { dataToReplicateDAO.add(new DataToReplicate(uri)); } } catch (DAOException ex) { - logger.error("Unable to add data to replication table: " + ex.getMessage()); + logger.error("Unable to add data to replication table: {}", ex.getMessage()); } } - /** - * - * @param uris - * @throws DAOException - */ public synchronized void addData(List uris) { - for (URI uri : uris) { addData(uri); } } - /** - * Terminates the fail over thread. - */ public synchronized void terminate() { - this.stop = true; } - /** - * - * @param uri - * @throws GaswException - */ private void replicate(URI uri) throws GaswException { List replicas = getReplicas(uri); @@ -171,7 +144,7 @@ private void replicate(URI uri) throws GaswException { } } - logger.info("Replicating '" + uri.getPath() + "'."); + logger.info("Replicating '{}'.", uri.getPath()); Process process = null; BufferedReader br = null; @@ -197,11 +170,11 @@ private void replicate(URI uri) throws GaswException { return; } } catch (InterruptedException ex) { - logger.warn(ex); + logger.warn("InterruptedException:", ex); } catch (DAOException ex) { - logger.warn("Unable to find entry point for '" + replica.getHost() + "'."); + logger.warn("Unable to find entry point for '{}'.", replica.getHost()); } catch (IOException ex) { - logger.warn(ex); + logger.warn("IOException:", ex); } finally { if (process != null) { close(process); @@ -210,7 +183,7 @@ private void replicate(URI uri) throws GaswException { try { br.close(); } catch (IOException ex) { - logger.error(ex); + logger.error("IOException:", ex); } } } @@ -218,12 +191,6 @@ private void replicate(URI uri) throws GaswException { throw new GaswException("Unable to replicate '" + uri.getPath() + "'."); } - /** - * - * @param uri - * @return - * @throws GaswException - */ private List getReplicas(URI uri) throws GaswException { Process process = null; @@ -244,17 +211,17 @@ private List getReplicas(URI uri) throws GaswException { process.waitFor(); if (process.exitValue() != 0) { - logger.error("Unable to get replicas from '" + uri.getPath() + "'."); + logger.error("Unable to get replicas from '{}'.", uri.getPath()); throw new GaswException("Unable to get replicas from '" + uri.getPath() + "'."); } } catch (InterruptedException ex) { - logger.error(ex); + logger.error("InterruptedException:", ex); throw new GaswException(ex); } catch (IOException ex) { - logger.error(ex); + logger.error("IOException:", ex); throw new GaswException(ex); } catch (URISyntaxException ex) { - logger.error(ex); + logger.error("URISyntaxException:", ex); throw new GaswException(ex); } finally { @@ -265,19 +232,13 @@ private List getReplicas(URI uri) throws GaswException { try { br.close(); } catch (IOException ex) { - logger.error(ex); + logger.error("IOException:", ex); } } } return replicas; } - /** - * Gets the destination SURL - * - * @return - * @throws GaswException - */ private String getDestinationSURL() throws GaswException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @@ -288,14 +249,6 @@ private String getDestinationSURL() throws GaswException { + "/" + sdf.format(new Date()) + "/file-" + UUID.randomUUID(); } - /** - * Gets the source file SURL and type - * - * @param host - * @param path - * @return - * @throws DAOException - */ private String[] getSourceTypeAndSURL(String host, String path) throws DAOException { SEEntryPoint ep = DAOFactory.getDAOFactory().getSEEntryPointDAO().getByHostName(host); diff --git a/src/main/java/fr/insalyon/creatis/gasw/execution/GaswMonitor.java b/src/main/java/fr/insalyon/creatis/gasw/execution/GaswMonitor.java index 691fa8c9..53a680c1 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/execution/GaswMonitor.java +++ b/src/main/java/fr/insalyon/creatis/gasw/execution/GaswMonitor.java @@ -40,25 +40,21 @@ import fr.insalyon.creatis.gasw.dao.JobDAO; import fr.insalyon.creatis.gasw.dao.NodeDAO; import fr.insalyon.creatis.gasw.plugin.ListenerPlugin; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; import java.util.List; -/** - * - * @author Rafael Ferreira da Silva - */ public abstract class GaswMonitor extends Thread { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(GaswMonitor.class); private volatile static int INVOCATION_ID = 1; protected JobDAO jobDAO; protected NodeDAO nodeDAO; protected GaswMonitor() { - try { jobDAO = DAOFactory.getDAOFactory().getJobDAO(); nodeDAO = DAOFactory.getDAOFactory().getNodeDAO(); @@ -68,12 +64,6 @@ protected GaswMonitor() { } } - /** - * Adds a job to the database. - * - * @param job - * @param fileName - */ protected synchronized void add(Job job) throws GaswException { try { // Defining invocation ID @@ -101,20 +91,12 @@ protected synchronized void add(Job job) throws GaswException { /** * Adds a job to be monitored. It should constructs a Job object and invoke * the protected method add(job). - * - * @param jobID - * @param symbolicName - * @param fileName - * @throws GaswException */ public abstract void add(String jobID, String symbolicName, String fileName, String parameters) throws GaswException; /** * Updates the job status and notifies listeners. - * - * @param job - * @throws DAOException */ protected void updateStatus(Job job) throws GaswException, DAOException { @@ -124,9 +106,6 @@ protected void updateStatus(Job job) throws GaswException, DAOException { jobDAO.update(job); } - /** - * Verifies if there are signaled jobs. - */ protected void verifySignaledJobs() { try { @@ -158,54 +137,20 @@ protected void verifySignaledJobs() { resume(job); } } catch (DAOException ex) { - logger.error("[Gasw Monitor] Error handling signaled jobs", ex); + logger.error("Error handling signaled jobs", ex); } } /** * Verifies if a job is replica and handles it in case it is. - * - * @param job - * @return - * @throws GaswException - * @throws DAOException */ protected boolean isReplica(Job job) throws DAOException { return jobDAO.getNumberOfCompletedJobsByInvocationID(job.getInvocationID()) > 0; } - /** - * Kills a job. - * - * @param jobID - */ protected abstract void kill(Job job); - - /** - * Reschedule a job. - * - * @param jobID - */ protected abstract void reschedule(Job job); - - /** - * Replicates a job. - * - * @param jobID - */ protected abstract void replicate(Job job); - - /** - * Kills job replicas. - * - * @param invocationID - */ protected abstract void killReplicas(Job job); - - /** - * Resumes a job. - * - * @param jobID - */ protected abstract void resume(Job job); } diff --git a/src/main/java/fr/insalyon/creatis/gasw/execution/GaswOutputParser.java b/src/main/java/fr/insalyon/creatis/gasw/execution/GaswOutputParser.java index d629b3d5..84aa1d50 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/execution/GaswOutputParser.java +++ b/src/main/java/fr/insalyon/creatis/gasw/execution/GaswOutputParser.java @@ -40,15 +40,12 @@ import java.io.*; import java.net.URI; import java.util.*; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -/** - * - * @author Rafael Ferreira da Silva - */ public abstract class GaswOutputParser extends Thread { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(GaswOutputParser.class); protected Job job; protected File appStdOut; protected File appStdErr; @@ -61,12 +58,7 @@ public abstract class GaswOutputParser extends Thread { protected StringBuilder appStdOutBuf; protected StringBuilder appStdErrBuf; - /** - * - * @param jobID job identification - */ public GaswOutputParser(String jobID) { - try { this.job = DAOFactory.getDAOFactory().getJobDAO().getJobByID(jobID); @@ -86,13 +78,12 @@ public GaswOutputParser(String jobID) { } catch (IOException | DAOException ex) { closeBuffers(); - logger.error("[GASW Parser] Error creating std out/err " + - "files and buffers for " + jobID, ex); + logger.error("Error creating std out/err " + + "files and buffers for {}", jobID, ex); } } private void closeBuffers() { - try { if (appStdOutWriter != null) { appStdOutWriter.close(); @@ -101,13 +92,12 @@ private void closeBuffers() { appStdErrWriter.close(); } } catch (IOException ex) { - logger.error("[GASW Parser] Error closing buffers", ex); + logger.error("Error closing buffers", ex); } } @Override public void run() { - try { GaswOutput gaswOutput = getGaswOutput(); @@ -129,10 +119,10 @@ public void run() { } else { int retries = DAOFactory.getDAOFactory().getJobDAO().getFailedJobsByInvocationID(job.getInvocationID()).size() - 1; if (retries < GaswConfiguration.getInstance().getDefaultRetryCount()) { - logger.warn("Job [" + job.getId() + "] finished as \"" + job.getStatus().name() + "\" (retried " + retries + " times)."); + logger.warn("Job [{}] finished as \"{}\" (retried {} times).", job.getId(), job.getStatus().name(), retries); resubmit(); } else { - logger.warn("Job [" + job.getId() + "] finished as \"" + job.getStatus().name() + "\": holding job (max retries reached)."); + logger.warn("Job [{}] finished as \"{}\": holding job (max retries reached).", job.getId(), job.getStatus().name()); if (job.getStatus() == GaswStatus.ERROR) { job.setStatus(GaswStatus.ERROR_HELD); } else if (job.getStatus() == GaswStatus.STALLED) { @@ -145,14 +135,12 @@ public void run() { return; } } catch (DAOException | GaswException ex) { - logger.error("[GASW Parser] Error finalising job " + - job.getId(), ex); + logger.error("Error finalising job {}", job.getId(), ex); } GaswNotification.getInstance().addFinishedJob(gaswOutput); } catch (GaswException ex) { - logger.error("[GASW Parser] Error processing output for" + - " job " + job.getId(), ex); + logger.error("Error processing output for job {}", job.getId(), ex); } } @@ -282,7 +270,7 @@ protected int parseStdOut(File stdOut) { } else if (line.startsWith("")) { isResultUpload = true; @@ -309,12 +297,11 @@ protected int parseStdOut(File stdOut) { } uploadedResults.put(outputId, uri); dataList.add(new Data(uri.toString(), Data.Type.Output)); - logger.info("[GASW Parser] Adding output " + outputId + " " + uri + " for job " + job.getId()); + logger.info("Adding output {} {} for job {}" + outputId, uri, job.getId()); } } } catch (Exception ex) { - logger.error("[GASW Parser] Error parsing stdout " + - stdOut.getAbsolutePath(), ex); + logger.error("Error parsing stdout {}", stdOut.getAbsolutePath(), ex); } finally { scanner.close(); } @@ -340,20 +327,12 @@ protected int parseStdOut(File stdOut) { } catch (DAOException | IOException ex) { closeBuffers(); - logger.error("[GASW Parser] Error parsing stdout " + - stdOut.getAbsolutePath(), ex); + logger.error("Error parsing stdout {}", stdOut.getAbsolutePath(), ex); } return exitCode; } - /** - * - * @param exitCode - * @return Exit code - */ protected int parseStdErr(File stdErr, int exitCode) { - - try { Scanner scanner = new Scanner(new FileInputStream(stdErr)); @@ -420,17 +399,12 @@ protected int parseStdErr(File stdErr, int exitCode) { } catch (DAOException | IOException ex) { closeBuffers(); - logger.error("[GASW Parser] Error parsing stderr " + - stdErr.getAbsolutePath(), ex); + logger.error("Error parsing stderr {}", stdErr.getAbsolutePath(), ex); } return exitCode; } - /** - * - * @param exitCode - */ protected void parseNonStdOut(int exitCode) { try { @@ -438,9 +412,7 @@ protected void parseNonStdOut(int exitCode) { DAOFactory factory = DAOFactory.getDAOFactory(); for (JobMinorStatus minorStatus : factory.getJobMinorStatusDAO().getExecutionMinorStatus(job.getId())) { - switch (minorStatus.getStatus()) { - case Application: job.setRunning(minorStatus.getDate()); break; @@ -454,14 +426,10 @@ protected void parseNonStdOut(int exitCode) { } catch (DAOException ex) { closeBuffers(); - logger.error("[GASW Parser] Error parsing NonStdOut", ex); + logger.error("Error parsing NonStdOut", ex); } } - /** - * - * @return - */ private void parseCheckpoint() { try { @@ -500,17 +468,10 @@ private void parseCheckpoint() { } } catch (DAOException ex) { closeBuffers(); - logger.error("[GASW Parser] Error parsing checkpoints", ex); + logger.error("Error parsing checkpoints", ex); } } - /** - * - * @param extension File extension - * @param dir Output directory - * @param content File content - * @return - */ protected File saveFile(String extension, String dir, String content) { FileWriter fstream = null; try { @@ -527,12 +488,12 @@ protected File saveFile(String extension, String dir, String content) { return stdFile; } catch (IOException ex) { - logger.error(ex); + logger.error("Error:", ex); } finally { try { fstream.close(); } catch (IOException ex) { - logger.error(ex); + logger.error("Error:", ex); } } return null; @@ -556,12 +517,6 @@ protected File moveProvenanceFile(String sourceDir) { GaswConstants.PROVENANCE_ROOT); } - /** - * - * @param extension - * @param dir - * @return - */ protected File getAppStdFile(String extension, String dir) { File stdDir = new File(dir); @@ -591,13 +546,6 @@ protected String getAppStdOut() { return appStdOutBuf.toString(); } - /** - * - * @param dateToBeAdded - * @param field - * @param amount - * @return - */ private Date addDate(Date dateToBeAdded, int field, int amount) { Calendar calendar = Calendar.getInstance(); diff --git a/src/main/java/fr/insalyon/creatis/gasw/execution/GaswSubmit.java b/src/main/java/fr/insalyon/creatis/gasw/execution/GaswSubmit.java index 43771eac..3f237722 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/execution/GaswSubmit.java +++ b/src/main/java/fr/insalyon/creatis/gasw/execution/GaswSubmit.java @@ -43,7 +43,8 @@ import java.nio.file.StandardCopyOption; import java.util.Map; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import fr.insalyon.creatis.gasw.GaswConfiguration; import fr.insalyon.creatis.gasw.GaswConstants; @@ -53,7 +54,7 @@ public abstract class GaswSubmit { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(GaswSubmit.class); protected GaswInput gaswInput; protected String scriptName; protected String jdlName; @@ -135,7 +136,7 @@ protected String publishJdl(String scriptName, String jdl) { return fileName; } catch (IOException ex) { - logger.error(ex); + logger.error("Failed to publishJdl", ex); return null; } } diff --git a/src/main/java/fr/insalyon/creatis/gasw/util/VelocityUtil.java b/src/main/java/fr/insalyon/creatis/gasw/util/VelocityUtil.java index 4940c9a4..d9003b70 100644 --- a/src/main/java/fr/insalyon/creatis/gasw/util/VelocityUtil.java +++ b/src/main/java/fr/insalyon/creatis/gasw/util/VelocityUtil.java @@ -35,12 +35,14 @@ package fr.insalyon.creatis.gasw.util; import fr.insalyon.creatis.gasw.GaswException; + import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.util.Properties; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; @@ -51,13 +53,9 @@ import org.apache.velocity.runtime.resource.loader.StringResourceLoader; import org.apache.velocity.runtime.resource.util.StringResourceRepository; -/** - * - * @author Rafael Ferreira da Silva - */ public class VelocityUtil { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = LoggerFactory.getLogger(VelocityUtil.class); private static volatile VelocityEngine ve; private Template template; private VelocityContext context; @@ -67,7 +65,6 @@ public VelocityUtil(String templatePath) throws Exception { } public VelocityUtil(String templatePath, boolean enableLogging) throws Exception { - if (ve == null) { Properties properties = new Properties(); properties.setProperty("resource.loader", "string"); @@ -109,7 +106,6 @@ public void put(String key, Object value) { * @throws GaswException */ public StringWriter merge() throws GaswException { - try { StringWriter writer = new StringWriter(); template.merge(context, writer); @@ -117,19 +113,18 @@ public StringWriter merge() throws GaswException { return writer; } catch (ResourceNotFoundException ex) { - logger.error(ex); + logger.error("Error:", ex); throw new GaswException(ex); } catch (ParseErrorException ex) { - logger.error(ex); + logger.error("Error:", ex); throw new GaswException(ex); } catch (MethodInvocationException ex) { - logger.error(ex); + logger.error("Error:", ex); throw new GaswException(ex); } } private String getTemplateFromResource(final String templatePath) { - try { InputStream stream = ClassLoader.getSystemResourceAsStream(templatePath); return IOUtils.toString(stream, "UTF-8"); diff --git a/src/main/resources/gaswLog4j.properties b/src/main/resources/gaswLog4j.properties deleted file mode 100644 index 34b132af..00000000 --- a/src/main/resources/gaswLog4j.properties +++ /dev/null @@ -1,10 +0,0 @@ -log4j.logger.fr.insalyon.creatis.gasw=INFO, FILE - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d |%5p | %c{1}:%L - %m%n - -log4j.appender.FILE=org.apache.log4j.FileAppender -log4j.appender.FILE.file=gasw.log -log4j.appender.FILE.layout=org.apache.log4j.PatternLayout -log4j.appender.FILE.layout.ConversionPattern=%d |%5p | %c{1}:%L - %m%n \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 00000000..206ef95a --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,25 @@ + + + + workflow.out + + %d | %5p | %t | %c{1}:%L - %m%n %ex{2} + + + + + + workflow.err + + WARN + + + %d | %5p | %t | %c{1}:%M:%L - %m%n %ex + + + + + + + + diff --git a/src/test/java/fr/insalyon/creatis/gasw/parser/output/GaswOutputParserTest.java b/src/test/java/fr/insalyon/creatis/gasw/parser/output/GaswOutputParserTest.java index 3c76328a..fd8d73b7 100644 --- a/src/test/java/fr/insalyon/creatis/gasw/parser/output/GaswOutputParserTest.java +++ b/src/test/java/fr/insalyon/creatis/gasw/parser/output/GaswOutputParserTest.java @@ -23,7 +23,10 @@ import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.apache.log4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.qos.logback.classic.Logger; + import org.h2.jdbcx.JdbcDataSource; import fr.insalyon.creatis.gasw.GaswConfiguration; @@ -35,7 +38,7 @@ import fr.insalyon.creatis.gasw.plugin.DatabasePlugin; public class GaswOutputParserTest { - private static final Logger logger = Logger.getLogger("fr.insalyon.creatis.gasw"); + private static final Logger logger = (Logger) LoggerFactory.getLogger(GaswOutputParserTest.class); @Mock private DatabasePlugin databasePlugin; @@ -101,7 +104,7 @@ public void testMultiOutputSameTime() throws DAOException, InterruptedException, assertDoesNotThrow(() -> parser.get(10, TimeUnit.SECONDS)); } - assertFalse(appender.getLogMessages().stream().anyMatch(msg -> msg.contains("[GASW Parser] Error parsing stdout"))); + assertFalse(appender.getLogMessages().stream().anyMatch(msg -> msg.contains("Error parsing stdout"))); } public Callable createCallable(String jobID, String filePath) { diff --git a/src/test/java/fr/insalyon/creatis/gasw/parser/output/MemoryAppender.java b/src/test/java/fr/insalyon/creatis/gasw/parser/output/MemoryAppender.java index 2375e87b..6b1518d4 100644 --- a/src/test/java/fr/insalyon/creatis/gasw/parser/output/MemoryAppender.java +++ b/src/test/java/fr/insalyon/creatis/gasw/parser/output/MemoryAppender.java @@ -3,23 +3,15 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.spi.LoggingEvent; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; -public class MemoryAppender extends AppenderSkeleton { +public class MemoryAppender extends AppenderBase { private final List logMessages = new ArrayList<>(); @Override - protected void append(LoggingEvent event) { - logMessages.add(event.getRenderedMessage()); - } - - @Override - public void close() {} - - @Override - public boolean requiresLayout() { - return false; + protected void append(ILoggingEvent event) { + logMessages.add(event.getFormattedMessage()); } public List getLogMessages() {