org.apache.kafka.common.config.ConfigException Java Examples
The following examples show how to use
org.apache.kafka.common.config.ConfigException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CronPolicyTest.java From kafka-connect-fs with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("fileSystemConfigProvider") public void invalidEndDate(PolicyFsTestConfig fsConfig) { Map<String, String> originals = fsConfig.getSourceTaskConfig().originalsStrings(); originals.put(CronPolicy.CRON_POLICY_END_DATE, "invalid"); FsSourceTaskConfig cfg = new FsSourceTaskConfig(originals); assertThrows(ConnectException.class, () -> ReflectionUtils.makePolicy((Class<? extends Policy>) fsConfig.getSourceTaskConfig() .getClass(FsSourceTaskConfig.POLICY_CLASS), cfg)); assertThrows(ConfigException.class, () -> { try { ReflectionUtils.makePolicy((Class<? extends Policy>) fsConfig.getSourceTaskConfig() .getClass(FsSourceTaskConfig.POLICY_CLASS), cfg); } catch (Exception e) { throw e.getCause(); } }); }
Example #2
Source File: Validators.java From connect-utils with Apache License 2.0 | 6 votes |
/** * Validator is used to ensure that the KeyStore type specified is valid. * @return */ public static Validator validKeyStoreType() { return (s, o) -> { if (!(o instanceof String)) { throw new ConfigException(s, o, "Must be a string."); } String keyStoreType = o.toString(); try { KeyStore.getInstance(keyStoreType); } catch (KeyStoreException e) { ConfigException exception = new ConfigException(s, o, "Invalid KeyStore type"); exception.initCause(e); throw exception; } }; }
Example #3
Source File: CronPolicyTest.java From kafka-connect-fs with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("fileSystemConfigProvider") public void invalidCronExpression(PolicyFsTestConfig fsConfig) { Map<String, String> originals = fsConfig.getSourceTaskConfig().originalsStrings(); originals.put(CronPolicy.CRON_POLICY_EXPRESSION, "invalid"); FsSourceTaskConfig cfg = new FsSourceTaskConfig(originals); assertThrows(ConnectException.class, () -> ReflectionUtils.makePolicy((Class<? extends Policy>) fsConfig.getSourceTaskConfig() .getClass(FsSourceTaskConfig.POLICY_CLASS), cfg)); assertThrows(ConfigException.class, () -> { try { ReflectionUtils.makePolicy((Class<? extends Policy>) fsConfig.getSourceTaskConfig() .getClass(FsSourceTaskConfig.POLICY_CLASS), cfg); } catch (Exception e) { throw e.getCause(); } }); }
Example #4
Source File: FsSourceTask.java From kafka-connect-fs with Apache License 2.0 | 6 votes |
@Override public void start(Map<String, String> properties) { log.info("Starting FS source task..."); try { config = new FsSourceTaskConfig(properties); if (config.getClass(FsSourceTaskConfig.POLICY_CLASS).isAssignableFrom(Policy.class)) { throw new ConfigException("Policy class " + config.getClass(FsSourceTaskConfig.POLICY_CLASS) + " is not a subclass of " + Policy.class); } if (config.getClass(FsSourceTaskConfig.FILE_READER_CLASS).isAssignableFrom(FileReader.class)) { throw new ConfigException("FileReader class " + config.getClass(FsSourceTaskConfig.FILE_READER_CLASS) + " is not a subclass of " + FileReader.class); } Class<Policy> policyClass = (Class<Policy>) Class.forName(properties.get(FsSourceTaskConfig.POLICY_CLASS)); policy = ReflectionUtils.makePolicy(policyClass, config); pollInterval = config.getInt(FsSourceTaskConfig.POLL_INTERVAL_MS); } catch (ConfigException ce) { log.error("Couldn't start FsSourceTask.", ce); throw new ConnectException("Couldn't start FsSourceTask due to configuration error: " + ce.getMessage(), ce); } catch (Exception e) { log.error("Couldn't start FsSourceConnector.", e); throw new ConnectException("A problem has occurred reading configuration: " + e.getMessage(), e); } log.info("FS source task started with policy [{}].", policy.getClass().getName()); }
Example #5
Source File: CollectionAwareConfig.java From kafka-connect-mongodb with Apache License 2.0 | 6 votes |
public Integer getInt(String property, String collection) { Object obj; if(collection == null || collection.isEmpty()) { obj = get(property); } else { obj = get(property,collection); } if(obj instanceof Integer) return (Integer) obj; if(obj instanceof String) return Integer.parseInt((String)obj); throw new ConfigException("error: unsupported property type for '"+obj+"' where Integer expected"); }
Example #6
Source File: Validators.java From connect-utils with Apache License 2.0 | 6 votes |
/** * Validator is used to ensure that the KeyManagerFactory Algorithm specified is valid. * @return */ public static Validator validKeyManagerFactory() { return (s, o) -> { if (!(o instanceof String)) { throw new ConfigException(s, o, "Must be a string."); } String keyStoreType = o.toString(); try { KeyManagerFactory.getInstance(keyStoreType); } catch (NoSuchAlgorithmException e) { ConfigException exception = new ConfigException(s, o, "Invalid Algorithm"); exception.initCause(e); throw exception; } }; }
Example #7
Source File: HourlyPartitioner.java From streamx with Apache License 2.0 | 6 votes |
@Override public void configure(Map<String, Object> config) { String localeString = (String) config.get(HdfsSinkConnectorConfig.LOCALE_CONFIG); if (localeString.equals("")) { throw new ConfigException(HdfsSinkConnectorConfig.LOCALE_CONFIG, localeString, "Locale cannot be empty."); } String timeZoneString = (String) config.get(HdfsSinkConnectorConfig.TIMEZONE_CONFIG); if (timeZoneString.equals("")) { throw new ConfigException(HdfsSinkConnectorConfig.TIMEZONE_CONFIG, timeZoneString, "Timezone cannot be empty."); } String hiveIntString = (String) config.get(HdfsSinkConnectorConfig.HIVE_INTEGRATION_CONFIG); boolean hiveIntegration = hiveIntString != null && hiveIntString.toLowerCase().equals("true"); Locale locale = new Locale(localeString); DateTimeZone timeZone = DateTimeZone.forID(timeZoneString); init(partitionDurationMs, pathFormat, locale, timeZone, hiveIntegration); }
Example #8
Source File: JsonSinkClickHouseTask.java From kafka-connectors with Apache License 2.0 | 6 votes |
@Override public void start(Map<String, String> props) { String hosts = props.get(CLICKHOUSE_HOSTS); String port = props.get(CLICKHOUSE_JDBC_PORT); String user = props.get(CLICKHOUSE_JDBC_USER); String password = props.get(CLICKHOUSE_JDBC_PASSWORD); sinkDb = props.get(CLICKHOUSE_SINK_DATABASE); JdbcConnectConfig connectConfig = JdbcConnectConfig.initCkConnectConfig(hosts, port, user, password); try { dataSource = new JdbcDataSource(connectConfig); } catch (SQLException e) { logger.error("创建ClickHouse连接失败, ", e); throw new ConfigException(e.getMessage()); } String inOptimize = props.get(CLICKHOUSE_OPTIMIZE); if (inOptimize != null && BOOLEAN_TRUE.equals(inOptimize.toLowerCase())) { optimize = true; } parseSinkTables(props); logger.info("start task, 开始连接ClickHouse"); }
Example #9
Source File: ConfigHelper.java From kafka-connect-couchbase with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public static <T> ConfigDef.Validator validate(SimpleValidator<T> validator, String description) { return new ConfigDef.Validator() { @Override public String toString() { return description; } @Override public void ensureValid(String name, Object value) { try { validator.validate((T) value); } catch (Exception e) { throw new ConfigException(name, value, e.getMessage()); } } }; }
Example #10
Source File: GcsSinkConfigTest.java From aiven-kafka-connect-gcs with GNU Affero General Public License v3.0 | 6 votes |
@ParameterizedTest @ValueSource(strings = { "", "{{topic}}", "{{partition}}", "{{start_offset}}", "{{topic}}-{{partition}}", "{{topic}}-{{start_offset}}", "{{partition}}-{{start_offset}}", "{{topic}}-{{partition}}-{{start_offset}}-{{unknown}}" }) final void incorrectFilenameTemplatesForTopicPartitionRecord(final String template) { final Map<String, String> properties = ImmutableMap.of( GcsSinkConfig.FILE_NAME_TEMPLATE_CONFIG, template); assertThrows( ConfigException.class, () -> new GcsSinkConfig(properties) ); }
Example #11
Source File: DailyPartitioner.java From streamx with Apache License 2.0 | 6 votes |
@Override public void configure(Map<String, Object> config) { String localeString = (String) config.get(HdfsSinkConnectorConfig.LOCALE_CONFIG); if (localeString.equals("")) { throw new ConfigException(HdfsSinkConnectorConfig.LOCALE_CONFIG, localeString, "Locale cannot be empty."); } String timeZoneString = (String) config.get(HdfsSinkConnectorConfig.TIMEZONE_CONFIG); if (timeZoneString.equals("")) { throw new ConfigException(HdfsSinkConnectorConfig.TIMEZONE_CONFIG, timeZoneString, "Timezone cannot be empty."); } String hiveIntString = (String) config.get(HdfsSinkConnectorConfig.HIVE_INTEGRATION_CONFIG); boolean hiveIntegration = hiveIntString != null && hiveIntString.toLowerCase().equals("true"); Locale locale = new Locale(localeString); DateTimeZone timeZone = DateTimeZone.forID(timeZoneString); init(partitionDurationMs, pathFormat, locale, timeZone, hiveIntegration); }
Example #12
Source File: HeaderToFieldConfig.java From kafka-connect-transform-common with Apache License 2.0 | 6 votes |
public HeaderToFieldConfig(Map<?, ?> originals) { super(config(), originals); List<HeaderToFieldMapping> mappings = new ArrayList<>(); List<String> rawMappings = getList(HEADER_MAPPINGS_CONF); for (String rawMapping : rawMappings) { try { HeaderToFieldMapping mapping = HeaderToFieldMapping.parse(rawMapping); mappings.add(mapping); } catch (Exception ex) { ConfigException configException = new ConfigException(HEADER_MAPPINGS_CONF, rawMapping); configException.initCause(ex); throw configException; } } this.mappings = ImmutableList.copyOf(mappings); }
Example #13
Source File: KafkaConfigurationWrapper.java From egeria with Apache License 2.0 | 6 votes |
/** * In Kafka 0.10.0.0 (which we are using), session.timeout.ms.config is used for this. In Kafka 0.10.1.0 and * later, we need to use the property max.poll.interval.ms * See https://kafka.apache.org/0100/documentation.html * * @return int */ public int getMaxPollIntervalMs() { try { //if this property is valid, use it return config.getInt("max.poll.interval.ms"); } catch(ConfigException ex) { //property does not exist. That is ok. That means we are using an older //version of Kafka } return config.getInt(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG); }
Example #14
Source File: SecurityAndSslConfigTest.java From cruise-control with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testSslConfigsSetUpThrowsExceptionOnNullSslProtocol() { KafkaCruiseControlConfig config = partialMockBuilder(KafkaCruiseControlConfig.class) .addMockedMethod("getBoolean") .addMockedMethod("getString") .addMockedMethod("hashCode") .createNiceMock(); expect(config.getBoolean(WebServerConfig.WEBSERVER_SSL_ENABLE_CONFIG)).andReturn(true); expect(config.getString(WebServerConfig.WEBSERVER_SSL_KEYSTORE_LOCATION_CONFIG)) .andReturn(getClass().getClassLoader().getResource("ssl_integration_test.keystore").toString()); expect(config.getString(WebServerConfig.WEBSERVER_SSL_KEYSTORE_PASSWORD_CONFIG)) .andReturn("jetty"); replay(config); _expectedException.expect(ConfigException.class); config.sanityCheckSecurity(); verify(config); }
Example #15
Source File: GcsSinkConfigTest.java From aiven-kafka-connect-gcs with GNU Affero General Public License v3.0 | 6 votes |
@Test void wrongVariableWithoutParameterValue() { final Map<String, String> properties = new HashMap<>(); properties.put("gcs.bucket.name", "test-bucket"); properties.put("file.name.template", "{{start_offset:padding=}}-{{partition}}-{{topic}}"); final Throwable t = assertThrows( ConfigException.class, () -> new GcsSinkConfig(properties) ); assertEquals( "Invalid value {{start_offset:padding=}}-{{partition}}-{{topic}} " + "for configuration file.name.template: " + "Parameter value for variable `start_offset` and parameter `padding` has not been set", t.getMessage() ); }
Example #16
Source File: GcsSinkConfigTest.java From aiven-kafka-connect-gcs with GNU Affero General Public License v3.0 | 6 votes |
@Test void noVariableWithParameter() { final Map<String, String> properties = new HashMap<>(); properties.put("gcs.bucket.name", "test-bucket"); properties.put("file.name.template", "{{:padding=true}}-{{partition}}-{{topic}}"); final Throwable t = assertThrows( ConfigException.class, () -> new GcsSinkConfig(properties) ); assertEquals( "Invalid value {{:padding=true}}-{{partition}}-{{topic}} " + "for configuration file.name.template: " + "Variable name has't been set for template: {{:padding=true}}-{{partition}}-{{topic}}", t.getMessage() ); }
Example #17
Source File: CloudPubSubSourceConnector.java From pubsub with Apache License 2.0 | 5 votes |
@Override public void ensureValid(String name, Object o) { String value = (String) o; if (!value.equals(CloudPubSubSourceConnector.PartitionScheme.ROUND_ROBIN.toString()) && !value.equals(CloudPubSubSourceConnector.PartitionScheme.HASH_VALUE.toString()) && !value.equals(CloudPubSubSourceConnector.PartitionScheme.HASH_KEY.toString()) && !value.equals(CloudPubSubSourceConnector.PartitionScheme.KAFKA_PARTITIONER.toString())) { throw new ConfigException( "Valid values for " + CloudPubSubSourceConnector.KAFKA_PARTITION_SCHEME_CONFIG + " are " + Arrays.toString(PartitionScheme.values())); } }
Example #18
Source File: HBaseSinkConfig.java From kafka-connect-hbase with Apache License 2.0 | 5 votes |
/** * Validates the properties to ensure the rowkey property is configured for each table. */ public void validate() { final String topicsAsStr = properties.get(ConnectorConfig.TOPICS_CONFIG); final String[] topics = topicsAsStr.split(","); for(String topic : topics) { String key = String.format(TABLE_ROWKEY_COLUMNS_TEMPLATE, topic); if(!properties.containsKey(key)) { throw new ConfigException(String.format(" No rowkey has been configured for table [%s]", key)); } } }
Example #19
Source File: ValidUrl.java From connect-utils with Apache License 2.0 | 5 votes |
static void validate(String config, String value) { try { new URL(value); } catch (MalformedURLException e) { ConfigException configException = new ConfigException( config, value, "Could not parse to URL." ); configException.initCause(e); throw configException; } }
Example #20
Source File: Validators.java From mongo-kafka with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static ValidatorWithOperators listMatchingPattern(final Pattern pattern) { return withStringDef( format("A list matching: `%s`", pattern), (name, value) -> ((List) value) .forEach( v -> { if (!pattern.matcher((String) v).matches()) { throw new ConfigException( name, value, "Contains an invalid value. Does not match: " + pattern); } })); }
Example #21
Source File: TaskConfigBuilder.java From mirus with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Map<String, String> makeClientIdUnique(Map<String, String> taskConfig, int taskCounter) { String clientId = taskConfig.get(TaskConfigDefinition.CONSUMER_CLIENT_ID); if (clientId == null) { throw new ConfigException("consumer.client.id must be set"); } // Build a task id similar to the one used by Worker. String taskId = sourceName + "-" + taskCounter; taskConfig.put(TaskConfigDefinition.CONSUMER_CLIENT_ID, clientId + taskId); return taskConfig; }
Example #22
Source File: OffsetFetcher.java From mirus with BSD 3-Clause "New" or "Revised" License | 5 votes |
OffsetFetcher(final WorkerConfig config, Converter internalConverter) { String topic = config.getString(DistributedConfig.OFFSET_STORAGE_TOPIC_CONFIG); if ("".equals(topic)) { throw new ConfigException("Offset storage topic must be specified"); } Map<String, Object> producerProps = new HashMap<>(config.originals()); producerProps.put( ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); producerProps.put( ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); producerProps.put(ProducerConfig.RETRIES_CONFIG, Integer.MAX_VALUE); Map<String, Object> consumerProps = new HashMap<>(config.originals()); consumerProps.put( ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName()); consumerProps.put( ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName()); Callback<ConsumerRecord<byte[], byte[]>> consumedCallback = (error, record) -> { ByteBuffer key = record.key() != null ? ByteBuffer.wrap(record.key()) : null; ByteBuffer value = record.value() != null ? ByteBuffer.wrap(record.value()) : null; data.put(key, value); }; this.offsetLog = new KafkaBasedLog<>( topic, producerProps, consumerProps, consumedCallback, Time.SYSTEM, null); this.internalConverter = internalConverter; }
Example #23
Source File: KafkaSourceConnector.java From MirrorTool-for-Kafka-Connect with Apache License 2.0 | 5 votes |
@Override public void start(Map<String, String> config) throws ConfigException { logger.info("Connector starting"); connectorConfig = new KafkaSourceConnectorConfig(config); logger.info("Starting Partition Monitor to monitor source kafka cluster partitions"); partitionMonitor = new PartitionMonitor(context, connectorConfig); partitionMonitor.start(); }
Example #24
Source File: JenkinsSourceConfig.java From kafka-connect-jenkins with Apache License 2.0 | 5 votes |
public URL getJobsResource() { try { return new URL(getString(JENKINS_BASE_URL_CONFIG) + JOBS_RESOURCE_PATH_DEFAULT); } catch (MalformedURLException e) { throw new ConfigException("Couldn't create the URL from " + getString(JENKINS_BASE_URL_CONFIG), e); } }
Example #25
Source File: SecurityAndSslConfigTest.java From cruise-control with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testAuthConfigThrowsExceptionOnNullSecurityProvider() { KafkaCruiseControlConfig config = partialMockBuilder(KafkaCruiseControlConfig.class) .addMockedMethod("getBoolean") .addMockedMethod("getClass") .addMockedMethod("hashCode") .createNiceMock(); expect(config.getBoolean(WebServerConfig.WEBSERVER_SSL_ENABLE_CONFIG)).andReturn(false); expect(config.getBoolean(WebServerConfig.WEBSERVER_SECURITY_ENABLE_CONFIG)).andReturn(true); replay(config); _expectedException.expect(ConfigException.class); config.sanityCheckSecurity(); verify(config); }
Example #26
Source File: KafkaCruiseControlUtils.java From cruise-control with BSD 2-Clause "Simplified" License | 5 votes |
private static void setPasswordConfigIfExists(KafkaCruiseControlConfig configs, Map<String, Object> props, String name) { try { props.put(name, configs.getPassword(name)); } catch (ConfigException ce) { // let it go. } }
Example #27
Source File: KafkaSourceConnectorTest.java From MirrorTool-for-Kafka-Connect with Apache License 2.0 | 5 votes |
@Test(expected = ConfigException.class) public void testStartBlankBootstrapServers() { suppress(method(PartitionMonitor.class, "start")); PowerMock.replayAll(); sourceProperties.put(KafkaSourceConnectorConfig.SOURCE_BOOTSTRAP_SERVERS_CONFIG, ""); connector.start(sourceProperties); PowerMock.verifyAll(); }
Example #28
Source File: GcsSinkConfigTest.java From aiven-kafka-connect-gcs with GNU Affero General Public License v3.0 | 5 votes |
@Test void wrongVariableParameterValue() { final Map<String, String> properties = new HashMap<>(); properties.put("gcs.bucket.name", "test-bucket"); properties.put("file.name.template", "{{start_offset:padding=FALSE}}-{{partition}}-{{topic}}"); final Throwable t = assertThrows( ConfigException.class, () -> new GcsSinkConfig(properties) ); assertEquals( "Invalid value {{start_offset:padding=FALSE}}-{{partition}}-{{topic}} " + "for configuration file.name.template: " + "unsupported set of template variables parameters, " + "supported sets are: start_offset:padding=true|false,timestamp:unit=YYYY|MM|dd|HH", t.getMessage()); }
Example #29
Source File: Validators.java From mongo-kafka with Apache License 2.0 | 5 votes |
public static ValidatorWithOperators errorCheckingValueValidator( final String validValuesString, final Consumer<String> consumer) { return withStringDef( validValuesString, ((name, value) -> { try { consumer.accept((String) value); } catch (Exception e) { throw new ConfigException(name, value, e.getMessage()); } })); }
Example #30
Source File: NotEmptyString.java From MongoDb-Sink-Connector with Apache License 2.0 | 5 votes |
@Override public void ensureValid(String name, Object value) { if (value == null) { throw new ConfigException(name, null, "Null"); } if (!(value instanceof String)) { throw new ConfigException(name, value, "Not a string"); } if (((String)value).trim().isEmpty()) { throw new ConfigException(name, value, "String may not be empty"); } }