Added:
/trunk/jwatch/src/main/java/org/jwatch/listener/settings/JWatchConfig.java
/trunk/jwatch/src/main/java/org/jwatch/persistence
/trunk/jwatch/src/main/java/org/jwatch/persistence/ConnectionUtil.java
Modified:
/trunk/jwatch/pom.xml
/trunk/jwatch/src/main/java/org/jwatch/handler/QuartzInstanceHandler.java
/trunk/jwatch/src/main/java/org/jwatch/listener/notification/EventService.java
/trunk/jwatch/src/main/java/org/jwatch/listener/settings/SettingsLoaderListener.java
/trunk/jwatch/src/main/java/org/jwatch/util/SettingsUtil.java
/trunk/jwatch/src/main/webapp/WEB-INF/web.xml
/trunk/jwatch/src/main/webapp/js/layout.js
=======================================
--- /dev/null
+++
/trunk/jwatch/src/main/java/org/jwatch/listener/settings/JWatchConfig.java
Fri Aug 5 11:00:38 2011
@@ -0,0 +1,54 @@
+/**
+ * JWatch - Quartz Monitor: http://code.google.com/p/jwatch/
+ * Copyright (C) 2011 Roy Russo and the original author or authors.
+ *
+ * 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 3 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 Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ **/
+
+package org.jwatch.listener.settings;
+
+/**
+ * @author <a href="mailto:royr...@gmail.com">Roy Russo</a>
+ * Date: 7/12/11 9:16 AM
+ */
+public class JWatchConfig
+{
+ public static final String PROPS_FILE_NAME = "jwatch.properties";
+ public static final String DB_FILE_PREFIX = "jwatchdb";
+ public static final String QUARTZ_INSTANCE_FILE = "jwatch.json";
+ private static boolean DBDebug = true;
+ private static int maxShowEvents = 50;
+
+ public static boolean isDBDebug()
+ {
+ return DBDebug;
+ }
+
+ public static void setDBDebug(boolean DBDebug)
+ {
+ JWatchConfig.DBDebug = DBDebug;
+ }
+
+ public static int getMaxShowEvents()
+ {
+ return maxShowEvents;
+ }
+
+ public static void setMaxShowEvents(int maxShowEvents)
+ {
+ JWatchConfig.maxShowEvents = maxShowEvents;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/jwatch/src/main/java/org/jwatch/persistence/ConnectionUtil.java
Fri Aug 5 11:00:38 2011
@@ -0,0 +1,138 @@
+/**
+ * JWatch - Quartz Monitor: http://code.google.com/p/jwatch/
+ * Copyright (C) 2011 Roy Russo and the original author or authors.
+ *
+ * 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 3 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 Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ **/
+
+package org.jwatch.persistence;
+
+import org.apache.log4j.Logger;
+import org.hsqldb.Server;
+import org.jwatch.util.SettingsUtil;
+
+import java.sql.*;
+
+/**
+ * Some portions taken from: http://hsqldb.org/doc/guide/apb.html
+ *
+ * @author <a href="mailto:royr...@gmail.com">Roy Russo</a>
+ * Date: 7/7/11 1:55 PM
+ */
+public class ConnectionUtil
+{
+ static Logger log = Logger.getLogger(ConnectionUtil.class);
+ Connection conn;
+ // 'Server' is a class of HSQLDB representing
+ // the database server
+ Server hsqlServer = null;
+
+ public ConnectionUtil(String db_file_name_prefix) throws Exception
+ {
+ hsqlServer = new Server();
+ // HSQLDB prints out a lot of informations when
+ // starting and closing, which we don't need now.
+ // Normally you should point the setLogWriter
+ // to some Writer object that could store the logs.
+ //hsqlServer.setLogWriter(null);
+ hsqlServer.setSilent(false);
+ hsqlServer.setDatabaseName(0, "JWATCHDB");
+ hsqlServer.setDatabasePath(0, "file:" +
SettingsUtil.getDBFilePath());
+ hsqlServer.start();
+
+ Class.forName("org.hsqldb.jdbcDriver");
+ // "jdbc:hsqldb:hsql://localhost/xdb", "sa", "");
+ conn =
DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/JWATCHDB", "SA", "");
+ //conn = DriverManager.getConnection("jdbc:hsqldb:file:" +
db_file_name_prefix, "sa", "");
+ log.info("JWatch Database connected.");
+ }
+
+ public void shutdown() throws SQLException
+ {
+ Statement st = conn.createStatement();
+
+ st.execute("SHUTDOWN");
+ conn.close();
+
+ if (hsqlServer != null)
+ {
+ hsqlServer.shutdown();
+ }
+ log.info("JWatch Database shutdown.");
+ }
+
+ public synchronized void query(String expression) throws SQLException
+ {
+ Statement st = null;
+ ResultSet rs = null;
+
+ st = conn.createStatement(); // statement objects can be
reused with
+
+ // repeated calls to execute but we
+ // choose to make a new one each time
+ rs = st.executeQuery(expression); // run the query
+
+ // do something with the result set.
+ dump(rs);
+ st.close(); // NOTE!! if you close a statement the associated
ResultSet is
+
+ // closed too
+ // so you should copy the contents to some other object.
+ // the result set is invalidated also if you recycle an Statement
+ // and try to execute some other query before the result set has
been
+ // completely examined.
+ }
+
+ //use for SQL commands CREATE, DROP, INSERT and UPDATE
+ public synchronized void update(String expression) throws SQLException
+ {
+ Statement st = null;
+ st = conn.createStatement(); // statements
+ int i = st.executeUpdate(expression); // run the query
+ if (i == -1)
+ {
+ System.out.println("db error : " + expression);
+ }
+ st.close();
+ }
+
+ public static void dump(ResultSet rs) throws SQLException
+ { // the order of the rows in a cursor
+ // are implementation dependent unless you use the SQL ORDER
statement
+ ResultSetMetaData meta = rs.getMetaData();
+ int colmax = meta.getColumnCount();
+ int i;
+ Object o = null;
+
+ // the result set is a cursor into the data. You can only
+ // point to one row at a time
+ // assume we are pointing to BEFORE the first row
+ // rs.next() points to next row and returns true
+ // or false if there is no next row, which breaks the loop
+ for (; rs.next(); )
+ {
+ for (i = 0; i < colmax; ++i)
+ {
+ o = rs.getObject(i + 1); // Is SQL the first column is
indexed
+
+ // with 1 not 0
+ System.out.print(o.toString() + " ");
+ }
+ System.out.println(" @@ ");
+ }
+ }
+
+}
=======================================
--- /trunk/jwatch/pom.xml Thu Jun 30 13:43:42 2011
+++ /trunk/jwatch/pom.xml Fri Aug 5 11:00:38 2011
@@ -142,6 +142,18 @@
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
-
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>2.2.4</version>
+ </dependency>
</dependencies>
+
+ <repositories>
+ <repository>
+ <id>codehaus</id>
+ <name>codehaus</name>
+ <url>http://snapshots.repository.codehaus.org</url>
+ </repository>
+ </repositories>
</project>
=======================================
---
/trunk/jwatch/src/main/java/org/jwatch/handler/QuartzInstanceHandler.java
Wed Jun 22 08:54:44 2011
+++
/trunk/jwatch/src/main/java/org/jwatch/handler/QuartzInstanceHandler.java
Fri Aug 5 11:00:38 2011
@@ -52,287 +52,293 @@
*/
public class QuartzInstanceHandler
{
- static Logger log = Logger.getLogger(QuartzInstanceHandler.class);
-
- /**
- * Returns instances found. For now, it pulls from the config file
every time.
- *
- * @return
- * @see org.jwatch.domain.instance.QuartzInstanceService
- */
- public static JSONObject loadInstances()
- {
- JSONObject jsonObject = new JSONObject();
- try
- {
- QuartzInstanceService.initQuartzInstanceMap();
- Map qMap = QuartzInstanceService.getQuartzInstanceMap();
- if (qMap != null)
- {
- JSONArray jsonArray = new JSONArray();
- for (Iterator it = qMap.entrySet().iterator(); it.hasNext();)
- {
- Map.Entry entry = (Map.Entry) it.next();
- String k = (String) entry.getKey();
- QuartzInstance quartzInstance = (QuartzInstance)
qMap.get(k);
- QuartzConfig quartzConfig = new
QuartzConfig(quartzInstance);
- JSONObject jo = JSONObject.fromObject(quartzConfig);
- jsonArray.add(jo);
- }
- jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
- jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, qMap.size());
- }
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
- }
- catch (Throwable t)
- {
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, false);
- }
- return jsonObject;
- }
-
- /**
- * Given JMX connection settings: this will connect to the instance,
and if successful
- * persist the new instance in the settings file and memory map.
- *
- * @param map
- * @return success/failure
- */
- public static JSONObject createInstance(Map map)
- {
- JSONObject jsonObject = new JSONObject();
-
- try
- {
- String host = StringUtils.trimToNull((String) map.get("host"));
- int port = Integer.valueOf(StringUtils.trimToNull((String)
map.get("port")));
- String username = StringUtils.trimToNull((String)
map.get("userName"));
- String password = StringUtils.trimToNull((String)
map.get("password"));
-
- if (StringUtils.trimToNull(host) != null)
- {
- QuartzConfig quartzConfig = new
QuartzConfig(Tools.generateUUID(), host, port, username, password);
- QuartzConnectService quartzConnectService = new
QuartzConnectServiceImpl();
- QuartzInstance quartzInstance =
quartzConnectService.initInstance(quartzConfig);
- if (quartzInstance == null)
- {
- log.error(GlobalConstants.MESSAGE_FAILED_CONNECT + " " +
quartzConfig);
- jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_FAILED_CONNECT + " " +
quartzConfig);
- return jsonObject;
- }
-
- // persist
- QuartzInstanceService.putQuartzInstance(quartzInstance);
- SettingsUtil.saveConfig(quartzConfig);
- jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY,
quartzConfig);
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
- }
- else
- {
- jsonObject.put(GlobalConstants.JSON_MESSAGE,
GlobalConstants.MESSAGE_CONFIG_EMPTY);
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, false);
- }
- }
- catch (UnknownHostException e)
- {
- log.error(e);
- jsonObject = JSONUtil.buildError("Unknown Host. " +
GlobalConstants.MESSAGE_ERR_CHECK_LOG);
- }
- catch (Throwable t)
- {
- log.error(t);
- jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_CHECK_LOG);
- }
- return jsonObject;
- }
-
- /**
- * Given a Quartz Instance id, it will load the schedulers associated
with it from the in-memory map.
- *
- * @param map
- * @return
- */
- public static JSONObject getSchedulersForForQuartzInstance(Map map)
- {
- JSONObject jsonObject = new JSONObject();
- JSONArray jsonArray = new JSONArray();
- String qiid = StringUtils.trimToNull((String) map.get("uuid"));
- try
- {
- QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(qiid);
- if (quartzInstance != null)
- {
- int totalCount = 0;
- List<Scheduler> schedulers = quartzInstance.getSchedulerList();
- if (schedulers != null && schedulers.size() > 0)
- {
- totalCount = schedulers.size();
- for (int i = 0; i < schedulers.size(); i++)
- {
- Scheduler scheduler = schedulers.get(i);
- JSONObject o = JSONObject.fromObject(scheduler);
- jsonArray.add(o);
- }
- }
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
- jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
- jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, totalCount);
- }
- }
- catch (Throwable t)
- {
- log.error(t);
- jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_CHECK_LOG);
- }
- return jsonObject;
- }
-
- public static JSONObject getJobsForScheduler(Map map)
- {
- JSONObject jsonObject = new JSONObject();
- JSONArray jsonArray = new JSONArray();
- int totalCount = 0;
-
- String uuidInstance = StringUtils.trimToNull((String)
map.get("uuidInstance"));
- try
- {
- if (uuidInstance != null)
- {
- String[] arr = uuidInstance.split("@@");
- String uuid = arr[0];
- String scheduleID = arr[1];
- QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(uuid);
- if (quartzInstance != null)
- {
- List<Job> jobs =
quartzInstance.getJmxAdapter().getJobDetails(quartzInstance, scheduleID);
- if (jobs != null && jobs.size() > 0)
- {
- totalCount = jobs.size();
- for (int i = 0; i < jobs.size(); i++)
- {
- Job job = jobs.get(i);
- JSONObject o = JSONObject.fromObject(job);
- o.put("nextFireTime",
Tools.toStringFromDate(job.getNextFireTime(), null));
-
- jsonArray.add(o);
- }
- }
- }
- }
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
- jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
- jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, totalCount);
- }
- catch (Throwable t)
- {
- log.error(t);
- jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_LOAD_JOBS);
- }
- return jsonObject;
- }
-
- public static JSONObject getSchedulerInfo(Map map)
- {
- JSONObject jsonObject = new JSONObject();
- String uuidInstance = StringUtils.trimToNull((String)
map.get("uuidInstance"));
- try
- {
- if (uuidInstance != null)
- {
- String[] arr = uuidInstance.split("@@");
- String uuid = arr[0];
- String scheduleID = arr[1];
- QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(uuid);
- if (quartzInstance != null)
- {
- Scheduler scheduler =
quartzInstance.getJmxAdapter().getScheduler(quartzInstance, scheduleID);
- if (scheduler != null)
- {
- jsonObject = JSONObject.fromObject(scheduler);
- }
- }
- }
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
- }
- catch (Throwable t)
- {
- log.error(t);
- jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_LOAD_SCHEDULER);
- }
- return jsonObject;
- }
-
- public static JSONObject getTriggersForJob(Map map)
- {
- JSONObject jsonObject = new JSONObject();
- JSONArray jsonArray = new JSONArray();
-
- String qiid = StringUtils.trimToNull((String) map.get("uuid"));
- String jobName = StringUtils.trimToNull((String) map.get("jobName"));
- String groupName = StringUtils.trimToNull((String)
map.get("groupName"));
- String scheduleID = StringUtils.trimToNull((String) map.get("sid"));
- int totalCount = 0;
- try
- {
- QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(qiid);
- List<Trigger> triggers =
quartzInstance.getJmxAdapter().getTriggersForJob(quartzInstance,
scheduleID, jobName, groupName);
- if (triggers != null && triggers.size() > 0)
- {
- totalCount = triggers.size();
- for (int i = 0; i < triggers.size(); i++)
- {
- Trigger trigger = triggers.get(i);
- JSONObject object = JSONObject.fromObject(trigger);
- object.put("endTime",
Tools.toStringFromDate(trigger.getEndTime(), null));
- object.put("finaleFireTime",
Tools.toStringFromDate(trigger.getFinalFireTime(), null));
- object.put("nextFireTime",
Tools.toStringFromDate(trigger.getNextFireTime(), null));
- object.put("previousFireTime",
Tools.toStringFromDate(trigger.getPreviousFireTime(), null));
- object.put("startTime",
Tools.toStringFromDate(trigger.getStartTime(), null));
- jsonArray.add(object);
- }
- }
- jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
- jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, totalCount);
- }
- catch (Throwable t)
- {
- log.error(t);
- jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_LOAD_TRIGGERS);
- }
- return jsonObject;
- }
-
- public static JSONObject getJobsList(Map map)
- {
- JSONObject jsonObject = new JSONObject();
- JSONArray jsonArray = new JSONArray();
- int totalCount = 0;
- try
- {
- LinkedList events = EventService.getEventList();
- if (events != null && events.size() > 0)
- {
- for (int i = 0; i < events.size(); i++)
- {
- JobEvent jEvent = (JobEvent) events.get(i);
- JSONObject object = JSONObject.fromObject(jEvent);
- object.put("fireTime",
Tools.toStringFromDate(jEvent.getFireTime(), null));
- object.put("nextFireTime",
Tools.toStringFromDate(jEvent.getNextFireTime(), null));
- object.put("previousFireTime",
Tools.toStringFromDate(jEvent.getPreviousFireTime(), null));
- object.put("scheduledFireTime",
Tools.toStringFromDate(jEvent.getScheduledFireTime(), null));
- jsonArray.add(object);
- }
- }
- jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
- jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
- jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, totalCount);
- }
- catch (Throwable t)
- {
- log.error(t);
- jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_TAIL_JOBS);
- }
- return jsonObject;
- }
-}
+ static Logger log = Logger.getLogger(QuartzInstanceHandler.class);
+
+ /**
+ * Returns instances found. For now, it pulls from the config file
every time.
+ *
+ * @return
+ * @see org.jwatch.domain.instance.QuartzInstanceService
+ */
+ public static JSONObject loadInstances()
+ {
+ JSONObject jsonObject = new JSONObject();
+ try
+ {
+ QuartzInstanceService.initQuartzInstanceMap();
+ Map qMap = QuartzInstanceService.getQuartzInstanceMap();
+ if (qMap != null)
+ {
+ JSONArray jsonArray = new JSONArray();
+ for (Iterator it = qMap.entrySet().iterator();
it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ String k = (String) entry.getKey();
+ QuartzInstance quartzInstance = (QuartzInstance)
qMap.get(k);
+ QuartzConfig quartzConfig = new
QuartzConfig(quartzInstance);
+ JSONObject jo = JSONObject.fromObject(quartzConfig);
+ jsonArray.add(jo);
+ }
+ jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY,
jsonArray);
+ jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT,
qMap.size());
+ }
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
+ }
+ catch (Throwable t)
+ {
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, false);
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Given JMX connection settings: this will connect to the instance,
and if successful
+ * persist the new instance in the settings file and memory map.
+ *
+ * @param map
+ * @return success/failure
+ */
+ public static JSONObject createInstance(Map map)
+ {
+ JSONObject jsonObject = new JSONObject();
+
+ try
+ {
+ String host = StringUtils.trimToNull((String) map.get("host"));
+ int port = Integer.valueOf(StringUtils.trimToNull((String)
map.get("port")));
+ String username = StringUtils.trimToNull((String)
map.get("userName"));
+ String password = StringUtils.trimToNull((String)
map.get("password"));
+
+ if (StringUtils.trimToNull(host) != null)
+ {
+ QuartzConfig quartzConfig = new
QuartzConfig(Tools.generateUUID(), host, port, username, password);
+ QuartzConnectService quartzConnectService = new
QuartzConnectServiceImpl();
+ QuartzInstance quartzInstance =
quartzConnectService.initInstance(quartzConfig);
+ if (quartzInstance == null)
+ {
+ log.error(GlobalConstants.MESSAGE_FAILED_CONNECT + " "
+ quartzConfig);
+ jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_FAILED_CONNECT + " " +
quartzConfig);
+ return jsonObject;
+ }
+
+ // persist
+ QuartzInstanceService.putQuartzInstance(quartzInstance);
+ SettingsUtil.saveConfig(quartzConfig);
+ jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY,
quartzConfig);
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
+ }
+ else
+ {
+ jsonObject.put(GlobalConstants.JSON_MESSAGE,
GlobalConstants.MESSAGE_CONFIG_EMPTY);
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, false);
+ }
+ }
+ catch (UnknownHostException e)
+ {
+ log.error(e);
+ jsonObject = JSONUtil.buildError("Unknown Host. " +
GlobalConstants.MESSAGE_ERR_CHECK_LOG);
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_CHECK_LOG);
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Given a Quartz Instance id, it will load the schedulers associated
with it from the in-memory map.
+ *
+ * @param map
+ * @return
+ */
+ public static JSONObject getSchedulersForForQuartzInstance(Map map)
+ {
+ JSONObject jsonObject = new JSONObject();
+ JSONArray jsonArray = new JSONArray();
+ String qiid = StringUtils.trimToNull((String) map.get("uuid"));
+ try
+ {
+ QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(qiid);
+ if (quartzInstance != null)
+ {
+ int totalCount = 0;
+ List<Scheduler> schedulers =
quartzInstance.getSchedulerList();
+ if (schedulers != null && schedulers.size() > 0)
+ {
+ totalCount = schedulers.size();
+ for (int i = 0; i < schedulers.size(); i++)
+ {
+ Scheduler scheduler = schedulers.get(i);
+ JSONObject o = JSONObject.fromObject(scheduler);
+ jsonArray.add(o);
+ }
+ }
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
+ jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY,
jsonArray);
+ jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT,
totalCount);
+ }
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_CHECK_LOG);
+ }
+ return jsonObject;
+ }
+
+ public static JSONObject getJobsForScheduler(Map map)
+ {
+ JSONObject jsonObject = new JSONObject();
+ JSONArray jsonArray = new JSONArray();
+ int totalCount = 0;
+
+ String uuidInstance = StringUtils.trimToNull((String)
map.get("uuidInstance"));
+ try
+ {
+ if (uuidInstance != null)
+ {
+ String[] arr = uuidInstance.split("@@");
+ String uuid = arr[0];
+ String scheduleID = arr[1];
+ QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(uuid);
+ if (quartzInstance != null)
+ {
+ List<Job> jobs =
quartzInstance.getJmxAdapter().getJobDetails(quartzInstance, scheduleID);
+ if (jobs != null && jobs.size() > 0)
+ {
+ totalCount = jobs.size();
+ for (int i = 0; i < jobs.size(); i++)
+ {
+ Job job = jobs.get(i);
+ JSONObject o = JSONObject.fromObject(job);
+ o.put("nextFireTime",
Tools.toStringFromDate(job.getNextFireTime(), null));
+
+ jsonArray.add(o);
+ }
+ }
+ }
+ }
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
+ jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
+ jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, totalCount);
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_LOAD_JOBS);
+ }
+ return jsonObject;
+ }
+
+ public static JSONObject getSchedulerInfo(Map map)
+ {
+ JSONObject jsonObject = new JSONObject();
+ String uuidInstance = StringUtils.trimToNull((String)
map.get("uuidInstance"));
+ try
+ {
+ if (uuidInstance != null)
+ {
+ String[] arr = uuidInstance.split("@@");
+ String uuid = arr[0];
+ String scheduleID = arr[1];
+ QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(uuid);
+ if (quartzInstance != null)
+ {
+ Scheduler scheduler =
quartzInstance.getJmxAdapter().getScheduler(quartzInstance, scheduleID);
+ if (scheduler != null)
+ {
+ jsonObject = JSONObject.fromObject(scheduler);
+ }
+ }
+ }
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_LOAD_SCHEDULER);
+ }
+ return jsonObject;
+ }
+
+ public static JSONObject getTriggersForJob(Map map)
+ {
+ JSONObject jsonObject = new JSONObject();
+ JSONArray jsonArray = new JSONArray();
+
+ String qiid = StringUtils.trimToNull((String) map.get("uuid"));
+ String jobName = StringUtils.trimToNull((String)
map.get("jobName"));
+ String groupName = StringUtils.trimToNull((String)
map.get("groupName"));
+ String scheduleID = StringUtils.trimToNull((String)
map.get("sid"));
+ int totalCount = 0;
+ try
+ {
+ QuartzInstance quartzInstance =
QuartzInstanceService.getQuartzInstanceByID(qiid);
+ List<Trigger> triggers =
quartzInstance.getJmxAdapter().getTriggersForJob(quartzInstance,
scheduleID, jobName, groupName);
+ if (triggers != null && triggers.size() > 0)
+ {
+ totalCount = triggers.size();
+ for (int i = 0; i < triggers.size(); i++)
+ {
+ Trigger trigger = triggers.get(i);
+ JSONObject object = JSONObject.fromObject(trigger);
+ object.put("endTime",
Tools.toStringFromDate(trigger.getEndTime(), null));
+ object.put("finaleFireTime",
Tools.toStringFromDate(trigger.getFinalFireTime(), null));
+ object.put("nextFireTime",
Tools.toStringFromDate(trigger.getNextFireTime(), null));
+ object.put("previousFireTime",
Tools.toStringFromDate(trigger.getPreviousFireTime(), null));
+ object.put("startTime",
Tools.toStringFromDate(trigger.getStartTime(), null));
+ jsonArray.add(object);
+ }
+ }
+ jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
+ jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, totalCount);
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_LOAD_TRIGGERS);
+ }
+ return jsonObject;
+ }
+
+ public static JSONObject getJobsList(Map map)
+ {
+ JSONObject jsonObject = new JSONObject();
+ JSONArray jsonArray = new JSONArray();
+ int totalCount = 0;
+ try
+ {
+ LinkedList events = EventService.getEventList();
+ if (events != null && events.size() > 0)
+ {
+ totalCount = events.size() >
EventService.getMaxShowEventListSize() ?
EventService.getMaxShowEventListSize() : events.size();
+
+ for (int i = 0; i < events.size(); i++)
+ {
+ JobEvent jEvent = (JobEvent) events.get(i);
+ JSONObject object = JSONObject.fromObject(jEvent);
+ object.put("fireTime",
Tools.toStringFromDate(jEvent.getFireTime(), null));
+ object.put("nextFireTime",
Tools.toStringFromDate(jEvent.getNextFireTime(), null));
+ object.put("previousFireTime",
Tools.toStringFromDate(jEvent.getPreviousFireTime(), null));
+ object.put("scheduledFireTime",
Tools.toStringFromDate(jEvent.getScheduledFireTime(), null));
+ jsonArray.add(object);
+ if (i == EventService.getMaxShowEventListSize() - 1)
+ {
+ break;
+ }
+ }
+ }
+ jsonObject.put(GlobalConstants.JSON_DATA_ROOT_KEY, jsonArray);
+ jsonObject.put(GlobalConstants.JSON_SUCCESS_KEY, true);
+ jsonObject.put(GlobalConstants.JSON_TOTAL_COUNT, totalCount);
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ jsonObject =
JSONUtil.buildError(GlobalConstants.MESSAGE_ERR_TAIL_JOBS);
+ }
+ return jsonObject;
+ }
+}
=======================================
---
/trunk/jwatch/src/main/java/org/jwatch/listener/notification/EventService.java
Wed Jun 22 08:54:44 2011
+++
/trunk/jwatch/src/main/java/org/jwatch/listener/notification/EventService.java
Fri Aug 5 11:00:38 2011
@@ -30,50 +30,62 @@
*/
public class EventService
{
- public static final int DEFAULT_MAX_EVENT_LIST_SIZE = 10;
-
- private static LinkedList<JobEvent> eventList;
- private static int maxEventListSize;
-
- public static LinkedList<JobEvent> getEventList()
- {
- return eventList;
- }
-
- public static int getMaxEventListSize()
- {
- return maxEventListSize;
- }
-
- public static void setMaxEventListSize(int maxEventListSize)
- {
- EventService.maxEventListSize = maxEventListSize;
- }
-
- public static void addEvent(JobEvent event)
- {
- if (eventList == null)
- {
- eventList = new LinkedList<JobEvent>();
- }
-
- // add event to the top of the list
- eventList.addFirst(event);
-
- // trim the list to size
- resizeEventList();
- }
-
- private static void resizeEventList()
- {
- if (eventList.size() > maxEventListSize)
- {
- eventList.removeLast();
- resizeEventList();
- }
- else
- {
- return;
- }
- }
-}
+ public static final int DEFAULT_MAX_EVENT_LIST_SIZE = 1000;
+ public static final int DEFAULT_MAX_SHOW_EVENT_LIST_SIZE = 100;
+
+ private static LinkedList<JobEvent> eventList;
+ private static int maxEventListSize;
+ private static int maxShowEventListSize;
+
+ public static LinkedList<JobEvent> getEventList()
+ {
+ return eventList;
+ }
+
+ public static int getMaxEventListSize()
+ {
+ return maxEventListSize;
+ }
+
+ public static int getMaxShowEventListSize()
+ {
+ return maxShowEventListSize;
+ }
+
+ public static void setMaxShowEventListSize(int maxShowEventListSize)
+ {
+ EventService.maxShowEventListSize = maxShowEventListSize;
+ }
+
+ public static void setMaxEventListSize(int maxEventListSize)
+ {
+ EventService.maxEventListSize = maxEventListSize;
+ }
+
+ public static void addEvent(JobEvent event)
+ {
+ if (eventList == null)
+ {
+ eventList = new LinkedList<JobEvent>();
+ }
+
+ // add event to the top of the list
+ eventList.addFirst(event);
+
+ // trim the list to size
+ resizeEventList();
+ }
+
+ private static void resizeEventList()
+ {
+ if (eventList.size() > maxEventListSize)
+ {
+ eventList.removeLast();
+ resizeEventList();
+ }
+ else
+ {
+ return;
+ }
+ }
+}
=======================================
---
/trunk/jwatch/src/main/java/org/jwatch/listener/settings/SettingsLoaderListener.java
Wed Jun 22 08:54:44 2011
+++
/trunk/jwatch/src/main/java/org/jwatch/listener/settings/SettingsLoaderListener.java
Fri Aug 5 11:00:38 2011
@@ -24,12 +24,18 @@
import org.jwatch.domain.instance.QuartzInstance;
import org.jwatch.domain.instance.QuartzInstanceService;
import org.jwatch.listener.notification.EventService;
+import org.jwatch.persistence.ConnectionUtil;
+import org.jwatch.util.SettingsUtil;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.IOException;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
import java.util.Calendar;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
@@ -41,52 +47,110 @@
*/
public class SettingsLoaderListener implements ServletContextListener
{
- static Logger log = Logger.getLogger(SettingsLoaderListener.class);
-
- public void contextInitialized(ServletContextEvent event)
- {
- try
- {
- log.info("Starting Settings Load...");
- long start = Calendar.getInstance().getTimeInMillis();
-
- ServletContext sc = event.getServletContext();
- if (sc != null)
- {
- String sMaxEvents = sc.getInitParameter("maxevents");
- int maxEvents = NumberUtils.toInt(sMaxEvents,
EventService.DEFAULT_MAX_EVENT_LIST_SIZE);
- sc.setAttribute("maxevents", maxEvents); // expose to
other servlets
- EventService.setMaxEventListSize(maxEvents);
- }
-
- QuartzInstanceService.initQuartzInstanceMap();
-
- long end = Calendar.getInstance().getTimeInMillis();
- log.info("Settings startup completed in: " + (end - start) + "
ms");
- }
- catch (Throwable t)
- {
- log.error("Failed to initialize Settings.", t);
- }
- }
-
- public void contextDestroyed(ServletContextEvent event)
- {
- log.info("Shutting down SettingsLoaderListener service...");
- Map qMap = QuartzInstanceService.getQuartzInstanceMap();
- for (Iterator it = qMap.entrySet().iterator(); it.hasNext();)
- {
- Map.Entry entry = (Map.Entry) it.next();
- String k = (String) entry.getKey();
- QuartzInstance quartzInstance = (QuartzInstance) qMap.get(k);
- try
- {
- quartzInstance.getJmxConnector().close();
- }
- catch (IOException e)
- {
- log.error("Failed to close Connection: " + quartzInstance, e);
- }
- }
- }
-}
+ static Logger log = Logger.getLogger(SettingsLoaderListener.class);
+ ConnectionUtil connectionUtil;
+
+ public void contextInitialized(ServletContextEvent event)
+ {
+ try
+ {
+ log.info("Starting Settings Load...");
+ long start = Calendar.getInstance().getTimeInMillis();
+
+ ServletContext sc = event.getServletContext();
+ if (sc != null)
+ {
+ String sMaxEvents = sc.getInitParameter("maxevents");
+ int maxEvents = NumberUtils.toInt(sMaxEvents,
EventService.DEFAULT_MAX_EVENT_LIST_SIZE);
+ sc.setAttribute("maxevents", maxEvents); // expose to
other servlets
+ EventService.setMaxEventListSize(maxEvents);
+
+ String sMaxShowEvents =
sc.getInitParameter("maxshowevents");
+ int maxShowEvents = NumberUtils.toInt(sMaxShowEvents,
EventService.DEFAULT_MAX_SHOW_EVENT_LIST_SIZE);
+ sc.setAttribute("maxshowevents", maxShowEvents); //
expose to other servlets
+ EventService.setMaxShowEventListSize(maxShowEvents);
+ }
+
+ // load config file and instances
+ QuartzInstanceService.initQuartzInstanceMap();
+
+ SettingsUtil.loadProperties();
+
+ // connect/start DB
+ connectionUtil = new
ConnectionUtil(SettingsUtil.getDBFilePath());
+ StringBuffer jwatchLog = new StringBuffer();
+ jwatchLog.append("CREATE TEXT TABLE IF NOT EXISTS JWATCHLOG (")
+ .append("id INTEGER IDENTITY,")
+ .append("CALENDARNAME VARCHAR(256),")
+ .append("JOBGROUP VARCHAR(256),")
+ .append("JOBNAME VARCHAR(256),")
+ .append("SCHEDULERNAME VARCHAR(256),")
+ .append("TRIGGERGROUP VARCHAR(256),")
+ .append("TRIGGERNAME VARCHAR(256),")
+ .append("FIRETIME DATE,")
+ .append("NEXTFIRETIME DATE,")
+ .append("PREVIOUSFIRETIME DATE,")
+ .append("SCHEDULEDFIRETIME DATE,")
+ .append("RECOVERING BOOLEAN,")
+ .append("JOBRUNTIME BIGINT, ")
+ .append("REFIRECOUNT INTEGER, ")
+ .append("SCHEDULERID VARCHAR(256),")
+ .append("QUARTZINSTANCEID VARCHAR(256)")
+ .append(")");
+ connectionUtil.update(jwatchLog.toString());
+
+ long end = Calendar.getInstance().getTimeInMillis();
+ log.info("Settings startup completed in: " + (end - start) + "
ms");
+ }
+ catch (Throwable t)
+ {
+ log.error("Failed to initialize Settings.", t);
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent event)
+ {
+ log.info("Shutting down SettingsLoaderListener service...");
+ Map qMap = QuartzInstanceService.getQuartzInstanceMap();
+ for (Iterator it = qMap.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ String k = (String) entry.getKey();
+ QuartzInstance quartzInstance = (QuartzInstance) qMap.get(k);
+ try
+ {
+ quartzInstance.getJmxConnector().close();
+ }
+ catch (IOException e)
+ {
+ log.error("Failed to close Connection: " + quartzInstance,
e);
+ }
+ }
+
+ try
+ {
+ connectionUtil.shutdown();
+ }
+ catch (SQLException e)
+ {
+ log.error("Failed closing DB", e);
+ }
+
+ // This manually deregisters JDBC driver, which prevents Tomcat 7
from complaining about memory leaks wrt this class
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+ while (drivers.hasMoreElements())
+ {
+ Driver driver = drivers.nextElement();
+ try
+ {
+ DriverManager.deregisterDriver(driver);
+ log.info(String.format("deregistering jdbc driver: %s",
driver));
+ }
+ catch (SQLException e)
+ {
+ log.error(String.format("Error deregistering driver %s",
driver), e);
+ }
+ }
+
+ }
+}
=======================================
--- /trunk/jwatch/src/main/java/org/jwatch/util/SettingsUtil.java Wed Jun
22 08:54:44 2011
+++ /trunk/jwatch/src/main/java/org/jwatch/util/SettingsUtil.java Fri Aug
5 11:00:38 2011
@@ -23,11 +23,13 @@
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
+import org.jwatch.listener.settings.JWatchConfig;
import org.jwatch.listener.settings.QuartzConfig;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
/**
* loads, edits, deleted settings file containing quartz instance
connection data.
@@ -37,118 +39,177 @@
*/
public class SettingsUtil
{
- static Logger log = Logger.getLogger(SettingsUtil.class);
- private static final String jwatchConfigFile = "jwatch.json";
-
- /**
- * Returns FULL drive path to config file.
- *
- * @return
- */
- public static String getConfigPath()
- {
- String userHome = (String) System.getProperties().get("user.home");
- String cfgFile = userHome + File.separator + jwatchConfigFile;
-
- File file = new File(cfgFile);
-
- if (!file.canRead())
- {
- log.error("Cannot read JWatch config at: " + cfgFile);
- }
-
- if (!file.canWrite())
- {
- log.error("Cannot write to JWatch config at: " + cfgFile);
- }
-
- return cfgFile;
- }
-
- public static List loadConfig()
- {
- List instances = new ArrayList();
- String configPath = SettingsUtil.getConfigPath();
- InputStream inputStream = null;
- try
- {
- File configFile = new File(configPath);
- if (!configFile.exists())
- {
- log.info("Settings file not found! Creating new file at " +
configPath);
- FileUtils.touch(configFile);
- log.info("Settings file created at " + configPath);
- }
- else
- {
- inputStream = new FileInputStream(configFile);
- }
-
- if (configFile.length() > 0)
- {
+ static Logger log = Logger.getLogger(SettingsUtil.class);
+
+ /**
+ * Returns FULL drive path to config file that contains a JSON
representation of
+ * all Quartz instances.
+ *
+ * @return
+ */
+ public static String getConfigPath()
+ {
+ String userHome = (String) System.getProperties().get("user.home");
+ String cfgFile = userHome + File.separator +
JWatchConfig.QUARTZ_INSTANCE_FILE;
+
+ File file = new File(cfgFile);
+
+ if (!file.canRead())
+ {
+ log.error("Cannot read JWatch config at: " + cfgFile);
+ }
+
+ if (!file.canWrite())
+ {
+ log.error("Cannot write to JWatch config at: " + cfgFile);
+ }
+
+ return cfgFile;
+ }
+
+ public static void loadProperties()
+ {
+ Properties props = new Properties();
+ try
+ {
+ props.load(new FileInputStream(getPropertiesPath()));
+ }
+ catch (FileNotFoundException fnfe)
+ {
+ props.setProperty("dbdebug", "true");
+ props.setProperty("maxshowevents", "20");
+ try
+ {
+ props.store(new FileOutputStream(getPropertiesPath()),
null);
+ }
+ catch (Throwable throwable)
+ {
+
+ }
+ }
+ catch (Exception e)
+ {
+
+ }
+ }
+
+ public static List loadConfig()
+ {
+ List instances = new ArrayList();
+ String configPath = SettingsUtil.getConfigPath();
+ InputStream inputStream = null;
+ try
+ {
+ File configFile = new File(configPath);
+ if (!configFile.exists())
+ {
+ log.info("Settings file not found! Creating new file at "
+ configPath);
+ FileUtils.touch(configFile);
+ log.info("Settings file created at " + configPath);
+ }
+ else
+ {
+ inputStream = new FileInputStream(configFile);
+ }
+
+ if (configFile.length() > 0)
+ {
+ XStream xStream = new XStream(new
JettisonMappedXmlDriver());
+ xStream.setMode(XStream.NO_REFERENCES);
+ xStream.alias(GlobalConstants.JSON_DATA_ROOT_KEY,
ArrayList.class);
+ instances = ((List) xStream.fromXML(inputStream));
+ }
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ }
+ finally
+ {
+ try
+ {
+ if (inputStream != null)
+ {
+ inputStream.close();
+ }
+ }
+ catch (IOException ioe)
+ {
+ log.error("Unable to close config file handle at " +
configPath, ioe);
+ }
+ }
+ return instances;
+ }
+
+ public static void saveConfig(List<QuartzConfig> configs, String
configFilePath)
+ {
+ FileOutputStream fileOutputStream = null;
+ try
+ {
+ fileOutputStream = new FileOutputStream(configFilePath);
+
XStream xStream = new XStream(new JettisonMappedXmlDriver());
xStream.setMode(XStream.NO_REFERENCES);
xStream.alias(GlobalConstants.JSON_DATA_ROOT_KEY,
ArrayList.class);
- instances = ((List) xStream.fromXML(inputStream));
- }
- }
- catch (Throwable t)
- {
- log.error(t);
- }
- finally
- {
- try
- {
- if (inputStream != null)
- {
- inputStream.close();
- }
- }
- catch (IOException ioe)
- {
- log.error("Unable to close config file handle at " +
configPath, ioe);
- }
- }
- return instances;
- }
-
- public static void saveConfig(List<QuartzConfig> configs, String
configFilePath)
- {
- FileOutputStream fileOutputStream = null;
- try
- {
- fileOutputStream = new FileOutputStream(configFilePath);
-
- XStream xStream = new XStream(new JettisonMappedXmlDriver());
- xStream.setMode(XStream.NO_REFERENCES);
- xStream.alias(GlobalConstants.JSON_DATA_ROOT_KEY,
ArrayList.class);
- xStream.toXML(configs, fileOutputStream);
- }
- catch (Throwable t)
- {
- log.error(t);
- }
- finally
- {
- try
- {
- if (fileOutputStream != null)
- {
- fileOutputStream.close();
- }
- }
- catch (IOException ioe)
- {
- log.error(GlobalConstants.MESSAGE_ERR_CLOSE_CONFIG + " " +
configFilePath, ioe);
- }
- }
- }
-
- public static void saveConfig(QuartzConfig quartzConfig)
- {
- List instances = loadConfig();
- instances.add(quartzConfig);
- saveConfig(instances, getConfigPath());
- }
-}
+ xStream.toXML(configs, fileOutputStream);
+ }
+ catch (Throwable t)
+ {
+ log.error(t);
+ }
+ finally
+ {
+ try
+ {
+ if (fileOutputStream != null)
+ {
+ fileOutputStream.close();
+ }
+ }
+ catch (IOException ioe)
+ {
+ log.error(GlobalConstants.MESSAGE_ERR_CLOSE_CONFIG + " " +
configFilePath, ioe);
+ }
+ }
+ }
+
+ public static void saveConfig(QuartzConfig quartzConfig)
+ {
+ List instances = loadConfig();
+ instances.add(quartzConfig);
+ saveConfig(instances, getConfigPath());
+ }
+
+ /**
+ * Returns FULL drive path to the DB files
+ *
+ * @return
+ */
+ public static String getDBFilePath()
+ {
+ String userHome = (String) System.getProperties().get("user.home");
+ String cfgFile = userHome + File.separator +
JWatchConfig.DB_FILE_PREFIX;
+
+ File file = new File(cfgFile);
+
+/* if (!file.canRead())
+ {
+ log.error("Cannot read JWatch config at: " + cfgFile);
+ }
+
+ if (!file.canWrite())
+ {
+ log.error("Cannot write to JWatch config at: " + cfgFile);
+ }*/
+ return cfgFile;
+ }
+
+ public static String getPropertiesPath()
+ {
+ String userHome = (String) System.getProperties().get("user.home");
+ String cfgFile = userHome + File.separator +
JWatchConfig.PROPS_FILE_NAME;
+
+ File file = new File(cfgFile);
+ return cfgFile;
+ }
+}
=======================================
--- /trunk/jwatch/src/main/webapp/WEB-INF/web.xml Wed Jun 22 08:54:44 2011
+++ /trunk/jwatch/src/main/webapp/WEB-INF/web.xml Fri Aug 5 11:00:38 2011
@@ -8,18 +8,10 @@
<servlet-name>JWatchUIServlet</servlet-name>
<servlet-class>org.jwatch.servlet.JWatchUIServlet</servlet-class>
</servlet>
- <servlet>
- <servlet-name>JWatchWSServlet</servlet-name>
- <servlet-class>org.jwatch.servlet.JWatchWSServlet</servlet-class>
- </servlet>
<servlet-mapping>
<servlet-name>JWatchUIServlet</servlet-name>
<url-pattern>/ui</url-pattern>
</servlet-mapping>
- <servlet-mapping>
- <servlet-name>JWatchWSServlet</servlet-name>
- <url-pattern>/ws</url-pattern>
- </servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
@@ -31,6 +23,11 @@
<param-value>1000</param-value>
<description>How many job execution events to keep in the
queue.</description>
</context-param>
+ <context-param>
+ <param-name>maxshowevents</param-name>
+ <param-value>50</param-value>
+ <description>How many job execution events from the queue to show
in the UI.</description>
+ </context-param>
<listener>
<listener-class>org.jwatch.listener.settings.SettingsLoaderListener</listener-class>
=======================================
--- /trunk/jwatch/src/main/webapp/js/layout.js Wed Jun 22 08:54:44 2011
+++ /trunk/jwatch/src/main/webapp/js/layout.js Fri Aug 5 11:00:38 2011
@@ -1,545 +1,608 @@
-Ext.onReady(function() {
-
- // load executing jobs
- var eventStore = new Ext.data.JsonStore({
- url : 'ui?action=monitor_jobs',
- root : 'data',
- totalProperty : 'totalCount',
- fields : ['calendarName', 'jobName', 'schedulerName',
- 'triggerGroup', 'triggerName', 'fireTime',
- 'nextFireTime', 'previousFireTime',
- 'scheduledFireTime', 'recovering', 'jobRunTime',
- 'refireCount', 'schedulerId', 'quartzInstanceId'],
- autoLoad : false
- });
- eventStore.setDefaultSort('fireTime', 'DESC');
-
- var jobTailPanel = new Ext.grid.GridPanel({
- iconCls : 'ico-proc',
- title : '<font style="font-size:14px">Job Monitor</font>',
- store : eventStore,
- closable : false,
- columns : [{
- id : 'jobName',
- header : "Job",
- width : 160,
- sortable : true,
- dataIndex : 'jobName',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.htmlEncode(record.data.jobName)
- + '</font></div>'
- }
- }, {
- id : 'calendarName',
- header : "Calendar",
- width : 160,
- sortable : true,
- hidden : true,
- dataIndex : 'calendarName',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.htmlEncode(record.data.calendarName)
- + '</font></div>'
- }
- }, {
- id : 'triggerName',
- header : "Trigger",
- width : 160,
- sortable : true,
- hidden : true,
- dataIndex : 'triggerName',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.htmlEncode(record.data.triggerName)
- + '</font></div>'
- }
- }, {
- id : 'triggerGroup',
- header : "Trigger Group",
- width : 160,
- sortable : true,
- hidden : true,
- dataIndex : 'triggerGroup',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.htmlEncode(record.data.triggerGroup)
- + '</font></div>'
- }
- }, {
- id : 'schedulerName',
- header : "Scheduler",
- width : 100,
- sortable : true,
- dataIndex : 'schedulerName',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.htmlEncode(record.data.schedulerName)
- + '</font></div>'
- }
- }, {
- id : 'scheduledFireTime',
- header : "Scheduled",
- width : 130,
- sortable : true,
- dataIndex : 'scheduledFireTime',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.date(record.data.scheduledFireTime,
- 'm/d/y H:i:s') + '</font></div>'
- }
- }, {
- id : 'fireTime',
- header : "Fired",
- width : 130,
- sortable : true,
- dataIndex : 'fireTime',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.date(record.data.fireTime,
- 'm/d/y H:i:s') + '</font></div>'
- }
- }, {
- id : 'nextFireTime',
- header : "Next Fire",
- width : 130,
- sortable : true,
- dataIndex : 'nextFireTime',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-weight:bold;
font-size: 12px;color:#333333">'
- + Ext.util.Format.date(record.data.nextFireTime,
- 'm/d/y H:i:s') + '</font></div>'
- }
- }, {
- id : 'previousFireTime',
- header : "Previous Fire",
- width : 130,
- sortable : true,
- dataIndex : 'previousFireTime',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + Ext.util.Format.date(record.data.previousFireTime,
- 'm/d/y H:i:s') + '</font></div>'
- }
- }, {
- id : 'jobRunTime',
- header : "Duration",
- width : 100,
- sortable : true,
- dataIndex : 'jobRunTime',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + record.data.jobRunTime + 'ms</font></div>'
- }
- }, {
- id : 'refireCount',
- header : "Refire Count",
- width : 50,
- hidden : true,
- sortable : true,
- dataIndex : 'refireCount',
- renderer : function(value, p, record) {
- return '<div style="padding:2px;"><font style="font-size:
12px;color:#333333">'
- + record.data.refireCount + '</font></div>'
- }
- }],
- autoHeight : false,
- autoWidth : true,
- height : 500,
- stripeRows : true,
- autoScroll : true,
- autoExpandColumn : 'jobName',
- floatable : false,
- border : false,
- frame : false,
- loadMask : true,
- region : 'center'
- });
- tabPanel = new Ext.TabPanel({
- region : 'center',
- autoScroll : false,
- enableTabScroll : true,
- border : true,
- frame : false,
- plain : false,
- activeTab : 0,
- // layoutOnTabChange : true, // IMPORTANT!
- items : [jobTailPanel]
- });
- new Ext.Viewport({
- layout : 'border',
- items : [{
- xtype : 'box',
- region : 'north',
- applyTo : 'headerDiv',
- height : 60
- }, {
- layout : 'border',
- region : 'center',
- border : false,
- split : false,
- items : [tabPanel]
- }],
- renderTo : Ext.getBody()
- });
-
- // start the job poll
- var jobMonitor = {
- run : function() {
- eventStore.reload();
- },
- interval : 20000
- }
- Ext.TaskMgr.start(jobMonitor);
-
- // load Quartz Instances
- var QIStore = new Ext.data.JsonStore({
- url : 'ui?action=get_all_instances',
- root : 'data',
- totalProperty : 'totalCount',
- fields : ['host', 'port', 'userName', 'password', 'uuid']
- });
- QIStore.load({
- callback : function(records, options, success) {
- // create tab
- for (var loop = 0; loop < QIStore.getTotalCount(); loop++) {
- if (QIStore.data.items[loop] != undefined) {
- doLoadInstance(QIStore.data.items[loop].data);
- popAlert('Quartz instance <b>'
- + QIStore.data.items[loop].data.host + ':'
- + QIStore.data.items[loop].data.port
- + '</b> loaded successfully', 'Success',
- 'icon-n-info', 3000);
- }
- }
-
- if (QIStore.getTotalCount() <= 0) {
- popAlert(
- 'Quartz Instances Not Configured, click on the Add link to get
started.',
- 'Nothing to see...', 'icon-n-warn', 8000);
- }
- }
- });
-
- var currentInstance;
- var jobStore;
- var triggerStore;
- var schedStore;
- doLoadInstance = function(instance) {
- currentInstance = instance;
- currentInstance.rendered = false;
-
- var html = '<div style="background-color:#DCF6D8;height: 42px; width:
100%;">'
- + '<table width="100%">'
- + '<tr>'
- + '<td style="text-align:left" width="200">'
- + '<div id="sched-select" style="margin-left:-100;"></div>'
- + '</td><td style="text-align:left">'
- + '<table><tr><td><div id="infoid"></div></td>'
- + '<td><div
id="refreshid"></div></td></tr></table></td></tr></table></div>'
- jobStore = new Ext.data.JsonStore({
- url : 'ui',
- root : 'data',
- autoLoad : false,
- totalProperty : 'totalCount',
- fields : ['jobName', 'description', 'group', 'jobClass',
- 'schedulerInstanceId', 'durability',
- 'shouldRecover', 'quartzInstanceId',
- 'nextFireTime', 'numTriggers']
- });
- jobStore.setDefaultSort('jobName', 'ASC');
-
- var jobGrid = new Ext.grid.GridPanel({
- // title : 'Jobs',
- store : jobStore,
- closable : false,
- columns : [{
- id : 'jobName',
- header : "Job",
- width : 160,
- sortable : true,
- css : 'font-size: 13px;font-weight:bold;color:#333333;',
- dataIndex : 'jobName',
- renderer : function(value, p, record) {
- return Ext.util.Format
- .htmlEncode(record.data.jobName);
- }
- }, {
- id : 'nextFireTime',
- header : "Next FireTime",
- width : 170,
- sortable : true,
- css : 'font-size: 13px;font-weight:bold;color:#333333;',
- dataIndex : 'nextFireTime'
- }, {
- id : 'numTriggers',
- header : "Triggers",
- width : 80,
- sortable : true,
- css : 'font-size:
13px;font-weight:bold;color:#333333;text-align:center;',
- dataIndex : 'numTriggers',
- renderer : function(value, p, record) {
- if (record.data.numTriggers < 1) {
- return '0';
- } else {
- return '<a ext:qtip="Click to view Job triggers." ext:qtitle="Show
Triggers" href="javascript:void(0);" onClick="getTriggersForJob(\''
- + record.data.quartzInstanceId
- + '\',\''
- + record.data.schedulerInstanceId
- + '\',\''
- + record.data.jobName
- + '\',\''
- + record.data.group
- + '\')">'
- + record.data.numTriggers + '</a>';
- }
- }
- }, {
- id : 'group',
- header : "Group",
- width : 100,
- sortable : true,
- css : 'font-size: 13px;font-weight:bold;color:#333333;',
- dataIndex : 'group',
- renderer : function(value, p, record) {
- return Ext.util.Format
- .htmlEncode(record.data.group);
- }
- }, {
- id : 'jobClass',
- header : "Job Class",
- width : 180,
- sortable : true,
- css : 'font-size: 13px;font-weight:bold;color:#333333;',
- dataIndex : 'jobClass',
- renderer : function(value, p, record) {
- return Ext.util.Format
- .htmlEncode(record.data.jobClass);
- }
- }, {
- id : 'durability',
- header : "Durable",
- width : 80,
- sortable : true,
- dataIndex : 'durability',
- css : '',
- renderer : function(value, p, record) {
- if (record.data.durability == true) {
- return '<div style="text-align:center;"><img src="images/ok.png"
border="0"/></div>';
- }
- }
- }, {
- id : 'shouldRecover',
- header : "Recoverable",
- width : 80,
- sortable : true,
- dataIndex : 'shouldRecover',
- css : 'padding:3px;',
- renderer : function(value, p, record) {
- if (record.data.shouldRecover == true) {
- return '<div style="text-align:center;"><img src="images/ok.png"
border="0"/></div>';
- }
- }
- }],
- stripeRows : true,
- autoScroll : true,
- autoExpandColumn : 'jobName',
- floatable : false,
- autoHeight : false,
- border : false,
- layout : 'fit',
- frame : false,
- loadMask : true,
- region : 'center'
- });
- var schedPanel = new Ext.Panel({
- id : 'schedPanel' + instance.uuid,
- border : false,
- frame : false,
- html : html,
- layout : 'fit',
- region : 'north'
- });
- var innerPanel = new Ext.Panel({
- region : 'center',
- autoScroll : true,
- activeTab : 0,
- enableTabScroll : true,
- border : false,
- frame : false,
- plain : false,
- // autoHeight : false,
- // height : '100%',
- layout : 'border',
- layoutOnTabChange : true,// IMPORTANT!
- items : [jobGrid]
- });
- var sampleTab = new Ext.Panel({
- id : instance.uuid,
- iconCls : 'ico-clock',
- frame : false,
- autoScroll : false,
- border : false,
- plain : true,
- autoWidth : true,
- title : '<font style="font-size:14px">' + instance.userName
- + '@' + instance.host + ':' + instance.port
- + '</font>',
- height : 50,
- closable : true,
- layout : 'border',
- items : [schedPanel, innerPanel],
- listeners : {
- activate : function() {
- handleInstanceTabActivate(instance);
- }
- }
- });
- innerPanel.doLayout();
- tabPanel.add(sampleTab);
- // tabPanel.setActiveTab(instance.uuid);
-
- schedStore = new Ext.data.JsonStore({
- url : 'ui?action=get_schedulers&uuid=' + instance.uuid,
- root : 'data',
- totalProperty : 'totalCount',
- fields : ['name', 'instanceId', 'uuidInstance'],
- autoLoad : false
- });
- }
-
- handleInstanceTabActivate = function(instance) {
- if (currentInstance.rendered == false) {
- // sched-select
- var comboTPL = new Ext.XTemplate(
- '<tpl for="."><div class="multiline-combo">',
- '<img src="images/schedule16x16.png"
style="vertical-align:middle"/> <b>{name:htmlEncode}</b></div></tpl>');
- schedStore.load({
- callback : function(records, options, success) {
- var schedbox = new Ext.form.ComboBox({
- tpl : comboTPL,
- itemSelector : 'div.multiline-combo',
- mode : 'remote',
- store : schedStore,
- allowBlank : true,
- emptyText : 'Select a Scheduler...',
- selectOnFocus : true,
- width : 180,
- listWidth : 300,
- editable : false,
- name : 'schedName',
- id : 'schedName',
- displayField : 'name',
- valueField : 'uuidInstance',
- hiddenName : 'uuidInstance',
- triggerAction : 'all',
- listeners : {
- 'select' : function(combo, record) {
- getJobsForScheduler(record.data.uuidInstance);
- }
- }
- });
- new Ext.form.FormPanel({
- baseCls : 'x-example-form',
- style : {
- margin : 0,
- padding : 10
- },
- border : false,
- renderTo : 'sched-select',
- items : [schedbox]
- });
- }
- });
- }
- currentInstance.rendered = true;
- }
-
- getJobsForScheduler = function(id) {
- jobStore.load({
- params : {
- action : 'get_jobs',
- 'uuidInstance' : id
- }
- });
- var ii = document.getElementById('infoid');
- ii.innerHTML = '<a href="javascript:void(0);"
onClick="getSchedulerInfo(\''
- + id
- + '\')"><img ext:qtip="Click to view Schedule details."
ext:qtitle="Show Schedule" src="images/info.png"
style="padding-bottom:5px;padding-left:7px;border:0;"/></a>';
- var ir = document.getElementById('refreshid');
- ir.innerHTML = '<a href="javascript:void(0);"
onClick="getJobsForScheduler(\''
- + id
- + '\')"><img ext:qtip="Click to refresh Jobs list."
ext:qtitle="Refresh Jobs" src="images/refresh.png"
style="padding-bottom:5px;padding-left:7px;border:0;"/></a>';
- }
-
- getSchedulerInfo = function(id) {
- Ext.Ajax.request({
- url : 'ui',
- params : {
- action : 'get_scheduler_info',
- 'uuidInstance' : id
- },
- waitMsg : 'Removing User Mapping...',
- success : function(response, request) {
- var res = new Object();
- res = Ext.util.JSON.decode(response.responseText);
- if (res.success == true) {
- var schedulerPanel = new Ext.Panel({
- title : '',
- region : 'center',
- autoHeight : true,
- html : ''
- });
- schedulerWin = new Ext.Window({
- id : 'addInstanceWin',
- title : '<font class="panelTitle">Scheduler Details</font>',
- layout : 'fit',
- width : 620,
- frame : true,
- autoScroll : true,
- height : 320,
- closeAction : 'close',
- plain : true,
- border : true,
- html : ''
- });
- schedulerWin.show(document.body);
-
- var html = '<div style="padding:10px;"><table class="panelTbl"
border="0" cellpadding="5" cellspacing="5">'
- + '<tr><td class="label">Scheduler Name:</td><td>'
- + res.name
- + '</td></tr>'
- + '<tr><td class="label">Job Store Class:</td><td>'
- + res.jobStoreClassName
- + '</td></tr>'
- + '<tr><td class="label">Scheduler ID:</td><td>'
- + res.instanceId
- + '</td></tr>'
- + '<tr><td class="label">Canonical Name:</td><td>'
- + res.objectName.canonicalName
- + '</td></tr>'
- + '<tr><td class="label">Domain:</td><td>'
- + res.objectName.domain
- + '</td></tr>'
- + '<tr><td class="label">Started:</td><td>'
- + res.started
- + '</td></tr>'
- + '<tr><td class="label">Shutdown:</td><td>'
- + res.shutdown
- + '</td></tr>'
- + '<tr><td class="label">Standby Mode:</td><td>'
- + res.standByMode
- + '</td></tr>'
- + '<tr><td class="label">ThreadPool Class:</td><td>'
- + res.threadPoolClassName
- + '</td></tr>'
- + '<tr><td class="label">ThreadPool Size:</td><td>'
- + res.threadPoolSize
- + '</td></tr>'
- + '</table></div>'
- schedulerWin.body.update(html);
- }
- }
- });
- }
+Ext.onReady(function()
+{
+
+ // load executing jobs
+ var eventStore = new Ext.data.JsonStore({
+ url : 'ui?action=monitor_jobs',
+ root : 'data',
+ totalProperty : 'totalCount',
+ fields : ['calendarName', 'jobName', 'schedulerName',
+ 'triggerGroup', 'triggerName', 'fireTime',
+ 'nextFireTime', 'previousFireTime',
+ 'scheduledFireTime', 'recovering', 'jobRunTime',
+ 'refireCount', 'schedulerId', 'quartzInstanceId'],
+ autoLoad : false
+ });
+ eventStore.setDefaultSort('fireTime', 'DESC');
+
+ var jobTailPanel = new Ext.grid.GridPanel({
+ iconCls : 'ico-proc',
+ title : '<font style="font-size:14px">Job Monitor</font>',
+ store : eventStore,
+ closable : false,
+ columns : [
+ {
+ id : 'jobName',
+ header : "Job",
+ width : 160,
+ sortable : true,
+ dataIndex : 'jobName',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ + Ext.util.Format.htmlEncode(record.data.jobName)
+ + '</font></div>'
+ }
+ },
+ {
+ id : 'calendarName',
+ header : "Calendar",
+ width : 160,
+ sortable : true,
+ hidden : true,
+ dataIndex : 'calendarName',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ +
Ext.util.Format.htmlEncode(record.data.calendarName)
+ + '</font></div>'
+ }
+ },
+ {
+ id : 'triggerName',
+ header : "Trigger",
+ width : 160,
+ sortable : true,
+ hidden : true,
+ dataIndex : 'triggerName',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ +
Ext.util.Format.htmlEncode(record.data.triggerName)
+ + '</font></div>'
+ }
+ },
+ {
+ id : 'triggerGroup',
+ header : "Trigger Group",
+ width : 160,
+ sortable : true,
+ hidden : true,
+ dataIndex : 'triggerGroup',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ +
Ext.util.Format.htmlEncode(record.data.triggerGroup)
+ + '</font></div>'
+ }
+ },
+ {
+ id : 'schedulerName',
+ header : "Scheduler",
+ width : 100,
+ sortable : true,
+ dataIndex : 'schedulerName',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ +
Ext.util.Format.htmlEncode(record.data.schedulerName)
+ + '</font></div>'
+ }
+ },
+ {
+ id : 'scheduledFireTime',
+ header : "Scheduled",
+ width : 130,
+ sortable : true,
+ dataIndex : 'scheduledFireTime',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ +
Ext.util.Format.date(record.data.scheduledFireTime,
+ 'm/d/y H:i:s') + '</font></div>'
+ }
+ },
+ {
+ id : 'fireTime',
+ header : "Fired",
+ width : 130,
+ sortable : true,
+ dataIndex : 'fireTime',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ + Ext.util.Format.date(record.data.fireTime,
+ 'm/d/y H:i:s') + '</font></div>'
+ }
+ },
+ {
+ id : 'nextFireTime',
+ header : "Next Fire",
+ width : 130,
+ sortable : true,
+ dataIndex : 'nextFireTime',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-weight:bold; font-size: 12px;color:#333333">'
+ + Ext.util.Format.date(record.data.nextFireTime,
+ 'm/d/y H:i:s') + '</font></div>'
+ }
+ },
+ {
+ id : 'previousFireTime',
+ header : "Previous Fire",
+ width : 130,
+ sortable : true,
+ dataIndex : 'previousFireTime',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ +
Ext.util.Format.date(record.data.previousFireTime,
+ 'm/d/y H:i:s') + '</font></div>'
+ }
+ },
+ {
+ id : 'jobRunTime',
+ header : "Duration",
+ width : 100,
+ sortable : true,
+ dataIndex : 'jobRunTime',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ + record.data.jobRunTime + 'ms</font></div>'
+ }
+ },
+ {
+ id : 'refireCount',
+ header : "Refire Count",
+ width : 50,
+ hidden : true,
+ sortable : true,
+ dataIndex : 'refireCount',
+ renderer : function(value, p, record)
+ {
+ return '<div style="padding:2px;"><font
style="font-size: 12px;color:#333333">'
+ + record.data.refireCount + '</font></div>'
+ }
+ }
+ ],
+ autoHeight : false,
+ autoWidth : true,
+ height : 500,
+ stripeRows : true,
+ autoScroll : true,
+ autoExpandColumn : 'jobName',
+ floatable : false,
+ border : false,
+ frame : false,
+ loadMask : true,
+ region : 'center'
+ });
+ tabPanel = new Ext.TabPanel({
+ region : 'center',
+ autoScroll : false,
+ enableTabScroll : true,
+ border : true,
+ frame : false,
+ plain : false,
+ activeTab : 0,
+ // layoutOnTabChange : true, // IMPORTANT!
+ items : [jobTailPanel]
+ });
+ new Ext.Viewport({
+ layout : 'border',
+ items : [
+ {
+ xtype : 'box',
+ region : 'north',
+ applyTo : 'headerDiv',
+ height : 60
+ },
+ {
+ layout : 'border',
+ region : 'center',
+ border : false,
+ split : false,
+ items : [tabPanel]
+ }
+ ],
+ renderTo : Ext.getBody()
+ });
+
+ // start the job poll
+ var jobMonitor = {
+ run : function()
+ {
+ eventStore.reload();
+ },
+ interval : 20000
+ }
+ Ext.TaskMgr.start(jobMonitor);
+
+ // load Quartz Instances
+ var QIStore = new Ext.data.JsonStore({
+ url : 'ui?action=get_all_instances',
+ root : 'data',
+ totalProperty : 'totalCount',
+ fields : ['host', 'port', 'userName', 'password', 'uuid']
+ });
+ QIStore.load({
+ callback : function(records, options, success)
+ {
+ // create tab
+ for (
+ var loop = 0; loop < QIStore.getTotalCount(); loop++
+ )
+ {
+ if (QIStore.data.items[loop] != undefined)
+ {
+ doLoadInstance(QIStore.data.items[loop].data);
+ popAlert('Quartz instance <b>'
+ + QIStore.data.items[loop].data.host + ':'
+ + QIStore.data.items[loop].data.port
+ + '</b> loaded successfully', 'Success',
+ 'icon-n-info', 3000);
+ }
+ }
+
+ if (QIStore.getTotalCount() <= 0)
+ {
+ popAlert(
+ 'Quartz Instances Not Configured, click on the Add
link to get started.',
+ 'Nothing to see...', 'icon-n-warn', 8000);
+ }
+ }
+ });
+
+ var currentInstance;
+ var jobStore;
+ var triggerStore;
+ var schedStore;
+ doLoadInstance = function(instance)
+ {
+ currentInstance = instance;
+ currentInstance.rendered = false;
+
+ var html = '<div style="background-color:#DCF6D8;height: 42px;
width: 100%;">'
+ + '<table width="100%">'
+ + '<tr>'
+ + '<td style="text-align:left" width="200">'
+ + '<div id="sched-select" style="margin-left:-100;"></div>'
+ + '</td><td style="text-align:left">'
+ + '<table><tr><td><div id="infoid"></div></td>'
+ + '<td><div
id="refreshid"></div></td></tr></table></td></tr></table></div>'
+ jobStore = new Ext.data.JsonStore({
+ url : 'ui',
+ root : 'data',
+ autoLoad : false,
+ totalProperty : 'totalCount',
+ fields : ['jobName', 'description', 'group', 'jobClass',
+ 'schedulerInstanceId', 'durability',
+ 'shouldRecover', 'quartzInstanceId',
+ 'nextFireTime', 'numTriggers']
+ });
+ jobStore.setDefaultSort('jobName', 'ASC');
+
+ var jobGrid = new Ext.grid.GridPanel({
+ // title : 'Jobs',
+ store : jobStore,
+ closable : false,
+ columns : [
+ {
+ id : 'jobName',
+ header : "Job",
+ width : 160,
+ sortable : true,
+ css : 'font-size:
13px;font-weight:bold;color:#333333;',
+ dataIndex : 'jobName',
+ renderer : function(value, p, record)
+ {
+ return Ext.util.Format
+ .htmlEncode(record.data.jobName);
+ }
+ },
+ {
+ id : 'nextFireTime',
+ header : "Next FireTime",
+ width : 170,
+ sortable : true,
+ css : 'font-size:
13px;font-weight:bold;color:#333333;',
+ dataIndex : 'nextFireTime'
+ },
+ {
+ id : 'numTriggers',
+ header : "Triggers",
+ width : 80,
+ sortable : true,
+ css : 'font-size:
13px;font-weight:bold;color:#333333;text-align:center;',
+ dataIndex : 'numTriggers',
+ renderer : function(value, p, record)
+ {
+ if (record.data.numTriggers < 1)
+ {
+ return '0';
+ }
+ else
+ {
+ return '<a ext:qtip="Click to view Job
triggers." ext:qtitle="Show Triggers" href="javascript:void(0);"
onClick="getTriggersForJob(\''
+ + record.data.quartzInstanceId
+ + '\',\''
+ + record.data.schedulerInstanceId
+ + '\',\''
+ + record.data.jobName
+ + '\',\''
+ + record.data.group
+ + '\')">'
+ + record.data.numTriggers + '</a>';
+ }
+ }
+ },
+ {
+ id : 'group',
+ header : "Group",
+ width : 100,
+ sortable : true,
+ css : 'font-size:
13px;font-weight:bold;color:#333333;',
+ dataIndex : 'group',
+ renderer : function(value, p, record)
+ {
+ return Ext.util.Format
+ .htmlEncode(record.data.group);
+ }
+ },
+ {
+ id : 'jobClass',
+ header : "Job Class",
+ width : 180,
+ sortable : true,
+ css : 'font-size:
13px;font-weight:bold;color:#333333;',
+ dataIndex : 'jobClass',
+ renderer : function(value, p, record)
+ {
+ return Ext.util.Format
+ .htmlEncode(record.data.jobClass);
+ }
+ },
+ {
+ id : 'durability',
+ header : "Durable",
+ width : 80,
+ sortable : true,
+ dataIndex : 'durability',
+ css : '',
+ renderer : function(value, p, record)
+ {
+ if (record.data.durability == true)
+ {
+ return '<div style="text-align:center;"><img
src="images/ok.png" border="0"/></div>';
+ }
+ }
+ },
+ {
+ id : 'shouldRecover',
+ header : "Recoverable",
+ width : 80,
+ sortable : true,
+ dataIndex : 'shouldRecover',
+ css : 'padding:3px;',
+ renderer : function(value, p, record)
+ {
+ if (record.data.shouldRecover == true)
+ {
+ return '<div style="text-align:center;"><img
src="images/ok.png" border="0"/></div>';
+ }
+ }
+ }
+ ],
+ stripeRows : true,
+ autoScroll : true,
+ autoExpandColumn : 'jobName',
+ floatable : false,
+ autoHeight : false,
+ border : false,
+ layout : 'fit',
+ frame : false,
+ loadMask : true,
+ region : 'center'
+ });
+ var schedPanel = new Ext.Panel({
+ id : 'schedPanel' + instance.uuid,
+ border : false,
+ frame : false,
+ html : html,
+ layout : 'fit',
+ region : 'north'
+ });
+ var innerPanel = new Ext.Panel({
+ region : 'center',
+ autoScroll : true,
+ activeTab : 0,
+ enableTabScroll : true,
+ border : false,
+ frame : false,
+ plain : false,
+ // autoHeight : false,
+ // height : '100%',
+ layout : 'border',
+ layoutOnTabChange : true,// IMPORTANT!
+ items : [jobGrid]
+ });
+ var sampleTab = new Ext.Panel({
+ id : instance.uuid,
+ iconCls : 'ico-clock',
+ frame : false,
+ autoScroll : false,
+ border : false,
+ plain : true,
+ autoWidth : true,
+ title : '<font style="font-size:14px">' + instance.userName
+ + '@' + instance.host + ':' + instance.port
+ + '</font>',
+ height : 50,
+ closable : true,
+ layout : 'border',
+ items : [schedPanel, innerPanel],
+ listeners : {
+ activate : function()
+ {
+ handleInstanceTabActivate(instance);
+ }
+ }
+ });
+ innerPanel.doLayout();
+ tabPanel.add(sampleTab);
***The diff for this file has been truncated for email.***