Search in sources :

Example 1 with RequestProcessorRegistry

use of com.linkedin.databus2.core.container.request.RequestProcessorRegistry in project databus by linkedin.

the class TestRelayCommandsLocal method setUp.

@BeforeMethod
public void setUp() throws Exception {
    // creates an event factory for us
    _relay = new HttpRelay(_staticConfig, null);
    _eventBuffer = _relay.getEventBuffer();
    DatabusEventProducer randomEventProducer = new DatabusEventRandomProducer(_eventBuffer, 10, 1, 10, _staticConfig.getSourceIds(), null, null);
    RequestProcessorRegistry processorRegistry = _relay.getProcessorRegistry();
    processorRegistry.register(EchoRequestProcessor.COMMAND_NAME, new EchoRequestProcessor(null));
    processorRegistry.register(GenerateDataEventsRequestProcessor.COMMAND_NAME, new GenerateDataEventsRequestProcessor(null, _relay, randomEventProducer));
    // Configure the server.
    _bootstrap = new ServerBootstrap(new DefaultLocalServerChannelFactory());
    // Set up the event pipeline factory.
    _bootstrap.setPipelineFactory(new HttpServerPipelineFactory(_relay));
    _serverAddress = new LocalAddress(10);
    _serverChannel = _bootstrap.bind(_serverAddress);
}
Also used : DatabusEventRandomProducer(com.linkedin.databus.core.util.DatabusEventRandomProducer) HttpServerPipelineFactory(com.linkedin.databus2.core.container.netty.HttpServerPipelineFactory) EchoRequestProcessor(com.linkedin.databus2.core.container.request.EchoRequestProcessor) DefaultLocalServerChannelFactory(org.jboss.netty.channel.local.DefaultLocalServerChannelFactory) LocalAddress(org.jboss.netty.channel.local.LocalAddress) RequestProcessorRegistry(com.linkedin.databus2.core.container.request.RequestProcessorRegistry) DatabusEventProducer(com.linkedin.databus.core.util.DatabusEventProducer) GenerateDataEventsRequestProcessor(com.linkedin.databus.container.request.GenerateDataEventsRequestProcessor) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with RequestProcessorRegistry

use of com.linkedin.databus2.core.container.request.RequestProcessorRegistry in project databus by linkedin.

the class DatabusRelayMain method addOneProducer.

/**
 * overrides HTTP relay method
 */
