Search in sources :

Example 26 with NodeSecurity

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

the class DefaultNodeIdCreator method selectNodeId.

public String selectNodeId(Node node, String remoteHost, String remoteAddress) {
    final int maxTries = parameterService.getInt(ParameterConstants.NODE_ID_CREATOR_MAX_NODES, 100);
    final boolean autoRegisterEnabled = parameterService.is(ParameterConstants.AUTO_REGISTER_ENABLED);
    if (StringUtils.isBlank(node.getNodeId())) {
        String nodeId = evaluateScript(node, remoteHost, remoteAddress);
        if (StringUtils.isBlank(nodeId)) {
            nodeId = buildNodeId(nodeService, node);
            for (int sequence = 0; sequence < maxTries; sequence++) {
                NodeSecurity security = nodeService.findNodeSecurity(nodeId);
                if ((security != null && security.isRegistrationEnabled()) || autoRegisterEnabled) {
                    return nodeId;
                }
                nodeId = buildNodeId(nodeService, node) + "-" + sequence;
            }
        }
        return nodeId;
    }
    return node.getNodeId();
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) IBuiltInExtensionPoint(org.jumpmind.extension.IBuiltInExtensionPoint)

Example 27 with NodeSecurity

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

the class PullUriHandler method pull.

public void pull(String nodeId, String remoteHost, String remoteAddress, OutputStream outputStream, String encoding, HttpServletResponse res, ChannelMap map) throws IOException {
    NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId, true);
    long ts = System.currentTimeMillis();
    try {
        ChannelMap remoteSuspendIgnoreChannelsList = configurationService.getSuspendIgnoreChannelLists(nodeId);
        map.addSuspendChannels(remoteSuspendIgnoreChannelsList.getSuspendChannels());
        map.addIgnoreChannels(remoteSuspendIgnoreChannelsList.getIgnoreChannels());
        if (nodeSecurity != null) {
            String createdAtNodeId = nodeSecurity.getCreatedAtNodeId();
            if (nodeSecurity.isRegistrationEnabled() && (createdAtNodeId == null || createdAtNodeId.equals(nodeService.findIdentityNodeId()))) {
                registrationService.registerNode(nodeService.findNode(nodeId), remoteHost, remoteAddress, outputStream, false);
            } else {
                IOutgoingTransport outgoingTransport = createOutgoingTransport(outputStream, encoding, map);
                ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), map.getThreadChannel(), nodeId, ProcessType.PULL_HANDLER));
                try {
                    Node targetNode = nodeService.findNode(nodeId, true);
                    List<OutgoingBatch> batchList = dataExtractorService.extract(processInfo, targetNode, map.getThreadChannel(), outgoingTransport);
                    logDataReceivedFromPush(targetNode, batchList);
                    if (processInfo.getStatus() != Status.ERROR) {
                        addPendingBatchCounts(targetNode.getNodeId(), res);
                        processInfo.setStatus(Status.OK);
                    }
                } finally {
                    if (processInfo.getStatus() != Status.OK) {
                        processInfo.setStatus(Status.ERROR);
                    }
                }
                outgoingTransport.close();
            }
        } else {
            log.warn("Node {} does not exist", nodeId);
        }
    } finally {
        statisticManager.incrementNodesPulled(1);
        statisticManager.incrementTotalNodesPulledTime(System.currentTimeMillis() - ts);
    }
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) IOutgoingTransport(org.jumpmind.symmetric.transport.IOutgoingTransport)

Example 28 with NodeSecurity

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

the class RestService method nodeImpl.

private Node nodeImpl(ISymmetricEngine engine) {
    Node xmlNode = new Node();
    if (isRegistered(engine)) {
        INodeService nodeService = engine.getNodeService();
        org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
        List<NodeHost> nodeHosts = nodeService.findNodeHosts(modelNode.getNodeId());
        NodeSecurity nodeSecurity = nodeService.findNodeSecurity(modelNode.getNodeId());
        xmlNode.setNodeId(modelNode.getNodeId());
        xmlNode.setExternalId(modelNode.getExternalId());
        xmlNode.setSyncUrl(modelNode.getSyncUrl());
        xmlNode.setRegistrationUrl(engine.getParameterService().getRegistrationUrl());
        xmlNode.setBatchInErrorCount(modelNode.getBatchInErrorCount());
        xmlNode.setBatchToSendCount(modelNode.getBatchToSendCount());
        if (nodeHosts.size() > 0) {
            xmlNode.setLastHeartbeat(nodeHosts.get(0).getHeartbeatTime());
        }
        xmlNode.setHeartbeatInterval(engine.getParameterService().getInt(ParameterConstants.HEARTBEAT_JOB_PERIOD_MS));
        xmlNode.setRegistered(nodeSecurity.hasRegistered());
        xmlNode.setInitialLoaded(nodeSecurity.hasInitialLoaded());
        xmlNode.setReverseInitialLoaded(nodeSecurity.hasReverseInitialLoaded());
        if (modelNode.getCreatedAtNodeId() == null) {
            xmlNode.setRegistrationServer(true);
        } else {
            xmlNode.setRegistrationServer(false);
        }
        xmlNode.setCreatedAtNodeId(modelNode.getCreatedAtNodeId());
    } else {
        throw new NotFoundException();
    }
    return xmlNode;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) INodeService(org.jumpmind.symmetric.service.INodeService) NodeHost(org.jumpmind.symmetric.model.NodeHost)

