Search in sources :

Example 1 with IClusterService

use of org.jumpmind.symmetric.service.IClusterService 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("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 (IOException 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) IOException(java.io.IOException) File(java.io.File) IClusterService(org.jumpmind.symmetric.service.IClusterService) Lock(org.jumpmind.symmetric.model.Lock)

Example 2 with IClusterService

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

the class PushService method push.

public synchronized RemoteNodeStatuses push(boolean force) {
    IConfigurationService configurationService = engine.getConfigurationService();
    IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
    INodeService nodeService = engine.getNodeService();
    IClusterService clusterService = engine.getClusterService();
    int availableThreadPairs = parameterService.getInt(ParameterConstants.PUSH_THREAD_COUNT_PER_SERVER);
    long minimumPeriodBetweenPushesMs = parameterService.getLong(ParameterConstants.PUSH_MINIMUM_PERIOD_MS, -1);
    RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
    Node identityNode = nodeService.findIdentity(false);
    if (identityNode != null && identityNode.isSyncEnabled()) {
        List<NodeHost> hosts = nodeService.findNodeHosts(identityNode.getNodeId());
        int clusterInstanceCount = hosts != null && hosts.size() > 0 ? hosts.size() : 1;
        NodeSecurity identitySecurity = nodeService.findNodeSecurity(identityNode.getNodeId());
        if (identitySecurity != null && (force || !clusterService.isInfiniteLocked(ClusterConstants.PUSH))) {
            Iterator<OutgoingBatchByNodeChannelCount> nodeChannels = outgoingBatchService.getOutgoingBatchByNodeChannelCount(availableThreadPairs * clusterInstanceCount, NodeGroupLinkAction.P, true).iterator();
            // based on percentage
            while (nodeChannels.hasNext() && pushWorkersWorking.size() < availableThreadPairs) {
                OutgoingBatchByNodeChannelCount batchCount = nodeChannels.next();
                String nodeId = batchCount.getNodeId();
                String channelId = batchCount.getChannelId();
                Node remoteNode = nodeService.findNode(nodeId);
                NodeChannel nodeChannel = configurationService.getNodeChannel(channelId, nodeId, false);
                if (nodeChannel != null && !nodeChannel.isFileSyncFlag() && !pushWorkersWorking.contains(nodeChannel)) {
                    boolean meetsMinimumTime = true;
                    // TODO error backoff logic
                    if (minimumPeriodBetweenPushesMs > 0 && nodeChannel.getLastExtractTime() != null && (System.currentTimeMillis() - nodeChannel.getLastExtractTime().getTime()) < minimumPeriodBetweenPushesMs) {
                        meetsMinimumTime = false;
                    }
                    if (meetsMinimumTime && clusterService.lockNodeChannel(ClusterConstants.PUSH, nodeId, channelId)) {
                        NodeChannelExtractForPushWorker worker = new NodeChannelExtractForPushWorker(remoteNode, identityNode, identitySecurity, nodeChannel, statuses.add(nodeId, channelId));
                        pushWorkersWorking.add(nodeChannel);
                        nodeChannelExtractForPushWorker.execute(worker);
                    }
                }
            }
        }
    }
    return statuses;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeHost(org.jumpmind.symmetric.model.NodeHost) OutgoingBatchByNodeChannelCount(org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount) RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) INodeService(org.jumpmind.symmetric.service.INodeService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) IClusterService(org.jumpmind.symmetric.service.IClusterService)

Aggregations

IClusterService (org.jumpmind.symmetric.service.IClusterService)2 INodeService (org.jumpmind.symmetric.service.INodeService)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 IJob (org.jumpmind.symmetric.job.IJob)1 IJobManager (org.jumpmind.symmetric.job.IJobManager)1 Lock (org.jumpmind.symmetric.model.Lock)1 Node (org.jumpmind.symmetric.model.Node)1 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)1 NodeHost (org.jumpmind.symmetric.model.NodeHost)1 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1 OutgoingBatchByNodeChannelCount (org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount)1 RemoteNodeStatuses (org.jumpmind.symmetric.model.RemoteNodeStatuses)1 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)1 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)1