use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class SymmetricPushClient method close.
public BatchAck close() {
try {
writer.end(batch, false);
BufferedReader reader = transport.readResponse();
String ackString = reader.readLine();
String ackExtendedString = reader.readLine();
log.debug("Reading ack: {}", ackString);
log.debug("Reading extend ack: {}", ackExtendedString);
List<BatchAck> batchAcks = new HttpTransportManager().readAcknowledgement(ackString, ackExtendedString);
if (batchAcks.size() > 0) {
return batchAcks.get(0);
} else {
return null;
}
} catch (IOException ex) {
throw new IoException(ex);
} finally {
transport.close();
}
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class AbstractService method readAcks.
protected List<BatchAck> readAcks(List<OutgoingBatch> batches, IOutgoingWithResponseTransport transport, ITransportManager transportManager, IAcknowledgeService acknowledgeService) throws IOException {
Set<Long> batchIds = new HashSet<Long>(batches.size());
for (OutgoingBatch outgoingBatch : batches) {
if (outgoingBatch.getStatus() == OutgoingBatch.Status.LD) {
batchIds.add(outgoingBatch.getBatchId());
}
}
BufferedReader reader = transport.readResponse();
String ackString = reader.readLine();
String ackExtendedString = reader.readLine();
log.debug("Reading ack: {}", ackString);
log.debug("Reading extend ack: {}", ackExtendedString);
String line = null;
do {
line = reader.readLine();
if (line != null) {
log.info("Read another unexpected line {}", line);
}
} while (line != null);
if (StringUtils.isBlank(ackString)) {
throw new SymmetricException("Did not receive an acknowledgement for the batches sent. " + "The 'ack string' was: '%s' and the 'extended ack string' was: '%s'", ackString, ackExtendedString);
}
List<BatchAck> batchAcks = transportManager.readAcknowledgement(ackString, ackExtendedString);
long batchIdInError = Long.MAX_VALUE;
for (BatchAck batchInfo : batchAcks) {
batchIds.remove(batchInfo.getBatchId());
if (!batchInfo.isOk()) {
batchIdInError = batchInfo.getBatchId();
}
log.debug("Saving ack: {}, {}", batchInfo.getBatchId(), (batchInfo.isOk() ? "OK" : "ER"));
acknowledgeService.ack(batchInfo);
}
for (Long batchId : batchIds) {
if (batchId < batchIdInError) {
log.error("We expected but did not receive an ack for batch {}", batchId);
}
}
return batchAcks;
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class PushService method pushToNode.
private void pushToNode(Node remote, RemoteNodeStatus status) {
Node identity = nodeService.findIdentity();
NodeSecurity identitySecurity = nodeService.findNodeSecurity(identity.getNodeId(), true);
IOutgoingWithResponseTransport transport = null;
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.PUSH_JOB));
Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put(WebConstants.THREAD_CHANNEL, status.getChannelId());
try {
transport = transportManager.getPushTransport(remote, identity, identitySecurity.getNodePassword(), requestProperties, parameterService.getRegistrationUrl());
List<OutgoingBatch> extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
if (extractedBatches.size() > 0) {
log.info("Push data sent to {}", remote);
List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
status.updateOutgoingStatus(extractedBatches, batchAcks);
}
if (processInfo.getStatus() != Status.ERROR) {
processInfo.setStatus(Status.OK);
}
fireOnline(remote, status);
} catch (Exception ex) {
processInfo.setStatus(Status.ERROR);
fireOffline(ex, remote, status);
} finally {
try {
transport.close();
} catch (Exception e) {
}
}
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class InternalTransportManager method sendAcknowledgement.
public int sendAcknowledgement(Node remote, List<IncomingBatch> list, Node local, String securityToken, String registrationUrl) throws IOException {
try {
if (list != null && list.size() > 0) {
ISymmetricEngine remoteEngine = getTargetEngine(remote.getSyncUrl());
String ackData = getAcknowledgementData(remote.requires13Compatiblity(), local.getNodeId(), list);
List<BatchAck> batches = readAcknowledgement(ackData);
for (BatchAck batchInfo : batches) {
remoteEngine.getAcknowledgeService().ack(batchInfo);
}
}
return HttpURLConnection.HTTP_OK;
} catch (Exception ex) {
log.error("", ex);
return -1;
}
}
use of org.jumpmind.symmetric.model.BatchAck in project symmetric-ds by JumpMind.
the class RestService method putAcknowledgeBatch.
@ApiOperation(value = "Acknowledge a set of batches for the specified engine")
@RequestMapping(value = "/engine/{engine}/acknowledgebatch", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final BatchAckResults putAcknowledgeBatch(@PathVariable("engine") String engineName, @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, @RequestBody BatchResults batchResults) {
BatchAckResults finalResult = new BatchAckResults();
ISymmetricEngine engine = getSymmetricEngine(engineName);
List<BatchAckResult> results = null;
if (batchResults.getBatchResults().size() > 0) {
if (securityVerified(batchResults.getNodeId(), engine, securityToken)) {
IAcknowledgeService ackService = engine.getAcknowledgeService();
List<BatchAck> batchAcks = convertBatchResultsToAck(batchResults);
results = ackService.ack(batchAcks);
} else {
throw new NotAllowedException();
}
}
finalResult.setBatchAckResults(results);
return finalResult;
}
Aggregations