Search in sources :

Example 6 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class TestBootstrap method testBootstrapService.

@Test
public void testBootstrapService() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException, BootstrapProcessingException, DatabusException, BootstrapDatabaseTooOldException, BootstrapDBException {
    final Logger log = Logger.getLogger("TestBootstrap.testBootstrapService");
    EventProcessor processorCallback = new EventProcessor();
    BootstrapConfig config = new BootstrapConfig();
    BootstrapReadOnlyConfig staticConfig = config.build();
    String[] sources = new String[4];
    sources[0] = "TestBootstrap.testBootstrapService.event";
    sources[1] = "TestBootstrap.testBootstrapService.event1";
    sources[2] = "TestBootstrap.testBootstrapService.event2";
    sources[3] = "TestBootstrap.testBootstrapService.event3";
    // Create the tables for all the sources before starting up the threads
    BootstrapConn _bootstrapConn = new BootstrapConn();
    final boolean autoCommit = true;
    _bootstrapConn.initBootstrapConn(autoCommit, staticConfig.getBootstrapDBUsername(), staticConfig.getBootstrapDBPassword(), staticConfig.getBootstrapDBHostname(), staticConfig.getBootstrapDBName());
    BootstrapDBMetaDataDAO dao = new BootstrapDBMetaDataDAO(_bootstrapConn, staticConfig.getBootstrapDBHostname(), staticConfig.getBootstrapDBUsername(), staticConfig.getBootstrapDBPassword(), staticConfig.getBootstrapDBName(), autoCommit);
    for (String source : sources) {
        SourceStatusInfo srcStatusInfo = dao.getSrcIdStatusFromDB(source, false);
        if (srcStatusInfo.getSrcId() >= 0) {
            dao.dropSourceInDB(srcStatusInfo.getSrcId());
        }
        dao.addNewSourceInDB(source, BootstrapProducerStatus.ACTIVE);
    }
    setBootstrapLoginfoTable(_bootstrapConn, 1, 1);
    DatabusBootstrapClient s = new DatabusBootstrapClient(sources);
    Checkpoint cp;
    while ((cp = s.getNextBatch(10, processorCallback)).getConsumptionMode() != DbusClientMode.ONLINE_CONSUMPTION) {
        log.debug(cp);
    }
}
Also used : BootstrapReadOnlyConfig(com.linkedin.databus.bootstrap.common.BootstrapReadOnlyConfig) Checkpoint(com.linkedin.databus.core.Checkpoint) BootstrapConn(com.linkedin.databus.bootstrap.common.BootstrapConn) BootstrapConfig(com.linkedin.databus.bootstrap.common.BootstrapConfig) BootstrapDBMetaDataDAO(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO) Logger(org.apache.log4j.Logger) SourceStatusInfo(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO.SourceStatusInfo) Test(org.testng.annotations.Test)

Example 7 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class ClusterCheckpointPersistenceProvider method loadCheckpoint.

/**
 * Function called by Databus Client to load checkpoint;
 */
@Override
public Checkpoint loadCheckpoint(List<String> sourceNames) {
    if (_propertyStore != null) {
        String key = makeKey(sourceNames);
        Checkpoint cp = getCheckpoint(key);
        return cp;
    }
    return null;
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint)

Example 8 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class RelayEventProducer method getCheckpoint.

protected Checkpoint getCheckpoint(long sinceSCN, MaxSCNReaderWriter scnReaderWriter) {
    long scn = sinceSCN;
    if ((scn < 0) && (_scnReaderWriter != null)) {
        try {
            scn = _scnReaderWriter.getMaxScn();
        } catch (DatabusException e) {
            LOG.info("Cannot read persisted SCN " + e);
            scn = -1;
        }
    }
    // return no cp if unable to read from saved SCN
    if (scn <= 0) {
        return null;
    }
    Checkpoint cp = new Checkpoint();
    cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
    // always have greater than semantic
    cp.setWindowOffset(-1);
    cp.setWindowScn(scn);
    return cp;
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) DatabusException(com.linkedin.databus2.core.DatabusException)

Example 9 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class RelayEventProducer method start.

@Override
public synchronized void start(long sinceSCN) {
    if (_dbusConnection != null && !_dbusConnection.getConnectionStatus().isRunningStatus()) {
        LOG.info("In RelayEventProducer start:  running =" + _dbusConnection.getConnectionStatus().isRunningStatus());
        // translate relay saved scn to client checkpoint
        LOG.info("Requested sinceSCN = " + sinceSCN);
        Checkpoint cp = getCheckpoint(sinceSCN, _scnReaderWriter);
        // check if the relay chaining consumer has been initialized [it could when the leader passes its active buffer]
        if ((cp != null) && (_consumerEventBuffer.getStartSCN() < 0)) {
            // note that the restartScnOffset comes into the picture only iff the buffer is empty
            long savedScn = cp.getWindowScn();
            LOG.info("Checkpoint read = " + savedScn + " restartScnOffset=" + _restartScnOffset);
            long newScn = (savedScn >= _restartScnOffset) ? savedScn - _restartScnOffset : 0;
            cp.setWindowScn(newScn);
            LOG.info("Setting start scn of event buffer to " + cp.getWindowScn());
            _consumerEventBuffer.setStartSCN(cp.getWindowScn());
        }
        LOG.info("Eventbuffer start scn = " + _consumerEventBuffer.getStartSCN());
        // now set the checkpoint in the databus client fetcher
        _dbusConnection.getRelayPullThread().getConnectionState().setCheckpoint(cp);
        // start the connection
        _dbusConnection.start();
        _relayLogger.setDaemon(true);
        _relayLogger.start();
    } else {
        if (_dbusConnection == null) {
            LOG.error("Not started! Connection is null");
        } else {
            LOG.warn("dbusConnection status=" + _dbusConnection.getConnectionStatus().getStatus());
        }
    }
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint)

Example 10 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class TestRelayCommandsLocal method doTestOneDataStreamCommand.

private void doTestOneDataStreamCommand() throws Exception {
    // try to read it
    Checkpoint cp = Checkpoint.createFlexibleCheckpoint();
    String streamRequest = "/stream?sources=100&size=100000&output=json&checkPoint=" + cp.toString();
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, streamRequest);
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    HttpResponse respObj = respHandler.getResponse();
    assertNull("/stream returned unexpected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    if (LOG.isDebugEnabled()) {
        LOG.debug("/stream response:" + new String(respHandler.getReceivedBytes()));
    }
    ObjectMapper objMapper = new ObjectMapper();
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    objMapper.readValue(in, new TypeReference<Map<String, String>>() {
    });
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Checkpoint(com.linkedin.databus.core.Checkpoint) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

Checkpoint (com.linkedin.databus.core.Checkpoint)139 Test (org.testng.annotations.Test)88 ArrayList (java.util.ArrayList)46 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)42 HashMap (java.util.HashMap)42 List (java.util.List)42 IdNamePair (com.linkedin.databus.core.util.IdNamePair)34 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)29 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)27 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)25 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)23 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)22 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)20 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)16 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)16 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)15 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)15 IOException (java.io.IOException)15 Logger (org.apache.log4j.Logger)14 InetSocketAddress (java.net.InetSocketAddress)13