Search in sources :

Example 6 with BatchAck

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();
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) BufferedReader(java.io.BufferedReader) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) HttpTransportManager(org.jumpmind.symmetric.transport.http.HttpTransportManager)

Example 7 with BatchAck

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;
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) SymmetricException(org.jumpmind.symmetric.SymmetricException) BufferedReader(java.io.BufferedReader) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) HashSet(java.util.HashSet)

Example 8 with BatchAck

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) {
        }
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) BatchAck(org.jumpmind.symmetric.model.BatchAck) IOutgoingWithResponseTransport(org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 9 with BatchAck

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;
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOException(java.io.IOException)

Example 10 with BatchAck

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;
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) BatchAckResults(org.jumpmind.symmetric.web.rest.model.BatchAckResults) BatchAckResult(org.jumpmind.symmetric.model.BatchAckResult) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IAcknowledgeService(org.jumpmind.symmetric.service.IAcknowledgeService) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BatchAck (org.jumpmind.symmetric.model.BatchAck)10 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)4 IOException (java.io.IOException)3 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 BufferedReader (java.io.BufferedReader)2 ArrayList (java.util.ArrayList)2 IoException (org.jumpmind.exception.IoException)2 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)2 SymmetricException (org.jumpmind.symmetric.SymmetricException)2 Node (org.jumpmind.symmetric.model.Node)2 IOutgoingWithResponseTransport (org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport)2 FileOutgoingTransport (org.jumpmind.symmetric.transport.file.FileOutgoingTransport)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 FileConflictException (org.jumpmind.symmetric.file.FileConflictException)1 BatchAckResult (org.jumpmind.symmetric.model.BatchAckResult)1 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1 IAcknowledgeService (org.jumpmind.symmetric.service.IAcknowledgeService)1