Search in sources :

Example 1 with IConfigurationService

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

the class ConfigurationChangedDataRouter method routeNodeTables.

protected void routeNodeTables(Set<String> nodeIds, Map<String, String> columnValues, NetworkedNode rootNetworkedNode, Node me, SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> possibleTargetNodes, boolean initialLoad) {
    String nodeIdForRecordBeingRouted = columnValues.get("NODE_ID");
    if (dataMetaData.getData().getDataEventType() == DataEventType.DELETE) {
        String createAtNodeId = columnValues.get("CREATED_AT_NODE_ID");
        for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
            if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeIdForRecordBeingRouted.equals(nodeThatMayBeRoutedTo.getNodeId()) && !nodeThatMayBeRoutedTo.getNodeId().equals(createAtNodeId) && (nodeThatMayBeRoutedTo.getCreatedAtNodeId() == null || !nodeThatMayBeRoutedTo.getCreatedAtNodeId().equals(nodeIdForRecordBeingRouted))) {
                nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
            }
        }
    } else {
        IConfigurationService configurationService = engine.getConfigurationService();
        List<NodeGroupLink> nodeGroupLinks = getNodeGroupLinksFromContext(routingContext);
        for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
            if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeThatMayBeRoutedTo.requires13Compatiblity() && isLinked(nodeIdForRecordBeingRouted, nodeThatMayBeRoutedTo, rootNetworkedNode, me, nodeGroupLinks) && (!isSameNumberOfLinksAwayFromRoot(nodeThatMayBeRoutedTo, rootNetworkedNode, me) || configurationService.isMasterToMaster()) || (nodeThatMayBeRoutedTo.getNodeId().equals(me.getNodeId()) && initialLoad)) {
                nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
            }
        }
        if (!initialLoad && nodeIds != null) {
            if (tableMatches(dataMetaData, TableConstants.SYM_NODE_SECURITY)) {
                routeSymNodeSecurity(me, nodeIdForRecordBeingRouted, dataMetaData, nodeIds, columnValues);
            }
            /*
                 * Don't route insert events for a node to itself. They will be
                 * loaded during registration. If we route them, then an old
                 * state can override the correct state
                 * 
                 * Don't send deletes to a node. A node should be responsible
                 * for deleting itself.
                 */
            if (dataMetaData.getData().getDataEventType() == DataEventType.INSERT) {
                nodeIds.remove(nodeIdForRecordBeingRouted);
            }
        }
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 2 with IConfigurationService

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

the class SymmetricEngineHolder method install.