Example 29 with NodeSecurity

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

the class RestService method childrenImpl.

private NodeList childrenImpl(ISymmetricEngine engine) {
    NodeList children = new NodeList();
    Node xmlChildNode = null;
    INodeService nodeService = engine.getNodeService();
    org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
    if (isRegistered(engine)) {
        if (isRootNode(engine, modelNode)) {
            NetworkedNode networkedNode = nodeService.getRootNetworkedNode();
            Set<NetworkedNode> childNetwork = networkedNode.getChildren();
            if (childNetwork != null) {
                for (NetworkedNode child : childNetwork) {
                    List<NodeHost> nodeHosts = nodeService.findNodeHosts(child.getNode().getNodeId());
                    NodeSecurity nodeSecurity = nodeService.findNodeSecurity(child.getNode().getNodeId());
                    xmlChildNode = new Node();
                    xmlChildNode.setNodeId(child.getNode().getNodeId());
                    xmlChildNode.setExternalId(child.getNode().getExternalId());
                    xmlChildNode.setRegistrationServer(false);
                    xmlChildNode.setSyncUrl(child.getNode().getSyncUrl());
                    xmlChildNode.setBatchInErrorCount(child.getNode().getBatchInErrorCount());
                    xmlChildNode.setBatchToSendCount(child.getNode().getBatchToSendCount());
                    if (nodeHosts.size() > 0) {
                        xmlChildNode.setLastHeartbeat(nodeHosts.get(0).getHeartbeatTime());
                    }
                    xmlChildNode.setRegistered(nodeSecurity.hasRegistered());
                    xmlChildNode.setInitialLoaded(nodeSecurity.hasInitialLoaded());
                    xmlChildNode.setReverseInitialLoaded(nodeSecurity.hasReverseInitialLoaded());
                    if (child.getNode().getCreatedAtNodeId() == null) {
                        xmlChildNode.setRegistrationServer(true);
                    }
                    children.addNode(xmlChildNode);
                }
            }
        }
    } else {
        throw new NotFoundException();
    }
    return children;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) NodeList(org.jumpmind.symmetric.web.rest.model.NodeList) Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) INodeService(org.jumpmind.symmetric.service.INodeService) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) NodeHost(org.jumpmind.symmetric.model.NodeHost)

Example 30 with NodeSecurity

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

the class RestService method nodeStatusImpl.

private NodeStatus nodeStatusImpl(ISymmetricEngine engine) {
    NodeStatus status = new NodeStatus();
    if (isRegistered(engine)) {
        INodeService nodeService = engine.getNodeService();
        org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
        NodeSecurity nodeSecurity = nodeService.findNodeSecurity(modelNode.getNodeId());
        List<NodeHost> nodeHost = nodeService.findNodeHosts(modelNode.getNodeId());
        status.setStarted(engine.isStarted());
        status.setRegistered(nodeSecurity.getRegistrationTime() != null);
        status.setInitialLoaded(nodeSecurity.getInitialLoadTime() != null);
        status.setReverseInitialLoaded(nodeSecurity.getRevInitialLoadTime() != null);
        status.setNodeId(modelNode.getNodeId());
        status.setNodeGroupId(modelNode.getNodeGroupId());
        status.setExternalId(modelNode.getExternalId());
        status.setSyncUrl(modelNode.getSyncUrl());
        status.setRegistrationUrl(engine.getParameterService().getRegistrationUrl());
        status.setDatabaseType(modelNode.getDatabaseType());
        status.setDatabaseVersion(modelNode.getDatabaseVersion());
        status.setSyncEnabled(modelNode.isSyncEnabled());
        status.setCreatedAtNodeId(modelNode.getCreatedAtNodeId());
        status.setBatchToSendCount(engine.getOutgoingBatchService().countOutgoingBatchesUnsent());
        status.setBatchInErrorCount(engine.getOutgoingBatchService().countOutgoingBatchesInError());
        status.setDeploymentType(modelNode.getDeploymentType());
        if (modelNode.getCreatedAtNodeId() == null) {
            status.setRegistrationServer(true);
        } else {
            status.setRegistrationServer(false);
        }
        if (nodeHost != null && nodeHost.size() > 0) {
            status.setLastHeartbeat(nodeHost.get(0).getHeartbeatTime());
        }
        status.setHeartbeatInterval(engine.getParameterService().getInt(ParameterConstants.HEARTBEAT_SYNC_ON_PUSH_PERIOD_SEC));
        if (status.getHeartbeatInterval() == 0) {
            status.setHeartbeatInterval(600);
        }
    } else {
        throw new NotFoundException();
    }
    return status;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) NodeStatus(org.jumpmind.symmetric.web.rest.model.NodeStatus) NodeHost(org.jumpmind.symmetric.model.NodeHost)

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