Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper-jute</artifactId>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Objects;

import org.apache.accumulo.core.spi.crypto.CryptoServiceFactory;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -43,9 +44,10 @@ public class ConfigCheckUtil {
* {@link Property#INSTANCE_ZK_TIMEOUT} within a valid range.
*
* @param entries iterable through configuration keys and values
* @param source the namespace, table id, site or system config where for diagnostic messages
* @throws ConfigCheckException if a fatal configuration error is found
*/
public static void validate(Iterable<Entry<String,String>> entries) {
public static void validate(Iterable<Entry<String,String>> entries, @NonNull String source) {
String instanceZkTimeoutValue = null;
for (Entry<String,String> entry : entries) {
String key = entry.getKey();
Expand All @@ -54,12 +56,12 @@ public static void validate(Iterable<Entry<String,String>> entries) {
if (prop == null && Property.isValidPropertyKey(key)) {
continue; // unknown valid property (i.e. has proper prefix)
} else if (prop == null) {
log.warn(PREFIX + "unrecognized property key (" + key + ")");
log.warn(PREFIX + "unrecognized property key ({}) for {}", key, source);
} else if (prop.getType() == PropertyType.PREFIX) {
fatal(PREFIX + "incomplete property key (" + key + ")");
fatal(PREFIX + "incomplete property key (" + key + ") for " + source);
} else if (!prop.getType().isValidFormat(value)) {
fatal(PREFIX + "improperly formatted value for key (" + key + ", type=" + prop.getType()
+ ") : " + value);
+ ") : " + value + " for " + source);
}

if (key.equals(Property.INSTANCE_ZK_TIMEOUT.getKey())) {
Expand Down Expand Up @@ -128,7 +130,7 @@ private static void verifyPropertyTypes(PropertyType type, Property... propertie
}

/**
* The exception thrown when {@link ConfigCheckUtil#validate(Iterable)} fails.
* The exception thrown when {@link ConfigCheckUtil#validate(Iterable, String)} fails.
*/
public static class ConfigCheckException extends RuntimeException {
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static SiteConfiguration auto() {
private final Map<String,String> config;

private SiteConfiguration(Map<String,String> config) {
ConfigCheckUtil.validate(config.entrySet());
ConfigCheckUtil.validate(config.entrySet(), "site config");
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,51 @@ public void testPass() {
m.put(Property.MANAGER_TABLET_BALANCER.getKey(),
"org.apache.accumulo.server.manager.balancer.TableLoadBalancer");
m.put(Property.MANAGER_BULK_RETRIES.getKey(), "3");
ConfigCheckUtil.validate(m.entrySet());
ConfigCheckUtil.validate(m.entrySet(), "test");
}

@Test
public void testPass_Empty() {
ConfigCheckUtil.validate(m.entrySet());
ConfigCheckUtil.validate(m.entrySet(), "test");
}

@Test
public void testPass_UnrecognizedValidProperty() {
m.put(Property.MANAGER_CLIENTPORT.getKey(), "9999");
m.put(Property.MANAGER_PREFIX.getKey() + "something", "abcdefg");
ConfigCheckUtil.validate(m.entrySet());
ConfigCheckUtil.validate(m.entrySet(), "test");
}

@Test
public void testPass_UnrecognizedProperty() {
m.put(Property.MANAGER_CLIENTPORT.getKey(), "9999");
m.put("invalid.prefix.value", "abcdefg");
ConfigCheckUtil.validate(m.entrySet());
ConfigCheckUtil.validate(m.entrySet(), "test");
}

@Test
public void testFail_Prefix() {
m.put(Property.MANAGER_CLIENTPORT.getKey(), "9999");
m.put(Property.MANAGER_PREFIX.getKey(), "oops");
assertThrows(ConfigCheckException.class, () -> ConfigCheckUtil.validate(m.entrySet()));
assertThrows(ConfigCheckException.class, () -> ConfigCheckUtil.validate(m.entrySet(), "test"));
}

@Test
public void testFail_InstanceZkTimeoutOutOfRange() {
m.put(Property.INSTANCE_ZK_TIMEOUT.getKey(), "10ms");
assertThrows(ConfigCheckException.class, () -> ConfigCheckUtil.validate(m.entrySet()));
assertThrows(ConfigCheckException.class, () -> ConfigCheckUtil.validate(m.entrySet(), "test"));
}

@Test
public void testFail_badCryptoFactory() {
m.put(Property.INSTANCE_CRYPTO_FACTORY.getKey(), "DoesNotExistCryptoFactory");
assertThrows(ConfigCheckException.class, () -> ConfigCheckUtil.validate(m.entrySet()));
assertThrows(ConfigCheckException.class, () -> ConfigCheckUtil.validate(m.entrySet(), "test"));
}

@Test
public void testPass_defaultCryptoFactory() {
m.put(Property.INSTANCE_CRYPTO_FACTORY.getKey(),
Property.INSTANCE_CRYPTO_FACTORY.getDefaultValue());
ConfigCheckUtil.validate(m.entrySet());
ConfigCheckUtil.validate(m.entrySet(), "test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public void testGetProperties() {

@Test
public void testSanityCheck() {
ConfigCheckUtil.validate(c);
ConfigCheckUtil.validate(c, "test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public TableConfiguration getTableConfiguration(TableId tableId) {
context.getPropStore().registerAsListener(TablePropKey.of(context, tableId), deleteWatcher);
var conf =
new TableConfiguration(context, tableId, getNamespaceConfigurationForTable(tableId));
ConfigCheckUtil.validate(conf);
ConfigCheckUtil.validate(conf, tableId.toString());
return conf;
}
return null;
Expand All @@ -129,7 +129,7 @@ public NamespaceConfiguration getNamespaceConfiguration(NamespaceId namespaceId)
context.getPropStore().registerAsListener(NamespacePropKey.of(context, namespaceId),
deleteWatcher);
var conf = new NamespaceConfiguration(context, namespaceId, getSystemConfiguration());
ConfigCheckUtil.validate(conf);
ConfigCheckUtil.validate(conf, namespaceId.toString());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are strings, I think I would have preferred something like:

ConfigCheckUtil.validate(conf, "Namespace id: " + namespaceId);

So we know it's a namespace and not a table ID. Same with the table IDs.

return conf;
});
}
Expand Down