Search in sources :

Example 86 with Node

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;
}
Also used : RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) Node(org.jumpmind.symmetric.model.Node) ChannelMap(org.jumpmind.symmetric.model.ChannelMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 87 with Node

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;
}
Also used : ProtocolDataWriter(org.jumpmind.symmetric.io.data.writer.ProtocolDataWriter) Node(org.jumpmind.symmetric.model.Node) ArrayList(java.util.ArrayList) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IDataWriter(org.jumpmind.symmetric.io.data.IDataWriter)

Example 88 with Node

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);
    }
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Node(org.jumpmind.symmetric.model.Node) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 89 with Node

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;
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Node(org.jumpmind.symmetric.model.Node) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 90 with Node

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();
        }
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Trigger(org.jumpmind.symmetric.model.Trigger) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Node(org.jumpmind.symmetric.model.Node)

Aggregations

Node (org.jumpmind.symmetric.model.Node)129 HashSet (java.util.HashSet)18 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)18 Test (org.junit.Test)18 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)17 ArrayList (java.util.ArrayList)14 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)14 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)13 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)13 Table (org.jumpmind.db.model.Table)12 Data (org.jumpmind.symmetric.model.Data)12 Router (org.jumpmind.symmetric.model.Router)12 Date (java.util.Date)11 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)11 IOException (java.io.IOException)10 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)10 HashMap (java.util.HashMap)9 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)9 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)8