Skip to content

Commit

Permalink
0001249 - Misc. changes including heartbeat on pull.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwilmer committed Jun 15, 2013
1 parent fca2fb0 commit 6d2a335
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 94 deletions.
Expand Up @@ -224,6 +224,8 @@ private ParameterConstants() {
public final static String SERVER_LOG_FILE = "server.log.file";

public final static String REST_API_ENABLED = "rest.api.enable";

public final static String REST_HEARTBEAT_ON_PULL = "rest.api.heartbeat.on.pull";

public final static String SYNCHRONIZE_ALL_JOBS = "jobs.synchronized.enable";

Expand Down
Expand Up @@ -58,6 +58,12 @@ public class NodeHost implements Serializable {
private Date lastRestartTime = LAST_RESTART_TIME;
private Date createTime;

public NodeHost(boolean refresh) {
if (refresh) {
refresh();
}
}

public NodeHost() {
this.refresh();
}
Expand Down
Expand Up @@ -115,6 +115,8 @@ public void ignoreNodeChannelForExternalId(boolean ignore, String channelId,

public void save(Node node);

public void updateNodeHost(NodeHost nodeHost);

public void updateNodeHostForCurrentNode();

public void insertNodeIdentity(String nodeId);
Expand Down
Expand Up @@ -168,27 +168,35 @@ public List<NodeHost> findNodeHosts(String nodeId) {
new NodeHostRowMapper(), nodeId);
}

public void updateNodeHost(NodeHost nodeHost) {

Object[] params = new Object[] {
nodeHost.getIpAddress(),
nodeHost.getOsUser(), nodeHost.getOsName(),
nodeHost.getOsArch(), nodeHost.getOsVersion(),
nodeHost.getAvailableProcessors(),
nodeHost.getFreeMemoryBytes(),
nodeHost.getTotalMemoryBytes(),
nodeHost.getMaxMemoryBytes(),
nodeHost.getJavaVersion(), nodeHost.getJavaVendor(),
nodeHost.getSymmetricVersion(),
nodeHost.getTimezoneOffset(),
nodeHost.getHeartbeatTime(),
nodeHost.getLastRestartTime(), nodeHost.getNodeId(),
nodeHost.getHostName() };

if (sqlTemplate.update(getSql("updateNodeHostSql"), params) == 0) {
sqlTemplate.update(getSql("insertNodeHostSql"), params);
}

}

public void updateNodeHostForCurrentNode() {
if (nodeHostForCurrentNode == null) {
nodeHostForCurrentNode = new NodeHost(findIdentityNodeId());
}
nodeHostForCurrentNode.refresh();
Object[] params = new Object[] { nodeHostForCurrentNode.getIpAddress(),
nodeHostForCurrentNode.getOsUser(), nodeHostForCurrentNode.getOsName(),
nodeHostForCurrentNode.getOsArch(), nodeHostForCurrentNode.getOsVersion(),
nodeHostForCurrentNode.getAvailableProcessors(),
nodeHostForCurrentNode.getFreeMemoryBytes(),
nodeHostForCurrentNode.getTotalMemoryBytes(),
nodeHostForCurrentNode.getMaxMemoryBytes(),
nodeHostForCurrentNode.getJavaVersion(), nodeHostForCurrentNode.getJavaVendor(),
nodeHostForCurrentNode.getSymmetricVersion(),
nodeHostForCurrentNode.getTimezoneOffset(),
nodeHostForCurrentNode.getHeartbeatTime(),
nodeHostForCurrentNode.getLastRestartTime(), nodeHostForCurrentNode.getNodeId(),
nodeHostForCurrentNode.getHostName() };
if (sqlTemplate.update(getSql("updateNodeHostSql"), params) == 0) {
sqlTemplate.update(getSql("insertNodeHostSql"), params);
}
updateNodeHost(nodeHostForCurrentNode);
}

public NodeSecurity findNodeSecurity(String nodeId, boolean createIfNotFound) {
Expand Down
Expand Up @@ -1041,6 +1041,13 @@ server.log.file=../logs/symmetric.log
# Type: boolean
rest.api.enable=false

# Enables the REST API to update the heartbeat when pulling data
#
# DatabaseOverridable: true
# Tags: general
# Type: boolean
rest.api.heartbeat.on.pull=false

# Enables File Synchronization capabilities
#
# Tags: filesync
Expand Down
Expand Up @@ -261,6 +261,11 @@ public List<NodeSecurity> findNodeSecurityWithLoadEnabled() {

public Node findIdentity(boolean useCache, boolean logSqlError) {
return null;
}
}

public void updateNodeHost(NodeHost nodeHost) {
// TODO Auto-generated method stub

}

}

Large diffs are not rendered by default.

@@ -0,0 +1,154 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric.web.rest.model;

import java.util.Date;

public class Heartbeat {

private String nodeId;
private String hostName;
private String ipAddress;
private String osUser;
private String osName;
private String osArchitecture;
private String osVersion;
private Integer availableProcessors;
private Long freeMemoryBytes;
private Long totalMemoryBytes;
private Long maxMemoryBytes;
private String javaVersion;
private String javaVendor;
private String symmetricVersion;
private String timezoneOffset;
private Date heartbeatTime;
private Date lastRestartTime;
private Date createTime;

public String getNodeId() {
return nodeId;
}
public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getOsUser() {
return osUser;
}
public void setOsUser(String osUser) {
this.osUser = osUser;
}
public String getOsName() {
return osName;
}
public void setOsName(String osName) {
this.osName = osName;
}
public String getOsArchitecture() {
return osArchitecture;
}
public void setOsArchitecture(String osArchitecture) {
this.osArchitecture = osArchitecture;
}
public String getOsVersion() {
return osVersion;
}
public void setOsVersion(String osVersion) {
this.osVersion = osVersion;
}
public Integer getAvailableProcessors() {
return availableProcessors;
}
public void setAvailableProcessors(Integer availableProcessors) {
this.availableProcessors = availableProcessors;
}
public Long getFreeMemoryBytes() {
return freeMemoryBytes;
}
public void setFreeMemoryBytes(Long freeMemoryBytes) {
this.freeMemoryBytes = freeMemoryBytes;
}
public Long getTotalMemoryBytes() {
return totalMemoryBytes;
}
public void setTotalMemoryBytes(Long totalMemoryBytes) {
this.totalMemoryBytes = totalMemoryBytes;
}
public Long getMaxMemoryBytes() {
return maxMemoryBytes;
}
public void setMaxMemoryBytes(Long maxMemoryBytes) {
this.maxMemoryBytes = maxMemoryBytes;
}
public String getJavaVersion() {
return javaVersion;
}
public void setJavaVersion(String javaVersion) {
this.javaVersion = javaVersion;
}
public String getJavaVendor() {
return javaVendor;
}
public void setJavaVendor(String javaVendor) {
this.javaVendor = javaVendor;
}
public String getSymmetricVersion() {
return symmetricVersion;
}
public void setSymmetricVersion(String symmetricVersion) {
this.symmetricVersion = symmetricVersion;
}
public String getTimezoneOffset() {
return timezoneOffset;
}
public void setTimezoneOffset(String timezoneOffset) {
this.timezoneOffset = timezoneOffset;
}
public Date getHeartbeatTime() {
return heartbeatTime;
}
public void setHeartbeatTime(Date heartbeatTime) {
this.heartbeatTime = heartbeatTime;
}
public Date getLastRestartTime() {
return lastRestartTime;
}
public void setLastRestartTime(Date lastRestartTime) {
this.lastRestartTime = lastRestartTime;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
Expand Up @@ -61,8 +61,8 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)
Assert.assertEquals("The only node we expected to be registered is a server node",
"server", nodes.get(0).getNodeGroupId());

RegistrationInfo registrationInfo = restService.registerNode("client", "client",
DatabaseNamesConstants.SQLITE, "3.0");
RegistrationInfo registrationInfo = restService.postRegisterNode("client", "client",
DatabaseNamesConstants.SQLITE, "3.0", "hostName");

Assert.assertNotNull("Registration should have returned a result object", registrationInfo);
Assert.assertFalse("Registration should not have been open",
Expand All @@ -71,39 +71,39 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)

engine.openRegistration("client", "client");

registrationInfo = restService.registerNode("client", "client",
DatabaseNamesConstants.SQLITE, "3.0");
registrationInfo = restService.postRegisterNode("client", "client",
DatabaseNamesConstants.SQLITE, "3.0", "hostName");

Assert.assertNotNull("Registration should have returned a result object", registrationInfo);
Assert.assertTrue("Registration should have been open", registrationInfo.isRegistered());
Assert.assertEquals("client", registrationInfo.getNodeId());

try {
restService.pullData(registrationInfo.getNodeId(), "wrong password", false, false, true);
restService.getPullData(registrationInfo.getNodeId(), "wrong password", false, false, true, null);
Assert.fail("We should have received an exception");
} catch (NotAllowedException ex) {
}

PullDataResults results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true);
PullDataResults results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(0, results.getNbrBatches());

engine.getSqlTemplate().update("insert into a values(?, ?, ?)", 1, "this is a test", FormatUtils.parseDate("2013-06-08 00:00:00.000", FormatUtils.TIMESTAMP_PATTERNS));

engine.route();

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(1, results.getNbrBatches());
Assert.assertEquals(3, results.getBatches().get(0).getBatchId());

log.info(results.getBatches().get(0).getSqlStatements().get(0));

// pull a second time without acking. should get the same results
results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, false);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, false, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(1, results.getNbrBatches());
Assert.assertEquals(3, results.getBatches().get(0).getBatchId());
Expand All @@ -119,8 +119,8 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)

