Search in sources :

Example 16 with NodeSecurity

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

the class RegistrationService method reOpenRegistration.

protected synchronized void reOpenRegistration(String nodeId, String remoteHost, String remoteAddress) {
    Node node = nodeService.findNode(nodeId);
    NodeSecurity security = nodeService.findNodeSecurity(nodeId);
    String password = null;
    if (security != null && parameterService.is(ParameterConstants.REGISTRATION_REOPEN_USE_SAME_PASSWORD, true)) {
        password = security.getNodePassword();
    } else {
        password = extensionService.getExtensionPoint(INodeIdCreator.class).generatePassword(node);
        password = filterPasswordOnSaveIfNeeded(password);
    }
    if (node != null) {
        int updateCount = sqlTemplate.update(getSql("reopenRegistrationSql"), new Object[] { password, nodeId });
        if (updateCount == 0 && nodeService.findNodeSecurity(nodeId) == null) {
            // if the update count was 0, then we probably have a row in the
            // node table, but not in node security.
            // lets go ahead and try to insert into node security.
            sqlTemplate.update(getSql("openRegistrationNodeSecuritySql"), new Object[] { nodeId, password, nodeService.findNode(nodeId).getNodeId() });
            log.info("Registration was opened for {}", nodeId);
        } else if (updateCount == 0) {
            log.warn("Registration was already enabled for {}.  No need to reenable it", nodeId);
        } else {
            log.info("Registration was reopened for {}", nodeId);
        }
        if (isNotBlank(remoteHost)) {
            NodeHost nodeHost = new NodeHost(node.getNodeId());
            nodeHost.setHeartbeatTime(new Date());
            nodeHost.setIpAddress(remoteAddress);
            nodeHost.setHostName(remoteHost);
            nodeService.updateNodeHost(nodeHost);
        }
        nodeService.flushNodeAuthorizedCache();
    } else {
        log.warn("There was no row with a node id of {} to 'reopen' registration for", nodeId);
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) Date(java.util.Date) NodeHost(org.jumpmind.symmetric.model.NodeHost)

Example 17 with NodeSecurity

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

the class SimpleIntegrationTest method test03InitialLoad.

@Test(timeout = 120000)
public void test03InitialLoad() {
    logTestRunning();
    serverTestService.insertIntoTestUseStreamLob(100, "test_use_stream_lob", THIS_IS_A_TEST);
    serverTestService.insertIntoTestUseStreamLob(100, "test_use_capture_lob", THIS_IS_A_TEST);
    Customer customer = new Customer(301, "Linus", true, "42 Blanket Street", "Santa Claus", "IN", 90009, new Date(), new Date(), THIS_IS_A_TEST, BINARY_DATA);
    serverTestService.insertCustomer(customer);
    serverTestService.insertIntoTestTriggerTable(new Object[] { 1, "wow", "mom" });
    serverTestService.insertIntoTestTriggerTable(new Object[] { 2, "mom", "wow" });
    INodeService rootNodeService = getServer().getNodeService();
    INodeService clientNodeService = getClient().getNodeService();
    String nodeId = rootNodeService.findNodeByExternalId(TestConstants.TEST_CLIENT_NODE_GROUP, TestConstants.TEST_CLIENT_EXTERNAL_ID).getNodeId();
    getServer().reloadNode(nodeId, "test");
    IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
    assertFalse(rootOutgoingBatchService.isInitialLoadComplete(nodeId));
    assertTrue(rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isInitialLoadEnabled());
    do {
        clientPull();
    } while (!rootOutgoingBatchService.isInitialLoadComplete(nodeId));
    assertFalse(rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isInitialLoadEnabled());
    NodeSecurity clientNodeSecurity = clientNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID);
    assertFalse(clientNodeSecurity.isInitialLoadEnabled());
    assertNotNull(clientNodeSecurity.getInitialLoadTime());
    IIncomingBatchService clientIncomingBatchService = getClient().getIncomingBatchService();
    // Running a query with dirty reads to make sure platform allows it
    getServer().getDataService().findMaxDataId();
    assertEquals("The initial load errored out." + printRootAndClientDatabases(), 0, clientIncomingBatchService.countIncomingBatchesInError());
    assertEquals("test_triggers_table on the client did not contain the expected number of rows", 2, clientTestService.countTestTriggersTable());
    assertEquals("test_customer on the client did not contain the expected number of rows", 2, clientTestService.count("test_customer"));
    assertEquals("Initial load was not successful according to the client", NodeStatus.DATA_LOAD_COMPLETED, clientNodeService.getNodeStatus());
    assertEquals("Initial load was not successful accordign to the root", false, rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isInitialLoadEnabled());
    clientTestService.assertTestBlobIsInDatabase(100, "test_use_capture_lob", THIS_IS_A_TEST);
    clientTestService.assertTestBlobIsInDatabase(100, "test_use_stream_lob", THIS_IS_A_TEST);
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) IIncomingBatchService(org.jumpmind.symmetric.service.IIncomingBatchService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) Date(java.util.Date) Test(org.junit.Test)

