Search in sources :

Example 1 with SymmetricException

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

the class DataLoaderService method loadDataFromPush.

/**
     * Load database from input stream and write acknowledgment to output
     * stream. This is used for a "push" request with a response of an
     * acknowledgment.
     */
public void loadDataFromPush(Node sourceNode, String channelId, InputStream in, OutputStream out) throws IOException {
    Node local = nodeService.findIdentity();
    if (local != null) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(sourceNode.getNodeId(), channelId, local.getNodeId(), ProcessInfoKey.ProcessType.PUSH_HANDLER));
        try {
            List<IncomingBatch> batchList = loadDataFromTransport(processInfo, sourceNode, new InternalIncomingTransport(in), out);
            logDataReceivedFromPush(sourceNode, batchList);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId());
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            transportManager.writeAcknowledgement(out, sourceNode, batchList, local, security != null ? security.getNodePassword() : null);
            if (containsError(batchList)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
        } catch (Exception e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof IOException) {
                throw (IOException) e;
            }
            throw new RuntimeException(e);
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) SymmetricException(org.jumpmind.symmetric.SymmetricException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) ConflictException(org.jumpmind.symmetric.io.data.writer.ConflictException) IOException(java.io.IOException) RegistrationNotOpenException(org.jumpmind.symmetric.service.RegistrationNotOpenException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ServiceUnavailableException(org.jumpmind.symmetric.transport.ServiceUnavailableException) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) SqlException(org.jumpmind.db.sql.SqlException) TransportException(org.jumpmind.symmetric.transport.TransportException) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException) ConnectionRejectedException(org.jumpmind.symmetric.transport.ConnectionRejectedException) SyncDisabledException(org.jumpmind.symmetric.transport.SyncDisabledException) IoException(org.jumpmind.exception.IoException) MalformedURLException(java.net.MalformedURLException) AuthenticationException(org.jumpmind.symmetric.transport.AuthenticationException)

Example 2 with SymmetricException

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

the class DataExtractorService method lookupAndOrderColumnsAccordingToTriggerHistory.

protected Table lookupAndOrderColumnsAccordingToTriggerHistory(String routerId, TriggerHistory triggerHistory, Node sourceNode, Node targetNode, boolean setTargetTableName, boolean useDatabaseDefinition) {
    String catalogName = triggerHistory.getSourceCatalogName();
    String schemaName = triggerHistory.getSourceSchemaName();
    String tableName = triggerHistory.getSourceTableName();
    Table table = null;
    if (useDatabaseDefinition) {
        table = platform.getTableFromCache(catalogName, schemaName, tableName, false);
        if (table != null && table.getColumnCount() < triggerHistory.getParsedColumnNames().length) {
            /*
                 * If the column count is less than what trigger history reports, then
                 * chances are the table cache is out of date.
                 */
            table = platform.getTableFromCache(catalogName, schemaName, tableName, true);
        }
        if (table != null) {
            table = table.copyAndFilterColumns(triggerHistory.getParsedColumnNames(), triggerHistory.getParsedPkColumnNames(), true);
        } else {
            throw new SymmetricException("Could not find the following table.  It might have been dropped: %s", Table.getFullyQualifiedTableName(catalogName, schemaName, tableName));
        }
    } else {
        table = new Table(tableName);
        table.addColumns(triggerHistory.getParsedColumnNames());
        table.setPrimaryKeys(triggerHistory.getParsedPkColumnNames());
    }
    Router router = triggerRouterService.getRouterById(routerId, false);
    if (router != null && setTargetTableName) {
        if (router.isUseSourceCatalogSchema()) {
            table.setCatalog(catalogName);
            table.setSchema(schemaName);
        } else {
            table.setCatalog(null);
            table.setSchema(null);
        }
        if (StringUtils.equals(Constants.NONE_TOKEN, router.getTargetCatalogName())) {
            table.setCatalog(null);
        } else if (StringUtils.isNotBlank(router.getTargetCatalogName())) {
            table.setCatalog(replaceVariables(sourceNode, targetNode, router.getTargetCatalogName()));
        }
        if (StringUtils.equals(Constants.NONE_TOKEN, router.getTargetSchemaName())) {
            table.setSchema(null);
        } else if (StringUtils.isNotBlank(router.getTargetSchemaName())) {
            table.setSchema(replaceVariables(sourceNode, targetNode, router.getTargetSchemaName()));
        }
        if (StringUtils.isNotBlank(router.getTargetTableName())) {
            table.setName(router.getTargetTableName());
        }
    }
    return table;
}
Also used : TransformTable(org.jumpmind.symmetric.io.data.transform.TransformTable) Table(org.jumpmind.db.model.Table) SymmetricException(org.jumpmind.symmetric.SymmetricException) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) AbstractFileParsingRouter(org.jumpmind.symmetric.route.AbstractFileParsingRouter)

