use of org.jumpmind.symmetric.web.rest.model.Heartbeat in project symmetric-ds by JumpMind.
the class RestService method getPullData.
@ApiOperation(value = "Pull pending batches for the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/pulldata", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final PullDataResults getPullData(@PathVariable("engine") String engineName, @RequestParam(value = WebConstants.NODE_ID) String nodeId, @ApiParam(value = "This the password for the nodeId being passed in. The password is stored in the node_security table.") @RequestParam(value = WebConstants.SECURITY_TOKEN) String securityToken, @RequestParam(value = "useJdbcTimestampFormat", required = false, defaultValue = "true") boolean useJdbcTimestampFormat, @RequestParam(value = "useUpsertStatements", required = false, defaultValue = "false") boolean useUpsertStatements, @RequestParam(value = "useDelimitedIdentifiers", required = false, defaultValue = "true") boolean useDelimitedIdentifiers, @RequestParam(value = "hostName", required = false) String hostName) {
ISymmetricEngine engine = getSymmetricEngine(engineName);
IDataExtractorService dataExtractorService = engine.getDataExtractorService();
IStatisticManager statisticManager = engine.getStatisticManager();
INodeService nodeService = engine.getNodeService();
org.jumpmind.symmetric.model.Node targetNode = nodeService.findNode(nodeId);
if (securityVerified(nodeId, engine, securityToken)) {
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), nodeId, ProcessType.REST_PULL_HANLDER));
try {
PullDataResults results = new PullDataResults();
List<OutgoingBatchWithPayload> extractedBatches = dataExtractorService.extractToPayload(processInfo, targetNode, PayloadType.SQL, useJdbcTimestampFormat, useUpsertStatements, useDelimitedIdentifiers);
List<Batch> batches = new ArrayList<Batch>();
for (OutgoingBatchWithPayload outgoingBatchWithPayload : extractedBatches) {
if (outgoingBatchWithPayload.getStatus() == org.jumpmind.symmetric.model.OutgoingBatch.Status.LD || outgoingBatchWithPayload.getStatus() == org.jumpmind.symmetric.model.OutgoingBatch.Status.IG) {
Batch batch = new Batch();
batch.setBatchId(outgoingBatchWithPayload.getBatchId());
batch.setChannelId(outgoingBatchWithPayload.getChannelId());
batch.setSqlStatements(outgoingBatchWithPayload.getPayload());
batches.add(batch);
}
}
results.setBatches(batches);
results.setNbrBatches(batches.size());
processInfo.setStatus(org.jumpmind.symmetric.model.ProcessInfo.Status.OK);
if (engine.getParameterService().is(ParameterConstants.REST_HEARTBEAT_ON_PULL) && hostName != null) {
Heartbeat heartbeat = new Heartbeat();
heartbeat.setNodeId(nodeId);
heartbeat.setHeartbeatTime(new Date());
heartbeat.setHostName(hostName);
this.heartbeatImpl(engine, heartbeat);
}
return results;
} finally {
if (processInfo.getStatus() != org.jumpmind.symmetric.model.ProcessInfo.Status.OK) {
processInfo.setStatus(org.jumpmind.symmetric.model.ProcessInfo.Status.ERROR);
}
}
} else {
throw new NotAllowedException();
}
}
use of org.jumpmind.symmetric.web.rest.model.Heartbeat in project symmetric-ds by JumpMind.
the class RestService method postRegisterNode.
@ApiOperation(value = "Register the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/registernode", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final RegistrationInfo postRegisterNode(@PathVariable("engine") String engineName, @RequestParam(value = "externalId") String externalId, @RequestParam(value = "nodeGroupId") String nodeGroupId, @RequestParam(value = "databaseType") String databaseType, @RequestParam(value = "databaseVersion") String databaseVersion, @RequestParam(value = "hostName") String hostName) {
ISymmetricEngine engine = getSymmetricEngine(engineName);
IRegistrationService registrationService = engine.getRegistrationService();
INodeService nodeService = engine.getNodeService();
RegistrationInfo regInfo = new org.jumpmind.symmetric.web.rest.model.RegistrationInfo();
try {
org.jumpmind.symmetric.model.Node processedNode = registrationService.registerPullOnlyNode(externalId, nodeGroupId, databaseType, databaseVersion);
regInfo.setRegistered(processedNode.isSyncEnabled());
if (regInfo.isRegistered()) {
regInfo.setNodeId(processedNode.getNodeId());
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(processedNode.getNodeId());
regInfo.setNodePassword(nodeSecurity.getNodePassword());
org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
regInfo.setSyncUrl(modelNode.getSyncUrl());
// do an initial heartbeat
Heartbeat heartbeat = new Heartbeat();
heartbeat.setNodeId(regInfo.getNodeId());
heartbeat.setHostName(hostName);
Date now = new Date();
heartbeat.setCreateTime(now);
heartbeat.setLastRestartTime(now);
heartbeat.setHeartbeatTime(now);
this.heartbeatImpl(engine, heartbeat);
}
// TODO: Catch a RegistrationRedirectException and redirect.
} catch (IOException e) {
throw new IoException(e);
}
return regInfo;
}
Aggregations