@Override
public void addOneProducer(PhysicalSourceStaticConfig pConfig) throws DatabusException, EventCreationException, UnsupportedKeyException, SQLException, InvalidConfigException {
    // Register a command to allow start/stop/status of the relay
    List<EventProducer> plist = new ArrayList<EventProducer>();
    PhysicalPartition pPartition = pConfig.getPhysicalPartition();
    MaxSCNReaderWriter maxScnReaderWriters = _maxScnReaderWriters.getOrCreateHandler(pPartition);
    LOG.info("Starting server container with maxScnReaderWriter:" + maxScnReaderWriters);
    // Get the event buffer
    DbusEventBufferAppendable dbusEventBuffer = getEventBuffer().getDbusEventBufferAppendable(pPartition);
    // Get the schema registry service
    SchemaRegistryService schemaRegistryService = getSchemaRegistryService();
    // Get a stats collector per physical source
    addPhysicalPartitionCollectors(pPartition);
    String statsCollectorName = pPartition.toSimpleString();
    /*
		 * _inBoundStatsCollectors.addStatsCollector(statsCollectorName, new
		 * DbusEventsStatisticsCollector(getContainerStaticConfig().getId(),
		 * statsCollectorName+".inbound", true, false, getMbeanServer()));
		 *
		 * _outBoundStatsCollectors.addStatsCollector(statsCollectorName, new
		 * DbusEventsStatisticsCollector(getContainerStaticConfig().getId(),
		 * statsCollectorName+".outbound", true, false, getMbeanServer()));
		 */
    // Create the event producer
    String uri = pConfig.getUri();
    if (uri == null)
        throw new DatabusException("Uri is required to start the relay");
    uri = uri.trim();
    EventProducer producer = null;
    if (uri.startsWith("jdbc:")) {
        SourceType sourceType = pConfig.getReplBitSetter().getSourceType();
        if (SourceType.TOKEN.equals(sourceType))
            throw new DatabusException("Token Source-type for Replication bit setter config cannot be set for trigger-based Databus relay !!");
        // if a buffer for this partiton exists - we are overwri
        producer = new OracleEventProducerFactory().buildEventProducer(pConfig, schemaRegistryService, dbusEventBuffer, getMbeanServer(), _inBoundStatsCollectors.getStatsCollector(statsCollectorName), maxScnReaderWriters);
    } else if (uri.startsWith("mock")) {
        // Get all relevant pConfig attributes
        // TODO add real instantiation
        EventProducerServiceProvider mockProvider = _producersRegistry.getEventProducerServiceProvider("mock");
        if (null == mockProvider) {
            throw new DatabusRuntimeException("relay event producer not available: " + "mock");
        }
        producer = mockProvider.createProducer(pConfig, schemaRegistryService, dbusEventBuffer, _inBoundStatsCollectors.getStatsCollector(statsCollectorName), maxScnReaderWriters);
    } else if (uri.startsWith("gg:")) {
        producer = new GoldenGateEventProducer(pConfig, schemaRegistryService, dbusEventBuffer, _inBoundStatsCollectors.getStatsCollector(statsCollectorName), maxScnReaderWriters);
    } else if (uri.startsWith("mysql:")) {
        LOG.info("Adding OpenReplicatorEventProducer for uri :" + uri);
        final String serviceName = "or";
        EventProducerServiceProvider orProvider = _producersRegistry.getEventProducerServiceProvider(serviceName);
        if (null == orProvider) {
            throw new DatabusRuntimeException("relay event producer not available: " + serviceName);
        }
        producer = orProvider.createProducer(pConfig, schemaRegistryService, dbusEventBuffer, _inBoundStatsCollectors.getStatsCollector(statsCollectorName), maxScnReaderWriters);
    } else {
        // Get all relevant pConfig attributes and initialize the nettyThreadPool objects
        RelayEventProducer.DatabusClientNettyThreadPools nettyThreadPools = new RelayEventProducer.DatabusClientNettyThreadPools(0, getNetworkTimeoutTimer(), getBossExecutorService(), getIoExecutorService(), getHttpChannelGroup());
        producer = new RelayEventProducer(pConfig, dbusEventBuffer, _inBoundStatsCollectors.getStatsCollector(statsCollectorName), maxScnReaderWriters, nettyThreadPools);
    }
    // if a buffer for this partiton exists - we are overwriting it.
    _producers.put(pPartition, producer);
    plist.add(producer);
    // append 'monitoring event producer'
    if (producer instanceof OracleEventProducer) {
        MonitoringEventProducer monitoringProducer = new MonitoringEventProducer("dbMonitor." + pPartition.toSimpleString(), pConfig.getName(), pConfig.getUri(), ((OracleEventProducer) producer).getMonitoredSourceInfos(), getMbeanServer());
        _monitoringProducers.put(pPartition, monitoringProducer);
        plist.add(monitoringProducer);
    }
    if (_csEventRequestProcessor == null)
        _csEventRequestProcessor = new ControlSourceEventsRequestProcessor(null, this, plist);
    else
        _csEventRequestProcessor.addEventProducers(plist);
    RequestProcessorRegistry processorRegistry = getProcessorRegistry();
    processorRegistry.reregister(ControlSourceEventsRequestProcessor.COMMAND_NAME, _csEventRequestProcessor);
}
Also used : MaxSCNReaderWriter(com.linkedin.databus2.core.seq.MaxSCNReaderWriter) DbusEventBufferAppendable(com.linkedin.databus.core.DbusEventBufferAppendable) SchemaRegistryService(com.linkedin.databus2.schemas.SchemaRegistryService) SourceType(com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.SourceType) OracleEventProducer(com.linkedin.databus2.producers.db.OracleEventProducer) RelayEventProducer(com.linkedin.databus2.producers.RelayEventProducer) EventProducer(com.linkedin.databus2.producers.EventProducer) ArrayList(java.util.ArrayList) OracleEventProducer(com.linkedin.databus2.producers.db.OracleEventProducer) EventProducerServiceProvider(com.linkedin.databus2.producers.EventProducerServiceProvider) ControlSourceEventsRequestProcessor(com.linkedin.databus.container.request.ControlSourceEventsRequestProcessor) DatabusException(com.linkedin.databus2.core.DatabusException) RequestProcessorRegistry(com.linkedin.databus2.core.container.request.RequestProcessorRegistry) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) DatabusRuntimeException(com.linkedin.databus.core.DatabusRuntimeException) RelayEventProducer(com.linkedin.databus2.producers.RelayEventProducer)

