From d6b71e07a8cecf19b1bbf920c9188666c5c7feb7 Mon Sep 17 00:00:00 2001 From: chenson42 Date: Thu, 3 Apr 2008 14:35:53 +0000 Subject: [PATCH] 1874255 - add timezone to sym_node table and heartbeat --- symmetric/src/changes/changes.xml | 6 ++++- .../org/jumpmind/symmetric/model/Node.java | 10 ++++++++ .../service/impl/BootstrapService.java | 2 ++ .../symmetric/service/impl/NodeService.java | 2 +- .../org/jumpmind/symmetric/util/AppUtils.java | 23 +++++++++++++++++++ symmetric/src/main/resources/ddl-config.xml | 1 + .../src/main/resources/symmetric-services.xml | 2 +- .../src/main/resources/symmetric-upgrade.xml | 4 ++++ .../test/resources/test-continuous-setup.sql | 8 +++---- .../resources/test-integration-root-setup.sql | 2 +- 10 files changed, 52 insertions(+), 8 deletions(-) diff --git a/symmetric/src/changes/changes.xml b/symmetric/src/changes/changes.xml index 9ddc7fbfcd..42c26a227c 100644 --- a/symmetric/src/changes/changes.xml +++ b/symmetric/src/changes/changes.xml @@ -6,9 +6,13 @@ + + + Record the timezone in sym_node for reporting purposes + Added a thick client configuration and administration utility application. - + Upgrade to Spring Framework 2.5.1. Make changes to the filter and servlet configuration so the web.xml does not contain dynamic diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/model/Node.java b/symmetric/src/main/java/org/jumpmind/symmetric/model/Node.java index 05dd90fe22..6fa7010466 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/model/Node.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/model/Node.java @@ -60,6 +60,8 @@ public class Node { private boolean syncEnabled; + private String timezoneOffset; + private Date heartbeatTime = new Date(); public Node() { @@ -163,4 +165,12 @@ public Date getHeartbeatTime() { public void setHeartbeatTime(Date heartbeatTime) { this.heartbeatTime = heartbeatTime; } + + public String getTimezoneOffset() { + return timezoneOffset; + } + + public void setTimezoneOffset(String timezoneOffset) { + this.timezoneOffset = timezoneOffset; + } } diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/BootstrapService.java b/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/BootstrapService.java index 6513e8015b..674e2ca8a8 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/BootstrapService.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/BootstrapService.java @@ -48,6 +48,7 @@ import org.jumpmind.symmetric.service.IUpgradeService; import org.jumpmind.symmetric.service.LockAction; import org.jumpmind.symmetric.transport.ITransportManager; +import org.jumpmind.symmetric.util.AppUtils; import org.jumpmind.symmetric.util.RandomTimeSlot; import org.springframework.transaction.annotation.Transactional; @@ -260,6 +261,7 @@ public void heartbeat() { if (node != null) { logger.info("Updating my node information and heartbeat time."); node.setHeartbeatTime(new Date()); + node.setTimezoneOffset(AppUtils.getTimezoneOffset()); node.setDatabaseType(dbDialect.getName()); node.setDatabaseVersion(dbDialect.getVersion()); node.setSchemaVersion(runtimeConfiguration.getSchemaVersion()); diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/NodeService.java b/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/NodeService.java index 3c9662ae3b..d40f774053 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/NodeService.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/service/impl/NodeService.java @@ -112,7 +112,7 @@ public NodeSecurity findNodeSecurity(String id) { public boolean updateNode(Node node) { boolean updated = jdbcTemplate.update(updateNodeSql, new Object[] { node.getNodeGroupId(), node.getExternalId(), node.getDatabaseType(), node.getDatabaseVersion(), node.getSchemaVersion(), - node.getSymmetricVersion(), node.getSyncURL(), node.getHeartbeatTime(), node.isSyncEnabled() ? 1 : 0, + node.getSymmetricVersion(), node.getSyncURL(), node.getHeartbeatTime(), node.isSyncEnabled() ? 1 : 0, node.getTimezoneOffset(), node.getNodeId() }) == 1; return updated; } diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/util/AppUtils.java b/symmetric/src/main/java/org/jumpmind/symmetric/util/AppUtils.java index 7ca27f96a0..ebe9e371d3 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/util/AppUtils.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/util/AppUtils.java @@ -20,13 +20,17 @@ package org.jumpmind.symmetric.util; import java.net.InetAddress; +import java.util.Date; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.FastDateFormat; public class AppUtils { private static String serverId; + private static FastDateFormat timezoneFormatter = FastDateFormat.getInstance("Z"); + /** * Get a unique identifier that represents the JVM instance this server is currently running in. */ @@ -34,6 +38,7 @@ public static String getServerId() { if (StringUtils.isBlank(serverId)) { serverId = System.getProperty("runtime.symmetric.cluster.server.id", null); if (StringUtils.isBlank(serverId)) { + // JBoss uses this system property to identify a server in a cluster serverId = System.getProperty("bind.address", null); if (StringUtils.isBlank(serverId)) { try { @@ -46,4 +51,22 @@ public static String getServerId() { } return serverId; } + + /** + * This method will return the timezone in RFC822 format. + *

+ * The format ("-+HH:MM") has advantages over the older timezone codes ("AAA"). The difference of 5 + * hours from GMT is obvious with "-05:00" but only implied with "EST". There is no ambiguity + * saying "-06:00", but you don't know if "CST" means Central Standard Time ("-06:00") or China + * Standard Time ("+08:00"). The timezone codes need to be loaded on the system, and definitions are + * not standardized between systems. Therefore, to remain agnostic to operating systems and databases, + * the RFC822 format is the best choice. + */ + public static String getTimezoneOffset() { + String tz = timezoneFormatter.format(new Date()); + if (tz != null && tz.length() == 5) { + return tz.substring(0, 3) + ":" + tz.substring(3, 5); + } + return null; + } } diff --git a/symmetric/src/main/resources/ddl-config.xml b/symmetric/src/main/resources/ddl-config.xml index 3ed013034b..d9cb82bdae 100644 --- a/symmetric/src/main/resources/ddl-config.xml +++ b/symmetric/src/main/resources/ddl-config.xml @@ -114,6 +114,7 @@ + diff --git a/symmetric/src/main/resources/symmetric-services.xml b/symmetric/src/main/resources/symmetric-services.xml index 5b6cd272c5..c8f260f2a9 100644 --- a/symmetric/src/main/resources/symmetric-services.xml +++ b/symmetric/src/main/resources/symmetric-services.xml @@ -460,7 +460,7 @@ update ${sync.table.prefix}_node set node_group_id=?, external_id=?, database_type=?, database_version=?, schema_version=?, symmetric_version=?, - sync_url=?, heartbeat_time=?, sync_enabled=? where node_id = ? + sync_url=?, heartbeat_time=?, sync_enabled=?, timezone_offset=? where node_id = ? diff --git a/symmetric/src/main/resources/symmetric-upgrade.xml b/symmetric/src/main/resources/symmetric-upgrade.xml index ee3d48d7c8..eac9cf1318 100644 --- a/symmetric/src/main/resources/symmetric-upgrade.xml +++ b/symmetric/src/main/resources/symmetric-upgrade.xml @@ -248,6 +248,10 @@ alter table ${sync.table.prefix}_node_security add (node_password varchar(50)) + + alter table ${sync.table.prefix}_node + add (timezone_offset varchar(6)) + update ${sync.table.prefix}_node_security set node_password = password diff --git a/symmetric/src/test/resources/test-continuous-setup.sql b/symmetric/src/test/resources/test-continuous-setup.sql index 430db036bc..ba1f9646b5 100644 --- a/symmetric/src/test/resources/test-continuous-setup.sql +++ b/symmetric/src/test/resources/test-continuous-setup.sql @@ -6,10 +6,10 @@ insert into sym_node_group values ('test-node-group','a test config'); insert into sym_node_group_link values ('test-root-group','test-root-group', 'P'); insert into sym_node_group_link values ('test-node-group','test-root-group', 'W'); insert into sym_node_group_link values ('symmetric','test-root-group', 'P'); -insert into sym_node values ('00000', 'test-root-group', '00000', 1, 'internal://root', '1', '1.1','MySQL', '5.0', current_timestamp); -insert into sym_node values ('00001', 'test-node-group', '00001', 1, 'http://localhost:8080/sync', '1', '1.1', 'MySQL', '5.0', current_timestamp); -insert into sym_node values ('00002', 'test-node-group', '00002', 0, null, null, '1.1', null, null, current_timestamp); -insert into sym_node values ('00003', 'test-node-group', '00003', 1, 'http://localhost:8080/', '0', '1.1', 'MySql', '4', current_timestamp); +insert into sym_node values ('00000', 'test-root-group', '00000', 1, 'internal://root', '1', '1.1','MySQL', '5.0', current_timestamp, null); +insert into sym_node values ('00001', 'test-node-group', '00001', 1, 'http://localhost:8080/sync', '1', '1.1', 'MySQL', '5.0', current_timestamp, null); +insert into sym_node values ('00002', 'test-node-group', '00002', 0, null, null, '1.1', null, null, current_timestamp, null); +insert into sym_node values ('00003', 'test-node-group', '00003', 1, 'http://localhost:8080/', '0', '1.1', 'MySql', '4', current_timestamp, null); insert into sym_node_security values ('00001', 'secret', 0, {ts '2007-01-01 01:01:01'}, 0, {ts '2007-01-01 01:01:01'}); insert into sym_node_security values ('00002', 'supersecret', 1, null, 0, null); insert into sym_node_security values ('00003', 'notsecret', 0, {ts '2007-01-01 01:01:01'}, 0, {ts '2007-01-01 01:01:01'}); diff --git a/symmetric/src/test/resources/test-integration-root-setup.sql b/symmetric/src/test/resources/test-integration-root-setup.sql index b11e4c56ed..91457a7329 100644 --- a/symmetric/src/test/resources/test-integration-root-setup.sql +++ b/symmetric/src/test/resources/test-integration-root-setup.sql @@ -5,7 +5,7 @@ insert into sym_node_group values ('test-node-group','a test config'); insert into sym_node_group_link values ('test-node-group','test-root-group', 'P'); insert into sym_node_group_link values ('test-root-group','test-node-group', 'W'); -insert into sym_node values ('00000', 'test-root-group', '00000', 1, null, null, '1.2.0', null, null, current_timestamp); +insert into sym_node values ('00000', 'test-root-group', '00000', 1, null, null, '1.3.2', null, null, current_timestamp, null); insert into sym_node_identity values ('00000'); insert into sym_trigger