Example 18 with NodeSecurity

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

the class AbstractSymmetricEngine method autoConfigRegistrationServer.

protected void autoConfigRegistrationServer() {
    Node node = nodeService.findIdentity();
    if (node == null) {
        buildTablesFromDdlUtilXmlIfProvided();
        loadFromScriptIfProvided();
        parameterService.rereadParameters();
    }
    node = nodeService.findIdentity();
    if (node == null && parameterService.isRegistrationServer() && parameterService.is(ParameterConstants.AUTO_INSERT_REG_SVR_IF_NOT_FOUND, false)) {
        log.info("Inserting rows for node, security, identity and group for registration server");
        String nodeId = parameterService.getExternalId();
        node = new Node(parameterService, symmetricDialect);
        node.setNodeId(node.getExternalId());
        nodeService.save(node);
        nodeService.insertNodeIdentity(nodeId);
        node = nodeService.findIdentity();
        nodeService.insertNodeGroup(node.getNodeGroupId(), null);
        NodeSecurity nodeSecurity = nodeService.findOrCreateNodeSecurity(nodeId);
        nodeSecurity.setInitialLoadTime(new Date());
        nodeSecurity.setRegistrationTime(new Date());
        nodeSecurity.setInitialLoadEnabled(false);
        nodeSecurity.setRegistrationEnabled(false);
        nodeService.updateNodeSecurity(nodeSecurity);
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) Date(java.util.Date)

Example 19 with NodeSecurity

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

the class DataLoaderService method loadDataFromPull.

public void loadDataFromPull(Node remote, RemoteNodeStatus status) throws IOException {
    Node local = nodeService.findIdentity();
    if (local == null) {
        local = new Node(this.parameterService, symmetricDialect);
    }
    try {
        NodeSecurity localSecurity = nodeService.findNodeSecurity(local.getNodeId(), true);
        IIncomingTransport transport = null;
        boolean isRegisterTransport = false;
        if (remote != null && localSecurity != null) {
            Map<String, String> requestProperties = new HashMap<String, String>();
            ChannelMap suspendIgnoreChannels = configurationService.getSuspendIgnoreChannelLists();
            requestProperties.put(WebConstants.SUSPENDED_CHANNELS, suspendIgnoreChannels.getSuspendChannelsAsString());
            requestProperties.put(WebConstants.IGNORED_CHANNELS, suspendIgnoreChannels.getIgnoreChannelsAsString());
            requestProperties.put(WebConstants.THREAD_CHANNEL, status.getChannelId());
            transport = transportManager.getPullTransport(remote, local, localSecurity.getNodePassword(), requestProperties, parameterService.getRegistrationUrl());
        } else {
            transport = transportManager.getRegisterTransport(local, parameterService.getRegistrationUrl());
            log.info("Using registration URL of {}", transport.getUrl());
            List<INodeRegistrationListener> registrationListeners = extensionService.getExtensionPointList(INodeRegistrationListener.class);
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationUrlUpdated(transport.getUrl());
            }
            remote = new Node();
            remote.setSyncUrl(parameterService.getRegistrationUrl());
            isRegisterTransport = true;
        }
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(remote.getNodeId(), status.getChannelId(), local.getNodeId(), ProcessType.PULL_JOB));
        try {
            List<IncomingBatch> list = loadDataFromTransport(processInfo, remote, transport, null);
            if (list.size() > 0) {
                processInfo.setStatus(ProcessInfo.Status.ACKING);
                status.updateIncomingStatus(list);
                local = nodeService.findIdentity();
                if (local != null) {
                    localSecurity = nodeService.findNodeSecurity(local.getNodeId(), !isRegisterTransport);
                    if (StringUtils.isNotBlank(transport.getRedirectionUrl())) {
                        /*
                             * We were redirected for the pull, we need to
                             * redirect for the ack
                             */
                        String url = transport.getRedirectionUrl();
                        int index = url.indexOf("/registration?");
                        if (index >= 0) {
                            url = url.substring(0, index);
                        }
                        log.info("Setting the sync url for ack to: {}", url);
                        remote.setSyncUrl(url);
                    }
                    sendAck(remote, local, localSecurity, list, transportManager);
                }
            }
            if (containsError(list)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
            updateBatchToSendCount(remote, transport);
        } catch (RuntimeException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        } catch (IOException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        }
    } catch (RegistrationRequiredException e) {
        if (StringUtils.isBlank(remote.getSyncUrl()) || remote.getSyncUrl().equals(parameterService.getRegistrationUrl())) {
            log.warn("Node information missing on the server.  Attempting to re-register remote.getSyncUrl()={}", remote.getSyncUrl());
            loadDataFromPull(null, status);
            nodeService.findIdentity(false);
        } else {
            log.warn("Failed to pull data from node '{}'. It probably is missing a node security record for '{}'.", remote.getNodeId(), local.getNodeId());
        }
    } catch (MalformedURLException e) {
        if (remote != null) {
            log.error("Could not connect to the {} node's transport because of a bad URL: '{}' {}", remote.getNodeId(), remote.getSyncUrl(), e);
        } else {
            log.error("", e);
        }
        throw e;
    }
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) MalformedURLException(java.net.MalformedURLException) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) TransformPoint(org.jumpmind.symmetric.io.data.transform.TransformPoint) IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) INodeRegistrationListener(org.jumpmind.symmetric.ext.INodeRegistrationListener) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException)

