Search in sources :

Example 1 with Status

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

the class OutgoingBatchService method getLoadSummaries.

public List<OutgoingLoadSummary> getLoadSummaries(boolean activeOnly) {
    final Map<String, OutgoingLoadSummary> loadSummaries = new TreeMap<String, OutgoingLoadSummary>();
    sqlTemplateDirty.query(getSql("getLoadSummariesSql"), new ISqlRowMapper<OutgoingLoadSummary>() {

        public OutgoingLoadSummary mapRow(Row rs) {
            long loadId = rs.getLong("load_id");
            String nodeId = rs.getString("node_id");
            String loadNodeId = String.format("%010d-%s", loadId, nodeId);
            OutgoingLoadSummary summary = loadSummaries.get(loadNodeId);
            if (summary == null) {
                summary = new OutgoingLoadSummary();
                summary.setLoadId(loadId);
                summary.setNodeId(nodeId);
                summary.setChannelId(rs.getString("channel_id"));
                summary.setCreateBy(rs.getString("create_by"));
                loadSummaries.put(loadNodeId, summary);
            }
            Status status = Status.valueOf(rs.getString("status"));
            int count = rs.getInt("cnt");
            Date lastUpdateTime = rs.getDateTime("last_update_time");
            if (summary.getLastUpdateTime() == null || summary.getLastUpdateTime().before(lastUpdateTime)) {
                summary.setLastUpdateTime(lastUpdateTime);
            }
            Date createTime = rs.getDateTime("create_time");
            if (summary.getCreateTime() == null || summary.getCreateTime().after(createTime)) {
                summary.setCreateTime(createTime);
            }
            summary.setReloadBatchCount(summary.getReloadBatchCount() + count);
            if (status == Status.OK || status == Status.IG) {
                summary.setFinishedBatchCount(summary.getFinishedBatchCount() + count);
            } else {
                summary.setPendingBatchCount(summary.getPendingBatchCount() + count);
                boolean inError = rs.getBoolean("error_flag");
                summary.setInError(inError || summary.isInError());
                if (status != Status.NE && count == 1) {
                    summary.setCurrentBatchId(rs.getLong("current_batch_id"));
                    summary.setCurrentDataEventCount(rs.getLong("current_data_event_count"));
                }
            }
            return null;
        }
    });
    List<OutgoingLoadSummary> loads = new ArrayList<OutgoingLoadSummary>(loadSummaries.values());
    Iterator<OutgoingLoadSummary> it = loads.iterator();
    while (it.hasNext()) {
        OutgoingLoadSummary loadSummary = it.next();
        if (activeOnly && !loadSummary.isActive()) {
            it.remove();
        }
    }
    return loads;
}
Also used : Status(org.jumpmind.symmetric.model.OutgoingBatch.Status) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) TreeMap(java.util.TreeMap) OutgoingLoadSummary(org.jumpmind.symmetric.model.OutgoingLoadSummary) Date(java.util.Date)

Example 2 with Status

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

the class AcknowledgeService method ack.

