Skip to content

Commit

Permalink
1874255 - add timezone to sym_node table and heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Apr 3, 2008
1 parent 68b5059 commit d6b71e0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 8 deletions.
6 changes: 5 additions & 1 deletion symmetric/src/changes/changes.xml
Expand Up @@ -6,9 +6,13 @@
</properties>
<body>
<release version="1.4.0" date="unknown" description="Lets add some polish">

<action dev="chenson42" type="add" issue="aid=1874255&amp;atid=997727">
Record the timezone in sym_node for reporting purposes
</action>
<action dev="chenson42" type="add">
Added a thick client configuration and administration utility application.
</action>
</action>
<action dev="chenson42" type="add">Upgrade to Spring Framework 2.5.1.</action>
<action dev="knaas" type="add">
Make changes to the filter and servlet configuration so the web.xml does not contain dynamic
Expand Down
10 changes: 10 additions & 0 deletions symmetric/src/main/java/org/jumpmind/symmetric/model/Node.java
Expand Up @@ -60,6 +60,8 @@ public class Node {

private boolean syncEnabled;

private String timezoneOffset;

private Date heartbeatTime = new Date();

public Node() {
Expand Down Expand Up @@ -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;
}
}
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions symmetric/src/main/java/org/jumpmind/symmetric/util/AppUtils.java
Expand Up @@ -20,20 +20,25 @@
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.
*/
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 {
Expand All @@ -46,4 +51,22 @@ public static String getServerId() {
}
return serverId;
}

/**
* This method will return the timezone in RFC822 format.
* </p>
* 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;
}
}
1 change: 1 addition & 0 deletions symmetric/src/main/resources/ddl-config.xml
Expand Up @@ -114,6 +114,7 @@
<column name="database_type" type="VARCHAR" size="50" />
<column name="database_version" type="VARCHAR" size="50" />
<column name="heartbeat_time" type="TIMESTAMP" />
<column name="timezone_offset" type="VARCHAR" size="6" />
<foreign-key name="fk_c_node_group_id" foreignTable="node_group">
<reference local="node_group_id" foreign="node_group_id" />
</foreign-key>
Expand Down
2 changes: 1 addition & 1 deletion symmetric/src/main/resources/symmetric-services.xml
Expand Up @@ -460,7 +460,7 @@
<value>
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 = ?
</value>
</property>
<property name="findNodeSql">
Expand Down
4 changes: 4 additions & 0 deletions symmetric/src/main/resources/symmetric-upgrade.xml
Expand Up @@ -248,6 +248,10 @@
alter table ${sync.table.prefix}_node_security
add (node_password varchar(50))
</value>
<value>
alter table ${sync.table.prefix}_node
add (timezone_offset varchar(6))
</value>
<value>
update ${sync.table.prefix}_node_security set node_password = password
</value>
Expand Down
8 changes: 4 additions & 4 deletions symmetric/src/test/resources/test-continuous-setup.sql
Expand Up @@ -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'});
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit d6b71e0

Please sign in to comment.