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);
}
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);
}
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");
}
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");
}
Aggregations