Search in sources :

Example 1 with Node

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

the class DefaultOfflineClientListener method syncDisabled.

public void syncDisabled(Node remoteNode) {
    Node identity = nodeService.findIdentity();
    if (identity != null && identity.getCreatedAtNodeId() != null && identity.getCreatedAtNodeId().equals(remoteNode.getNodeId())) {
        log.warn("Removing identity because sync has been disabled");
        nodeService.deleteIdentity();
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node)

Example 2 with Node

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

the class MonitorService method update.

@Override
public synchronized void update() {
    Map<String, IMonitorType> monitorTypes = extensionService.getExtensionPointMap(IMonitorType.class);
    Node identity = nodeService.findIdentity();
    List<Monitor> activeMonitors = getActiveMonitorsForNode(identity.getNodeGroupId(), identity.getExternalId());
    Map<String, MonitorEvent> unresolved = getMonitorEventsNotResolvedForNode(identity.getNodeId());
    for (Monitor monitor : activeMonitors) {
        IMonitorType monitorType = monitorTypes.get(monitor.getType());
        if (monitorType != null) {
            if (!monitorType.requiresClusterLock()) {
                Long lastCheckTimeLong = checkTimesByType.get(monitor.getMonitorId());
                long lastCheckTime = lastCheckTimeLong != null ? lastCheckTimeLong : 0;
                if (lastCheckTime == 0 || (System.currentTimeMillis() - lastCheckTime) / 1000 >= monitor.getRunPeriod()) {
                    checkTimesByType.put(monitor.getMonitorId(), System.currentTimeMillis());
                    updateMonitor(monitor, monitorType, identity, unresolved);
                }
            }
        } else {
            log.warn("Could not find monitor of type '" + monitor.getType() + "'");
        }
    }
    if (clusterService.lock(ClusterConstants.MONITOR)) {
        Lock lock = clusterService.findLocks().get(ClusterConstants.MONITOR);
        long clusterLastCheckTime = lock.getLastLockTime() != null ? lock.getLastLockTime().getTime() : 0;
        try {
            for (Monitor monitor : activeMonitors) {
                IMonitorType monitorType = monitorTypes.get(monitor.getType());
                if (monitorType != null && monitorType.requiresClusterLock() && (System.currentTimeMillis() - clusterLastCheckTime) / 1000 >= monitor.getRunPeriod()) {
                    updateMonitor(monitor, monitorType, identity, unresolved);
                }
            }
            int minSeverityLevel = Integer.MAX_VALUE;
            List<Notification> notifications = getActiveNotificationsForNode(identity.getNodeGroupId(), identity.getExternalId());
            if (notifications.size() > 0) {
                for (Notification notification : notifications) {
                    if (notification.getSeverityLevel() < minSeverityLevel) {
                        minSeverityLevel = notification.getSeverityLevel();
                    }
                }
                Map<String, INotificationType> notificationTypes = extensionService.getExtensionPointMap(INotificationType.class);
                List<MonitorEvent> allMonitorEvents = getMonitorEventsForNotification(minSeverityLevel);
                for (Notification notification : notifications) {
                    List<MonitorEvent> monitorEvents = new ArrayList<MonitorEvent>();
                    for (MonitorEvent monitorEvent : allMonitorEvents) {
                        if (monitorEvent.getSeverityLevel() >= notification.getSeverityLevel()) {
                            monitorEvents.add(monitorEvent);
                        }
                    }
                    if (monitorEvents.size() > 0) {
                        INotificationType notificationType = notificationTypes.get(notification.getType());
                        if (notificationType != null) {
                            notificationType.notify(notification, monitorEvents);
                            updateMonitorEventAsNotified(monitorEvents);
                        } else {
                            log.warn("Could not find notification of type '" + notification.getType() + "'");
                        }
                    }
                }
            }
        } finally {
            clusterService.unlock(ClusterConstants.MONITOR);
        }
    }
}
Also used : MonitorEvent(org.jumpmind.symmetric.model.MonitorEvent) Node(org.jumpmind.symmetric.model.Node) ArrayList(java.util.ArrayList) INotificationType(org.jumpmind.symmetric.notification.INotificationType) Notification(org.jumpmind.symmetric.model.Notification) Lock(org.jumpmind.symmetric.model.Lock) IMonitorType(org.jumpmind.symmetric.monitor.IMonitorType) Monitor(org.jumpmind.symmetric.model.Monitor)

Example 3 with Node

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

the class AbstractRouterServiceTest method testLargeNumberOfEventsToManyNodes.

public void testLargeNumberOfEventsToManyNodes() {
    resetBatches();
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getRouter().setRouterType("column");
    // set up a constant to force the data to be routed through the column
    // data matcher, but to everyone
    trigger1.getRouter().setRouterExpression("ROUTING_VARCHAR=00001");
    getTriggerRouterService().saveTriggerRouter(trigger1);
    getTriggerRouterService().syncTriggers();
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(10000);
    testChannel.setMaxBatchSize(10000);
    testChannel.setBatchAlgorithm("default");
    getConfigurationService().saveChannel(testChannel, true);
    final int ROWS_TO_INSERT = 1000;
    final int NODES_TO_INSERT = 10;
    logger.info(String.format("About to insert %s nodes", NODES_TO_INSERT));
    for (int i = 0; i < 1000; i++) {
        String nodeId = String.format("100%s", i);
        getRegistrationService().openRegistration(TestConstants.TEST_CLIENT_NODE_GROUP, nodeId);
        Node node = getNodeService().findNode(nodeId);
        node.setSyncEnabled(true);
        getNodeService().save(node);
    }
    logger.info(String.format("Done inserting %s nodes", NODES_TO_INSERT));
    logger.info(String.format("About to insert %s rows", ROWS_TO_INSERT));
    insert(TEST_TABLE_1, ROWS_TO_INSERT, false);
    logger.info(String.format("Done inserting %s rows", ROWS_TO_INSERT));
    logger.info("About to route data");
    getRouterService().routeData(true);
    logger.info("Done routing data");
}
Also used : Node(org.jumpmind.symmetric.model.Node) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 4 with Node

use of org.jumpmind.symmetric.model.Node 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 5 with Node

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

the class SymmetricEngineHolder method uninstallEngine.

public void uninstallEngine(ISymmetricEngine engine) {
    Node node = engine.getNodeService().getCachedIdentity();
    String engineName = engine.getEngineName();
    File file = new SymmetricAdmin("uninstall", "", "").findPropertiesFileForEngineWithName(engineName);
    engine.uninstall();
    engine.destroy();
    if (file != null) {
        file.delete();
    }
    getEngines().remove(engineName);
    for (ISymmetricEngine existingEngine : this.getEngines().values()) {
        existingEngine.removeAndCleanupNode(node.getNodeId());
    }
}
Also used : SymmetricAdmin(org.jumpmind.symmetric.SymmetricAdmin) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) File(java.io.File)

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