public ISymmetricEngine install(Properties passedInProperties) throws Exception {
    TypedProperties properties = new TypedProperties(passedInProperties);
    String password = properties.getProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD);
    if (StringUtils.isNotBlank(password) && !password.startsWith(SecurityConstants.PREFIX_ENC)) {
        try {
            ISecurityService service = SecurityServiceFactory.create(SecurityServiceType.CLIENT, properties);
            properties.setProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD, SecurityConstants.PREFIX_ENC + service.encrypt(password));
        } catch (Exception ex) {
            log.warn("Could not encrypt password", ex);
        }
    }
    String engineName = validateRequiredProperties(properties);
    passedInProperties.setProperty(ParameterConstants.ENGINE_NAME, engineName);
    if (engines.get(engineName) != null) {
        try {
            engines.get(engineName).stop();
        } catch (Exception e) {
            log.error("", e);
        }
        engines.remove(engineName);
    }
    File enginesDir = new File(AbstractCommandLauncher.getEnginesDir());
    File symmetricProperties = new File(enginesDir, engineName + ".properties");
    FileOutputStream fileOs = null;
    try {
        fileOs = new FileOutputStream(symmetricProperties);
        properties.store(fileOs, "Updated by SymmetricDS Pro");
    } catch (IOException ex) {
        throw new RuntimeException("Failed to write symmetric.properties to engine directory", ex);
    } finally {
        IOUtils.closeQuietly(fileOs);
    }
    ISymmetricEngine engine = null;
    try {
        String registrationUrl = properties.getProperty(ParameterConstants.REGISTRATION_URL);
        if (StringUtils.isNotBlank(registrationUrl)) {
            Collection<ServerSymmetricEngine> all = getEngines().values();
            for (ISymmetricEngine currentEngine : all) {
                if (currentEngine.getParameterService().getSyncUrl().equals(registrationUrl)) {
                    String serverNodeGroupId = currentEngine.getParameterService().getNodeGroupId();
                    String clientNodeGroupId = properties.getProperty(ParameterConstants.NODE_GROUP_ID);
                    String externalId = properties.getProperty(ParameterConstants.EXTERNAL_ID);
                    IConfigurationService configurationService = currentEngine.getConfigurationService();
                    ITriggerRouterService triggerRouterService = currentEngine.getTriggerRouterService();
                    List<NodeGroup> groups = configurationService.getNodeGroups();
                    boolean foundGroup = false;
                    for (NodeGroup nodeGroup : groups) {
                        if (nodeGroup.getNodeGroupId().equals(clientNodeGroupId)) {
                            foundGroup = true;
                        }
                    }
                    if (!foundGroup) {
                        configurationService.saveNodeGroup(new NodeGroup(clientNodeGroupId));
                    }
                    boolean foundLink = false;
                    List<NodeGroupLink> links = configurationService.getNodeGroupLinksFor(serverNodeGroupId, false);
                    for (NodeGroupLink nodeGroupLink : links) {
                        if (nodeGroupLink.getTargetNodeGroupId().equals(clientNodeGroupId)) {
                            foundLink = true;
                        }
                    }
                    if (!foundLink) {
                        configurationService.saveNodeGroupLink(new NodeGroupLink(serverNodeGroupId, clientNodeGroupId, NodeGroupLinkAction.W));
                        triggerRouterService.syncTriggers();
                    }
                    IRegistrationService registrationService = currentEngine.getRegistrationService();
                    if (!registrationService.isAutoRegistration() && !registrationService.isRegistrationOpen(clientNodeGroupId, externalId)) {
                        Node node = new Node(properties);
                        registrationService.openRegistration(node);
                    }
                }
            }
        }
        engine = create(symmetricProperties.getAbsolutePath());
        if (engine != null) {
            engineCount++;
            engine.start();
        } else {
            FileUtils.deleteQuietly(symmetricProperties);
            log.warn("The engine could not be created.  It will not be started");
        }
        return engine;
    } catch (RuntimeException ex) {
        if (engine != null) {
            engine.destroy();
        }
        FileUtils.deleteQuietly(symmetricProperties);
        throw ex;
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IRegistrationService(org.jumpmind.symmetric.service.IRegistrationService) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) IOException(java.io.IOException) TypedProperties(org.jumpmind.properties.TypedProperties) IOException(java.io.IOException) ISecurityService(org.jumpmind.security.ISecurityService) FileOutputStream(java.io.FileOutputStream) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) File(java.io.File) NodeGroup(org.jumpmind.symmetric.model.NodeGroup)

Example 3 with IConfigurationService

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

the class RouterService method findNodesThatAreReadyForInitialLoad.

public List<NodeSecurity> findNodesThatAreReadyForInitialLoad() {
    INodeService nodeService = engine.getNodeService();
    IConfigurationService configurationService = engine.getConfigurationService();
    String me = nodeService.findIdentityNodeId();
    List<NodeSecurity> toReturn = new ArrayList<NodeSecurity>();
    List<NodeSecurity> securities = nodeService.findNodeSecurityWithLoadEnabled();
    for (NodeSecurity nodeSecurity : securities) {
        if (((!nodeSecurity.getNodeId().equals(me) && nodeSecurity.isInitialLoadEnabled()) || (!nodeSecurity.getNodeId().equals(me) && configurationService.isMasterToMaster()) || (nodeSecurity.getNodeId().equals(me) && nodeSecurity.isRevInitialLoadEnabled()))) {
            toReturn.add(nodeSecurity);
        }
    }
    return toReturn;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) ArrayList(java.util.ArrayList) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService)

