Search in sources :

Example 1 with NodeGroup

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

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

the class ConfigurationService method doesNodeGroupExist.

public boolean doesNodeGroupExist(String nodeGroupId) {
    boolean exists = false;
    List<NodeGroup> groups = getNodeGroups();
    for (NodeGroup nodeGroup : groups) {
        exists |= nodeGroup.getNodeGroupId().equals(nodeGroupId);
    }
    return exists;
}
Also used : NodeGroup(org.jumpmind.symmetric.model.NodeGroup)

Example 3 with NodeGroup

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

the class ConfigurationService method saveNodeGroupLink.

public void saveNodeGroupLink(NodeGroupLink link) {
    if (!doesNodeGroupExist(link.getSourceNodeGroupId())) {
        saveNodeGroup(new NodeGroup(link.getSourceNodeGroupId()));
    }
    if (!doesNodeGroupExist(link.getTargetNodeGroupId())) {
        saveNodeGroup(new NodeGroup(link.getTargetNodeGroupId()));
    }
    link.setLastUpdateTime(new Date());
    if (sqlTemplate.update(getSql("updateNodeGroupLinkSql"), link.getDataEventAction().name(), link.isSyncConfigEnabled() ? 1 : 0, link.isReversible() ? 1 : 0, link.getLastUpdateTime(), link.getLastUpdateBy(), link.getSourceNodeGroupId(), link.getTargetNodeGroupId()) == 0) {
        link.setCreateTime(new Date());
        sqlTemplate.update(getSql("insertNodeGroupLinkSql"), link.getDataEventAction().name(), link.getSourceNodeGroupId(), link.getTargetNodeGroupId(), link.isSyncConfigEnabled() ? 1 : 0, link.isReversible() ? 1 : 0, link.getLastUpdateTime(), link.getLastUpdateBy(), link.getCreateTime());
    }
}
Also used : Date(java.util.Date) NodeGroup(org.jumpmind.symmetric.model.NodeGroup)

Aggregations

NodeGroup (org.jumpmind.symmetric.model.NodeGroup)3 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 TypedProperties (org.jumpmind.properties.TypedProperties)1 ISecurityService (org.jumpmind.security.ISecurityService)1 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)1 Node (org.jumpmind.symmetric.model.Node)1 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)1 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)1 IRegistrationService (org.jumpmind.symmetric.service.IRegistrationService)1 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)1