Example 3 with RequestProcessorRegistry

use of com.linkedin.databus2.core.container.request.RequestProcessorRegistry 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 RequestProcessorRegistry

use of com.linkedin.databus2.core.container.request.RequestProcessorRegistry in project databus by linkedin.

the class BootstrapHttpServer method initializeBootstrapServerCommandProcessors.

protected void initializeBootstrapServerCommandProcessors() throws DatabusException {
    LOG.info("Initializing Bootstrap HTTP Server");
    LOG.info("Config=" + _bootstrapServerConfig);
    try {
        RequestProcessorRegistry processorRegistry = getProcessorRegistry();
        processorRegistry.register(ConfigRequestProcessor.COMMAND_NAME, new ConfigRequestProcessor(null, this));
        processorRegistry.register(BootstrapRequestProcessor.COMMAND_NAME, new BootstrapRequestProcessor(null, _bootstrapServerConfig, this));
        processorRegistry.register(StartSCNRequestProcessor.COMMAND_NAME, new StartSCNRequestProcessor(null, _bootstrapServerConfig, this));
        processorRegistry.register(TargetSCNRequestProcessor.COMMAND_NAME, new TargetSCNRequestProcessor(null, _bootstrapServerConfig, this));
        processorRegistry.register(ContainerOperationProcessor.COMMAND_NAME, new ContainerOperationProcessor(null, this));
    } catch (SQLException sqle) {
        throw new DatabusException("command registration failed", sqle);
    } catch (InstantiationException e) {
        throw new DatabusException("command registration failed", e);
    } catch (IllegalAccessException e) {
        throw new DatabusException("command registration failed", e);
    } catch (ClassNotFoundException e) {
        throw new DatabusException("command registration failed", e);
    }
    LOG.info("Done Initializing Bootstrap HTTP Server");
}
Also used : RequestProcessorRegistry(com.linkedin.databus2.core.container.request.RequestProcessorRegistry) DatabusException(com.linkedin.databus2.core.DatabusException) SQLException(java.sql.SQLException) ContainerOperationProcessor(com.linkedin.databus2.core.container.request.ContainerOperationProcessor) ConfigRequestProcessor(com.linkedin.databus2.core.container.request.ConfigRequestProcessor)

Aggregations

RequestProcessorRegistry (com.linkedin.databus2.core.container.request.RequestProcessorRegistry)4 DatabusException (com.linkedin.databus2.core.DatabusException)3 GenerateDataEventsRequestProcessor (com.linkedin.databus.container.request.GenerateDataEventsRequestProcessor)2 DatabusEventProducer (com.linkedin.databus.core.util.DatabusEventProducer)2 DatabusEventRandomProducer (com.linkedin.databus.core.util.DatabusEventRandomProducer)2 EchoRequestProcessor (com.linkedin.databus2.core.container.request.EchoRequestProcessor)2 SchemaRegistryService (com.linkedin.databus2.schemas.SchemaRegistryService)2 SQLException (java.sql.SQLException)2 ControlSourceEventsRequestProcessor (com.linkedin.databus.container.request.ControlSourceEventsRequestProcessor)1 LoadDataEventsRequestProcessor (com.linkedin.databus.container.request.LoadDataEventsRequestProcessor)1 DatabusRuntimeException (com.linkedin.databus.core.DatabusRuntimeException)1 DbusEventBufferAppendable (com.linkedin.databus.core.DbusEventBufferAppendable)1 UnsupportedKeyException (com.linkedin.databus.core.UnsupportedKeyException)1 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)1 IdNamePair (com.linkedin.databus.core.util.IdNamePair)1 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)1 BufferNotFoundException (com.linkedin.databus2.core.BufferNotFoundException)1 HttpServerPipelineFactory (com.linkedin.databus2.core.container.netty.HttpServerPipelineFactory)1 ConfigRequestProcessor (com.linkedin.databus2.core.container.request.ConfigRequestProcessor)1 ContainerOperationProcessor (com.linkedin.databus2.core.container.request.ContainerOperationProcessor)1