Example 4 with IConfigurationService

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

the class PushService method push.

public synchronized RemoteNodeStatuses push(boolean force) {
    IConfigurationService configurationService = engine.getConfigurationService();
    IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
    INodeService nodeService = engine.getNodeService();
    IClusterService clusterService = engine.getClusterService();
    int availableThreadPairs = parameterService.getInt(ParameterConstants.PUSH_THREAD_COUNT_PER_SERVER);
    long minimumPeriodBetweenPushesMs = parameterService.getLong(ParameterConstants.PUSH_MINIMUM_PERIOD_MS, -1);
    RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
    Node identityNode = nodeService.findIdentity(false);
    if (identityNode != null && identityNode.isSyncEnabled()) {
        List<NodeHost> hosts = nodeService.findNodeHosts(identityNode.getNodeId());
        int clusterInstanceCount = hosts != null && hosts.size() > 0 ? hosts.size() : 1;
        NodeSecurity identitySecurity = nodeService.findNodeSecurity(identityNode.getNodeId());
        if (identitySecurity != null && (force || !clusterService.isInfiniteLocked(ClusterConstants.PUSH))) {
            Iterator<OutgoingBatchByNodeChannelCount> nodeChannels = outgoingBatchService.getOutgoingBatchByNodeChannelCount(availableThreadPairs * clusterInstanceCount, NodeGroupLinkAction.P, true).iterator();
            // based on percentage
            while (nodeChannels.hasNext() && pushWorkersWorking.size() < availableThreadPairs) {
                OutgoingBatchByNodeChannelCount batchCount = nodeChannels.next();
                String nodeId = batchCount.getNodeId();
                String channelId = batchCount.getChannelId();
                Node remoteNode = nodeService.findNode(nodeId);
                NodeChannel nodeChannel = configurationService.getNodeChannel(channelId, nodeId, false);
                if (nodeChannel != null && !nodeChannel.isFileSyncFlag() && !pushWorkersWorking.contains(nodeChannel)) {
                    boolean meetsMinimumTime = true;
                    // TODO error backoff logic
                    if (minimumPeriodBetweenPushesMs > 0 && nodeChannel.getLastExtractTime() != null && (System.currentTimeMillis() - nodeChannel.getLastExtractTime().getTime()) < minimumPeriodBetweenPushesMs) {
                        meetsMinimumTime = false;
                    }
                    if (meetsMinimumTime && clusterService.lockNodeChannel(ClusterConstants.PUSH, nodeId, channelId)) {
                        NodeChannelExtractForPushWorker worker = new NodeChannelExtractForPushWorker(remoteNode, identityNode, identitySecurity, nodeChannel, statuses.add(nodeId, channelId));
                        pushWorkersWorking.add(nodeChannel);
                        nodeChannelExtractForPushWorker.execute(worker);
                    }
                }
            }
        }
    }
    return statuses;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeHost(org.jumpmind.symmetric.model.NodeHost) OutgoingBatchByNodeChannelCount(org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount) RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) INodeService(org.jumpmind.symmetric.service.INodeService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) IClusterService(org.jumpmind.symmetric.service.IClusterService)

Example 5 with IConfigurationService

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

the class RestService method sendSchemaImpl.

