Search in sources :

Example 1 with InvalidConfigException

use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.

the class TestDbusKeyCompositeFilter method testDbusKeyRangeFilterErrors.

@Test
public void testDbusKeyRangeFilterErrors() throws Exception {
    boolean isException = false;
    //Error Case: Range Size is negative
    try {
        KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
        partConf.setType("RANGE");
        KeyRangeFilterConfig.Config rangeConf = new KeyRangeFilterConfig.Config();
        rangeConf.setSize(-1);
        rangeConf.setPartitions("[0,3-4]");
        partConf.setRange(rangeConf);
        DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    } catch (InvalidConfigException ice) {
        isException = true;
    }
    assertEquals("Got Exception for invalid Config (Range Size is negative) ", true, isException);
    isException = false;
    //Error Case: min is greater than max
    try {
        KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
        partConf.setType("RANGE");
        KeyRangeFilterConfig.Config rangeConf = new KeyRangeFilterConfig.Config();
        rangeConf.setSize(100);
        rangeConf.setPartitions("[0,5-4]");
        partConf.setRange(rangeConf);
        DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    } catch (InvalidConfigException ice) {
        isException = true;
    }
    assertEquals("Got Exception for invalid Config (min is greater than max) ", true, isException);
    isException = false;
    //Error Case: min is -ve
    try {
        KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
        partConf.setType("RANGE");
        KeyRangeFilterConfig.Config rangeConf = new KeyRangeFilterConfig.Config();
        rangeConf.setSize(100);
        rangeConf.setPartitions("[-3,2-4]");
        partConf.setRange(rangeConf);
        DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    } catch (InvalidConfigException ice) {
        isException = true;
    }
    assertEquals("Got Exception for invalid Config (min is greater than max) ", true, isException);
}
Also used : KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) KeyRangeFilterConfig(com.linkedin.databus2.core.filter.KeyRangeFilterConfig) KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) KeyRangeFilterConfig(com.linkedin.databus2.core.filter.KeyRangeFilterConfig) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) DbusKeyFilter(com.linkedin.databus2.core.filter.DbusKeyFilter) Test(org.testng.annotations.Test)

Example 2 with InvalidConfigException

use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.

the class TestDbusKeyCompositeFilter method testDbusKeyModFilterErrors.

@Test
public void testDbusKeyModFilterErrors() throws Exception {
    //Error Config : MaxBucket is more than numBuckets
    boolean isException = false;
    try {
        KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
        partConf.setType("MOD");
        KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
        modConf.setNumBuckets(5);
        //invalid config
        modConf.setBuckets("[0,3-9]");
        partConf.setMod(modConf);
        DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    } catch (InvalidConfigException ie) {
        ie.printStackTrace();
        isException = true;
    }
    assertEquals("Got Exception for invalid Config (MaxBucket is more than numBuckets) ", true, isException);
    //Error Case : Min Bucket is more than maxBucket
    isException = false;
    try {
        KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
        partConf.setType("MOD");
        KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
        modConf.setNumBuckets(50);
        //invalid config
        modConf.setBuckets("[0,9-3]");
        partConf.setMod(modConf);
        DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    } catch (InvalidConfigException ie) {
        ie.printStackTrace();
        isException = true;
    }
    assertEquals("Got Exception for invalid Config (Min Bucket is more than maxBucket) ", true, isException);
    //Error Case : numBuckets is negative
    isException = false;
    try {
        KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
        partConf.setType("MOD");
        KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
        modConf.setNumBuckets(-5);
        //invalid config
        modConf.setBuckets("[0]");
        partConf.setMod(modConf);
        DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    } catch (InvalidConfigException ie) {
        ie.printStackTrace();
        isException = true;
    }
    assertEquals("Got Exception for invalid Config numBuckets is negative) ", true, isException);
    //Error Case : minBucket is negative
    isException = false;
    try {
        KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
        partConf.setType("MOD");
        KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
        modConf.setNumBuckets(50);
        //invalid config
        modConf.setBuckets("[-5,1-3]");
        partConf.setMod(modConf);
        DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    } catch (InvalidConfigException ie) {
        ie.printStackTrace();
        isException = true;
    }
    assertEquals("Got Exception for invalid Config (minBucket is negative) ", true, isException);
}
Also used : KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) KeyRangeFilterConfig(com.linkedin.databus2.core.filter.KeyRangeFilterConfig) KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) DbusKeyFilter(com.linkedin.databus2.core.filter.DbusKeyFilter) Test(org.testng.annotations.Test)

Example 3 with InvalidConfigException

use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.

the class SchemaRegistryConfigBuilder method build.

