use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class OfflinePushService method pushToNode.
private void pushToNode(Node remote, RemoteNodeStatus status) {
Node identity = nodeService.findIdentity();
FileOutgoingTransport transport = null;
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.OFFLINE_PUSH));
List<OutgoingBatch> extractedBatches = null;
try {
transport = (FileOutgoingTransport) transportManager.getPushTransport(remote, identity, null, null);
extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
if (extractedBatches.size() > 0) {
log.info("Offline push data written for {} at {}", remote, transport.getOutgoingDir());
List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
status.updateOutgoingStatus(extractedBatches, batchAcks);
}
if (processInfo.getStatus() != Status.ERROR) {
processInfo.setStatus(Status.OK);
}
} catch (Exception ex) {
processInfo.setStatus(Status.ERROR);
log.error("Failed to write offline file", ex);
} finally {
transport.close();
transport.complete(processInfo.getStatus() == Status.OK);
}
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class FileSyncService method pushFilesToNode.
protected void pushFilesToNode(NodeCommunication nodeCommunication, RemoteNodeStatus status, Node identity, NodeSecurity security) {
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeCommunication.getNodeId(), identity.getNodeId(), ProcessType.FILE_SYNC_PUSH_JOB));
IOutgoingWithResponseTransport transport = null;
try {
transport = engine.getTransportManager().getFilePushTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), parameterService.getRegistrationUrl());
List<OutgoingBatch> batches = sendFiles(processInfo, nodeCommunication.getNode(), transport);
if (batches.size() > 0) {
List<BatchAck> batchAcks = readAcks(batches, transport, engine.getTransportManager(), engine.getAcknowledgeService());
status.updateOutgoingStatus(batches, batchAcks);
}
} catch (Exception e) {
fireOffline(e, nodeCommunication.getNode(), status);
} finally {
if (transport != null) {
transport.close();
}
if (processInfo.getStatus() != ProcessInfo.Status.ERROR) {
processInfo.setStatus(ProcessInfo.Status.OK);
}
}
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class PushService method updateBatchStatus.
protected Status updateBatchStatus(OutgoingBatch batch, Node targetNode, Node identityNode, NodeSecurity identitySecurity) {
OutgoingBatch.Status returnStatus = batch.getStatus();
ITransportManager transportManager = engine.getTransportManager();
IAcknowledgeService acknowledgeService = engine.getAcknowledgeService();
IIncomingTransport transport = null;
try {
transport = transportManager.getAckStatusTransport(batch, targetNode, identityNode, identitySecurity.getNodePassword(), parameterService.getRegistrationUrl());
BufferedReader reader = transport.openReader();
String line = null;
do {
line = reader.readLine();
if (line != null) {
log.info("Updating batch status: {}", line);
List<BatchAck> batchAcks = transportManager.readAcknowledgement(line, "");
for (BatchAck batchInfo : batchAcks) {
if (batchInfo.getBatchId() == batch.getBatchId()) {
acknowledgeService.ack(batchInfo);
returnStatus = batchInfo.getStatus();
}
}
}
} while (line != null);
} catch (FileNotFoundException ex) {
log.info("Failed to read batch status for {}. It is probably because the server is not online yet", batch.getNodeBatchId());
} catch (Exception ex) {
log.warn(String.format("Failed to read the batch status for %s", batch.getNodeBatchId()), ex);
} finally {
transport.close();
}
return returnStatus;
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class AbstractTransportManager method getBatchInfo.
private static BatchAck getBatchInfo(Map<String, ? extends Object> parameters, long batchId) {
BatchAck batchInfo = new BatchAck(batchId);
String nodeId = getParam(parameters, WebConstants.ACK_NODE_ID + batchId);
if (StringUtils.isBlank(nodeId)) {
nodeId = getParam(parameters, WebConstants.NODE_ID);
}
batchInfo.setNodeId(nodeId);
batchInfo.setNetworkMillis(getParamAsNum(parameters, WebConstants.ACK_NETWORK_MILLIS + batchId));
batchInfo.setFilterMillis(getParamAsNum(parameters, WebConstants.ACK_FILTER_MILLIS + batchId));
batchInfo.setDatabaseMillis(getParamAsNum(parameters, WebConstants.ACK_DATABASE_MILLIS + batchId));
batchInfo.setByteCount(getParamAsNum(parameters, WebConstants.ACK_BYTE_COUNT + batchId));
batchInfo.setIgnored(getParamAsBoolean(parameters, WebConstants.ACK_IGNORE_COUNT + batchId));
String status = getParam(parameters, WebConstants.ACK_BATCH_NAME + batchId, "").trim();
if (status.equalsIgnoreCase(WebConstants.ACK_BATCH_OK)) {
batchInfo.setStatus(OutgoingBatch.Status.OK);
} else if (status.equalsIgnoreCase(WebConstants.ACK_BATCH_LD)) {
batchInfo.setStatus(OutgoingBatch.Status.LD);
} else {
batchInfo.setStatus(OutgoingBatch.Status.ER);
batchInfo.setErrorLine(NumberUtils.toLong(status));
batchInfo.setSqlState(getParam(parameters, WebConstants.ACK_SQL_STATE + batchId));
batchInfo.setSqlCode((int) getParamAsNum(parameters, WebConstants.ACK_SQL_CODE + batchId));
batchInfo.setSqlMessage(getParam(parameters, WebConstants.ACK_SQL_MESSAGE + batchId));
}
return batchInfo;
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class AbstractTransportManager method readAcknowledgement.
public static List<BatchAck> readAcknowledgement(Map<String, ? extends Object> parameters) {
List<BatchAck> batches = new ArrayList<BatchAck>();
for (String parameterName : parameters.keySet()) {
if (parameterName.startsWith(WebConstants.ACK_BATCH_NAME)) {
long batchId = NumberUtils.toLong(parameterName.substring(WebConstants.ACK_BATCH_NAME.length()));
BatchAck batchInfo = getBatchInfo(parameters, batchId);
batches.add(batchInfo);
}
}
return batches;
}
Aggregations