use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.
the class OpenReplicatorAvroEventFactory method createAndAppendEvent.
public int createAndAppendEvent(DbChangeEntry changeEntry, DbusEventBufferAppendable eventBuffer, boolean enableTracing, DbusEventsStatisticsCollector dbusEventsStatisticsCollector) throws EventCreationException, UnsupportedKeyException, DatabusException {
Object keyObj = obtainKey(changeEntry);
//Construct the Databus Event key, determine the key type and construct the key
DbusEventKey eventKey = new DbusEventKey(keyObj);
short lPartitionId = _partitionFunction.getPartition(eventKey);
//Get the md5 for the schema
SchemaId schemaId = SchemaId.createWithMd5(changeEntry.getSchema());
byte[] payload = serializeEvent(changeEntry.getRecord());
DbusEventInfo eventInfo = new DbusEventInfo(changeEntry.getOpCode(), changeEntry.getScn(), (short) _pSourceId, lPartitionId, changeEntry.getTimestampInNanos(), (short) _sourceId, schemaId.getByteArray(), payload, enableTracing, false);
boolean success = eventBuffer.appendEvent(eventKey, eventInfo, dbusEventsStatisticsCollector);
return success ? payload.length : -1;
}
use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.
the class OpenReplicatorEventProducer method registerMbeans.
// register each source with the mbeanServer
private void registerMbeans(ORMonitoredSourceInfo source) throws DatabusException {
try {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("type", "SourceStatistics");
props.put("name", source.getSourceName());
ObjectName objectName = new ObjectName(_jmxDomain, props);
if (_mbeanServer.isRegistered(objectName)) {
_log.warn("Unregistering old or-source statistics mbean: " + objectName);
_mbeanServer.unregisterMBean(objectName);
}
_mbeanServer.registerMBean(source.getStatisticsBean(), objectName);
_log.info("Registered or-source statistics mbean: " + objectName);
_registeredMbeans.add(objectName);
} catch (Exception ex) {
_log.error("Failed to register the or-source statistics mbean for source (" + source.getSourceName() + ") due to an exception.", ex);
throw new DatabusException("Failed to initialize or event statistics mbeans.", ex);
}
}
use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.
the class HttpRelay method initializeRelayCommandProcessors.
protected void initializeRelayCommandProcessors() throws DatabusException {
/**
* Re-register containerStats to expose DB level aggregate inbound/event stats.
* The ContainerStatsRequestProcessor is registered in ServiceContainer. Since,
* we are overriding the behavior of ContainerStatsRequestProcessor, we are
* re-registering the subclass (RelayContainerStatsRequestProcessor) in place
* of ContainerStatsRequestProcessor.
*/
_processorRegistry.reregister(ContainerStatsRequestProcessor.COMMAND_NAME, new RelayContainerStatsRequestProcessor(null, this));
_processorRegistry.register(ConfigRequestProcessor.COMMAND_NAME, new ConfigRequestProcessor(null, this));
_processorRegistry.register(RelayStatsRequestProcessor.COMMAND_NAME, new RelayStatsRequestProcessor(null, this));
_processorRegistry.register(SourcesRequestProcessor.COMMAND_NAME, new SourcesRequestProcessor(null, this));
_processorRegistry.register(RegisterRequestProcessor.COMMAND_NAME, new RegisterRequestProcessor(null, this));
_processorRegistry.register(ReadEventsRequestProcessor.COMMAND_NAME, new ReadEventsRequestProcessor(null, this));
_processorRegistry.register(PhysicalSourcesRequestProcessor.COMMAND_NAME, new PhysicalSourcesRequestProcessor(null, this));
_processorRegistry.register(PhysicalBuffersRequestProcessor.COMMAND_NAME, new PhysicalBuffersRequestProcessor(null, this));
_processorRegistry.register(BufferInfoRequestProcessor.COMMAND_NAME, new BufferInfoRequestProcessor(null, _eventBufferMult));
_processorRegistry.register(RelayCommandRequestProcessor.COMMAND_NAME, new RelayCommandRequestProcessor(null, this));
}
use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.
the class ORListener method generateAvroEvent.
private void generateAvroEvent(Schema schema, List<Column> cols, GenericRecord record) throws DatabusException {
// Get Ordered list of field by dbFieldPosition
List<Schema.Field> orderedFields = SchemaHelper.getOrderedFieldsByMetaField(schema, "dbFieldPosition", new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
Integer pos1 = Integer.parseInt(o1);
Integer pos2 = Integer.parseInt(o2);
return pos1.compareTo(pos2);
}
});
// Build Map<AvroFieldType, Columns>
if (orderedFields.size() != cols.size()) {
throw new DatabusException("Mismatch in db schema vs avro schema");
}
int cnt = 0;
Map<String, Column> avroFieldCol = new HashMap<String, Column>();
for (Schema.Field field : orderedFields) {
avroFieldCol.put(field.name(), cols.get(cnt));
cnt++;
}
for (Schema.Field field : orderedFields) {
if (field.schema().getType() == Schema.Type.ARRAY) {
throw new DatabusException("The parser cannot handle ARRAY datatypes. Found in field: " + field);
} else {
// The current database field being processed
// (field is avro field name and databaseFieldName is oracle field name (one to one mapping)
String databaseFieldName = SchemaHelper.getMetaField(field, "dbFieldName").toLowerCase();
_log.debug("databaseFieldName = " + databaseFieldName);
//Insert the field into the generic record
insertFieldIntoRecord(avroFieldCol, record, databaseFieldName, field);
}
}
if (_log.isDebugEnabled()) {
_log.debug("Generic record = " + record);
}
}
use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.
the class ORListener method endXtion.
/**
* Per {@link http://code.google.com/p/open-replicator/source/browse/trunk/open-replicator/src/main/java/com/google/code/or/binlog/impl/event/XidEvent.java}
* XidEvent signals a commit
*/
private void endXtion(AbstractBinlogEventV4 e) {
_currTxnTimestamp = e.getHeader().getTimestamp() * 1000000L;
long txnReadLatency = System.nanoTime() - _currTxnStartReadTimestamp;
boolean em = ((e instanceof QueryEvent) || (e instanceof XidEvent));
if (!em) {
throw new DatabusRuntimeException("endXtion should be called with either QueryEvent of XidEvent");
}
_transaction.setSizeInBytes(_currTxnSizeInBytes);
_transaction.setTxnNanoTimestamp(_currTxnTimestamp);
_transaction.setTxnReadLatencyNanos(txnReadLatency);
if (_ignoreSource) {
long scn = scn(_currFileNum, (int) e.getHeader().getPosition());
_transaction.setIgnoredSourceScn(scn);
}
try {
_txnProcessor.onEndTransaction(_transaction);
} catch (DatabusException e3) {
_log.error("Got exception in the transaction handler ", e3);
throw new DatabusRuntimeException(e3);
} finally {
reset();
if (_log.isDebugEnabled()) {
_log.debug("endXtion" + e);
}
}
}
Aggregations