Search in sources :

Example 1 with IdNamePair

use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.

the class SourceIdNameRegistry method updateFromIdNamePairs.

public void updateFromIdNamePairs(Collection<IdNamePair> newPairs) {
    ArrayList<LogicalSource> srcCollection = new ArrayList<LogicalSource>(newPairs.size());
    for (IdNamePair pair : newPairs) srcCollection.add(new LogicalSource(pair.getId().intValue(), pair.getName()));
    update(srcCollection);
}
Also used : ArrayList(java.util.ArrayList) IdNamePair(com.linkedin.databus.core.util.IdNamePair) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource)

Example 2 with IdNamePair

use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.

the class SchemaMetaDataManager method updateAndGetNewSrcId.

public short updateAndGetNewSrcId(String dbName, String srcName) throws DatabusException {
    _maxSrcId++;
    dbName = dbName.toLowerCase(Locale.ENGLISH);
    if (null != _idNameRegistry.getSource(srcName))
        throw new DatabusException("Source Name (" + srcName + ") already available in the schema registry !!");
    TreeSet<String> s = null;
    if (_physicalToLogicalSrcMap.containsKey(dbName)) {
        s = _physicalToLogicalSrcMap.get(dbName);
    } else {
        s = new TreeSet<String>();
        _physicalToLogicalSrcMap.put(dbName, s);
    }
    s.add(srcName);
    IdNamePair pair = new IdNamePair(Long.valueOf(_maxSrcId), srcName);
    LogicalSource src = new LogicalSource(pair);
    List<LogicalSource> newSources = new ArrayList<LogicalSource>();
    newSources.add(src);
    _idNameRegistry.add(newSources);
    return _maxSrcId;
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) ArrayList(java.util.ArrayList) IdNamePair(com.linkedin.databus.core.util.IdNamePair) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource)

Example 3 with IdNamePair

use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.

the class HttpRelay method main.

public static void main(String[] args) throws Exception {
    Cli cli = new Cli();
    cli.processCommandLineArgs(args);
    cli.parseRelayConfig();
    StaticConfig staticConfig = cli.getRelayConfigBuilder().build();
    HttpRelay relay = new HttpRelay(staticConfig, cli.getPhysicalSourceStaticConfigs());
    RequestProcessorRegistry processorRegistry = relay.getProcessorRegistry();
    //Changes to add schemaId to event; DDSDBUS-3421
    //The long term fix is to remove DatabusEventRandomProducer in favour of RelayEventGenerator
    //The medium term fix is to send SchemaRegistry to DatabusEventRandomProducer, but move RandomProducer to databus-relay-impl (from databus-core-impl)
    //Reason: SchemaHelper classes required to parse/generate schemaId from schemaRegistry requires databus-schemas-core which depends on databus-core-impl
    SchemaRegistryService sr = relay.getSchemaRegistryService();
    HashMap<Long, byte[]> schemaIds = new HashMap<Long, byte[]>(staticConfig.getSourceIds().size());
    for (IdNamePair pair : staticConfig.getSourceIds()) {
        LOG.info("Http Relay Schema Reg:" + pair.getName() + " id=" + pair.getId());
        String schemaStr = sr.fetchLatestSchemaBySourceName(pair.getName());
        if (schemaStr != null) {
            Schema s = Schema.parse(schemaStr);
            byte[] sid = SchemaHelper.getSchemaId(s.toString());
            LOG.info("Found schema! Adding schemaId for sourceName=" + pair.getName() + " id=" + pair.getId() + " schemaId=" + sid);
            schemaIds.put(pair.getId(), sid);
        } else {
            byte[] defaultSid = "abcde".getBytes(Charset.defaultCharset());
            LOG.info("Didn't find schema! Adding default schemaId for sourceName=" + pair.getName() + "id=" + pair.getId() + " schemaId=" + defaultSid);
            schemaIds.put(pair.getId(), defaultSid);
        }
    }
    DatabusEventProducer randomEventProducer = new DatabusEventRandomProducer(relay.getEventBuffer(), 10, 100, 1000, staticConfig.getSourceIds(), schemaIds);
    // specify stats collector for this producer
    ((DatabusEventRandomProducer) randomEventProducer).setStatsCollector(relay.getInboundEventStatisticsCollector());
    processorRegistry.register(EchoRequestProcessor.COMMAND_NAME, new EchoRequestProcessor(null));
    processorRegistry.register(SleepRequestProcessor.COMMAND_NAME, new SleepRequestProcessor(null));
    processorRegistry.register(GenerateDataEventsRequestProcessor.COMMAND_NAME, new GenerateDataEventsRequestProcessor(null, relay, randomEventProducer));
    processorRegistry.register(LoadDataEventsRequestProcessor.COMMAND_NAME, new LoadDataEventsRequestProcessor(relay.getDefaultExecutorService(), relay));
    LOG.info("source = " + relay.getSourcesIdNameRegistry().getAllSources());
    try {
        relay.registerShutdownHook();
        relay.startAndBlock();
    } catch (Exception e) {
        LOG.error("Error starting the relay", e);
    }
    LOG.info("Exiting relay");
}
Also used : DatabusEventRandomProducer(com.linkedin.databus.core.util.DatabusEventRandomProducer) EchoRequestProcessor(com.linkedin.databus2.core.container.request.EchoRequestProcessor) LoadDataEventsRequestProcessor(com.linkedin.databus.container.request.LoadDataEventsRequestProcessor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FileSystemSchemaRegistryService(com.linkedin.databus2.schemas.FileSystemSchemaRegistryService) SchemaRegistryService(com.linkedin.databus2.schemas.SchemaRegistryService) Schema(org.apache.avro.Schema) DataSourcesStaticConfig(com.linkedin.databus2.relay.config.DataSourcesStaticConfig) SchemaRegistryStaticConfig(com.linkedin.databus2.schemas.SchemaRegistryStaticConfig) PhysicalSourceStaticConfig(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig) SleepRequestProcessor(com.linkedin.databus2.core.container.request.SleepRequestProcessor) BufferNotFoundException(com.linkedin.databus2.core.BufferNotFoundException) DatabusException(com.linkedin.databus2.core.DatabusException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) UnsupportedKeyException(com.linkedin.databus.core.UnsupportedKeyException) SQLException(java.sql.SQLException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) EventCreationException(com.linkedin.databus2.producers.EventCreationException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) RequestProcessorRegistry(com.linkedin.databus2.core.container.request.RequestProcessorRegistry) IdNamePair(com.linkedin.databus.core.util.IdNamePair) DatabusEventProducer(com.linkedin.databus.core.util.DatabusEventProducer) GenerateDataEventsRequestProcessor(com.linkedin.databus.container.request.GenerateDataEventsRequestProcessor)

Example 4 with IdNamePair

use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.

the class SourcesRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    int protoVersion = request.getOptionalIntParam(VERSION_PARAM_NAME, 1);
    ObjectMapper mapper = new ObjectMapper();
    StringWriter out = new StringWriter(10240);
    Collection<LogicalSource> sources = _relay.getSourcesIdNameRegistry().getAllSources();
    if (1 == protoVersion) {
        ArrayList<IdNamePair> sourcePairs = new ArrayList<IdNamePair>(sources.size());
        for (LogicalSource source : sources) sourcePairs.add(new IdNamePair(source.getId().longValue(), source.getName()));
        mapper.writeValue(out, sourcePairs);
    } else if (2 == protoVersion)
        mapper.writeValue(out, sources);
    else
        throw new InvalidRequestParamValueException(COMMAND_NAME, VERSION_PARAM_NAME, Integer.toString(protoVersion));
    byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
    request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
    HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
    if (null != relayStatsCollector) {
        HttpStatisticsCollector connStatsCollector = (HttpStatisticsCollector) request.getParams().get(relayStatsCollector.getName());
        if (null != connStatsCollector) {
            connStatsCollector.registerSourcesCall();
        } else {
            relayStatsCollector.registerSourcesCall();
        }
    }
    return request;
}
Also used : StringWriter(java.io.StringWriter) HttpStatisticsCollector(com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector) ArrayList(java.util.ArrayList) IdNamePair(com.linkedin.databus.core.util.IdNamePair) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 5 with IdNamePair

