Search in sources :

Example 1 with INodeService

use of org.jumpmind.symmetric.service.INodeService in project symmetric-ds by JumpMind.

the class ConfigurationChangedDatabaseWriterFilter method batchCommitted.

@Override
public void batchCommitted(DataContext context) {
    IParameterService parameterService = engine.getParameterService();
    INodeService nodeService = engine.getNodeService();
    if (context.getBatch().getBatchId() == Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
        // mark registration as complete
        String nodeId = nodeService.findIdentityNodeId();
        if (nodeId != null) {
            NodeSecurity security = nodeService.findNodeSecurity(nodeId);
            if (security != null && (security.isRegistrationEnabled() || security.getRegistrationTime() == null)) {
                engine.getRegistrationService().markNodeAsRegistered(nodeId);
            }
        }
    }
    if (context.get(CTX_KEY_FLUSH_GROUPLETS_NEEDED) != null) {
        log.info("Grouplets flushed because new grouplet config came through the data loader");
        engine.getGroupletService().clearCache();
        context.remove(CTX_KEY_FLUSH_GROUPLETS_NEEDED);
    }
    if (context.get(CTX_KEY_FLUSH_LOADFILTERS_NEEDED) != null) {
        log.info("Load filters flushed because new filter config came through the data loader");
        engine.getLoadFilterService().clearCache();
        context.remove(CTX_KEY_FLUSH_LOADFILTERS_NEEDED);
    }
    if (context.get(CTX_KEY_FLUSH_CHANNELS_NEEDED) != null) {
        log.info("Channels flushed because new channels came through the data loader");
        engine.getConfigurationService().clearCache();
        context.remove(CTX_KEY_FLUSH_CHANNELS_NEEDED);
    }
    if (context.get(CTX_KEY_FLUSH_CONFLICTS_NEEDED) != null) {
        log.info("About to refresh the cache of conflict settings because new configuration came through the data loader");
        engine.getDataLoaderService().clearCache();
        context.remove(CTX_KEY_FLUSH_CONFLICTS_NEEDED);
    }
    if (context.get(CTX_KEY_FLUSH_PARAMETERS_NEEDED) != null) {
        log.info("About to refresh the cache of parameters because new configuration came through the data loader");
        parameterService.rereadParameters();
        context.remove(CTX_KEY_FLUSH_PARAMETERS_NEEDED);
    }
    if (context.get(CTX_KEY_FLUSH_NODE_SECURITY_NEEDED) != null) {
        log.info("About to refresh the cache of node security because new configuration came through the data loader");
        nodeService.flushNodeAuthorizedCache();
        context.remove(CTX_KEY_FLUSH_NODE_SECURITY_NEEDED);
    }
    if (context.get(CTX_KEY_FLUSH_NODE_NEEDED) != null) {
        log.info("About to refresh the cache of nodes because new configuration came through the data loader");
        nodeService.flushNodeCache();
        nodeService.flushNodeGroupCache();
        context.remove(CTX_KEY_FLUSH_NODE_NEEDED);
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) IParameterService(org.jumpmind.symmetric.service.IParameterService)

Example 2 with INodeService

use of org.jumpmind.symmetric.service.INodeService in project symmetric-ds by JumpMind.

the class RestService method sendSchemaImpl.

private SendSchemaResponse sendSchemaImpl(ISymmetricEngine engine, SendSchemaRequest request) {
    IConfigurationService configurationService = engine.getConfigurationService();
    INodeService nodeService = engine.getNodeService();
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    IDataService dataService = engine.getDataService();
    SendSchemaResponse response = new SendSchemaResponse();
    org.jumpmind.symmetric.model.Node identity = nodeService.findIdentity();
    if (identity != null) {
        List<org.jumpmind.symmetric.model.Node> nodesToSendTo = new ArrayList<org.jumpmind.symmetric.model.Node>();
        List<String> nodeIds = request.getNodeIdsToSendTo();
        if (nodeIds == null || nodeIds.size() == 0) {
            nodeIds = new ArrayList<String>();
            String nodeGroupIdToSendTo = request.getNodeGroupIdToSendTo();
            if (isNotBlank(nodeGroupIdToSendTo)) {
                NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), nodeGroupIdToSendTo, false);
                if (link != null) {
                    Collection<org.jumpmind.symmetric.model.Node> nodes = nodeService.findEnabledNodesFromNodeGroup(nodeGroupIdToSendTo);
                    nodesToSendTo.addAll(nodes);
                } else {
                    log.warn("Could not send schema to all nodes in the '" + nodeGroupIdToSendTo + "' node group.  No node group link exists");
                }
            } else {
                log.warn("Could not send schema to nodes.  There are none that were provided and the nodeGroupIdToSendTo was also not provided");
            }
        } else {
            for (String nodeIdToValidate : nodeIds) {
                org.jumpmind.symmetric.model.Node node = nodeService.findNode(nodeIdToValidate);
                if (node != null) {
                    NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), node.getNodeGroupId(), false);
                    if (link != null) {
                        nodesToSendTo.add(node);
                    } else {
                        log.warn("Could not send schema to node '" + nodeIdToValidate + "'. No node group link exists");
                    }
                } else {
                    log.warn("Could not send schema to node '" + nodeIdToValidate + "'.  It was not present in the database");
                }
            }
        }
        Map<String, List<TableName>> results = response.getNodeIdsSentTo();
        List<String> nodeIdsToSendTo = toNodeIds(nodesToSendTo);
        for (String nodeId : nodeIdsToSendTo) {
            results.put(nodeId, new ArrayList<TableName>());
        }
        if (nodesToSendTo.size() > 0) {
            List<TableName> tablesToSend = request.getTablesToSend();
            List<TriggerRouter> triggerRouters = triggerRouterService.getTriggerRouters(false);
            for (TriggerRouter triggerRouter : triggerRouters) {
                Trigger trigger = triggerRouter.getTrigger();
                NodeGroupLink link = triggerRouter.getRouter().getNodeGroupLink();
                if (link.getSourceNodeGroupId().equals(identity.getNodeGroupId())) {
                    for (org.jumpmind.symmetric.model.Node node : nodesToSendTo) {
                        if (link.getTargetNodeGroupId().equals(node.getNodeGroupId())) {
                            if (tablesToSend == null || tablesToSend.size() == 0 || contains(trigger, tablesToSend)) {
                                dataService.sendSchema(node.getNodeId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName(), false);
                                results.get(node.getNodeId()).add(new TableName(trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()));
                            }
                        }
                    }
                }
            }
        }
    }
    return response;
}
Also used : Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) ArrayList(java.util.ArrayList) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) Trigger(org.jumpmind.symmetric.model.Trigger) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) ArrayList(java.util.ArrayList) List(java.util.List) EngineList(org.jumpmind.symmetric.web.rest.model.EngineList) NodeList(org.jumpmind.symmetric.web.rest.model.NodeList) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IDataService(org.jumpmind.symmetric.service.IDataService) TableName(org.jumpmind.symmetric.web.rest.model.TableName) INodeService(org.jumpmind.symmetric.service.INodeService) SendSchemaResponse(org.jumpmind.symmetric.web.rest.model.SendSchemaResponse)

