use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class AbstractHerderTest method testGenerateResultWithConfigValuesMoreThanConfigKeysAndWithSomeErrors.
@Test
public void testGenerateResultWithConfigValuesMoreThanConfigKeysAndWithSomeErrors() {
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", "error c1");
addValue(values, "config.extra1", "value.extra1");
addValue(values, "config.extra2", "value.extra2", "error extra2");
ConfigInfos infos = AbstractHerder.generateResult(name, keys, values, groups);
assertEquals(name, infos.name());
assertEquals(groups, infos.groups());
assertEquals(values.size(), infos.values().size());
assertEquals(2, 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");
assertNoInfoKey(infos, "config.extra1");
assertNoInfoKey(infos, "config.extra2");
assertInfoValue(infos, "config.a1", "value.a1");
assertInfoValue(infos, "config.b1", "value.b1");
assertInfoValue(infos, "config.b2", "value.b2");
assertInfoValue(infos, "config.c1", "value.c1", "error c1");
assertInfoValue(infos, "config.extra1", "value.extra1");
assertInfoValue(infos, "config.extra2", "value.extra2", "error extra2");
}
use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class AbstractHerder method validateClientOverrides.
private static ConfigInfos validateClientOverrides(String connName, String prefix, AbstractConfig connectorConfig, ConfigDef configDef, Class<? extends Connector> connectorClass, org.apache.kafka.connect.health.ConnectorType connectorType, ConnectorClientConfigRequest.ClientType clientType, ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy) {
int errorCount = 0;
List<ConfigInfo> configInfoList = new LinkedList<>();
Map<String, ConfigKey> configKeys = configDef.configKeys();
Set<String> groups = new LinkedHashSet<>();
Map<String, Object> clientConfigs = new HashMap<>();
for (Map.Entry<String, Object> rawClientConfig : connectorConfig.originalsWithPrefix(prefix).entrySet()) {
String configName = rawClientConfig.getKey();
Object rawConfigValue = rawClientConfig.getValue();
ConfigKey configKey = configDef.configKeys().get(configName);
Object parsedConfigValue = configKey != null ? ConfigDef.parseType(configName, rawConfigValue, configKey.type) : rawConfigValue;
clientConfigs.put(configName, parsedConfigValue);
}
ConnectorClientConfigRequest connectorClientConfigRequest = new ConnectorClientConfigRequest(connName, connectorType, connectorClass, clientConfigs, clientType);
List<ConfigValue> configValues = connectorClientConfigOverridePolicy.validate(connectorClientConfigRequest);
if (configValues != null) {
for (ConfigValue validatedConfigValue : configValues) {
ConfigKey configKey = configKeys.get(validatedConfigValue.name());
ConfigKeyInfo configKeyInfo = null;
if (configKey != null) {
if (configKey.group != null) {
groups.add(configKey.group);
}
configKeyInfo = convertConfigKey(configKey, prefix);
}
ConfigValue configValue = new ConfigValue(prefix + validatedConfigValue.name(), validatedConfigValue.value(), validatedConfigValue.recommendedValues(), validatedConfigValue.errorMessages());
if (configValue.errorMessages().size() > 0) {
errorCount++;
}
ConfigValueInfo configValueInfo = convertConfigValue(configValue, configKey != null ? configKey.type : null);
configInfoList.add(new ConfigInfo(configKeyInfo, configValueInfo));
}
}
return new ConfigInfos(connectorClass.toString(), errorCount, new ArrayList<>(groups), configInfoList);
}
use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class AbstractHerder method generateResult.
// public for testing
public static ConfigInfos generateResult(String connType, Map<String, ConfigKey> configKeys, List<ConfigValue> configValues, List<String> groups) {
int errorCount = 0;
List<ConfigInfo> configInfoList = new LinkedList<>();
Map<String, ConfigValue> configValueMap = new HashMap<>();
for (ConfigValue configValue : configValues) {
String configName = configValue.name();
configValueMap.put(configName, configValue);
if (!configKeys.containsKey(configName)) {
configInfoList.add(new ConfigInfo(null, convertConfigValue(configValue, null)));
errorCount += configValue.errorMessages().size();
}
}
for (Map.Entry<String, ConfigKey> entry : configKeys.entrySet()) {
String configName = entry.getKey();
ConfigKeyInfo configKeyInfo = convertConfigKey(entry.getValue());
Type type = entry.getValue().type;
ConfigValueInfo configValueInfo = null;
if (configValueMap.containsKey(configName)) {
ConfigValue configValue = configValueMap.get(configName);
configValueInfo = convertConfigValue(configValue, type);
errorCount += configValue.errorMessages().size();
}
configInfoList.add(new ConfigInfo(configKeyInfo, configValueInfo));
}
return new ConfigInfos(connType, errorCount, groups, configInfoList);
}
use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.
the class ConnectorPluginsResourceTest method testValidateConfigWithAlias.
@Test
public void testValidateConfigWithAlias() throws Throwable {
Capture<Callback<ConfigInfos>> configInfosCallback = EasyMock.newCapture();
herder.validateConnectorConfig(EasyMock.eq(props), EasyMock.capture(configInfosCallback), EasyMock.anyBoolean());
PowerMock.expectLastCall().andAnswer((IAnswer<ConfigInfos>) () -> {
ConfigDef connectorConfigDef = ConnectorConfig.configDef();
List<ConfigValue> connectorConfigValues = connectorConfigDef.validate(props);
Connector connector = new ConnectorPluginsResourceTestConnector();
Config config = connector.validate(props);
ConfigDef configDef = connector.config();
Map<String, ConfigDef.ConfigKey> configKeys = configDef.configKeys();
List<ConfigValue> configValues = config.configValues();
Map<String, ConfigDef.ConfigKey> resultConfigKeys = new HashMap<>(configKeys);
resultConfigKeys.putAll(connectorConfigDef.configKeys());
configValues.addAll(connectorConfigValues);
ConfigInfos configInfos = AbstractHerder.generateResult(ConnectorPluginsResourceTestConnector.class.getName(), resultConfigKeys, configValues, Collections.singletonList("Test"));
configInfosCallback.getValue().onCompletion(null, configInfos);
return null;
});
PowerMock.replayAll();
// make a request to connector-plugins resource using a valid alias.
ConfigInfos configInfos = connectorPluginsResource.validateConfigs("ConnectorPluginsResourceTest", props);
assertEquals(CONFIG_INFOS.name(), configInfos.name());
assertEquals(0, configInfos.errorCount());
assertEquals(CONFIG_INFOS.groups(), configInfos.groups());
assertEquals(new HashSet<>(CONFIG_INFOS.values()), new HashSet<>(configInfos.values()));
PowerMock.verifyAll();
}
Aggregations