Search in sources :

Example 6 with Node

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

the class StatisticManager method flush.

public void flush() {
    boolean recordStatistics = parameterService.is(ParameterConstants.STATISTIC_RECORD_ENABLE, false);
    if (channelStats != null) {
        channelStatsLock.acquireUninterruptibly(NUMBER_OF_PERMITS);
        try {
            if (recordStatistics) {
                Date endTime = new Date();
                for (ChannelStats stats : channelStats.values()) {
                    if (stats.getNodeId().equals(UNKNOWN)) {
                        Node node = nodeService.getCachedIdentity();
                        if (node != null) {
                            stats.setNodeId(node.getNodeId());
                        }
                    }
                    stats.setEndTime(endTime);
                    statisticService.save(stats);
                }
            }
            resetChannelStats(true);
        } finally {
            channelStatsLock.release(NUMBER_OF_PERMITS);
        }
    }
    if (hostStats != null) {
        hostStatsLock.acquireUninterruptibly(NUMBER_OF_PERMITS);
        try {
            if (recordStatistics) {
                if (hostStats.getNodeId().equals(UNKNOWN)) {
                    Node node = nodeService.getCachedIdentity();
                    if (node != null) {
                        hostStats.setNodeId(node.getNodeId());
                    }
                }
                hostStats.setEndTime(new Date());
                statisticService.save(hostStats);
            }
            hostStats = null;
        } finally {
            hostStatsLock.release(NUMBER_OF_PERMITS);
        }
    }
    if (jobStats != null) {
        List<JobStats> toFlush = null;
        jobStatsLock.acquireUninterruptibly(NUMBER_OF_PERMITS);
        try {
            toFlush = jobStats;
            jobStats = new ArrayList<JobStats>();
        } finally {
            jobStatsLock.release(NUMBER_OF_PERMITS);
        }
        if (toFlush != null && recordStatistics) {
            Node node = nodeService.getCachedIdentity();
            if (node != null) {
                String nodeId = node.getNodeId();
                String serverId = clusterService.getServerId();
                for (JobStats stats : toFlush) {
                    stats.setNodeId(nodeId);
                    stats.setHostName(serverId);
                    statisticService.save(stats);
                }
            }
        }
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node) Date(java.util.Date)

Example 7 with Node

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

the class DefaultNodeIdCreatorTest method testSelectNodeId.

@Test
public void testSelectNodeId() throws Exception {
    final String EXPECTED_NODE_ID = "100-2";
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(new MockParameterService(), new MockNodeService() {

        @Override
        public NodeSecurity findNodeSecurity(String nodeId) {
            if (nodeId.equals(EXPECTED_NODE_ID)) {
                NodeSecurity security = new NodeSecurity();
                security.setNodeId(EXPECTED_NODE_ID);
                security.setRegistrationEnabled(true);
                return security;
            } else {
                return null;
            }
        }
    }, SecurityServiceFactory.create());
    Node node = new Node();
    node.setExternalId("100");
    String selectedNodeId = generator.selectNodeId(node, null, null);
    assertEquals(EXPECTED_NODE_ID, selectedNodeId);
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) MockParameterService(org.jumpmind.symmetric.service.impl.MockParameterService) Node(org.jumpmind.symmetric.model.Node) Test(org.junit.Test)

Example 8 with Node

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

the class DefaultNodeIdCreatorTest method testSelectNodeIdWithNodeIdSet.

@Test
public void testSelectNodeIdWithNodeIdSet() throws Exception {
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(new MockParameterService(), new MockNodeService(), SecurityServiceFactory.create());
    Node node = new Node();
    final String EXPECTED_NODE_ID = "10001";
    node.setExternalId(EXPECTED_NODE_ID);
    node.setNodeId(EXPECTED_NODE_ID);
    String selectedNodeId = generator.selectNodeId(node, null, null);
    assertEquals(EXPECTED_NODE_ID, selectedNodeId);
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) MockParameterService(org.jumpmind.symmetric.service.impl.MockParameterService) Node(org.jumpmind.symmetric.model.Node) Test(org.junit.Test)

Example 9 with Node

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

the class DefaultNodeIdCreatorTest method testGenerateNodeIdExistingWithUniqueParam.

@Test
public void testGenerateNodeIdExistingWithUniqueParam() throws Exception {
    final String EXPECTED_NODE_ID = "100-0";
    IParameterService paramService = mock(IParameterService.class);
    Mockito.when(paramService.is(ParameterConstants.EXTERNAL_ID_IS_UNIQUE)).thenReturn(false);
    Mockito.when(paramService.getInt(ParameterConstants.NODE_ID_CREATOR_MAX_NODES, 100)).thenReturn(100);
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(paramService, new MockNodeService() {

        @Override
        public Node findNode(String nodeId) {
            if (nodeId.equals("100")) {
                Node node = new Node();
                node.setNodeId("100");
                return node;
            } else {
                return null;
            }
        }
    }, SecurityServiceFactory.create());
    Node node = new Node();
    node.setExternalId("100");
    String selectedNodeId = generator.generateNodeId(node, null, null);
    assertEquals(EXPECTED_NODE_ID, selectedNodeId);
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) Node(org.jumpmind.symmetric.model.Node) IParameterService(org.jumpmind.symmetric.service.IParameterService) Test(org.junit.Test)

Example 10 with Node

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

the class ConfigurationUriHandler method handle.

public void handle(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    Node remoteNode = new Node();
    String symVersion = ServletUtils.getParameter(req, WebConstants.SYMMETRIC_VERSION);
    String configVersion = ServletUtils.getParameter(req, WebConstants.CONFIG_VERSION);
    remoteNode.setNodeId(ServletUtils.getParameter(req, WebConstants.NODE_ID));
    remoteNode.setSymmetricVersion(symVersion);
    remoteNode.setConfigVersion(configVersion);
    log.info("Configuration request from node ID " + remoteNode.getNodeId() + " {symmetricVersion={}, configVersion={}}", symVersion, configVersion);
    if (StringUtils.isBlank(configVersion) || Version.isOlderThanVersion(configVersion, Version.version())) {
        OutputStream outputStream = res.getOutputStream();
        dataExtractorService.extractConfigurationStandalone(remoteNode, outputStream);
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node) OutputStream(java.io.OutputStream)

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