use of org.jumpmind.symmetric.model.ProcessInfoKey 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");
}
}
use of org.jumpmind.symmetric.model.ProcessInfoKey in project symmetric-ds by JumpMind.
the class FileSyncService method pushFilesToNode.
protected void pushFilesToNode(NodeCommunication nodeCommunication, RemoteNodeStatus status, Node identity, NodeSecurity security) {
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeCommunication.getNodeId(), identity.getNodeId(), ProcessType.FILE_SYNC_PUSH_JOB));
IOutgoingWithResponseTransport transport = null;
ITransportManager transportManager = null;
try {
if (!engine.getParameterService().is(ParameterConstants.NODE_OFFLINE)) {
transportManager = engine.getTransportManager();
transport = transportManager.getFilePushTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), parameterService.getRegistrationUrl());
} else {
transportManager = ((AbstractSymmetricEngine) engine).getOfflineTransportManager();
transport = transportManager.getFilePushTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), parameterService.getRegistrationUrl());
}
List<OutgoingBatch> batches = sendFiles(processInfo, nodeCommunication.getNode(), transport);
if (batches.size() > 0) {
if (transport instanceof FileOutgoingTransport) {
((FileOutgoingTransport) transport).setProcessedBatches(batches);
}
List<BatchAck> batchAcks = readAcks(batches, transport, transportManager, engine.getAcknowledgeService());
status.updateOutgoingStatus(batches, batchAcks);
}
if (!status.failed() && batches.size() > 0) {
log.info("Pushed files to {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
} else if (status.failed()) {
log.info("There was a failure while pushing files to {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
}
} catch (Exception e) {
fireOffline(e, nodeCommunication.getNode(), status);
} finally {
if (processInfo.getStatus() != ProcessInfo.Status.ERROR) {
processInfo.setStatus(ProcessInfo.Status.OK);
}
if (transport != null) {
transport.close();
if (transport instanceof FileOutgoingTransport) {
((FileOutgoingTransport) transport).complete(processInfo.getStatus() == ProcessInfo.Status.OK);
}
}
}
}
use of org.jumpmind.symmetric.model.ProcessInfoKey in project symmetric-ds by JumpMind.
the class FileSyncService method pullFilesFromNode.
protected void pullFilesFromNode(NodeCommunication nodeCommunication, RemoteNodeStatus status, Node identity, NodeSecurity security) {
IIncomingTransport transport = null;
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeCommunication.getNodeId(), identity.getNodeId(), ProcessType.FILE_SYNC_PULL_JOB));
try {
processInfo.setStatus(ProcessInfo.Status.TRANSFERRING);
ITransportManager transportManager;
if (!engine.getParameterService().is(ParameterConstants.NODE_OFFLINE)) {
transportManager = engine.getTransportManager();
transport = transportManager.getFilePullTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), null, parameterService.getRegistrationUrl());
} else {
transportManager = ((AbstractSymmetricEngine) engine).getOfflineTransportManager();
transport = transportManager.getFilePullTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), null, parameterService.getRegistrationUrl());
}
List<IncomingBatch> batchesProcessed = processZip(transport.openStream(), nodeCommunication.getNodeId(), processInfo);
if (batchesProcessed.size() > 0) {
processInfo.setStatus(ProcessInfo.Status.ACKING);
status.updateIncomingStatus(batchesProcessed);
sendAck(nodeCommunication.getNode(), identity, security, batchesProcessed, transportManager);
}
if (!status.failed() && batchesProcessed.size() > 0) {
log.info("Pull files received from {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
} else if (status.failed()) {
log.info("There was a failure while pulling files from {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
}
} catch (NoContentException noContentEx) {
log.debug("Server reported no batches. " + noContentEx);
} catch (Exception e) {
fireOffline(e, nodeCommunication.getNode(), status);
} finally {
if (transport != null) {
transport.close();
if (processInfo.getStatus() != ProcessInfo.Status.ERROR) {
processInfo.setStatus(ProcessInfo.Status.OK);
}
if (transport instanceof FileIncomingTransport) {
((FileIncomingTransport) transport).complete(!status.failed());
}
}
}
}
use of org.jumpmind.symmetric.model.ProcessInfoKey in project symmetric-ds by JumpMind.
the class RouterService method insertInitialLoadEvents.
/**
* If a load has been queued up by setting the initial load enabled or
* reverse initial load enabled flags, then the router service will insert
* the reload events. This process will not run at the same time sync
* triggers is running.
*/
protected void insertInitialLoadEvents() {
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), null, ProcessType.INSERT_LOAD_EVENTS));
processInfo.setStatus(ProcessInfo.Status.PROCESSING);
try {
INodeService nodeService = engine.getNodeService();
Node identity = nodeService.findIdentity();
if (identity != null) {
boolean isClusteringEnabled = parameterService.is(ParameterConstants.CLUSTER_LOCKING_ENABLED);
NodeSecurity identitySecurity = nodeService.findNodeSecurity(identity.getNodeId(), !isClusteringEnabled);
if (engine.getParameterService().isRegistrationServer() || (identitySecurity != null && !identitySecurity.isRegistrationEnabled() && identitySecurity.getRegistrationTime() != null)) {
List<NodeSecurity> nodeSecurities = findNodesThatAreReadyForInitialLoad();
if (nodeSecurities != null && nodeSecurities.size() > 0) {
gapDetector.setFullGapAnalysis(true);
boolean reverseLoadFirst = parameterService.is(ParameterConstants.INITIAL_LOAD_REVERSE_FIRST);
boolean isInitialLoadQueued = false;
for (NodeSecurity security : nodeSecurities) {
if (engine.getTriggerRouterService().getActiveTriggerHistories().size() > 0) {
boolean thisMySecurityRecord = security.getNodeId().equals(identity.getNodeId());
boolean reverseLoadQueued = security.isRevInitialLoadEnabled();
boolean initialLoadQueued = security.isInitialLoadEnabled();
boolean registered = security.getRegistrationTime() != null;
if (thisMySecurityRecord && reverseLoadQueued && (reverseLoadFirst || !initialLoadQueued)) {
sendReverseInitialLoad(processInfo);
} else if (!thisMySecurityRecord && registered && initialLoadQueued && (!reverseLoadFirst || !reverseLoadQueued)) {
long ts = System.currentTimeMillis();
engine.getDataService().insertReloadEvents(engine.getNodeService().findNode(security.getNodeId()), false, processInfo);
isInitialLoadQueued = true;
ts = System.currentTimeMillis() - ts;
if (ts > Constants.LONG_OPERATION_THRESHOLD) {
log.warn("Inserted reload events for node {} took longer than expected. It took {} ms", security.getNodeId(), ts);
} else {
log.info("Inserted reload events for node {} in {} ms", security.getNodeId(), ts);
}
}
} else {
List<NodeGroupLink> links = engine.getConfigurationService().getNodeGroupLinksFor(parameterService.getNodeGroupId(), false);
if (links == null || links.size() == 0) {
log.warn("Could not queue up a load for {} because a node group link is NOT configured over which a load could be delivered", security.getNodeId());
} else {
log.warn("Could not queue up a load for {} because sync triggers has not yet run", security.getNodeId());
if (!syncTriggersBeforeInitialLoadAttempted) {
syncTriggersBeforeInitialLoadAttempted = true;
engine.getTriggerRouterService().syncTriggers();
}
}
}
}
if (isInitialLoadQueued) {
gapDetector.setFullGapAnalysis(true);
}
}
processTableRequestLoads(identity, processInfo);
}
}
processInfo.setStatus(ProcessInfo.Status.OK);
} catch (Exception ex) {
processInfo.setStatus(ProcessInfo.Status.ERROR);
log.error("", ex);
}
}
use of org.jumpmind.symmetric.model.ProcessInfoKey in project symmetric-ds by JumpMind.
the class DataGapFastDetector method beforeRouting.
public void beforeRouting() {
maxDataToSelect = parameterService.getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE);
detectInvalidGaps = parameterService.is(ParameterConstants.ROUTING_DETECT_INVALID_GAPS);
reset();
if (isFullGapAnalysis()) {
ProcessInfo processInfo = this.statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), null, ProcessType.GAP_DETECT));
processInfo.setStatus(Status.QUERYING);
log.info("Full gap analysis is running");
long ts = System.currentTimeMillis();
gaps = dataService.findDataGaps();
if (detectInvalidGaps) {
fixOverlappingGaps(gaps, processInfo);
}
queryDataIdMap();
processInfo.setStatus(Status.OK);
log.info("Querying data in gaps from database took {} ms", System.currentTimeMillis() - ts);
afterRouting();
reset();
log.info("Full gap analysis is done after {} ms", System.currentTimeMillis() - ts);
} else if (gaps == null || parameterService.is(ParameterConstants.CLUSTER_LOCKING_ENABLED)) {
ProcessInfo processInfo = this.statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), null, ProcessType.GAP_DETECT));
processInfo.setStatus(Status.QUERYING);
gaps = dataService.findDataGaps();
if (detectInvalidGaps) {
fixOverlappingGaps(gaps, processInfo);
}
processInfo.setStatus(Status.OK);
}
}
Aggregations