Search in sources :

Example 6 with INodeService

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

the class RestService method isRegistered.

private boolean isRegistered(ISymmetricEngine engine) {
    boolean registered = true;
    INodeService nodeService = engine.getNodeService();
    org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
    if (modelNode == null) {
        registered = false;
    } else {
        NodeSecurity nodeSecurity = nodeService.findNodeSecurity(modelNode.getNodeId());
        if (nodeSecurity == null) {
            registered = false;
        }
    }
    return registered;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService)

Example 7 with INodeService

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

the class RestService method securityVerified.

protected boolean securityVerified(String nodeId, ISymmetricEngine engine, String securityToken) {
    INodeService nodeService = engine.getNodeService();
    boolean allowed = false;
    org.jumpmind.symmetric.model.Node targetNode = nodeService.findNode(nodeId);
    if (targetNode != null) {
        NodeSecurity security = nodeService.findNodeSecurity(nodeId);
        allowed = security.getNodePassword().equals(securityToken);
    }
    return allowed;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService)

Example 8 with INodeService

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

the class RestService method isRootNode.

private boolean isRootNode(ISymmetricEngine engine, org.jumpmind.symmetric.model.Node node) {
    INodeService nodeService = engine.getNodeService();
    org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
    if (modelNode.getCreatedAtNodeId() == null || modelNode.getCreatedAtNodeId().equalsIgnoreCase(modelNode.getExternalId())) {
        return true;
    } else {
        return false;
    }
}
Also used : INodeService(org.jumpmind.symmetric.service.INodeService)

Example 9 with INodeService

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

the class SnapshotUtil method writeJobsStats.

protected static void writeJobsStats(ISymmetricEngine engine, File tmpDir) {
    FileWriter writer = null;
    try {
        writer = new FileWriter(new File(tmpDir, "jobs.txt"));
        IJobManager jobManager = engine.getJobManager();
        IClusterService clusterService = engine.getClusterService();
        INodeService nodeService = engine.getNodeService();
        writer.write("Clustering is " + (clusterService.isClusteringEnabled() ? "" : "not ") + "enabled and there are " + nodeService.findNodeHosts(nodeService.findIdentityNodeId()).size() + " instances in the cluster\n\n");
        writer.write(StringUtils.rightPad("Job Name", 30) + StringUtils.rightPad("Schedule", 20) + StringUtils.rightPad("Status", 10) + StringUtils.rightPad("Server Id", 30) + StringUtils.rightPad("Last Server Id", 30) + StringUtils.rightPad("Last Finish Time", 30) + StringUtils.rightPad("Last Run Period", 20) + StringUtils.rightPad("Avg. Run Period", 20) + "\n");
        List<IJob> jobs = jobManager.getJobs();
        Map<String, Lock> locks = clusterService.findLocks();
        for (IJob job : jobs) {
            Lock lock = locks.get(job.getClusterLockName());
            String status = getJobStatus(job, lock);
            String runningServerId = lock != null ? lock.getLockingServerId() : "";
            String lastServerId = clusterService.getServerId();
            if (lock != null) {
                lastServerId = lock.getLastLockingServerId();
            }
            String schedule = StringUtils.isBlank(job.getCronExpression()) ? Long.toString(job.getTimeBetweenRunsInMs()) : job.getCronExpression();
            String lastFinishTime = getLastFinishTime(job, lock);
            writer.write(StringUtils.rightPad(job.getClusterLockName().replace("_", " "), 30) + StringUtils.rightPad(schedule, 20) + StringUtils.rightPad(status, 10) + StringUtils.rightPad(runningServerId == null ? "" : runningServerId, 30) + StringUtils.rightPad(lastServerId == null ? "" : lastServerId, 30) + StringUtils.rightPad(lastFinishTime == null ? "" : lastFinishTime, 30) + StringUtils.rightPad(job.getLastExecutionTimeInMs() + "", 20) + StringUtils.rightPad(job.getAverageExecutionTimeInMs() + "", 20) + "\n");
        }
    } catch (Exception e) {
        log.warn("Failed to write jobs information", e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
Also used : IJob(org.jumpmind.symmetric.job.IJob) FileWriter(java.io.FileWriter) INodeService(org.jumpmind.symmetric.service.INodeService) IJobManager(org.jumpmind.symmetric.job.IJobManager) File(java.io.File) IClusterService(org.jumpmind.symmetric.service.IClusterService) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) Lock(org.jumpmind.symmetric.model.Lock)

Example 10 with INodeService

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

the class FileSyncService method loadFilesFromPush.

public void loadFilesFromPush(String nodeId, InputStream in, OutputStream out) {
    INodeService nodeService = engine.getNodeService();
    Node local = nodeService.findIdentity();
    Node sourceNode = nodeService.findNode(nodeId, true);
    if (local != null && sourceNode != null) {
        ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeId, local.getNodeId(), ProcessInfoKey.ProcessType.FILE_SYNC_PUSH_HANDLER));
        try {
            List<IncomingBatch> list = processZip(in, nodeId, processInfo);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId(), true);
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            engine.getTransportManager().writeAcknowledgement(out, sourceNode, list, local, security != null ? security.getNodePassword() : null);
            processInfo.setStatus(ProcessInfo.Status.OK);
        } catch (Throwable e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            if (e instanceof IOException) {
                throw new IoException((IOException) e);
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) IoException(org.jumpmind.exception.IoException) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

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