use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class AbstractHerderTest method testConfigValidationMissingName.
@Test()
public void testConfigValidationMissingName() {
AbstractHerder herder = createConfigValidationHerder(TestSourceConnector.class, noneConnectorClientConfigOverridePolicy);
replayAll();
Map<String, String> config = Collections.singletonMap(ConnectorConfig.CONNECTOR_CLASS_CONFIG, TestSourceConnector.class.getName());
ConfigInfos result = herder.validateConnectorConfig(config, false);
// We expect there to be errors due to the missing name and .... Note that these assertions depend heavily on
// the config fields for SourceConnectorConfig, but we expect these to change rarely.
assertEquals(TestSourceConnector.class.getName(), result.name());
assertEquals(Arrays.asList(ConnectorConfig.COMMON_GROUP, ConnectorConfig.TRANSFORMS_GROUP, ConnectorConfig.PREDICATES_GROUP, ConnectorConfig.ERROR_GROUP, SourceConnectorConfig.TOPIC_CREATION_GROUP), result.groups());
assertEquals(2, result.errorCount());
Map<String, ConfigInfo> infos = result.values().stream().collect(Collectors.toMap(info -> info.configKey().name(), Function.identity()));
// Base connector config has 14 fields, connector's configs add 2
assertEquals(17, infos.size());
// Missing name should generate an error
assertEquals(ConnectorConfig.NAME_CONFIG, infos.get(ConnectorConfig.NAME_CONFIG).configValue().name());
assertEquals(1, infos.get(ConnectorConfig.NAME_CONFIG).configValue().errors().size());
// "required" config from connector should generate an error
assertEquals("required", infos.get("required").configValue().name());
assertEquals(1, infos.get("required").configValue().errors().size());
verifyAll();
}
use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class AbstractHerderTest method testConfigValidationMultipleNullConfig.
@Test
public void testConfigValidationMultipleNullConfig() {
AbstractHerder herder = createConfigValidationHerder(TestSourceConnector.class, noneConnectorClientConfigOverridePolicy);
replayAll();
Map<String, String> config = new HashMap<>();
config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, TestSourceConnector.class.getName());
config.put("name", "somename");
config.put("required", "value");
config.put("testKey", null);
config.put("secondTestKey", null);
final ConfigInfos configInfos = herder.validateConnectorConfig(config, false);
assertEquals(2, configInfos.errorCount());
assertErrorForKey(configInfos, "testKey");
assertErrorForKey(configInfos, "secondTestKey");
verifyAll();
}
use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class AbstractHerderTest method testGenerateResultWithConfigValuesAllUsingConfigKeysAndWithNoErrors.
@Test
public void testGenerateResultWithConfigValuesAllUsingConfigKeysAndWithNoErrors() {
String name = "com.acme.connector.MyConnector";
Map<String, ConfigDef.ConfigKey> keys = new HashMap<>();
addConfigKey(keys, "config.a1", null);
addConfigKey(keys, "config.b1", "group B");
addConfigKey(keys, "config.b2", "group B");
addConfigKey(keys, "config.c1", "group C");
List<String> groups = Arrays.asList("groupB", "group C");
List<ConfigValue> values = new ArrayList<>();
addValue(values, "config.a1", "value.a1");
addValue(values, "config.b1", "value.b1");
addValue(values, "config.b2", "value.b2");
addValue(values, "config.c1", "value.c1");
ConfigInfos infos = AbstractHerder.generateResult(name, keys, values, groups);
assertEquals(name, infos.name());
assertEquals(groups, infos.groups());
assertEquals(values.size(), infos.values().size());
assertEquals(0, infos.errorCount());
assertInfoKey(infos, "config.a1", null);
assertInfoKey(infos, "config.b1", "group B");
assertInfoKey(infos, "config.b2", "group B");
assertInfoKey(infos, "config.c1", "group C");
assertInfoValue(infos, "config.a1", "value.a1");
assertInfoValue(infos, "config.b1", "value.b1");
assertInfoValue(infos, "config.b2", "value.b2");
assertInfoValue(infos, "config.c1", "value.c1");
}
use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class AbstractHerderTest method testConfigValidationPrincipalOnlyOverride.
@Test()
public void testConfigValidationPrincipalOnlyOverride() {
AbstractHerder herder = createConfigValidationHerder(TestSourceConnector.class, new PrincipalConnectorClientConfigOverridePolicy());
replayAll();
Map<String, String> config = new HashMap<>();
config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, TestSourceConnector.class.getName());
config.put(ConnectorConfig.NAME_CONFIG, "connector-name");
// connector required config
config.put("required", "value");
String ackConfigKey = producerOverrideKey(ProducerConfig.ACKS_CONFIG);
String saslConfigKey = producerOverrideKey(SaslConfigs.SASL_JAAS_CONFIG);
config.put(ackConfigKey, "none");
config.put(saslConfigKey, "jaas_config");
ConfigInfos result = herder.validateConnectorConfig(config, false);
assertEquals(herder.connectorTypeForClass(config.get(ConnectorConfig.CONNECTOR_CLASS_CONFIG)), ConnectorType.SOURCE);
// We expect there to be errors due to now allowed override policy for ACKS.... Note that these assertions depend heavily on
// the config fields for SourceConnectorConfig, but we expect these to change rarely.
assertEquals(TestSourceConnector.class.getName(), result.name());
// Each transform also gets its own group
List<String> expectedGroups = Arrays.asList(ConnectorConfig.COMMON_GROUP, ConnectorConfig.TRANSFORMS_GROUP, ConnectorConfig.PREDICATES_GROUP, ConnectorConfig.ERROR_GROUP, SourceConnectorConfig.TOPIC_CREATION_GROUP);
assertEquals(expectedGroups, result.groups());
assertEquals(1, result.errorCount());
// Base connector config has 14 fields, connector's configs add 2, and 2 producer overrides
assertEquals(19, result.values().size());
assertTrue(result.values().stream().anyMatch(configInfo -> ackConfigKey.equals(configInfo.configValue().name()) && !configInfo.configValue().errors().isEmpty()));
assertTrue(result.values().stream().anyMatch(configInfo -> saslConfigKey.equals(configInfo.configValue().name()) && configInfo.configValue().errors().isEmpty()));
verifyAll();
}
use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class ConnectorPluginsResource method validateConfigs.
@PUT
@Path("/{connectorType}/config/validate")
public ConfigInfos validateConfigs(@PathParam("connectorType") final String connType, final Map<String, String> connectorConfig) throws Throwable {
String includedConnType = connectorConfig.get(ConnectorConfig.CONNECTOR_CLASS_CONFIG);
if (includedConnType != null && !normalizedPluginName(includedConnType).endsWith(normalizedPluginName(connType))) {
throw new BadRequestException("Included connector type " + includedConnType + " does not match request type " + connType);
}
// the validated configs don't need to be logged
FutureCallback<ConfigInfos> validationCallback = new FutureCallback<>();
herder.validateConnectorConfig(connectorConfig, validationCallback, false);
try {
return validationCallback.get(ConnectorsResource.REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
// error is the best option
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request timed out");
} catch (InterruptedException e) {
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request interrupted");
}
}
Aggregations