use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.
the class FileSyncPullUriHandler method handle.
public void handle(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
String nodeId = ServletUtils.getParameter(req, WebConstants.NODE_ID);
if (StringUtils.isBlank(nodeId)) {
ServletUtils.sendError(res, HttpServletResponse.SC_BAD_REQUEST, "Node must be specified");
return;
} else {
log.debug("File sync pull request received from {}", nodeId);
}
IOutgoingTransport outgoingTransport = createOutgoingTransport(res.getOutputStream(), req.getHeader(WebConstants.HEADER_ACCEPT_CHARSET), engine.getConfigurationService().getSuspendIgnoreChannelLists(nodeId));
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), nodeId, ProcessType.FILE_SYNC_PULL_HANDLER));
try {
res.setContentType("application/zip");
res.addHeader("Content-Disposition", "attachment; filename=\"file-sync.zip\"");
engine.getFileSyncService().sendFiles(processInfo, engine.getNodeService().findNode(nodeId), outgoingTransport);
processInfo.setStatus(Status.OK);
} catch (RuntimeException ex) {
processInfo.setStatus(Status.ERROR);
throw ex;
} finally {
if (outgoingTransport != null) {
outgoingTransport.close();
}
}
}
use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.
the class PullUriHandler method pull.
public void pull(String nodeId, String remoteHost, String remoteAddress, OutputStream outputStream, String encoding, HttpServletResponse res, ChannelMap map) throws IOException {
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId, true);
long ts = System.currentTimeMillis();
try {
ChannelMap remoteSuspendIgnoreChannelsList = configurationService.getSuspendIgnoreChannelLists(nodeId);
map.addSuspendChannels(remoteSuspendIgnoreChannelsList.getSuspendChannels());
map.addIgnoreChannels(remoteSuspendIgnoreChannelsList.getIgnoreChannels());
if (nodeSecurity != null) {
String createdAtNodeId = nodeSecurity.getCreatedAtNodeId();
if (nodeSecurity.isRegistrationEnabled() && (createdAtNodeId == null || createdAtNodeId.equals(nodeService.findIdentityNodeId()))) {
registrationService.registerNode(nodeService.findNode(nodeId), remoteHost, remoteAddress, outputStream, false);
} else {
IOutgoingTransport outgoingTransport = createOutgoingTransport(outputStream, encoding, map);
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), map.getThreadChannel(), nodeId, ProcessType.PULL_HANDLER));
try {
Node targetNode = nodeService.findNode(nodeId, true);
List<OutgoingBatch> batchList = dataExtractorService.extract(processInfo, targetNode, map.getThreadChannel(), outgoingTransport);
logDataReceivedFromPush(targetNode, batchList);
if (processInfo.getStatus() != Status.ERROR) {
addPendingBatchCounts(targetNode.getNodeId(), res);
processInfo.setStatus(Status.OK);
}
} finally {
if (processInfo.getStatus() != Status.OK) {
processInfo.setStatus(Status.ERROR);
}
}
outgoingTransport.close();
}
} else {
log.warn("Node {} does not exist", nodeId);
}
} finally {
statisticManager.incrementNodesPulled(1);
statisticManager.incrementTotalNodesPulledTime(System.currentTimeMillis() - ts);
}
}
use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.
the class InternalTransportManager method getPullTransport.
public IIncomingTransport getPullTransport(Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
final PipedOutputStream respOs = new PipedOutputStream();
final PipedInputStream respIs = new PipedInputStream(respOs);
final ChannelMap suspendIgnoreChannels = symmetricEngine.getConfigurationService().getSuspendIgnoreChannelLists(remote.getNodeId());
runAtClient(remote.getSyncUrl(), null, respOs, new IClientRunnable() {
public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
IOutgoingTransport transport = new InternalOutgoingTransport(respOs, suspendIgnoreChannels, IoConstants.ENCODING);
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), local.getNodeId(), ProcessType.PULL_HANDLER));
try {
engine.getDataExtractorService().extract(processInfo, local, transport);
processInfo.setStatus(Status.OK);
} catch (RuntimeException ex) {
processInfo.setStatus(Status.ERROR);
throw ex;
}
transport.close();
}
});
return new InternalIncomingTransport(respIs);
}
use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.
the class InternalTransportManager method getFilePullTransport.
public IIncomingTransport getFilePullTransport(Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
final PipedOutputStream respOs = new PipedOutputStream();
final PipedInputStream respIs = new PipedInputStream(respOs);
runAtClient(remote.getSyncUrl(), null, respOs, new IClientRunnable() {
public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
IOutgoingTransport transport = new InternalOutgoingTransport(respOs, null);
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), local.getNodeId(), ProcessType.FILE_SYNC_PULL_HANDLER));
try {
engine.getFileSyncService().sendFiles(processInfo, local, transport);
processInfo.setStatus(Status.OK);
} catch (RuntimeException ex) {
processInfo.setStatus(Status.ERROR);
throw ex;
}
transport.close();
}
});
return new InternalIncomingTransport(respIs);
}
use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.
the class PullUriHandler method pull.
public void pull(String nodeId, String remoteHost, String remoteAddress, OutputStream outputStream, String encoding, ChannelMap map) throws IOException {
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId);
long ts = System.currentTimeMillis();
try {
ChannelMap remoteSuspendIgnoreChannelsList = configurationService.getSuspendIgnoreChannelLists(nodeId);
map.addSuspendChannels(remoteSuspendIgnoreChannelsList.getSuspendChannels());
map.addIgnoreChannels(remoteSuspendIgnoreChannelsList.getIgnoreChannels());
if (nodeSecurity != null) {
String createdAtNodeId = nodeSecurity.getCreatedAtNodeId();
if (nodeSecurity.isRegistrationEnabled() && (createdAtNodeId == null || createdAtNodeId.equals(nodeService.findIdentityNodeId()))) {
registrationService.registerNode(nodeService.findNode(nodeId), remoteHost, remoteAddress, outputStream, false);
} else {
IOutgoingTransport outgoingTransport = createOutgoingTransport(outputStream, encoding, map);
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), nodeId, ProcessType.PULL_HANDLER));
try {
Node targetNode = nodeService.findNode(nodeId);
List<OutgoingBatch> batchList = dataExtractorService.extract(processInfo, targetNode, outgoingTransport);
logDataReceivedFromPush(targetNode, batchList);
if (processInfo.getStatus() != Status.ERROR) {
processInfo.setStatus(Status.OK);
}
} finally {
if (processInfo.getStatus() != Status.OK) {
processInfo.setStatus(Status.ERROR);
}
}
outgoingTransport.close();
}
} else {
log.warn("Node {} does not exist", nodeId);
}
} finally {
statisticManager.incrementNodesPulled(1);
statisticManager.incrementTotalNodesPulledTime(System.currentTimeMillis() - ts);
}
}
Aggregations