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");
}
}
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;
}
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);
}
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");
}
}
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");
}
}
Aggregations