Search in sources :

Example 81 with DatabusException

use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.

the class DbusEventBufferMult method constructFilters.

/**
   * Processes all {@link DatabusSubscription} and generates a filter to match events for any of
   * those subscriptions.
   */
public DbusFilter constructFilters(Collection<DatabusSubscription> subs) throws DatabusException {
    HashMap<PhysicalPartition, PhysicalPartitionDbusFilter> filterMap = null;
    for (DatabusSubscription sub : subs) {
        PhysicalPartition ppart = sub.getPhysicalPartition();
        if (sub.getLogicalSource().isWildcard()) {
            if (!ppart.isWildcard()) {
                if (null == filterMap)
                    filterMap = new HashMap<PhysicalPartition, PhysicalPartitionDbusFilter>(10);
                filterMap.put(ppart, new PhysicalPartitionDbusFilter(ppart, null));
            } else {
                LOG.warn("ignoring subscription with both physical partition and logical source wildcards");
            }
        } else {
            PhysicalPartitionDbusFilter ppartFilter = null != filterMap ? filterMap.get(ppart) : null;
            LogicalSourceAndPartitionDbusFilter logFilter = null;
            if (null == ppartFilter) {
                logFilter = new LogicalSourceAndPartitionDbusFilter();
                ppartFilter = new PhysicalPartitionDbusFilter(ppart, logFilter);
                if (null == filterMap)
                    filterMap = new HashMap<PhysicalPartition, PhysicalPartitionDbusFilter>(10);
                filterMap.put(ppart, ppartFilter);
            } else {
                logFilter = (LogicalSourceAndPartitionDbusFilter) ppartFilter.getNestedFilter();
            }
            if (null != logFilter)
                logFilter.addSourceCondition(sub.getLogicalPartition());
            else
                LOG.error("unexpected null filter for logical source");
        }
    }
    if (0 == filterMap.size())
        return AllowAllDbusFilter.THE_INSTANCE;
    else if (1 == filterMap.size()) {
        DbusFilter result = filterMap.entrySet().iterator().next().getValue();
        return result;
    } else {
        ConjunctionDbusFilter result = new ConjunctionDbusFilter();
        for (Map.Entry<PhysicalPartition, PhysicalPartitionDbusFilter> filterEntry : filterMap.entrySet()) {
            result.addFilter(filterEntry.getValue());
        }
        return result;
    }
}
Also used : PhysicalPartitionDbusFilter(com.linkedin.databus2.core.filter.PhysicalPartitionDbusFilter) HashMap(java.util.HashMap) ConjunctionDbusFilter(com.linkedin.databus2.core.filter.ConjunctionDbusFilter) LogicalSourceAndPartitionDbusFilter(com.linkedin.databus2.core.filter.LogicalSourceAndPartitionDbusFilter) DatabusSubscription(com.linkedin.databus.core.data_model.DatabusSubscription) ConjunctionDbusFilter(com.linkedin.databus2.core.filter.ConjunctionDbusFilter) AllowAllDbusFilter(com.linkedin.databus2.core.filter.AllowAllDbusFilter) LogicalSourceAndPartitionDbusFilter(com.linkedin.databus2.core.filter.LogicalSourceAndPartitionDbusFilter) PhysicalPartitionDbusFilter(com.linkedin.databus2.core.filter.PhysicalPartitionDbusFilter) DbusFilter(com.linkedin.databus2.core.filter.DbusFilter) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 82 with DatabusException

use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.

the class TestParser method missingScnCheck.

/**
   * Missing scn should throw an exception
   */
@Test
public void missingScnCheck() throws Exception {
    BasicOperationsCheckCallback callback = new BasicOperationsCheckCallback();
    try {
        StaxBuilderTest test = new StaxBuilderTest(actualXmlDataDir + "missingscn.xml", service, callback);
        test.processXml();
        Assert.fail("Test has not detected failure on missing scn");
    } catch (DatabusException e) {
        LOG.info("Caught databus exception, verifying if it's for missing scn..");
        String error = e.getMessage();
        String expected = "Unable to find scn for the given dbUpdate, terminating the parser";
        Assert.assertEquals(error, expected);
    }
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) StaxBuilderTest(com.linkedin.databus2.ggParser.staxparser.StaxBuilderTest) StaxBuilderTest(com.linkedin.databus2.ggParser.staxparser.StaxBuilderTest) Test(org.testng.annotations.Test)

Example 83 with DatabusException

use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.

the class TestParser method basicOperationsTest.

/**
   * Makes sure there are no exceptions is thrown on parsing xml, verify the keys processed.
   * @throws DatabusException
   * @throws FileNotFoundException
   */
@Test
public void basicOperationsTest() throws Exception {
    BasicOperationsCheckCallback callback = new BasicOperationsCheckCallback();
    StaxBuilderTest test = new StaxBuilderTest(actualXmlDataDir + "basicprocessing.xml", service, callback);
    test.processXml();
}
Also used : StaxBuilderTest(com.linkedin.databus2.ggParser.staxparser.StaxBuilderTest) StaxBuilderTest(com.linkedin.databus2.ggParser.staxparser.StaxBuilderTest) Test(org.testng.annotations.Test)

Example 84 with DatabusException

use of com.linkedin.databus2.core.DatabusException in project databus by linkedin.

the class BootstrapProducerCallback method onStartDataEventSequence.

@Override
public ConsumerCallbackResult onStartDataEventSequence(SCN startScn) {
    _srcRm.start();
    _totalNumEvents = 0;
    ConsumerCallbackResult success = ConsumerCallbackResult.SUCCESS;
    try {
        if (_oldWindowScn == -1) {
            initWindowScn();
        }
    } catch (SQLException e) {
        if (null != _statsCollector)
            _statsCollector.registerSQLException();
        LOG.error("Got SQLException in startDataEventSequence Hanlder!! Connections will be reset !!", e);
        try {
            reset();
        } catch (DatabusException e2) {
            DbusPrettyLogUtils.logExceptionAtError("Unable to reset connection", e2, LOG);
        } catch (SQLException sqlEx) {
            DbusPrettyLogUtils.logExceptionAtError("Got exception while resetting connections. Stopping Client !!", sqlEx, LOG);
            return ConsumerCallbackResult.ERROR_FATAL;
        }
        success = ConsumerCallbackResult.ERROR;
    }
    return success;
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) SQLException(java.sql.SQLException) ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

Example 85 with DatabusException

use of com.linkedin.databus2.core.DatabusException 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

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