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);
}
}
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;
}
Aggregations