private SendSchemaResponse sendSchemaImpl(ISymmetricEngine engine, SendSchemaRequest request) {
    IConfigurationService configurationService = engine.getConfigurationService();
    INodeService nodeService = engine.getNodeService();
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    IDataService dataService = engine.getDataService();
    SendSchemaResponse response = new SendSchemaResponse();
    org.jumpmind.symmetric.model.Node identity = nodeService.findIdentity();
    if (identity != null) {
        List<org.jumpmind.symmetric.model.Node> nodesToSendTo = new ArrayList<org.jumpmind.symmetric.model.Node>();
        List<String> nodeIds = request.getNodeIdsToSendTo();
        if (nodeIds == null || nodeIds.size() == 0) {
            nodeIds = new ArrayList<String>();
            String nodeGroupIdToSendTo = request.getNodeGroupIdToSendTo();
            if (isNotBlank(nodeGroupIdToSendTo)) {
                NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), nodeGroupIdToSendTo, false);
                if (link != null) {
                    Collection<org.jumpmind.symmetric.model.Node> nodes = nodeService.findEnabledNodesFromNodeGroup(nodeGroupIdToSendTo);
                    nodesToSendTo.addAll(nodes);
                } else {
                    log.warn("Could not send schema to all nodes in the '" + nodeGroupIdToSendTo + "' node group.  No node group link exists");
                }
            } else {
                log.warn("Could not send schema to nodes.  There are none that were provided and the nodeGroupIdToSendTo was also not provided");
            }
        } else {
            for (String nodeIdToValidate : nodeIds) {
                org.jumpmind.symmetric.model.Node node = nodeService.findNode(nodeIdToValidate);
                if (node != null) {
                    NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), node.getNodeGroupId(), false);
                    if (link != null) {
                        nodesToSendTo.add(node);
                    } else {
                        log.warn("Could not send schema to node '" + nodeIdToValidate + "'. No node group link exists");
                    }
                } else {
                    log.warn("Could not send schema to node '" + nodeIdToValidate + "'.  It was not present in the database");
                }
            }
        }
        Map<String, List<TableName>> results = response.getNodeIdsSentTo();
        List<String> nodeIdsToSendTo = toNodeIds(nodesToSendTo);
        for (String nodeId : nodeIdsToSendTo) {
            results.put(nodeId, new ArrayList<TableName>());
        }
        if (nodesToSendTo.size() > 0) {
            List<TableName> tablesToSend = request.getTablesToSend();
            List<TriggerRouter> triggerRouters = triggerRouterService.getTriggerRouters(true, false);
            for (TriggerRouter triggerRouter : triggerRouters) {
                Trigger trigger = triggerRouter.getTrigger();
                NodeGroupLink link = triggerRouter.getRouter().getNodeGroupLink();
                if (link.getSourceNodeGroupId().equals(identity.getNodeGroupId())) {
                    for (org.jumpmind.symmetric.model.Node node : nodesToSendTo) {
                        if (link.getTargetNodeGroupId().equals(node.getNodeGroupId())) {
                            if (tablesToSend == null || tablesToSend.size() == 0 || contains(trigger, tablesToSend)) {
                                dataService.sendSchema(node.getNodeId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName(), false);
                                results.get(node.getNodeId()).add(new TableName(trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()));
                            }
                        }
                    }
                }
            }
        }
    }
    return response;
}
Also used : Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) ArrayList(java.util.ArrayList) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) Trigger(org.jumpmind.symmetric.model.Trigger) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList) EngineList(org.jumpmind.symmetric.web.rest.model.EngineList) NodeList(org.jumpmind.symmetric.web.rest.model.NodeList) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IDataService(org.jumpmind.symmetric.service.IDataService) TableName(org.jumpmind.symmetric.web.rest.model.TableName) INodeService(org.jumpmind.symmetric.service.INodeService) SendSchemaResponse(org.jumpmind.symmetric.web.rest.model.SendSchemaResponse)

Aggregations

IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)14 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)7 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)7 Date (java.util.Date)6 Test (org.junit.Test)6 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)5 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)5 INodeService (org.jumpmind.symmetric.service.INodeService)5 FixMethodOrder (org.junit.FixMethodOrder)5 Node (org.jumpmind.symmetric.model.Node)4 ArrayList (java.util.ArrayList)3 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)2 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)2 IRegistrationService (org.jumpmind.symmetric.service.IRegistrationService)2 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1