use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class DataExtractorService method queueWork.
public RemoteNodeStatuses queueWork(boolean force) {
final RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
Node identity = nodeService.findIdentity();
if (identity != null) {
if (force || clusterService.lock(ClusterConstants.INITIAL_LOAD_EXTRACT)) {
try {
Map<String, String> nodes = getExtractRequestNodes();
for (Map.Entry<String, String> entry : nodes.entrySet()) {
queue(entry.getKey(), entry.getValue(), statuses);
}
} finally {
if (!force) {
clusterService.unlock(ClusterConstants.INITIAL_LOAD_EXTRACT);
}
}
}
} else {
log.debug("Not running initial load extract service because this node does not have an identity");
}
return statuses;
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class DataExtractorService method extractOnlyOutgoingBatch.
/**
* This method will extract an outgoing batch, but will not update the outgoing batch status
*/
public boolean extractOnlyOutgoingBatch(String nodeId, long batchId, Writer writer) {
boolean extracted = false;
Node targetNode = null;
if (Constants.UNROUTED_NODE_ID.equals(nodeId)) {
targetNode = new Node(nodeId, parameterService.getNodeGroupId());
} else {
targetNode = nodeService.findNode(nodeId);
}
if (targetNode != null) {
OutgoingBatch batch = outgoingBatchService.findOutgoingBatch(batchId, nodeId);
if (batch != null) {
IDataWriter dataWriter = new ProtocolDataWriter(nodeService.findIdentityNodeId(), writer, targetNode.requires13Compatiblity());
List<OutgoingBatch> batches = new ArrayList<OutgoingBatch>(1);
batches.add(batch);
batches = extract(new ProcessInfo(), targetNode, batches, dataWriter, null, ExtractMode.EXTRACT_ONLY);
extracted = batches.size() > 0;
}
}
return extracted;
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class DataService method sendScript.
public void sendScript(String nodeId, String script, boolean isLoad) {
Node targetNode = engine.getNodeService().findNode(nodeId);
TriggerHistory history = engine.getTriggerRouterService().findTriggerHistoryForGenericSync();
Data data = new Data(history.getSourceTableName(), DataEventType.BSH, CsvUtils.escapeCsvData(script), null, history, Constants.CHANNEL_CONFIG, null, null);
data.setNodeList(nodeId);
if (!isLoad) {
insertData(data);
} else {
insertDataAndDataEventAndOutgoingBatch(data, targetNode.getNodeId(), Constants.UNKNOWN_ROUTER_ID, isLoad, -1, null);
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class DataService method sendSchema.
public boolean sendSchema(String nodeId, String catalogName, String schemaName, String tableName, boolean isLoad) {
Node sourceNode = engine.getNodeService().findIdentity();
Node targetNode = engine.getNodeService().findNode(nodeId);
if (targetNode == null) {
log.error("Could not send schema to the node {}. The target node does not exist", nodeId);
return false;
}
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
List<TriggerHistory> triggerHistories = triggerRouterService.findTriggerHistories(catalogName, schemaName, tableName);
Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = triggerRouterService.fillTriggerRoutersByHistIdAndSortHist(sourceNode.getNodeGroupId(), targetNode.getNodeGroupId(), triggerHistories);
int eventCount = 0;
for (TriggerHistory triggerHistory : triggerHistories) {
List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
for (TriggerRouter triggerRouter : triggerRouters) {
eventCount++;
insertCreateEvent(targetNode, triggerHistory, triggerRouter.getRouter().getRouterId(), false, -1, null);
}
}
if (eventCount > 0) {
return true;
} else {
return false;
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class DataService method sendSQL.
public String sendSQL(String nodeId, String catalogName, String schemaName, String tableName, String sql) {
Node sourceNode = engine.getNodeService().findIdentity();
Node targetNode = engine.getNodeService().findNode(nodeId);
if (targetNode == null) {
return "Unknown node " + nodeId;
}
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
TriggerHistory triggerHistory = triggerRouterService.findTriggerHistory(catalogName, schemaName, tableName);
if (triggerHistory == null) {
return "Trigger for table " + tableName + " does not exist from node " + sourceNode.getNodeGroupId();
} else {
Trigger trigger = triggerRouterService.getTriggerById(triggerHistory.getTriggerId());
if (trigger != null) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
insertSqlEvent(transaction, triggerHistory, trigger.getChannelId(), targetNode, sql, false, -1, null);
transaction.commit();
return "Successfully create SQL event for node " + targetNode.getNodeId();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
close(transaction);
}
} else {
return "Trigger for table " + tableName + " does not exist from node " + sourceNode.getNodeGroupId();
}
}
}
Aggregations