Example 3 with INodeService

use of org.jumpmind.symmetric.service.INodeService in project symmetric-ds by JumpMind.

the class RestService method heartbeatImpl.

private void heartbeatImpl(ISymmetricEngine engine, Heartbeat heartbeat) {
    INodeService nodeService = engine.getNodeService();
    NodeHost nodeHost = new NodeHost();
    if (heartbeat.getAvailableProcessors() != null) {
        nodeHost.setAvailableProcessors(heartbeat.getAvailableProcessors());
    }
    if (heartbeat.getCreateTime() != null) {
        nodeHost.setCreateTime(heartbeat.getCreateTime());
    }
    if (heartbeat.getFreeMemoryBytes() != null) {
        nodeHost.setFreeMemoryBytes(heartbeat.getFreeMemoryBytes());
    }
    if (heartbeat.getHeartbeatTime() != null) {
        nodeHost.setHeartbeatTime(heartbeat.getHeartbeatTime());
    }
    if (heartbeat.getHostName() != null) {
        nodeHost.setHostName(heartbeat.getHostName());
    }
    if (heartbeat.getIpAddress() != null) {
        nodeHost.setIpAddress(heartbeat.getIpAddress());
    }
    if (heartbeat.getJavaVendor() != null) {
        nodeHost.setJavaVendor(heartbeat.getJavaVendor());
    }
    if (heartbeat.getJdbcVersion() != null) {
        nodeHost.setJdbcVersion(heartbeat.getJdbcVersion());
    }
    if (heartbeat.getJavaVersion() != null) {
        nodeHost.setJavaVersion(heartbeat.getJavaVersion());
    }
    if (heartbeat.getLastRestartTime() != null) {
        nodeHost.setLastRestartTime(heartbeat.getLastRestartTime());
    }
    if (heartbeat.getMaxMemoryBytes() != null) {
        nodeHost.setMaxMemoryBytes(heartbeat.getMaxMemoryBytes());
    }
    if (heartbeat.getNodeId() != null) {
        nodeHost.setNodeId(heartbeat.getNodeId());
    }
    if (heartbeat.getOsArchitecture() != null) {
        nodeHost.setOsArch(heartbeat.getOsArchitecture());
    }
    if (heartbeat.getOsName() != null) {
        nodeHost.setOsName(heartbeat.getOsName());
    }
    if (heartbeat.getOsUser() != null) {
        nodeHost.setOsUser(heartbeat.getOsUser());
    }
    if (heartbeat.getOsVersion() != null) {
        nodeHost.setOsVersion(heartbeat.getOsVersion());
    }
    if (heartbeat.getSymmetricVersion() != null) {
        nodeHost.setSymmetricVersion(heartbeat.getSymmetricVersion());
    }
    if (heartbeat.getTimezoneOffset() != null) {
        nodeHost.setTimezoneOffset(heartbeat.getTimezoneOffset());
    }
    if (heartbeat.getTotalMemoryBytes() != null) {
        nodeHost.setTotalMemoryBytes(heartbeat.getTotalMemoryBytes());
    }
    nodeService.updateNodeHost(nodeHost);
}
Also used : INodeService(org.jumpmind.symmetric.service.INodeService) NodeHost(org.jumpmind.symmetric.model.NodeHost)