Example 3 with SymmetricException

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

the class MultiBatchStagingWriter method startNewBatch.

protected void startNewBatch() {
    this.nextBatch();
    long memoryThresholdInBytes = this.dataExtractorService.parameterService.getLong(ParameterConstants.STREAM_TO_FILE_THRESHOLD);
    this.currentDataWriter = buildWriter(memoryThresholdInBytes);
    this.batch = new Batch(BatchType.EXTRACT, outgoingBatch.getBatchId(), outgoingBatch.getChannelId(), this.dataExtractorService.symmetricDialect.getBinaryEncoding(), sourceNodeId, outgoingBatch.getNodeId(), false);
    this.currentDataWriter.open(context);
    this.currentDataWriter.start(batch);
    processInfo.incrementBatchCount();
    if (table == null) {
        throw new SymmetricException("'table' cannot null while starting new batch.  Batch: " + outgoingBatch + ". Check trigger/router configs.");
    }
    this.currentDataWriter.start(table);
}
Also used : OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) Batch(org.jumpmind.symmetric.io.data.Batch) SymmetricException(org.jumpmind.symmetric.SymmetricException)

Example 4 with SymmetricException

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

the class FileSyncService method loadFilesFromPush.

public void loadFilesFromPush(String nodeId, InputStream in, OutputStream out) {
    INodeService nodeService = engine.getNodeService();
    Node local = nodeService.findIdentity();
    Node sourceNode = nodeService.findNode(nodeId);
    if (local != null && sourceNode != null) {
        ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeId, local.getNodeId(), ProcessType.FILE_SYNC_PUSH_HANDLER));
        try {
            List<IncomingBatch> list = processZip(in, nodeId, processInfo);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId());
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            engine.getTransportManager().writeAcknowledgement(out, sourceNode, list, local, security != null ? security.getNodePassword() : null);
            processInfo.setStatus(ProcessInfo.Status.OK);
        } catch (Throwable e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            if (e instanceof IOException) {
                throw new IoException((IOException) e);
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) 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)

Example 5 with SymmetricException

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

the class DataLoaderService method loadDataFromPush.

/**
 * Load database from input stream and write acknowledgment to output
 * stream. This is used for a "push" request with a response of an
 * acknowledgment.
 */
public void loadDataFromPush(Node sourceNode, InputStream in, OutputStream out) throws IOException {
    Node local = nodeService.findIdentity();
    if (local != null) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(sourceNode.getNodeId(), local.getNodeId(), ProcessType.LOAD_FROM_PUSH));
        try {
            List<IncomingBatch> batchList = loadDataFromTransport(processInfo, sourceNode, new InternalIncomingTransport(in));
            logDataReceivedFromPush(sourceNode, batchList);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId());
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            transportManager.writeAcknowledgement(out, sourceNode, batchList, local, security != null ? security.getNodePassword() : null);
            if (containsError(batchList)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
        } catch (RuntimeException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Aggregations

SymmetricException (org.jumpmind.symmetric.SymmetricException)14 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)3 Node (org.jumpmind.symmetric.model.Node)3 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)3 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 Table (org.jumpmind.db.model.Table)2 IoException (org.jumpmind.exception.IoException)2 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2 Router (org.jumpmind.symmetric.model.Router)2 InternalIncomingTransport (org.jumpmind.symmetric.transport.internal.InternalIncomingTransport)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 ParseException (bsh.ParseException)1 TargetError (bsh.TargetError)1 DB (com.mongodb.DB)1