Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package datawave.accumulo.core.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

import org.apache.accumulo.core.client.PluginEnvironment;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.conf.PropertyType;

/**
* A utility class that wraps an AccumuloConfiguration and implements PluginEnvironment.Configuration. This replaces the non-public
* org.apache.accumulo.core.util.ConfigurationImpl class.
*/
public class AccumuloConfigurationWrapper implements PluginEnvironment.Configuration {
Comment thread
SethSmucker marked this conversation as resolved.

private final AccumuloConfiguration conf;

public AccumuloConfigurationWrapper(AccumuloConfiguration conf) {
this.conf = conf;
}

@Override
public boolean isSet(String key) {
return conf.get(key) != null;
}

@Override
public String get(String key) {
return conf.get(key);
}

@Override
public Map<String,String> getWithPrefix(String prefix) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This method needs to add validation for the property and call
conf.getAllPropertiesWithPrefix.

The code in AccumuloConfiguration is special since most properties that use a defined accumulo prefix must be returned as a snapshot set.

This is handled in AccumuloConfiguration.getAllPropertiesWithPrefix() by using a ReentrantLock.

// For a defined prefix property, defer to AccumuloConfiguration.getAllPropertiesWithPrefix, which returns a
// consistent snapshot taken under the configuration's lock. Mirrors the non-public ConfigurationImpl behavior.
Property propertyPrefix = Property.getPropertyByKey(prefix);
if (propertyPrefix != null && propertyPrefix.getType() == PropertyType.PREFIX) {
return conf.getAllPropertiesWithPrefix(propertyPrefix);
}
Map<String,String> result = new HashMap<>();
for (Map.Entry<String,String> entry : conf) {
if (entry.getKey().startsWith(prefix)) {
result.put(entry.getKey(), entry.getValue());
}
}
return result;
}

@Override
public Map<String,String> getCustom() {
return getWithPrefix("general.custom.");
}

@Override
public String getCustom(String keySuffix) {
return get("general.custom." + keySuffix);
}

@Override
public Map<String,String> getTableCustom() {
return getWithPrefix("table.custom.");
}

@Override
public String getTableCustom(String keySuffix) {
return get("table.custom." + keySuffix);
}

@Override
public Iterator<Map.Entry<String,String>> iterator() {
return conf.iterator();
}

@Override
public <T> Supplier<T> getDerived(Function<PluginEnvironment.Configuration,T> computeDerivedValue) {
T value = computeDerivedValue.apply(this);
return () -> value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.spi.common.ServiceEnvironment;
import org.apache.accumulo.core.util.ConfigurationImpl;
import org.apache.commons.lang.NotImplementedException;

import datawave.accumulo.core.util.AccumuloConfigurationWrapper;

public class ConfigurableIteratorEnvironment implements IteratorEnvironment {

private IteratorUtil.IteratorScope scope;
Expand Down Expand Up @@ -114,7 +115,7 @@ public Configuration getConfiguration() {

@Override
public Configuration getConfiguration(TableId tableId) {
return new ConfigurationImpl(conf);
return new AccumuloConfigurationWrapper(conf);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.util.ConfigurationImpl;
import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.After;
Expand All @@ -59,6 +58,7 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

import datawave.accumulo.core.util.AccumuloConfigurationWrapper;
import datawave.data.type.LcNoDiacriticsType;
import datawave.data.type.Type;
import datawave.ingest.protobuf.TermWeight;
Expand Down Expand Up @@ -174,7 +174,7 @@ public void setup() throws IOException {
pluginEnv = createMock(PluginEnvironment.class);
EasyMock.expect(iterEnv.getConfig()).andReturn(DefaultConfiguration.getInstance()).anyTimes();
EasyMock.expect(iterEnv.getPluginEnv()).andReturn(pluginEnv).anyTimes();
EasyMock.expect(pluginEnv.getConfiguration()).andReturn(new ConfigurationImpl(DefaultConfiguration.getInstance())).anyTimes();
EasyMock.expect(pluginEnv.getConfiguration()).andReturn(new AccumuloConfigurationWrapper(DefaultConfiguration.getInstance())).anyTimes();
filter = createMock(EventDataQueryFilter.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.accumulo.core.spi.common.ServiceEnvironment;
import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
import org.apache.accumulo.core.spi.crypto.CryptoService;
import org.apache.accumulo.core.util.ConfigurationImpl;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.junit.Before;
Expand All @@ -45,6 +44,8 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import datawave.accumulo.core.util.AccumuloConfigurationWrapper;

public class SourceManagerTest {
private static final SimpleDateFormat shardFormatter = new SimpleDateFormat("yyyyMMdd HHmmss");
private static long ts = -1;
Expand Down Expand Up @@ -435,12 +436,12 @@ public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
public class MockPluginEnvironment implements PluginEnvironment {
@Override
public Configuration getConfiguration() {
return new ConfigurationImpl(conf);
return new AccumuloConfigurationWrapper(conf);
}

@Override
public Configuration getConfiguration(TableId tableId) {
return new ConfigurationImpl(conf);
return new AccumuloConfigurationWrapper(conf);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.DefaultConfiguration;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.util.ConfigurationImpl;

import datawave.accumulo.core.util.AccumuloConfigurationWrapper;

public class TestPluginEnv implements PluginEnvironment {

private final AccumuloConfiguration conf = DefaultConfiguration.getInstance();

@Override
public Configuration getConfiguration() {
return new ConfigurationImpl(conf);
return new AccumuloConfigurationWrapper(conf);
}

@Override
public Configuration getConfiguration(TableId tableId) {
return new ConfigurationImpl(conf);
return new AccumuloConfigurationWrapper(conf);
}

@Override
Expand Down
Loading