Example 4 with INodeService

use of org.jumpmind.symmetric.service.INodeService in project symmetric-ds by JumpMind.

the class RestService method postRequestInitialLoad.

/**
     * Requests an initial load from the server for the node id provided. The
     * initial load requst directs the server to queue up initial load data for
     * the client node. Data is obtained for the initial load by the client
     * calling the pull method.
     * 
     * @param nodeID
     */
@ApiOperation(value = "Request an initial load for the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/requestinitialload", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public final void postRequestInitialLoad(@PathVariable("engine") String engineName, @RequestParam(value = "nodeId") String nodeId) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    INodeService nodeService = engine.getNodeService();
    nodeService.setInitialLoadEnabled(nodeId, true, false, -1, "restapi");
}
Also used : INodeService(org.jumpmind.symmetric.service.INodeService) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with INodeService

use of org.jumpmind.symmetric.service.INodeService in project symmetric-ds by JumpMind.

the class RouterService method findNodesThatAreReadyForInitialLoad.

public List<NodeSecurity> findNodesThatAreReadyForInitialLoad() {
    INodeService nodeService = engine.getNodeService();
    IConfigurationService configurationService = engine.getConfigurationService();
    String me = nodeService.findIdentityNodeId();
    List<NodeSecurity> toReturn = new ArrayList<NodeSecurity>();
    List<NodeSecurity> securities = nodeService.findNodeSecurityWithLoadEnabled();
    for (NodeSecurity nodeSecurity : securities) {
        if (((!nodeSecurity.getNodeId().equals(me) && nodeSecurity.isInitialLoadEnabled()) || (!nodeSecurity.getNodeId().equals(me) && configurationService.isMasterToMaster()) || (nodeSecurity.getNodeId().equals(me) && nodeSecurity.isRevInitialLoadEnabled()))) {
            toReturn.add(nodeSecurity);
        }
    }
    return toReturn;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) ArrayList(java.util.ArrayList) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService)

Aggregations

INodeService (org.jumpmind.symmetric.service.INodeService)27 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)12 Node (org.jumpmind.symmetric.model.Node)8 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 IoException (org.jumpmind.exception.IoException)4 NodeHost (org.jumpmind.symmetric.model.NodeHost)4 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)4 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 IOException (java.io.IOException)3 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)3 SymmetricException (org.jumpmind.symmetric.SymmetricException)3 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)3 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 Trigger (org.jumpmind.symmetric.model.Trigger)3 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)3 Test (org.junit.Test)3