@Override
public SchemaRegistryStaticConfig build() throws InvalidConfigException {
    RegistryType registryType = null;
    try {
        registryType = RegistryType.valueOf(_type);
    } catch (Exception e) {
        throw new InvalidConfigException("invalid schema registry type: " + _type);
    }
    _fileSystem.setEnabled(SchemaRegistryStaticConfig.RegistryType.FILE_SYSTEM == registryType);
    // TODO Add config verification
    return new SchemaRegistryStaticConfig(registryType, getFileSystem().build(), getExistingService());
}
Also used : RegistryType(com.linkedin.databus2.schemas.SchemaRegistryStaticConfig.RegistryType) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException)

Example 4 with InvalidConfigException

use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.

the class OpenReplicatorEventProducerServiceProvider method buildPartitionFunction.

public PartitionFunction buildPartitionFunction(LogicalSourceStaticConfig sourceConfig) throws InvalidConfigException {
    String partitionFunction = sourceConfig.getPartitionFunction();
    if (partitionFunction.startsWith("constant:")) {
        try {
            String numberPart = partitionFunction.substring("constant:".length()).trim();
            short constantPartitionNumber = Short.valueOf(numberPart);
            return new ConstantPartitionFunction(constantPartitionNumber);
        } catch (Exception ex) {
            // Could be a NumberFormatException, IndexOutOfBoundsException or other exception when trying to parse the partition number.
            throw new InvalidConfigException("Invalid partition configuration (" + partitionFunction + "). " + "Could not parse the constant partition number.");
        }
    } else {
        throw new InvalidConfigException("Invalid partition configuration (" + partitionFunction + ").");
    }
}
Also used : InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) DatabusException(com.linkedin.databus2.core.DatabusException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) UnsupportedKeyException(com.linkedin.databus.core.UnsupportedKeyException) NoSuchSchemaException(com.linkedin.databus2.schemas.NoSuchSchemaException)

Example 5 with InvalidConfigException

use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.

the class OpenReplicatorEventProducerServiceProvider method buildEventFactory.

public OpenReplicatorAvroEventFactory buildEventFactory(LogicalSourceStaticConfig sourceConfig, PhysicalSourceStaticConfig pConfig, SchemaRegistryService schemaRegistryService) throws DatabusException, EventCreationException, UnsupportedKeyException, InvalidConfigException {
    String schema = null;
    try {
        schema = schemaRegistryService.fetchLatestSchemaBySourceName(sourceConfig.getName());
    } catch (NoSuchSchemaException e) {
        throw new InvalidConfigException("Unable to load the schema for source (" + sourceConfig.getName() + ").");
    }
    if (schema == null) {
        throw new InvalidConfigException("Unable to load the schema for source (" + sourceConfig.getName() + ").");
    }
    LOG.info("Loading schema for source id " + sourceConfig.getId() + ": " + schema);
    String eventViewSchema;
    String eventView;
    if (sourceConfig.getUri().indexOf('.') != -1) {
        String[] parts = sourceConfig.getUri().split("\\.");
        eventViewSchema = parts[0];
        eventView = parts[1];
    } else {
        eventViewSchema = null;
        eventView = sourceConfig.getUri();
    }
    PartitionFunction partitionFunction = buildPartitionFunction(sourceConfig);
    OpenReplicatorAvroEventFactory factory = createEventFactory(eventViewSchema, eventView, sourceConfig, pConfig, schema, partitionFunction);
    return factory;
}
Also used : PartitionFunction(com.linkedin.databus2.producers.PartitionFunction) NoSuchSchemaException(com.linkedin.databus2.schemas.NoSuchSchemaException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException)

Aggregations

InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)29 DatabusException (com.linkedin.databus2.core.DatabusException)7 IOException (java.io.IOException)7 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)6 NoSuchSchemaException (com.linkedin.databus2.schemas.NoSuchSchemaException)6 ArrayList (java.util.ArrayList)6 DbusEventV2Factory (com.linkedin.databus.core.DbusEventV2Factory)5 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)5 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)5 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)5 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)5 HttpServerCodec (org.jboss.netty.handler.codec.http.HttpServerCodec)5 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)5 Log4JLoggerFactory (org.jboss.netty.logging.Log4JLoggerFactory)5 BeforeClass (org.testng.annotations.BeforeClass)5 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)4 UnsupportedKeyException (com.linkedin.databus.core.UnsupportedKeyException)4 OracleTriggerMonitoredSourceInfo (com.linkedin.databus2.producers.db.OracleTriggerMonitoredSourceInfo)4 Test (org.testng.annotations.Test)4 Checkpoint (com.linkedin.databus.core.Checkpoint)3