customSettings = new ArrayList<>();
ServletFileUpload su = new ServletFileUpload();
try {
@@ -58,7 +62,7 @@ public class AddSettingServlet extends EntityManagerServlet{
}
} catch (FileUploadException ex) {
- // Logger.getLogger(SettingsServlet.class.getName()).log(Level.SEVERE, null, ex);
+ log.warn("Exception in AddSettingServlet", ex);
}
SettingsUtil.updateSettings(customSettings);
diff --git a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/AutoAuditMigrationContextListener.java b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/AutoAuditMigrationContextListener.java
index 21d7584f0296ad8216523b2af9ce83e9ac84357d..882147e6a5bdf589ce2e8eca4e80f29ac0494148 100644
--- a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/AutoAuditMigrationContextListener.java
+++ b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/AutoAuditMigrationContextListener.java
@@ -2,7 +2,9 @@ package edu.umiacs.ace.monitor.settings;
import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.sql.SQL;
+import edu.umiacs.util.Check;
import org.apache.log4j.Logger;
+import org.apache.log4j.NDC;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -12,45 +14,77 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import static edu.umiacs.ace.monitor.settings.SettingsConstants.PARAM_IMS_MAX_RETRY;
+import static edu.umiacs.ace.monitor.settings.SettingsConstants.PARAM_IMS_RESET_TIMEOUT;
+import static edu.umiacs.ace.monitor.settings.SettingsConstants.imsMaxRetry;
+import static edu.umiacs.ace.monitor.settings.SettingsConstants.imsResetTimeout;
+
/**
- * Context listener to migrate from auto.audit.disable to auto.audit.enable
- *
+ * Context listener to migrate audit/ims settings
+ * auto.audit.disable to auto.audit.enable
+ * audit.max.block.time to ims.max.retry
+ * add ims.reset.timeout
+ *
* Created by shake on 4/5/17.
*/
public class AutoAuditMigrationContextListener implements ServletContextListener {
private static final Logger LOG = Logger.getLogger(AutoAuditMigrationContextListener.class);
- private ResultSet set;
- private Connection conn;
- private PreparedStatement statement;
-
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
- Connection conn = null;
+ NDC.push("[MIGRATION] ");
DataSource ds = PersistUtil.getDataSource();
- try {
- conn = ds.getConnection();
- migrate(conn);
+ try (Connection conn = ds.getConnection()) {
+ migrateAutoAudit(conn);
+ migrateAuditBlocking(conn);
} catch (Exception e) {
- LOG.error("[MIGRATION] Error migrating audo.audit.disable setting", e);
+ LOG.error("Error migrating audit settings", e);
} finally {
- release();
-
+ NDC.pop();
}
}
- private void migrate(Connection conn) throws SQLException {
- PreparedStatement statement = conn.prepareStatement("SELECT id, value, custom FROM system_settings WHERE attr = 'auto.audit.disable'");
- ResultSet set = statement.executeQuery();
- while (set.next()) {
- Long id = set.getLong(1);
- Boolean value = Boolean.valueOf(set.getString(2));
- Boolean custom = set.getBoolean(3);
- if (!custom) {
- LOG.info("[MIGRATION] Found auto.audit setting to migrate from " + value + " -> " + !value);
- createNew(conn, !value);
+ /**
+ * Migrate from auto.audit.disable to auto.audit.enable
+ *
+ * @param conn The database connection
+ * @throws SQLException if there's an exception communicating with the database
+ */
+ private void migrateAutoAudit(Connection conn) throws SQLException {
+ String query = "SELECT id, value, custom FROM system_settings WHERE attr = 'auto.audit.disable'";
+ try (PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet set = statement.executeQuery()) {
+ while (set.next()) {
+ Long id = set.getLong(1);
+ Boolean value = Boolean.valueOf(set.getString(2));
+ Boolean custom = set.getBoolean(3);
+ if (!custom) {
+ LOG.info("Found auto.audit setting to migrate from " + value + " -> " + !value);
+ createNew(conn, "auto.audit.enable", String.valueOf(!value));
+ delete(conn, id);
+ }
+ }
+ }
+ }
+
+ /**
+ * Check if audit.max.block.time exists. If true, add ims.max.retry and ims.reset.timeout and
+ * remove audit.max.block.time
+ *
+ * @param conn The database connection
+ * @throws SQLException if there's an exception communicating with the database
+ */
+ private void migrateAuditBlocking(Connection conn) throws SQLException {
+ String query = "SELECT id FROM system_settings WHERE attr = 'audit.max.block.time'";
+ try (PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet set = statement.executeQuery()) {
+ while (set.next()) {
+ Long id = set.getLong(1);
+ LOG.info("Found audit.max.block.time setting to migrate to ims.max.retry");
+ createNew(conn, PARAM_IMS_MAX_RETRY, imsMaxRetry);
+ createNew(conn, PARAM_IMS_RESET_TIMEOUT, imsResetTimeout);
delete(conn, id);
}
}
@@ -62,21 +96,14 @@ public class AutoAuditMigrationContextListener implements ServletContextListener
SQL.release(statement);
}
- private void createNew(Connection conn, Boolean value) throws SQLException {
- PreparedStatement statement = conn.prepareStatement("INSERT INTO system_settings VALUES (DEFAULT, 'auto.audit.enable','" + value.toString() + "',0)");
- statement.executeUpdate();
- SQL.release(statement);
- }
+ private void createNew(Connection conn, String attr, String value) throws SQLException {
+ Check.notNull("attr", attr);
+ Check.notNull("value", value);
- private void release() {
- if (conn != null) {
- SQL.release(conn);
- }
- if (statement != null) {
- SQL.release(statement);
- }
- if (set != null) {
- SQL.release(set);
+ String query = "INSERT INTO system_settings VALUES (DEFAULT, '%s', '%s', 0)";
+ try (PreparedStatement statement =
+ conn.prepareStatement(String.format(query, attr, value))) {
+ statement.executeUpdate();
}
}
diff --git a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/DeleteSettingsServlet.java b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/DeleteSettingsServlet.java
index aa07688fe56d956021a48c61e54b7dfe7cee27c6..f5b9c260b87015c2e48153ad9572731abdc03f66 100644
--- a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/DeleteSettingsServlet.java
+++ b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/DeleteSettingsServlet.java
@@ -7,15 +7,16 @@ package edu.umiacs.ace.monitor.settings;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.util.Strings;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+
import javax.persistence.EntityManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
/**
*
@@ -25,10 +26,11 @@ public class DeleteSettingsServlet extends EntityManagerServlet{
public static final String PARAM_SETTING = "setting";
@Override
- protected void processRequest(HttpServletRequest request, HttpServletResponse
- response, EntityManager em) throws ServletException, IOException {
+ protected void processRequest(HttpServletRequest request,
+ HttpServletResponse response,
+ EntityManager em) throws ServletException, IOException {
- List settingsToDelete = new ArrayList();
+ List settingsToDelete = new ArrayList<>();
RequestDispatcher dispatcher = null;
if ( !Strings.isEmpty(request.getParameter(PARAM_SETTING)) ) {
diff --git a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsConstants.java b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsConstants.java
index 6fd3e18b82db9899b2026a7e220b8e046678f5fa..438325c2a46f858850d4e48270ac45c4e132ac98 100644
--- a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsConstants.java
+++ b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsConstants.java
@@ -1,18 +1,19 @@
package edu.umiacs.ace.monitor.settings;
/**
- *
* @author shake
*/
public class SettingsConstants {
+
// Attributes
public static final String PARAM_AUDIT_BLOCKING = "audit.blocking";
- public static final String PARAM_AUDIT_MAX_BLOCK_TIME = "audit.max.block.time";
- public static final String PARAM_AUDIT_ONLY="audit.only";
+ public static final String PARAM_AUDIT_ONLY = "audit.only";
public static final String PARAM_AUDIT_SAMPLE = "audit.sample";
public static final String PARAM_IMS = "ims";
public static final String PARAM_IMS_PORT = "ims.port";
public static final String PARAM_IMS_TOKEN_CLASS = "ims.tokenclass";
+ public static final String PARAM_IMS_MAX_RETRY = "ims.max.retry";
+ public static final String PARAM_IMS_RESET_TIMEOUT = "ims.reset.timeout";
public static final String PARAM_IMS_SSL = "ims.ssl";
public static final String PARAM_AUTO_AUDIT_ENABLE = "auto.audit.enable";
public static final String PARAM_THROTTLE_MAXAUDIT = "throttle.maxaudit";
@@ -22,19 +23,17 @@ public class SettingsConstants {
public static final String PARAM_FROM = "mail.from";
public static final String PARAM_USER_AUTH = "auth.management";
public static final String PARAM_4J_FILE = "log4j.appender.A1.File";
- public static final String PARAM_4J_APPENDER = "log4j.appender.A1";
+ public static final String PARAM_4J_APPENDER = "log4j.appender.A1";
public static final String PARAM_4J_FILE_SIZE = "log4j.appender.A1.maxFileSize";
public static final String PARAM_4J_BACKUP_INDEX = "log4j.appender.A1.maxBackupIndex";
public static final String PARAM_4J_ROOT_LOGGER = "log4j.rootLogger";
- public static final String PARAM_4J_LAYOUT = "log4j.appender.A1.layout";
+ public static final String PARAM_4J_LAYOUT = "log4j.appender.A1.layout";
public static final String PARAM_4J_CONV_PAT = "log4j.appender.A1.layout.ConversionPattern";
public static final String PARAM_4J_IRODS = "log4j.logger.edu.umiacs.irods";
- public static final String PARAM_4J_CLASS ="log4j.logger.edu.umiacs";
- public static final String PARAM_INGEST = "ingest.maxthreads";
+ public static final String PARAM_4J_CLASS = "log4j.logger.edu.umiacs";
// Default Values
public static final String auditBlocking = "false";
- public static final String auditMaxBlockTime = "0";
public static final String auditOnly = "false";
public static final String auditSample = "false";
public static final String mailServer = "localhost.localdomain";
@@ -44,22 +43,45 @@ public class SettingsConstants {
public static final String ims = "ims.umiacs.umd.edu";
public static final String imsPort = "80";
public static final String imsTokenClass = "SHA-256";
+ public static final String imsMaxRetry = "3";
+ public static final String imsResetTimeout = "3000";
public static final String imsSSL = "false";
public static final String authManagement = "true";
- public static final String maxIngestThreads = "4";
public static final String throttleWait = "0";
- public static final String throttleBPS= "0";
+ public static final String throttleBPS = "0";
// Yay log4j
public static final String log4JA1File = "/tmp/aceam.log";
public static final String log4JA1 = "org.apache.log4j.RollingFileAppender";
public static final String log4JA1MaxFileSize = "100000KB";
public static final String log4JA1MaxBackupIndex = "5";
public static final String log4JRootLogger = "FATAL, A1";
- public static final String log4JA1Layout = "org.apache.log4j.PatternLayout";
+ public static final String log4JA1Layout = "org.apache.log4j.PatternLayout";
public static final String log4JA1layoutConversationPattern =
"%d{[dd/MMM/yyyy:HH:mm:ss]} %x%m%n";
public static final String log4JLoggerIrods = "ERROR";
public static final String log4JLoggerUMIACS = "TRACE";
+ /**
+ * @deprecated migrated to PARAM_IMS_MAX_RETRY and PARAM_IMS_RESET_TIMEOUT
+ */
+ @Deprecated
+ public static final String PARAM_AUDIT_MAX_BLOCK_TIME = "audit.max.block.time";
+ /**
+ * @deprecated migrated to PARAM_IMS_MAX_RETRY and PARAM_IMS_RESET_TIMEOUT
+ */
+ @Deprecated
+ public static final String auditMaxBlockTime = "0";
+
+ /**
+ * @deprecated no longer used
+ */
+ @Deprecated
+ public static final String PARAM_INGEST = "ingest.maxthreads";
+
+ /**
+ * @deprecated no longer used
+ */
+ @Deprecated
+ public static final String maxIngestThreads = "4";
}
diff --git a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsParameter.java b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsParameter.java
index 897a909db5a329aa523fa3b7649ff353acbede93..c5ba602458bb13ce450e6f31ab710b0cf6574db1 100644
--- a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsParameter.java
+++ b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsParameter.java
@@ -49,6 +49,7 @@ public class SettingsParameter implements Serializable {
public SettingsParameter(String attr, String value) {
this.attr = attr;
this.value = value;
+ this.custom = false;
}
public Long getId() {
diff --git a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsServlet.java b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsServlet.java
index e004e5cf8f3c33ee2320ec7790f83266c0f71b72..97055e9468326f4c370fe74004161b094e3b40ef 100644
--- a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsServlet.java
+++ b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsServlet.java
@@ -63,10 +63,8 @@ public class SettingsServlet extends EntityManagerServlet {
}
}
- Map settingsMap =
- settingsToMap(SettingsUtil.getCurrentSettings());
- Map customMap =
- settingsToMap(SettingsUtil.getCustomSettings());
+ Map settingsMap = settingsToMap(SettingsUtil.getCurrentSettings());
+ Map customMap = settingsToMap(SettingsUtil.getCustomSettings());
request.setAttribute("currSettings", settingsMap);
request.setAttribute("customSettings", customMap);
diff --git a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsUtil.java b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsUtil.java
index 0868f39e9d09dfad2e26905b807da571205ef134..cadbb984c8fdee2d35c866e73e326ed4c5347ae9 100644
--- a/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsUtil.java
+++ b/ace-am/src/main/java/edu/umiacs/ace/monitor/settings/SettingsUtil.java
@@ -4,6 +4,7 @@ import edu.umiacs.ace.monitor.audit.AuditThreadFactory;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.reporting.SchedulerContextListener;
import edu.umiacs.ace.util.PersistUtil;
+import edu.umiacs.util.Strings;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
@@ -11,12 +12,11 @@ import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+
+import static edu.umiacs.ace.monitor.settings.SettingsConstants.*;
/**
- *
* @author shake
*/
public class SettingsUtil {
@@ -27,7 +27,7 @@ public class SettingsUtil {
* @param attr the attribute to query on
* @return the Setting associated with the attribute
*/
- public static SettingsParameter getItemByAttr( String attr ) {
+ public static SettingsParameter getItemByAttr(String attr) {
EntityManager em = PersistUtil.getEntityManager();
Query q = em.createNamedQuery("SettingsParameter.getAttr");
q.setParameter("attr", attr);
@@ -35,7 +35,7 @@ public class SettingsUtil {
try {
return (SettingsParameter) q.getSingleResult();
} catch (NoResultException ex) {
- // zzz
+ // ignore, return null
} finally {
em.close();
}
@@ -87,17 +87,17 @@ public class SettingsUtil {
EntityTransaction trans = em.getTransaction();
trans.begin();
- for ( SettingsParameter setting : settings ) {
+ for (SettingsParameter setting : settings) {
// Skip any empty settings
- if ( setting.getName().trim().isEmpty() ||
- setting.getValue().trim().isEmpty() ) {
+ if (setting.getName().trim().isEmpty() ||
+ setting.getValue().trim().isEmpty()) {
continue;
}
SettingsParameter old = getItemByAttr(setting.getName());
// If there is no item, persist the new setting
- if ( old == null ) {
+ if (old == null) {
em.persist(setting);
} else {
// Else update and merge the old item
@@ -122,14 +122,14 @@ public class SettingsUtil {
EntityTransaction trans = em.getTransaction();
trans.begin();
- for ( String name : settings ) {
+ for (String name : settings) {
// TODO: Find a better way to do this
// Could possibly wrap the ID into the settings list
SettingsParameter setting = getItemByAttr(name);
SettingsParameter managedSetting =
em.find(SettingsParameter.class, setting.getId());
- if ( setting != null ) {
+ if (setting != null) {
em.remove(managedSetting);
}
}
@@ -138,16 +138,6 @@ public class SettingsUtil {
em.close();
}
- // Get the names of all current settings
- public static Set getParamNames() {
- List settings = getCurrentSettings();
- Set paramSet = new HashSet<>();
- for ( SettingsParameter s : settings ) {
- paramSet.add(s.getName());
- }
- return paramSet;
- }
-
/**
* Get the default values for all settings
@@ -157,68 +147,43 @@ public class SettingsUtil {
public static List getDefaultSettings() {
List defaults = new ArrayList<>();
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_IMS,
- SettingsConstants.ims,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_IMS_PORT,
- SettingsConstants.imsPort,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_IMS_SSL,
- SettingsConstants.imsSSL,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_IMS_TOKEN_CLASS,
- SettingsConstants.imsTokenClass,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_AUTO_AUDIT_ENABLE,
- SettingsConstants.autoAudit,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_THROTTLE_MAXAUDIT,
- SettingsConstants.maxAudit,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_TIME,
- SettingsConstants.throttleWait,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_BPS,
- SettingsConstants.throttleBPS,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_SMTP_SERVER,
- SettingsConstants.mailServer,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_FROM,
- SettingsConstants.mailFrom,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_USER_AUTH,
- SettingsConstants.authManagement,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_APPENDER,
- SettingsConstants.log4JA1,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_BACKUP_INDEX,
- SettingsConstants.log4JA1MaxBackupIndex,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_CLASS,
- SettingsConstants.log4JLoggerUMIACS,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_CONV_PAT,
- SettingsConstants.log4JA1layoutConversationPattern,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_FILE,
- SettingsConstants.log4JA1File,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_FILE_SIZE,
- SettingsConstants.log4JA1MaxFileSize,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_IRODS,
- SettingsConstants.log4JLoggerIrods,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_LAYOUT,
- SettingsConstants.log4JA1Layout,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_4J_ROOT_LOGGER,
- SettingsConstants.log4JRootLogger,false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_INGEST,
- SettingsConstants.maxIngestThreads, false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_AUDIT_ONLY,
- SettingsConstants.auditOnly, false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_AUDIT_SAMPLE,
- SettingsConstants.auditSample, false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_AUDIT_BLOCKING,
- SettingsConstants.auditBlocking, false));
- defaults.add(new SettingsParameter(SettingsConstants.PARAM_AUDIT_MAX_BLOCK_TIME,
- SettingsConstants.auditMaxBlockTime, false));
+ defaults.add(new SettingsParameter(PARAM_IMS, ims));
+ defaults.add(new SettingsParameter(PARAM_IMS_PORT, imsPort));
+ defaults.add(new SettingsParameter(PARAM_IMS_SSL, imsSSL));
+ defaults.add(new SettingsParameter(PARAM_IMS_TOKEN_CLASS, imsTokenClass));
+ defaults.add(new SettingsParameter(PARAM_AUTO_AUDIT_ENABLE, autoAudit));
+ defaults.add(new SettingsParameter(PARAM_THROTTLE_MAXAUDIT, maxAudit));
+ defaults.add(new SettingsParameter(PARAM_TIME, throttleWait));
+ defaults.add(new SettingsParameter(PARAM_BPS, throttleBPS));
+ defaults.add(new SettingsParameter(PARAM_SMTP_SERVER, mailServer));
+ defaults.add(new SettingsParameter(PARAM_FROM, mailFrom));
+ defaults.add(new SettingsParameter(PARAM_USER_AUTH, authManagement));
+ defaults.add(new SettingsParameter(PARAM_4J_APPENDER, log4JA1));
+ defaults.add(new SettingsParameter(PARAM_4J_BACKUP_INDEX, log4JA1MaxBackupIndex));
+ defaults.add(new SettingsParameter(PARAM_4J_CLASS, log4JLoggerUMIACS));
+ defaults.add(new SettingsParameter(PARAM_4J_CONV_PAT, log4JA1layoutConversationPattern));
+ defaults.add(new SettingsParameter(PARAM_4J_FILE, log4JA1File));
+ defaults.add(new SettingsParameter(PARAM_4J_FILE_SIZE, log4JA1MaxFileSize));
+ defaults.add(new SettingsParameter(PARAM_4J_IRODS, log4JLoggerIrods));
+ defaults.add(new SettingsParameter(PARAM_4J_LAYOUT, log4JA1Layout));
+ defaults.add(new SettingsParameter(PARAM_4J_ROOT_LOGGER, log4JRootLogger));
+ // defaults.add(new SettingsParameter(PARAM_INGEST, maxIngestThreads));
+ defaults.add(new SettingsParameter(PARAM_AUDIT_ONLY, auditOnly));
+ defaults.add(new SettingsParameter(PARAM_AUDIT_SAMPLE, auditSample));
+ defaults.add(new SettingsParameter(PARAM_AUDIT_BLOCKING, auditBlocking));
+ defaults.add(new SettingsParameter(PARAM_IMS_MAX_RETRY, imsMaxRetry));
+ defaults.add(new SettingsParameter(PARAM_IMS_RESET_TIMEOUT, imsResetTimeout));
return defaults;
}
/**
- *
- * @param c The collection to query
+ * @param c The collection to query
* @param attr The attribute to query for
* @return true if collection, settings are not null and parameter is "true"
*/
public static boolean getBoolean(Collection c, String attr) {
- if (!containsKey(c, attr)) {
+ if (notContains(c, attr)) {
return false;
}
@@ -226,7 +191,7 @@ public class SettingsUtil {
}
public static String getString(Collection c, String attr) {
- if (!containsKey(c, attr)) {
+ if (notContains(c, attr)) {
return null;
}
@@ -234,7 +199,7 @@ public class SettingsUtil {
}
public static int getInt(Collection c, String attr, int def) {
- if (!containsKey(c, attr)) {
+ if (notContains(c, attr)) {
return def;
}
try {
@@ -244,40 +209,34 @@ public class SettingsUtil {
}
}
- private static boolean containsKey(Collection c, String attr) {
- return (c != null && c.getSettings() != null
- && c.getSettings().containsKey(attr));
+ private static boolean notContains(Collection c, String attr) {
+ return (c == null || c.getSettings() == null
+ || !c.getSettings().containsKey(attr));
}
// Update the settings our context listeners would normally do
private static void reloadSettings() {
EntityManager em = PersistUtil.getEntityManager();
- Query q = em.createNamedQuery("SettingsParameter.getAttr");
- SettingsParameter s = null;
+ SettingsParameter s;
// Host
- q.setParameter("attr", SettingsConstants.PARAM_IMS);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_IMS, ims, em);
AuditThreadFactory.setIMS(s.getValue());
// Port
- q.setParameter("attr", SettingsConstants.PARAM_IMS_PORT);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_IMS_PORT, imsPort, em);
AuditThreadFactory.setImsPort(Integer.parseInt(s.getValue()));
// SSL
- q.setParameter("attr", SettingsConstants.PARAM_IMS_SSL);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_IMS_SSL, imsSSL, em);
AuditThreadFactory.setSSL(Boolean.valueOf(s.getValue()));
// Token Class
- q.setParameter("attr", SettingsConstants.PARAM_IMS_TOKEN_CLASS);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_IMS_TOKEN_CLASS, imsTokenClass, em);
AuditThreadFactory.setTokenClass(s.getValue());
// Audit Only
- q.setParameter("attr", SettingsConstants.PARAM_AUDIT_ONLY);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_AUDIT_ONLY, auditOnly, em);
AuditThreadFactory.setAuditOnly(Boolean.valueOf(s.getValue()));
// Max Audits
@@ -291,39 +250,42 @@ public class SettingsUtil {
*/
// Mail Server
- q.setParameter("attr", SettingsConstants.PARAM_SMTP_SERVER);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_SMTP_SERVER, mailServer, em);
SchedulerContextListener.setMailServer(s.getValue());
// Mail From
- q.setParameter("attr", SettingsConstants.PARAM_FROM);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_FROM, mailFrom, em);
SchedulerContextListener.setMailFrom(s.getValue());
// Audit Blocking
- q.setParameter("attr", SettingsConstants.PARAM_AUDIT_BLOCKING);
- s = (SettingsParameter) q.getSingleResult();
+ s = getOrDefault(PARAM_AUDIT_BLOCKING, auditBlocking, em);
AuditThreadFactory.setBlocking(Boolean.valueOf(s.getValue()));
- // Max block time
- q.setParameter("attr", SettingsConstants.PARAM_AUDIT_MAX_BLOCK_TIME);
- s = (SettingsParameter) q.getSingleResult();
- AuditThreadFactory.setMaxBlockTime(Integer.parseInt(s.getValue()));
+ s = getOrDefault(PARAM_IMS_MAX_RETRY, imsMaxRetry, em);
+ if (Strings.isNonNegativeInt(s.getValue())) {
+ AuditThreadFactory.setImsRetryAttempts(Integer.parseInt(s.getValue()));
+ }
+
+ s = getOrDefault(PARAM_IMS_RESET_TIMEOUT, imsResetTimeout, em);
+ if (Strings.isNonNegativeInt(s.getValue())) {
+ AuditThreadFactory.setImsResetTimeout(Integer.parseInt(s.getValue()));
+ }
}
/**
* Get a SettingsParameter by its attribute name or set the default value and persist it
*
- * @param attr the Attribute to query for
+ * @param attr the Attribute to query for
* @param defaultValue the default value of the attribute
- * @param em the EntityManager to query with
+ * @param em the EntityManager to query with
* @return the queried SettingsParameter
*/
public static SettingsParameter getOrDefault(String attr,
String defaultValue,
EntityManager em) {
SettingsParameter result = new SettingsParameter(attr, defaultValue, false);
- TypedQuery q = em.createNamedQuery("SettingsParameter.getAttr",
+ TypedQuery q = em.createNamedQuery(
+ "SettingsParameter.getAttr",
SettingsParameter.class);
q.setParameter("attr", attr);
@@ -331,7 +293,10 @@ public class SettingsUtil {
result = q.getSingleResult();
// just in case
if (result.getValue() == null || result.getValue().isEmpty()) {
+ em.getTransaction().begin();
result.setValue(defaultValue);
+ em.merge(result);
+ em.getTransaction().commit();
}
} catch (NoResultException ex) {
em.getTransaction().begin();
diff --git a/ace-am/src/main/webapp/settings.jsp b/ace-am/src/main/webapp/settings.jsp
index 8b0c36351513381daa8523b9126d89e746e00202..948f6d32fb998e7791c91834b40631e2afdcc061 100644
--- a/ace-am/src/main/webapp/settings.jsp
+++ b/ace-am/src/main/webapp/settings.jsp
@@ -1,185 +1,306 @@
-<%--
+<%--
Document : settings
Created on : Jul 30, 2012, 4:07:16 PM
Author : shake
- TODO: Enable sampling when we have it properly implemented
TODO: The Settings should come from a bean or smth so we can loop similar to the custom settings
--%>
-<%@page contentType="text/html" pageEncoding="UTF-8"%>
-<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+"http://www.w3.org/TR/html4/loose.dtd">
+
-
-
- System Settings
-
-
-
-
-