use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.

the class TestRelayCommandsLocal method testSourcesTrackingCommand.

@Test
public void testSourcesTrackingCommand() throws Exception {
    LOG.debug("\n\nstarting testSourcesTrackingCommand()\n");
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/sources");
    httpRequest.setHeader(DatabusHttpHeaders.DBUS_CLIENT_HOST_HDR, "localhost");
    httpRequest.setHeader(DatabusHttpHeaders.DBUS_CLIENT_SERVICE_HDR, "unittestclient");
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    ObjectMapper objMapper = new ObjectMapper();
    List<IdNamePair> res = objMapper.readValue(in, new TypeReference<List<IdNamePair>>() {
    });
    assertNotNull("no result", res);
    if (LOG.isDebugEnabled()) {
        LOG.debug("/sources response:" + new String(respHandler.getReceivedBytes()));
    }
    HashSet<IdNamePair> origSet = new HashSet<IdNamePair>(_staticConfig.getSourceIds());
    HashSet<IdNamePair> resSet = new HashSet<IdNamePair>(res);
    Assert.assertEquals(origSet, resSet);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) List(java.util.List) IdNamePair(com.linkedin.databus.core.util.IdNamePair) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

IdNamePair (com.linkedin.databus.core.util.IdNamePair)77 ArrayList (java.util.ArrayList)66 HashMap (java.util.HashMap)60 Test (org.testng.annotations.Test)56 List (java.util.List)51 Checkpoint (com.linkedin.databus.core.Checkpoint)48 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)47 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 Logger (org.apache.log4j.Logger)21 DatabusStreamConsumer (com.linkedin.databus.client.pub.DatabusStreamConsumer)18 DbusEvent (com.linkedin.databus.core.DbusEvent)18 Hashtable (java.util.Hashtable)18 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)17 DatabusV2ConsumerRegistration (com.linkedin.databus.client.consumer.DatabusV2ConsumerRegistration)16 MultiConsumerCallback (com.linkedin.databus.client.consumer.MultiConsumerCallback)16 StreamConsumerCallbackFactory (com.linkedin.databus.client.consumer.StreamConsumerCallbackFactory)16 UncaughtExceptionTrackingThread (com.linkedin.databus.core.util.UncaughtExceptionTrackingThread)16 SelectingDatabusCombinedConsumer (com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer)14 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)14