diff --git a/jeeves/src/main/java/jeeves/constants/ConfigFile.java b/jeeves/src/main/java/jeeves/constants/ConfigFile.java index 9340da28386..dff60340102 100644 --- a/jeeves/src/main/java/jeeves/constants/ConfigFile.java +++ b/jeeves/src/main/java/jeeves/constants/ConfigFile.java @@ -44,7 +44,6 @@ private Child() {} public static final String RESOURCES = "resources"; public static final String APP_HANDLER = "appHandler"; public static final String SERVICES = "services"; - public static final String SCHEDULES = "schedules"; public static final String INCLUDE = "include"; public static final String MONITORS = "monitors"; } @@ -118,36 +117,6 @@ private Attr() {} } } - //-------------------------------------------------------------------------- - //--- - //--- Schedule elements - //--- - //-------------------------------------------------------------------------- - - public static class Schedules - { - public static final class Attr - { - /** - * Default constructor. - * Builds a Attr. - */ - private Attr() {} - - public static final String PACKAGE = "package"; - } - - public static final class Child - { - /** - * Default constructor. - * Builds a Child. - */ - private Child() {} - - public static final String SCHEDULE = "schedule"; - } - } public static class Monitors { public static final class Attr { diff --git a/jeeves/src/main/java/jeeves/server/JeevesEngine.java b/jeeves/src/main/java/jeeves/server/JeevesEngine.java index 4cb906ebeb5..c190dd6e9dd 100644 --- a/jeeves/src/main/java/jeeves/server/JeevesEngine.java +++ b/jeeves/src/main/java/jeeves/server/JeevesEngine.java @@ -88,8 +88,6 @@ public class JeevesEngine { private XmlCacheManager _xmlCacheManager; @Autowired private MonitorManager _monitorManager; - @Autowired - private ScheduleManager _scheduleMan; @Autowired private ConfigurableApplicationContext _applicationContext; @@ -157,8 +155,6 @@ public void init(final String appPath, final String configPath, final String bas _serviceMan.setBaseUrl(baseUrl); _serviceMan.setServlet(servlet); - _scheduleMan.setAppPath(appPath); - _scheduleMan.setBaseUrl(baseUrl); loadConfigFile(servletContext, configPath, Jeeves.CONFIG_FILE, _serviceMan); loadConfigDB(_applicationContext, -1); @@ -169,9 +165,6 @@ public void init(final String appPath, final String configPath, final String bas for (int i = 0; i < _appHandList.size(); i++) initAppHandler(_appHandList.get(i), servlet); - info("Starting schedule manager..."); - _scheduleMan.start(); - //--------------------------------------------------------------------- long end = System.currentTimeMillis(); @@ -311,15 +304,6 @@ private void loadConfigFile(ServletContext servletContext, String path, String f for (Element aSrvList : srvList) { initServices(aSrvList); } - - //--- init schedules - - List schedList = configRoot.getChildren(ConfigFile.Child.SCHEDULES); - - for (Element aSchedList : schedList) { - initSchedules(aSchedList); - } - //--- init monitoring List monitorList = configRoot.getChildren(ConfigFile.Child.MONITORS); @@ -471,7 +455,6 @@ private void initAppHandler(Element handler, JeevesServlet servlet) throws Excep _appHandlers.add(h); _serviceMan.registerContext(h.getContextName(), context); - _scheduleMan.registerContext(h.getContextName(), context); _monitorManager.initMonitorsForApp(srvContext); info("--- Handler started ---------------------------------------"); @@ -536,52 +519,6 @@ public void initServices(Element services) throws Exception } } - //--------------------------------------------------------------------------- - //--- - //--- 'schedules' element - //--- - //--------------------------------------------------------------------------- - - /** Setup schedules found in the 'schedules' element (config.xml) - */ - - @SuppressWarnings("unchecked") - private void initSchedules(Element schedules) throws Exception - { - info("Initializing schedules..."); - - //--- get schedules root package - String pack = schedules.getAttributeValue(ConfigFile.Schedules.Attr.PACKAGE); - - // --- scan schedules elements - for (Element schedule : (List) schedules - .getChildren(ConfigFile.Schedules.Child.SCHEDULE)) { - String name = schedule - .getAttributeValue(ConfigFile.Schedule.Attr.NAME); - - info(" Adding schedule : " + name); - - try { - _scheduleMan.addSchedule(pack, schedule); - } catch (Exception e) { - error("Raised exception while registering schedule. Skipped."); - error(" Schedule : " + name); - error(" Package : " + pack); - error(" Exception : " + e); - error(" Message : " + e.getMessage()); - error(" Stack : " + Util.getStackTrace(e)); - } - } - } - - //--------------------------------------------------------------------------- - //--- - //--- 'schedules' element - //--- - //--------------------------------------------------------------------------- - - /** Setup schedules found in the 'schedules' element (config.xml) - */ //--------------------------------------------------------------------------- //--- //--- Destroy @@ -597,9 +534,6 @@ public void destroy() info("Shutting down monitor manager..."); _monitorManager.shutdown(); - info("Stopping schedule manager..."); - _scheduleMan.exit(); - info("Stopping handlers..."); stopHandlers(); diff --git a/jeeves/src/main/java/jeeves/server/ScheduleJob.java b/jeeves/src/main/java/jeeves/server/ScheduleJob.java deleted file mode 100644 index d63d3d89c01..00000000000 --- a/jeeves/src/main/java/jeeves/server/ScheduleJob.java +++ /dev/null @@ -1,75 +0,0 @@ -package jeeves.server; - -import jeeves.interfaces.Schedule; -import jeeves.server.context.ScheduleContext; -import org.fao.geonet.Util; -import org.fao.geonet.exceptions.JeevesException; -import org.fao.geonet.utils.Log; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -/** - * A Quartz job that executes a Schedule instance. - * - * @author jeichar - */ -public class ScheduleJob implements Job { - - public static final String NAME_FIELD_NAME = "scheduleName"; - - private String scheduleName; - private Schedule schedule; - private ScheduleContext scheduleContext; - - public void execute(JobExecutionContext context) throws JobExecutionException { - try { - schedule.exec(scheduleContext); - - return; - } catch (JeevesException e) { - error("Communication exception while executing schedule : " + scheduleContext.getScheduleName()); - error(" (C) Status : " + e.getId()); - error(" (C) Message : " + e.getMessage()); - - if (e.getObject() != null) - error(" (C) Object : " + e.getObject()); - } - - catch (Exception e) { - error("Raised exception when executing schedule : " + scheduleContext.getScheduleName()); - error(" (C) Stack trace : " + Util.getStackTrace(e)); - } - - // --- in case of exception we have to abort all resources - - abort(scheduleContext); - - } - - // -------------------------------------------------------------------------- - - private void abort(ScheduleContext context) { - - } - - private void error(String message) { - Log.error(Log.SCHEDULER, message); - } - - public void setSchedule(Schedule schedule) { - this.schedule = schedule; - } - - public void setScheduleContext(ScheduleContext scheduleContext) { - this.scheduleContext = scheduleContext; - } - - public String getScheduleName() { - return scheduleName; - } - public void setScheduleName(String scheduleName) { - this.scheduleName = scheduleName; - } - -} diff --git a/jeeves/src/main/java/jeeves/server/ScheduleListener.java b/jeeves/src/main/java/jeeves/server/ScheduleListener.java deleted file mode 100644 index 9059c20cc41..00000000000 --- a/jeeves/src/main/java/jeeves/server/ScheduleListener.java +++ /dev/null @@ -1,53 +0,0 @@ -package jeeves.server; - -import jeeves.server.context.ScheduleContext; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.quartz.JobListener; - -/** - * Put the ScheduleContext and Schedule objects in JobExecutionContext so that - * ScheduleJob can access them. - * - * This is necessary since Schedule objects could contain state (even if it is - * bad). So the same Schedule object must be used. Also the ScheduleContext - * object is required by ScheduleContext for executing the schedule. - * - * @author jeichar - */ -public class ScheduleListener implements JobListener { - - private final ScheduleManager scheduleManager; - - public ScheduleListener(ScheduleManager scheduleManager) { - this.scheduleManager = scheduleManager; - } - - public String getName() { - return "ScheduleJob configuration listener"; - } - - public void jobToBeExecuted(JobExecutionContext context) { - if (context.getJobInstance() instanceof ScheduleJob) { - ScheduleJob scheduleJob = (ScheduleJob) context.getJobInstance(); - - ScheduleInfo info = scheduleManager.getScheduleInfo(scheduleJob.getScheduleName()); - ScheduleContext scheduleContext = new ScheduleContext(info.name, scheduleManager.getApplicationContext(), - scheduleManager.getHtContexts(), scheduleManager.getEntityManager()); - scheduleContext.setBaseUrl(scheduleManager.getBaseUrl()); - scheduleContext.setAppPath(scheduleManager.getAppPath()); - - scheduleJob.setSchedule(info.schedule); - scheduleJob.setScheduleContext(scheduleContext); - } - } - - public void jobExecutionVetoed(JobExecutionContext context) { - // no action - } - - public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { - // no action - } - -} diff --git a/jeeves/src/main/java/jeeves/server/ScheduleManager.java b/jeeves/src/main/java/jeeves/server/ScheduleManager.java deleted file mode 100644 index 47cf0b5bfc9..00000000000 --- a/jeeves/src/main/java/jeeves/server/ScheduleManager.java +++ /dev/null @@ -1,190 +0,0 @@ -//============================================================================= -//=== Copyright (C) 2001-2005 Food and Agriculture Organization of the -//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) -//=== and United Nations Environment Programme (UNEP) -//=== -//=== This library is free software; you can redistribute it and/or -//=== modify it under the terms of the GNU Lesser General Public -//=== License as published by the Free Software Foundation; either -//=== version 2.1 of the License, or (at your option) any later version. -//=== -//=== This library is distributed in the hope that it will be useful, -//=== but WITHOUT ANY WARRANTY; without even the implied warranty of -//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -//=== Lesser General Public License for more details. -//=== -//=== You should have received a copy of the GNU Lesser General Public -//=== License along with this library; if not, write to the Free Software -//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -//=== -//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, -//=== Rome - Italy. email: GeoNetwork@fao.org -//============================================================================== - -package jeeves.server; - -import jeeves.config.springutil.JeevesApplicationContext; -import jeeves.constants.ConfigFile; -import jeeves.interfaces.Schedule; -import jeeves.monitor.MonitorManager; -import org.fao.geonet.utils.QuartzSchedulerUtils; -import org.jdom.Element; -import org.quartz.JobDetail; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.Trigger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.stereotype.Component; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; -import java.util.UUID; - -import static org.quartz.JobBuilder.newJob; -import static org.quartz.impl.matchers.GroupMatcher.jobGroupEquals; - -//============================================================================= -public class ScheduleManager -{ - /** - * Id for the Quartz scheduler for the Schedule jobs. - */ - public static final String SCHEDULER_ID = "scheduleManager"; - - private String appPath; - private String baseUrl; - private String instanceId = SCHEDULER_ID+"-"+UUID.randomUUID().toString(); - private Hashtable htContexts = new Hashtable(); - private Scheduler scheduler; - private Map vSchedules = new HashMap(); - - @Autowired - private ConfigurableApplicationContext jeevesApplicationContext; - @PersistenceContext - private EntityManager entityManager; - - //-------------------------------------------------------------------------- - //--- - //--- Constructor - //--- - //-------------------------------------------------------------------------- - - public ScheduleManager() {} - - //-------------------------------------------------------------------------- - //--- - //--- API methods - //--- - //--------------------------------------------------------------------------- - - public void registerContext(String name, Object context) - { - htContexts.put(name, context); - } - - //--------------------------------------------------------------------------- - - public void setBaseUrl(String name) - { - baseUrl = name; - - if (!baseUrl.startsWith("/")) - baseUrl = "/"+ baseUrl; - } - - //-------------------------------------------------------------------------- - - public void setAppPath(String path) { appPath = path; } - - //-------------------------------------------------------------------------- - - public String getAppPath() { return appPath;} - public String getBaseUrl() {return baseUrl;} - public ConfigurableApplicationContext getApplicationContext() { return jeevesApplicationContext; } - public Hashtable getHtContexts() {return new Hashtable(htContexts);} - - //-------------------------------------------------------------------------- - - @SuppressWarnings("unchecked") - void addSchedule(String pack, Element sched) throws Exception - { - String name = sched.getAttributeValue(ConfigFile.Schedule.Attr.NAME); - String clas = sched.getAttributeValue(ConfigFile.Schedule.Attr.CLASS); - String when = sched.getAttributeValue(ConfigFile.Schedule.Attr.WHEN); - - //--- get class name - - if (clas == null) - throw new IllegalArgumentException("Missing 'class' attrib in 'schedule' element"); - - if (clas.startsWith(".")) - clas = pack + clas; - - //--- create instance - - Schedule schedule = (Schedule) Class.forName(clas).newInstance(); - - schedule.init(appPath, new ServiceConfig(sched.getChildren(ConfigFile.Schedule.Child.PARAM))); - - //--- store schedule - - ScheduleInfo si = new ScheduleInfo(); - - si.name = name; - si.schedule = schedule; - si.job = newJob(ScheduleJob.class).withIdentity(name, instanceId).usingJobData(ScheduleJob.NAME_FIELD_NAME, name).build(); - si.trigger = QuartzSchedulerUtils.getTrigger(name, instanceId, when, Integer.MAX_VALUE); - - vSchedules.put(name, si); - } - - //-------------------------------------------------------------------------- - - public void start() throws SchedulerException { - scheduler = QuartzSchedulerUtils.getScheduler(SCHEDULER_ID, true); - scheduler.getListenerManager().addJobListener(new ScheduleListener(this), jobGroupEquals(instanceId)); - - for (ScheduleInfo info : vSchedules.values()) { - scheduler.scheduleJob(info.job, info.trigger); - } - } - - public void exit() throws SchedulerException - { - if (scheduler != null) { - scheduler.shutdown(); - } - } - - //-------------------------------------------------------------------------- - - public ScheduleInfo getScheduleInfo(String scheduleName) { - return vSchedules.get(scheduleName); - } - - public EntityManager getEntityManager() { - return entityManager; - } - - //--------------------------------------------------------------------------- - - -} - -//============================================================================= - -class ScheduleInfo -{ - public Schedule schedule; - public JobDetail job; - public Trigger trigger; - public String name; -} - -//============================================================================= - diff --git a/jeeves/src/main/resources/config-spring-geonetwork.xml b/jeeves/src/main/resources/config-spring-geonetwork.xml index a2061160da8..cd606098748 100644 --- a/jeeves/src/main/resources/config-spring-geonetwork.xml +++ b/jeeves/src/main/resources/config-spring-geonetwork.xml @@ -17,7 +17,6 @@ - diff --git a/test/resources/config/config.xml b/test/resources/config/config.xml index 2cb22780f76..2589a0c0f7c 100644 --- a/test/resources/config/config.xml +++ b/test/resources/config/config.xml @@ -149,10 +149,6 @@ - - - - diff --git a/web/src/main/webapp/WEB-INF/classes/quartz-scheduleManager.properties.disabled b/web/src/main/webapp/WEB-INF/classes/quartz-scheduleManager.properties.disabled deleted file mode 100644 index 3cbcb6289b5..00000000000 --- a/web/src/main/webapp/WEB-INF/classes/quartz-scheduleManager.properties.disabled +++ /dev/null @@ -1,2 +0,0 @@ -org.quartz.threadPool.threadCount = 2 -org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore diff --git a/web/src/main/webapp/WEB-INF/config.xml b/web/src/main/webapp/WEB-INF/config.xml index c35c310e495..04a37b9dd9e 100644 --- a/web/src/main/webapp/WEB-INF/config.xml +++ b/web/src/main/webapp/WEB-INF/config.xml @@ -121,10 +121,6 @@ - - - -