Example 20 with NodeSecurity

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

the class DataLoaderService method loadDataFromConfig.

public void loadDataFromConfig(Node remote, RemoteNodeStatus status, boolean force) throws IOException {
    if (engine.getParameterService().isRegistrationServer()) {
        return;
    }
    Node local = nodeService.findIdentity();
    try {
        NodeSecurity localSecurity = nodeService.findNodeSecurity(local.getNodeId(), true);
        String configVersion = force ? "" : local.getConfigVersion();
        IIncomingTransport transport = engine.getTransportManager().getConfigTransport(remote, local, localSecurity.getNodePassword(), Version.version(), configVersion, remote.getSyncUrl());
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(remote.getNodeId(), Constants.CHANNEL_CONFIG, local.getNodeId(), ProcessType.PULL_CONFIG_JOB));
        try {
            log.info("Requesting current configuration {symmetricVersion={}, configVersion={}}", Version.version(), local.getConfigVersion());
            List<IncomingBatch> list = loadDataFromTransport(processInfo, remote, transport, null);
            if (containsError(list)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                if (list.size() > 0) {
                    status.updateIncomingStatus(list);
                    local.setConfigVersion(Version.version());
                    nodeService.save(local);
                }
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
        } catch (RuntimeException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        } catch (IOException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        }
    } catch (RegistrationRequiredException e) {
        log.warn("Failed to pull configuration from node '{}'. It probably is missing a node security record for '{}'.", remote.getNodeId(), local.getNodeId());
    } catch (MalformedURLException e) {
        log.error("Could not connect to the {} node's transport because of a bad URL: '{}' {}", remote.getNodeId(), remote.getSyncUrl(), e);
        throw e;
    }
}
Also used : IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) MalformedURLException(java.net.MalformedURLException) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Aggregations

NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)31 Node (org.jumpmind.symmetric.model.Node)13 INodeService (org.jumpmind.symmetric.service.INodeService)12 Date (java.util.Date)7 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)7 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 IoException (org.jumpmind.exception.IoException)4 SymmetricException (org.jumpmind.symmetric.SymmetricException)4 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)4 NodeHost (org.jumpmind.symmetric.model.NodeHost)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 UniqueKeyException (org.jumpmind.db.sql.UniqueKeyException)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)2 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)2 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2