Search in sources :

Example 1 with ISymmetricEngine

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

the class InternalTransportManager method getPushTransport.

@Override
public IOutgoingWithResponseTransport getPushTransport(final Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
    final PipedOutputStream pushOs = new PipedOutputStream();
    final PipedInputStream pushIs = new PipedInputStream(pushOs);
    final PipedOutputStream respOs = new PipedOutputStream();
    final PipedInputStream respIs = new PipedInputStream(respOs);
    runAtClient(remote.getSyncUrl(), pushIs, respOs, new IClientRunnable() {

        public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
            // This should be basically what the push servlet does ...
            engine.getDataLoaderService().loadDataFromPush(local, pushIs, respOs);
        }
    });
    return new InternalOutgoingWithResponseTransport(pushOs, respIs);
}
Also used : PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Example 2 with ISymmetricEngine

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

the class DataExtractorService method sendOutgoingBatch.

protected OutgoingBatch sendOutgoingBatch(ProcessInfo processInfo, Node targetNode, OutgoingBatch currentBatch, boolean isRetry, IDataWriter dataWriter, BufferedWriter writer, ExtractMode mode) {
    if (currentBatch.getStatus() != Status.OK || ExtractMode.EXTRACT_ONLY == mode) {
        currentBatch.setSentCount(currentBatch.getSentCount() + 1);
        long ts = System.currentTimeMillis();
        IStagedResource extractedBatch = getStagedResource(currentBatch);
        if (extractedBatch != null) {
            if (mode == ExtractMode.FOR_SYM_CLIENT && writer != null) {
                if (!isRetry && parameterService.is(ParameterConstants.OUTGOING_BATCH_COPY_TO_INCOMING_STAGING) && !parameterService.is(ParameterConstants.NODE_OFFLINE, false)) {
                    ISymmetricEngine targetEngine = AbstractSymmetricEngine.findEngineByUrl(targetNode.getSyncUrl());
                    if (targetEngine != null && extractedBatch.isFileResource()) {
                        try {
                            Node sourceNode = nodeService.findIdentity();
                            IStagedResource targetResource = targetEngine.getStagingManager().create(Constants.STAGING_CATEGORY_INCOMING, Batch.getStagedLocation(false, sourceNode.getNodeId()), currentBatch.getBatchId());
                            SymmetricUtils.copyFile(extractedBatch.getFile(), targetResource.getFile());
                            targetResource.setState(State.DONE);
                            isRetry = true;
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
                Channel channel = configurationService.getChannel(currentBatch.getChannelId());
                DataContext ctx = new DataContext();
                transferFromStaging(mode, BatchType.EXTRACT, currentBatch, isRetry, extractedBatch, writer, ctx, channel.getMaxKBytesPerSecond());
            } else {
                IDataReader dataReader = new ProtocolDataReader(BatchType.EXTRACT, currentBatch.getNodeId(), extractedBatch);
                DataContext ctx = new DataContext();
                ctx.put(Constants.DATA_CONTEXT_TARGET_NODE, targetNode);
                ctx.put(Constants.DATA_CONTEXT_SOURCE_NODE, nodeService.findIdentity());
                new DataProcessor(dataReader, new ProcessInfoDataWriter(dataWriter, processInfo), "send from stage").process(ctx);
                if (dataReader.getStatistics().size() > 0) {
                    Statistics stats = dataReader.getStatistics().values().iterator().next();
                    statisticManager.incrementDataSent(currentBatch.getChannelId(), stats.get(DataReaderStatistics.READ_RECORD_COUNT));
                    long byteCount = stats.get(DataReaderStatistics.READ_BYTE_COUNT);
                    statisticManager.incrementDataBytesSent(currentBatch.getChannelId(), byteCount);
                } else {
                    log.warn("Could not find recorded statistics for batch {}", currentBatch.getNodeBatchId());
                }
            }
        } else {
            throw new IllegalStateException(String.format("Could not find the staged resource for batch %s", currentBatch.getNodeBatchId()));
        }
        currentBatch = requeryIfEnoughTimeHasPassed(ts, currentBatch);
    }
    return currentBatch;
}
Also used : IDataReader(org.jumpmind.symmetric.io.data.IDataReader) Node(org.jumpmind.symmetric.model.Node) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) Channel(org.jumpmind.symmetric.model.Channel) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) DataProcessor(org.jumpmind.symmetric.io.data.DataProcessor) Statistics(org.jumpmind.util.Statistics) DataReaderStatistics(org.jumpmind.symmetric.io.data.reader.DataReaderStatistics) CancellationException(java.util.concurrent.CancellationException) SymmetricException(org.jumpmind.symmetric.SymmetricException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ProtocolException(org.jumpmind.symmetric.io.data.ProtocolException) TimeoutException(java.util.concurrent.TimeoutException) IoException(org.jumpmind.exception.IoException) DataContext(org.jumpmind.symmetric.io.data.DataContext) IStagedResource(org.jumpmind.symmetric.io.stage.IStagedResource) ProtocolDataReader(org.jumpmind.symmetric.io.data.reader.ProtocolDataReader) ProcessInfoDataWriter(org.jumpmind.symmetric.model.ProcessInfoDataWriter)

Example 3 with ISymmetricEngine

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

the class DataGapDetectorTest method setUp.

@Before
public void setUp() throws Exception {
    sqlTemplate = mock(ISqlTemplate.class);
    sqlTransaction = mock(ISqlTransaction.class);
    when(sqlTemplate.startSqlTransaction()).thenReturn(sqlTransaction);
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
    symmetricDialect = mock(AbstractSymmetricDialect.class);
    when(symmetricDialect.getPlatform()).thenReturn(platform);
    when(symmetricDialect.supportsTransactionViews()).thenReturn(false);
    when(symmetricDialect.getDatabaseTime()).thenReturn(0L);
    parameterService = mock(ParameterService.class);
    when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
    when(parameterService.getLong(ParameterConstants.ROUTING_STALE_DATA_ID_GAP_TIME)).thenReturn(60000000L);
    when(parameterService.getInt(ParameterConstants.DATA_ID_INCREMENT_BY)).thenReturn(1);
    when(parameterService.getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE)).thenReturn(50000000L);
    when(parameterService.getLong(ParameterConstants.DBDIALECT_ORACLE_TRANSACTION_VIEW_CLOCK_SYNC_THRESHOLD_MS)).thenReturn(60000L);
    when(parameterService.getLong(ParameterConstants.ROUTING_STALE_GAP_BUSY_EXPIRE_TIME)).thenReturn(60000L);
    when(parameterService.is(ParameterConstants.ROUTING_DETECT_INVALID_GAPS)).thenReturn(true);
    when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAP_CHANGES)).thenReturn(1000);
    IExtensionService extensionService = mock(ExtensionService.class);
    ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getStatisticManager()).thenReturn(statisticManager);
    when(engine.getNodeService()).thenReturn(nodeService);
    when(engine.getDataService()).thenReturn(dataService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    when(engine.getExtensionService()).thenReturn(extensionService);
    routerService = new RouterService(engine);
    when(engine.getRouterService()).thenReturn(routerService);
    contextService = mock(ContextService.class);
    dataService = mock(DataService.class);
    statisticManager = mock(StatisticManager.class);
    when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
    nodeService = mock(NodeService.class);
    when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
    detector = newGapDetector();
    detector.setFullGapAnalysis(false);
}
Also used : RouterService(org.jumpmind.symmetric.service.impl.RouterService) IRouterService(org.jumpmind.symmetric.service.IRouterService) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) IContextService(org.jumpmind.symmetric.service.IContextService) ContextService(org.jumpmind.symmetric.service.impl.ContextService) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) IParameterService(org.jumpmind.symmetric.service.IParameterService) ParameterService(org.jumpmind.symmetric.service.impl.ParameterService) INodeService(org.jumpmind.symmetric.service.INodeService) NodeService(org.jumpmind.symmetric.service.impl.NodeService) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) DataService(org.jumpmind.symmetric.service.impl.DataService) IDataService(org.jumpmind.symmetric.service.IDataService) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) IExtensionService(org.jumpmind.symmetric.service.IExtensionService) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) StatisticManager(org.jumpmind.symmetric.statistic.StatisticManager) AbstractSymmetricDialect(org.jumpmind.symmetric.db.AbstractSymmetricDialect) Before(org.junit.Before)

