Search in sources :

Example 21 with INodeService

use of org.jumpmind.symmetric.service.INodeService 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 22 with INodeService

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

the class RestService method getPullData.

@ApiOperation(value = "Pull pending batches for the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/pulldata", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final PullDataResults getPullData(@PathVariable("engine") String engineName, @RequestParam(value = WebConstants.NODE_ID) String nodeId, @ApiParam(value = "This the password for the nodeId being passed in.  The password is stored in the node_security table.") @RequestParam(value = WebConstants.SECURITY_TOKEN) String securityToken, @RequestParam(value = "useJdbcTimestampFormat", required = false, defaultValue = "true") boolean useJdbcTimestampFormat, @RequestParam(value = "useUpsertStatements", required = false, defaultValue = "false") boolean useUpsertStatements, @RequestParam(value = "useDelimitedIdentifiers", required = false, defaultValue = "true") boolean useDelimitedIdentifiers, @RequestParam(value = "hostName", required = false) String hostName) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    IDataExtractorService dataExtractorService = engine.getDataExtractorService();
    IStatisticManager statisticManager = engine.getStatisticManager();
    INodeService nodeService = engine.getNodeService();
    org.jumpmind.symmetric.model.Node targetNode = nodeService.findNode(nodeId);
    if (securityVerified(nodeId, engine, securityToken)) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), nodeId, ProcessType.REST_PULL_HANLDER));
        try {
            PullDataResults results = new PullDataResults();
            List<OutgoingBatchWithPayload> extractedBatches = dataExtractorService.extractToPayload(processInfo, targetNode, PayloadType.SQL, useJdbcTimestampFormat, useUpsertStatements, useDelimitedIdentifiers);
            List<Batch> batches = new ArrayList<Batch>();
            for (OutgoingBatchWithPayload outgoingBatchWithPayload : extractedBatches) {
                if (outgoingBatchWithPayload.getStatus() == org.jumpmind.symmetric.model.OutgoingBatch.Status.LD || outgoingBatchWithPayload.getStatus() == org.jumpmind.symmetric.model.OutgoingBatch.Status.IG) {
                    Batch batch = new Batch();
                    batch.setBatchId(outgoingBatchWithPayload.getBatchId());
                    batch.setChannelId(outgoingBatchWithPayload.getChannelId());
                    batch.setSqlStatements(outgoingBatchWithPayload.getPayload());
                    batches.add(batch);
                }
            }
            results.setBatches(batches);
            results.setNbrBatches(batches.size());
            processInfo.setStatus(org.jumpmind.symmetric.model.ProcessInfo.Status.OK);
            if (engine.getParameterService().is(ParameterConstants.REST_HEARTBEAT_ON_PULL) && hostName != null) {
                Heartbeat heartbeat = new Heartbeat();
                heartbeat.setNodeId(nodeId);
                heartbeat.setHeartbeatTime(new Date());
                heartbeat.setHostName(hostName);
                this.heartbeatImpl(engine, heartbeat);
            }
            return results;
        } finally {
            if (processInfo.getStatus() != org.jumpmind.symmetric.model.ProcessInfo.Status.OK) {
                processInfo.setStatus(org.jumpmind.symmetric.model.ProcessInfo.Status.ERROR);
            }
        }
    } else {
        throw new NotAllowedException();
    }
}
Also used : OutgoingBatchWithPayload(org.jumpmind.symmetric.model.OutgoingBatchWithPayload) ArrayList(java.util.ArrayList) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) Date(java.util.Date) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) PullDataResults(org.jumpmind.symmetric.web.rest.model.PullDataResults) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) Batch(org.jumpmind.symmetric.web.rest.model.Batch) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) INodeService(org.jumpmind.symmetric.service.INodeService) Heartbeat(org.jumpmind.symmetric.web.rest.model.Heartbeat) IDataExtractorService(org.jumpmind.symmetric.service.IDataExtractorService) 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 23 with INodeService

use of org.jumpmind.symmetric.service.INodeService 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 24 with INodeService

use of org.jumpmind.symmetric.service.INodeService 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)

Example 25 with INodeService

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

the class RestService method postRegisterNode.

@ApiOperation(value = "Register the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/registernode", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final RegistrationInfo postRegisterNode(@PathVariable("engine") String engineName, @RequestParam(value = "externalId") String externalId, @RequestParam(value = "nodeGroupId") String nodeGroupId, @RequestParam(value = "databaseType") String databaseType, @RequestParam(value = "databaseVersion") String databaseVersion, @RequestParam(value = "hostName") String hostName) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    IRegistrationService registrationService = engine.getRegistrationService();
    INodeService nodeService = engine.getNodeService();
    RegistrationInfo regInfo = new org.jumpmind.symmetric.web.rest.model.RegistrationInfo();
    try {
        org.jumpmind.symmetric.model.Node processedNode = registrationService.registerPullOnlyNode(externalId, nodeGroupId, databaseType, databaseVersion);
        regInfo.setRegistered(processedNode.isSyncEnabled());
        if (regInfo.isRegistered()) {
            regInfo.setNodeId(processedNode.getNodeId());
            NodeSecurity nodeSecurity = nodeService.findNodeSecurity(processedNode.getNodeId());
            regInfo.setNodePassword(nodeSecurity.getNodePassword());
            org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
            regInfo.setSyncUrl(modelNode.getSyncUrl());
            // do an initial heartbeat
            Heartbeat heartbeat = new Heartbeat();
            heartbeat.setNodeId(regInfo.getNodeId());
            heartbeat.setHostName(hostName);
            Date now = new Date();
            heartbeat.setCreateTime(now);
            heartbeat.setLastRestartTime(now);
            heartbeat.setHeartbeatTime(now);
            this.heartbeatImpl(engine, heartbeat);
        }
    // TODO: Catch a RegistrationRedirectException and redirect.
    } catch (IOException e) {
        throw new IoException(e);
    }
    return regInfo;
}
Also used : RegistrationInfo(org.jumpmind.symmetric.web.rest.model.RegistrationInfo) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) IRegistrationService(org.jumpmind.symmetric.service.IRegistrationService) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOException(java.io.IOException) Date(java.util.Date) INodeService(org.jumpmind.symmetric.service.INodeService) Heartbeat(org.jumpmind.symmetric.web.rest.model.Heartbeat) IoException(org.jumpmind.exception.IoException) 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)

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