Search in sources :

Example 61 with DatabusException

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;
}
Also used : DbusEventInfo(com.linkedin.databus.core.DbusEventInfo) SchemaId(com.linkedin.databus2.schemas.SchemaId) DbusEventKey(com.linkedin.databus.core.DbusEventKey)

Example 62 with DatabusException

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);
    }
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) Hashtable(java.util.Hashtable) URISyntaxException(java.net.URISyntaxException) UnsupportedKeyException(com.linkedin.databus.core.UnsupportedKeyException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) DatabusException(com.linkedin.databus2.core.DatabusException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) ObjectName(javax.management.ObjectName)

Example 63 with DatabusException

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));
}
Also used : PhysicalBuffersRequestProcessor(com.linkedin.databus.container.request.PhysicalBuffersRequestProcessor) PhysicalSourcesRequestProcessor(com.linkedin.databus.container.request.PhysicalSourcesRequestProcessor) SourcesRequestProcessor(com.linkedin.databus.container.request.SourcesRequestProcessor) PhysicalSourcesRequestProcessor(com.linkedin.databus.container.request.PhysicalSourcesRequestProcessor) RelayCommandRequestProcessor(com.linkedin.databus.container.request.RelayCommandRequestProcessor) RelayStatsRequestProcessor(com.linkedin.databus.container.request.RelayStatsRequestProcessor) RegisterRequestProcessor(com.linkedin.databus.container.request.RegisterRequestProcessor) ReadEventsRequestProcessor(com.linkedin.databus.container.request.ReadEventsRequestProcessor) BufferInfoRequestProcessor(com.linkedin.databus.container.request.BufferInfoRequestProcessor) RelayContainerStatsRequestProcessor(com.linkedin.databus.container.request.RelayContainerStatsRequestProcessor) ConfigRequestProcessor(com.linkedin.databus2.core.container.request.ConfigRequestProcessor)

Example 64 with DatabusException

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);
    }
}
Also used : HashMap(java.util.HashMap) Schema(org.apache.avro.Schema) PrimaryKeySchema(com.linkedin.databus2.producers.ds.PrimaryKeySchema) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema) Field(org.apache.avro.Schema.Field) BigInteger(java.math.BigInteger) Field(org.apache.avro.Schema.Field) DatabusException(com.linkedin.databus2.core.DatabusException) FloatColumn(com.google.code.or.common.glossary.column.FloatColumn) SetColumn(com.google.code.or.common.glossary.column.SetColumn) DatetimeColumn(com.google.code.or.common.glossary.column.DatetimeColumn) EnumColumn(com.google.code.or.common.glossary.column.EnumColumn) TimestampColumn(com.google.code.or.common.glossary.column.TimestampColumn) TimeColumn(com.google.code.or.common.glossary.column.TimeColumn) BitColumn(com.google.code.or.common.glossary.column.BitColumn) LongColumn(com.google.code.or.common.glossary.column.LongColumn) YearColumn(com.google.code.or.common.glossary.column.YearColumn) Datetime2Column(com.google.code.or.common.glossary.column.Datetime2Column) DecimalColumn(com.google.code.or.common.glossary.column.DecimalColumn) DoubleColumn(com.google.code.or.common.glossary.column.DoubleColumn) LongLongColumn(com.google.code.or.common.glossary.column.LongLongColumn) TinyColumn(com.google.code.or.common.glossary.column.TinyColumn) Column(com.google.code.or.common.glossary.Column) StringColumn(com.google.code.or.common.glossary.column.StringColumn) Int24Column(com.google.code.or.common.glossary.column.Int24Column) BlobColumn(com.google.code.or.common.glossary.column.BlobColumn) NullColumn(com.google.code.or.common.glossary.column.NullColumn) ShortColumn(com.google.code.or.common.glossary.column.ShortColumn) DateColumn(com.google.code.or.common.glossary.column.DateColumn)

Example 65 with DatabusException

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);
        }
    }
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) XidEvent(com.google.code.or.binlog.impl.event.XidEvent) QueryEvent(com.google.code.or.binlog.impl.event.QueryEvent) DatabusRuntimeException(com.linkedin.databus.core.DatabusRuntimeException)

Aggregations

DatabusException (com.linkedin.databus2.core.DatabusException)76 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)14 Schema (org.apache.avro.Schema)14 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)13 Logger (org.apache.log4j.Logger)13 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)12 Channel (org.jboss.netty.channel.Channel)12 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)11 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)10 UnsupportedKeyException (com.linkedin.databus.core.UnsupportedKeyException)9 VersionedSchema (com.linkedin.databus2.schemas.VersionedSchema)9 InetSocketAddress (java.net.InetSocketAddress)9 SocketAddress (java.net.SocketAddress)9 SQLException (java.sql.SQLException)9 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)9 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)9 EventCreationException (com.linkedin.databus2.producers.EventCreationException)7 PhysicalSourceStaticConfig (com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig)7