public BatchAckResult ack(final BatchAck batch) {
    IRegistrationService registrationService = engine.getRegistrationService();
    IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
    BatchAckResult result = new BatchAckResult(batch);
    for (IAcknowledgeEventListener listener : engine.getExtensionService().getExtensionPointList(IAcknowledgeEventListener.class)) {
        listener.onAcknowledgeEvent(batch);
    }
    if (batch.getBatchId() == Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
        if (batch.isOk()) {
            registrationService.markNodeAsRegistered(batch.getNodeId());
        }
    } else {
        OutgoingBatch outgoingBatch = outgoingBatchService.findOutgoingBatch(batch.getBatchId(), batch.getNodeId());
        Status status = batch.isOk() ? Status.OK : batch.isResend() ? Status.RS : Status.ER;
        if (outgoingBatch != null) {
            // is OK.
            if (outgoingBatch.getStatus() != Status.OK && outgoingBatch.getStatus() != Status.IG) {
                outgoingBatch.setStatus(status);
                outgoingBatch.setErrorFlag(!batch.isOk());
            } else {
                // clearing the error flag in case the user set the batch
                // status to OK
                Status oldStatus = outgoingBatch.getStatus();
                outgoingBatch.setStatus(Status.OK);
                outgoingBatch.setErrorFlag(false);
                log.info("Batch {} for {} was set to {}.  Updating the status to OK", new Object[] { batch.getBatchId(), batch.getNodeId(), oldStatus.name() });
            }
            if (batch.isIgnored()) {
                outgoingBatch.incrementIgnoreCount();
            }
            outgoingBatch.setNetworkMillis(batch.getNetworkMillis());
            outgoingBatch.setFilterMillis(batch.getFilterMillis());
            outgoingBatch.setLoadMillis(batch.getDatabaseMillis());
            outgoingBatch.setSqlCode(batch.getSqlCode());
            outgoingBatch.setSqlState(batch.getSqlState());
            outgoingBatch.setSqlMessage(batch.getSqlMessage());
            boolean isNewError = false;
            if (!batch.isOk() && batch.getErrorLine() != 0) {
                List<Number> ids = sqlTemplateDirty.query(getSql("selectDataIdSql"), new NumberMapper(), outgoingBatch.getBatchId());
                if (ids.size() >= batch.getErrorLine()) {
                    long failedDataId = ids.get((int) batch.getErrorLine() - 1).longValue();
                    if (outgoingBatch.getFailedDataId() == 0 || outgoingBatch.getFailedDataId() != failedDataId) {
                        isNewError = true;
                    }
                    outgoingBatch.setFailedDataId(failedDataId);
                }
            }
            if (status == Status.ER) {
                log.error("The outgoing batch {} failed: {}{}", outgoingBatch.getNodeBatchId(), (batch.getSqlCode() != 0 ? "[" + batch.getSqlState() + "," + batch.getSqlCode() + "] " : ""), batch.getSqlMessage());
                RouterStats routerStats = engine.getStatisticManager().getRouterStatsByBatch(batch.getBatchId());
                if (routerStats != null) {
                    log.info("Router stats for batch " + outgoingBatch.getBatchId() + ": " + routerStats.toString());
                }
                if (isNewError && outgoingBatch.getSqlCode() == ErrorConstants.FK_VIOLATION_CODE && parameterService.is(ParameterConstants.AUTO_RESOLVE_FOREIGN_KEY_VIOLATION)) {
                    Channel channel = engine.getConfigurationService().getChannel(outgoingBatch.getChannelId());
                    if (channel != null && !channel.isReloadFlag()) {
                        engine.getDataService().reloadMissingForeignKeyRows(outgoingBatch.getNodeId(), outgoingBatch.getFailedDataId());
                    }
                }
            } else if (status == Status.RS) {
                log.info("The outgoing batch {} received resend request", outgoingBatch.getNodeBatchId());
            }
            outgoingBatchService.updateOutgoingBatch(outgoingBatch);
            if (status == Status.OK) {
                Channel channel = engine.getConfigurationService().getChannel(outgoingBatch.getChannelId());
                if (channel != null && channel.isFileSyncFlag()) {
                    /* Acknowledge the file_sync in case the file needs deleted. */
                    engine.getFileSyncService().acknowledgeFiles(outgoingBatch);
                }
                engine.getStatisticManager().removeRouterStatsByBatch(batch.getBatchId());
            }
        } else {
            log.error("Could not find batch {}-{} to acknowledge as {}", new Object[] { batch.getNodeId(), batch.getBatchId(), status.name() });
            result.setOk(false);
        }
    }
    return result;
}
Also used : Status(org.jumpmind.symmetric.model.OutgoingBatch.Status) NumberMapper(org.jumpmind.db.sql.mapper.NumberMapper) IAcknowledgeEventListener(org.jumpmind.symmetric.transport.IAcknowledgeEventListener) IRegistrationService(org.jumpmind.symmetric.service.IRegistrationService) Channel(org.jumpmind.symmetric.model.Channel) BatchAckResult(org.jumpmind.symmetric.model.BatchAckResult) RouterStats(org.jumpmind.symmetric.statistic.RouterStats) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Aggregations

Status (org.jumpmind.symmetric.model.OutgoingBatch.Status)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TreeMap (java.util.TreeMap)1 Row (org.jumpmind.db.sql.Row)1 NumberMapper (org.jumpmind.db.sql.mapper.NumberMapper)1 BatchAckResult (org.jumpmind.symmetric.model.BatchAckResult)1 Channel (org.jumpmind.symmetric.model.Channel)1 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)1 OutgoingLoadSummary (org.jumpmind.symmetric.model.OutgoingLoadSummary)1 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)1 IRegistrationService (org.jumpmind.symmetric.service.IRegistrationService)1 RouterStats (org.jumpmind.symmetric.statistic.RouterStats)1 IAcknowledgeEventListener (org.jumpmind.symmetric.transport.IAcknowledgeEventListener)1