Example 4 with ISymmetricEngine

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

the class XmlPublisherDataRouterTest method setUp.

@Before
public void setUp() {
    ISymmetricEngine engine = mock(ISymmetricEngine.class);
    when(engine.getSymmetricDialect()).thenReturn(mock(AbstractSymmetricDialect.class));
    when(engine.getSymmetricDialect().getBinaryEncoding()).thenReturn(BinaryEncoding.BASE64);
    table = Table.buildTable(TABLE_NAME, new String[] { "ID" }, new String[] { "ID", "DATA" });
    context = new SimpleRouterContext();
    router = new XmlPublisherDataRouter();
    router.setSymmetricEngine(engine);
    router.setTimeStringGenerator(new XmlPublisherDatabaseWriterFilter.ITimeGenerator() {

        public String getTime() {
            return "test";
        }
    });
    List<String> groupByColumnNames = new ArrayList<String>();
    groupByColumnNames.add("ID");
    router.setGroupByColumnNames(groupByColumnNames);
    output = new Output();
    router.setPublisher(output);
}
Also used : ArrayList(java.util.ArrayList) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) AbstractSymmetricDialect(org.jumpmind.symmetric.db.AbstractSymmetricDialect) SimpleRouterContext(org.jumpmind.symmetric.route.SimpleRouterContext) Before(org.junit.Before)

Example 5 with ISymmetricEngine

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

the class SymmetricEngineHolder method uninstallEngine.

public void uninstallEngine(ISymmetricEngine engine) {
    Node node = engine.getNodeService().getCachedIdentity();
    String engineName = engine.getEngineName();
    File file = new SymmetricAdmin("uninstall", "", "").findPropertiesFileForEngineWithName(engineName);
    engine.uninstall();
    engine.destroy();
    if (file != null) {
        file.delete();
    }
    getEngines().remove(engineName);
    for (ISymmetricEngine existingEngine : this.getEngines().values()) {
        existingEngine.removeAndCleanupNode(node.getNodeId());
    }
}
Also used : SymmetricAdmin(org.jumpmind.symmetric.SymmetricAdmin) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) File(java.io.File)

Aggregations

ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)35 IOException (java.io.IOException)12 INodeService (org.jumpmind.symmetric.service.INodeService)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 InputStream (java.io.InputStream)7 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)7 Node (org.jumpmind.symmetric.model.Node)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 OutputStream (java.io.OutputStream)6 PipedInputStream (java.io.PipedInputStream)6 PipedOutputStream (java.io.PipedOutputStream)6 NotImplementedException (org.apache.commons.lang.NotImplementedException)6 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)6 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)6 File (java.io.File)5 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)5 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)5 IParameterService (org.jumpmind.symmetric.service.IParameterService)5