Search in sources :

Example 1 with BatchAck

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);
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) FileOutgoingTransport(org.jumpmind.symmetric.transport.file.FileOutgoingTransport) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 2 with BatchAck

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);
        }
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) IOutgoingWithResponseTransport(org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) FileConflictException(org.jumpmind.symmetric.file.FileConflictException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException)

Example 3 with BatchAck

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;
}
Also used : Status(org.jumpmind.symmetric.model.OutgoingBatch.Status) BatchAck(org.jumpmind.symmetric.model.BatchAck) ITransportManager(org.jumpmind.symmetric.transport.ITransportManager) IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) IAcknowledgeService(org.jumpmind.symmetric.service.IAcknowledgeService) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) FileNotFoundException(java.io.FileNotFoundException) ChannelDisabledException(org.jumpmind.symmetric.transport.ChannelDisabledException) ConnectionRejectedException(org.jumpmind.symmetric.transport.ConnectionRejectedException) ServiceUnavailableException(org.jumpmind.symmetric.transport.ServiceUnavailableException)

Example 4 with BatchAck

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

Example 5 with BatchAck

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

Aggregations

BatchAck (org.jumpmind.symmetric.model.BatchAck)11 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)5 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 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 IAcknowledgeService (org.jumpmind.symmetric.service.IAcknowledgeService)2 IOutgoingWithResponseTransport (org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 FileConflictException (org.jumpmind.symmetric.file.FileConflictException)1 BatchAckResult (org.jumpmind.symmetric.model.BatchAckResult)1