Search in sources :

Example 6 with IncomingBatch

use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.

the class AbstractDataLoaderServiceTest method test03UpdateCollision.

@Test
public void test03UpdateCollision() throws Exception {
    Level old = setLoggingLevelForTest(Level.OFF);
    String[] insertValues = new String[TEST_COLUMNS.length];
    insertValues[0] = getNextId();
    insertValues[2] = insertValues[4] = "inserted row for testUpdateCollision";
    String[] updateValues = new String[TEST_COLUMNS.length + 1];
    updateValues[0] = getId();
    updateValues[TEST_COLUMNS.length] = getNextId();
    updateValues[2] = updateValues[4] = "update will become an insert that violates PK";
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    CsvWriter writer = getWriter(out);
    writer.writeRecord(new String[] { CsvConstants.NODEID, TestConstants.TEST_CLIENT_EXTERNAL_ID });
    writer.writeRecord(new String[] { CsvConstants.CHANNEL, TestConstants.TEST_CHANNEL_ID });
    String nextBatchId = getNextBatchId();
    writer.writeRecord(new String[] { CsvConstants.BATCH, nextBatchId });
    writeTable(writer, TEST_TABLE, TEST_KEYS, TEST_COLUMNS);
    // This insert will be OK
    writer.write(CsvConstants.INSERT);
    writer.writeRecord(insertValues, true);
    // Update becomes fallback insert, and then violate the primary key
    writer.write(CsvConstants.UPDATE);
    writer.writeRecord(updateValues, true);
    writer.writeRecord(new String[] { CsvConstants.COMMIT, nextBatchId });
    writer.close();
    load(out);
    IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
    assertNotNull(batch);
    load(out);
    assertEquals(batch.getStatus(), IncomingBatch.Status.OK, "Wrong status");
    batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
    assertNotNull(batch);
    assertEquals(batch.getStatus(), IncomingBatch.Status.OK, "Wrong status");
    setLoggingLevelForTest(old);
}
Also used : CsvWriter(org.jumpmind.symmetric.csv.CsvWriter) Level(org.apache.log4j.Level) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) Test(org.junit.Test)

Example 7 with IncomingBatch

use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.

the class AbstractTest method loadConfigAtRegistrationServer.

/**
     * Loads configuration in the format of classname.csv at the registration
     * server
     */
protected void loadConfigAtRegistrationServer() throws Exception {
    ISymmetricEngine regEngine = getRegServer().getEngine();
    IDataLoaderService dataLoaderService = regEngine.getDataLoaderService();
    boolean inError = false;
    String fileName = getClass().getSimpleName() + ".csv";
    log.info("Loading " + fileName + " on " + regEngine.getEngineName());
    InputStream is = getClass().getResourceAsStream(fileName);
    assertNotNull("Could not find configuration as a resource", is);
    List<IncomingBatch> batches = dataLoaderService.loadDataBatch(IOUtils.toString(is));
    for (IncomingBatch batch : batches) {
        if (batch.getStatus() == Status.ER) {
            inError = true;
        }
    }
    assertFalse("Failed to load configuration", inError);
}
Also used : IDataLoaderService(org.jumpmind.symmetric.service.IDataLoaderService) InputStream(java.io.InputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 8 with IncomingBatch

use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.

the class MonitorTypeBatchError method check.

@Override
public long check(Monitor monitor) {
    int outgoingErrorCount = 0;
    OutgoingBatches outgoingBatches = outgoingBatchService.getOutgoingBatchErrors(1000);
    for (OutgoingBatch batch : outgoingBatches.getBatches()) {
        int batchErrorMinutes = (int) (System.currentTimeMillis() - batch.getCreateTime().getTime()) / 60000;
        if (batchErrorMinutes >= monitor.getThreshold()) {
            outgoingErrorCount++;
        }
    }
    int incomingErrorCount = 0;
    List<IncomingBatch> incomingBatches = incomingBatchService.findIncomingBatchErrors(1000);
    for (IncomingBatch batch : incomingBatches) {
        int batchErrorMinutes = (int) (System.currentTimeMillis() - batch.getCreateTime().getTime()) / 60000;
        if (batchErrorMinutes >= monitor.getThreshold()) {
            incomingErrorCount++;
        }
    }
    return outgoingErrorCount + incomingErrorCount;
}
Also used : OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) IBuiltInExtensionPoint(org.jumpmind.extension.IBuiltInExtensionPoint) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 9 with IncomingBatch

use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.

the class DataLoaderService method logDataReceivedFromPush.

private void logDataReceivedFromPush(Node sourceNode, List<IncomingBatch> batchList) {
    int okBatchesCount = 0;
    int errorBatchesCount = 0;
    int okDataCount = 0;
    for (IncomingBatch incomingBatch : batchList) {
        if (incomingBatch.getStatus() == Status.OK) {
            okBatchesCount++;
            okDataCount += incomingBatch.getStatementCount();
        } else if (incomingBatch.getStatus() == Status.ER) {
            errorBatchesCount++;
        }
    }
    if (okBatchesCount > 0) {
        if (errorBatchesCount > 0) {
            log.info("{} data and {} batches loaded during push request from {}.  There were {} batches in error", new Object[] { okDataCount, okBatchesCount, sourceNode.toString(), errorBatchesCount });
        } else {
            log.info("{} data and {} batches loaded during push request from {}.", new Object[] { okDataCount, okBatchesCount, sourceNode.toString() });
        }
    }
}
Also used : TransformPoint(org.jumpmind.symmetric.io.data.transform.TransformPoint) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 10 with IncomingBatch

use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.

the class DataLoaderService method loadDataBatch.

public List<IncomingBatch> loadDataBatch(String batchData) {
    String nodeId = nodeService.findIdentityNodeId();
    if (StringUtils.isNotBlank(nodeId)) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeId, nodeId, ProcessInfoKey.ProcessType.MANUAL_LOAD));
        try {
            InternalIncomingTransport transport = new InternalIncomingTransport(new BufferedReader(new StringReader(batchData)));
            List<IncomingBatch> list = loadDataFromTransport(processInfo, nodeService.findIdentity(), transport, null);
            processInfo.setStatus(ProcessInfo.Status.OK);
            return list;
        } catch (IOException ex) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw new IoException();
        } catch (RuntimeException ex) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw ex;
        }
    } else {
        return new ArrayList<IncomingBatch>(0);
    }
}
Also used : InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) IoException(org.jumpmind.exception.IoException) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Aggregations

IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)26 Test (org.junit.Test)9 IOException (java.io.IOException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Level (org.apache.log4j.Level)7 CsvWriter (org.jumpmind.symmetric.csv.CsvWriter)7 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)7 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)7 IoException (org.jumpmind.exception.IoException)6 Node (org.jumpmind.symmetric.model.Node)6 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)4 MalformedURLException (java.net.MalformedURLException)3 SymmetricException (org.jumpmind.symmetric.SymmetricException)3 ArrayList (java.util.ArrayList)2 UniqueKeyException (org.jumpmind.db.sql.UniqueKeyException)2 FileConflictException (org.jumpmind.symmetric.file.FileConflictException)2 TransformPoint (org.jumpmind.symmetric.io.data.transform.TransformPoint)2 RegistrationRequiredException (org.jumpmind.symmetric.service.RegistrationRequiredException)2 IIncomingTransport (org.jumpmind.symmetric.transport.IIncomingTransport)2 InternalIncomingTransport (org.jumpmind.symmetric.transport.internal.InternalIncomingTransport)2