engine.route();

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), true, false, true);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), true, false, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(2, results.getNbrBatches());
Assert.assertEquals(3, results.getBatches().get(0).getBatchId());
Expand All @@ -140,8 +140,8 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)
batchResults.getBatchResults().add(new BatchResult(registrationInfo.getNodeId(), 4, true));
restService.putAcknowledgeBatch("server", registrationInfo.getNodePassword(), batchResults);

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(0, results.getNbrBatches());

Expand All @@ -153,8 +153,8 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)

engine.route();

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, true, true);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, true, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(1, results.getNbrBatches());
List<String> sqls = results.getBatches().get(0).getSqlStatements();
Expand All @@ -168,8 +168,8 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)
batchResults.getBatchResults().add(new BatchResult(registrationInfo.getNodeId(), results.getBatches().get(0).getBatchId(), true));
restService.putAcknowledgeBatch("server", registrationInfo.getNodePassword(), batchResults);

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(0, results.getNbrBatches());

Expand All @@ -182,8 +182,8 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)

engine.route();

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(3, results.getNbrBatches());
List<Batch> batches = results.getBatches();
Expand All @@ -196,8 +196,8 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)

restService.putAcknowledgeBatch("server", registrationInfo.getNodePassword(), batchResults);

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true);
results = restService.getPullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword(), false, false, true, null);
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(0, results.getNbrBatches());

Expand Down

0 comments on commit 6d2a335

Please sign in to comment.