Search in sources :

Example 36 with Property

use of org.apache.accumulo.core.conf.Property in project accumulo by apache.

the class ClientOpts method getClientConfiguration.

public ClientConfiguration getClientConfiguration() throws IllegalArgumentException {
    if (cachedClientConfig != null)
        return cachedClientConfig;
    ClientConfiguration clientConfig;
    try {
        if (clientConfigFile == null)
            clientConfig = ClientConfiguration.loadDefault();
        else
            clientConfig = ClientConfiguration.fromFile(new File(clientConfigFile));
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    if (sslEnabled)
        clientConfig.setProperty(ClientProperty.INSTANCE_RPC_SSL_ENABLED, "true");
    if (saslEnabled)
        clientConfig.setProperty(ClientProperty.INSTANCE_RPC_SASL_ENABLED, "true");
    if (siteFile != null) {
        AccumuloConfiguration config = new AccumuloConfiguration() {

            Configuration xml = new Configuration();

            {
                xml.addResource(new Path(siteFile));
            }

            @Override
            public void getProperties(Map<String, String> props, Predicate<String> filter) {
                for (Entry<String, String> prop : DefaultConfiguration.getInstance()) if (filter.test(prop.getKey()))
                    props.put(prop.getKey(), prop.getValue());
                for (Entry<String, String> prop : xml) if (filter.test(prop.getKey()))
                    props.put(prop.getKey(), prop.getValue());
            }

            @Override
            public String get(Property property) {
                String value = xml.get(property.getKey());
                if (value != null)
                    return value;
                return DefaultConfiguration.getInstance().get(property);
            }
        };
        this.zookeepers = config.get(Property.INSTANCE_ZK_HOST);
        String volDir = VolumeConfiguration.getVolumeUris(config)[0];
        Path instanceDir = new Path(volDir, "instance_id");
        String instanceIDFromFile = ZooUtil.getInstanceIDFromHdfs(instanceDir, config);
        if (config.getBoolean(Property.INSTANCE_RPC_SSL_ENABLED))
            clientConfig.setProperty(ClientProperty.INSTANCE_RPC_SSL_ENABLED, "true");
        return cachedClientConfig = clientConfig.withInstance(UUID.fromString(instanceIDFromFile)).withZkHosts(zookeepers);
    }
    return cachedClientConfig = clientConfig.withInstance(instance).withZkHosts(zookeepers);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) VolumeConfiguration(org.apache.accumulo.core.volume.VolumeConfiguration) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ClientProperty(org.apache.accumulo.core.client.ClientConfiguration.ClientProperty) Property(org.apache.accumulo.core.conf.Property) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Predicate(java.util.function.Predicate)

Example 37 with Property

use of org.apache.accumulo.core.conf.Property in project accumulo by apache.

the class TableOperationsImpl method addSummarizers.

@Override
public void addSummarizers(String tableName, SummarizerConfiguration... newConfigs) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    HashSet<SummarizerConfiguration> currentConfigs = new HashSet<>(SummarizerConfiguration.fromTableProperties(getProperties(tableName)));
    HashSet<SummarizerConfiguration> newConfigSet = new HashSet<>(Arrays.asList(newConfigs));
    newConfigSet.removeIf(sc -> currentConfigs.contains(sc));
    Set<String> newIds = newConfigSet.stream().map(sc -> sc.getPropertyId()).collect(toSet());
    for (SummarizerConfiguration csc : currentConfigs) {
        if (newIds.contains(csc.getPropertyId())) {
            throw new IllegalArgumentException("Summarizer property id is in use by " + csc);
        }
    }
    Set<Entry<String, String>> es = SummarizerConfiguration.toTableProperties(newConfigSet).entrySet();
    for (Entry<String, String> entry : es) {
        setProperty(tableName, entry.getKey(), entry.getValue());
    }
}
Also used : ByteSequence(org.apache.accumulo.core.data.ByteSequence) Arrays(java.util.Arrays) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) FileSystem(org.apache.hadoop.fs.FileSystem) Constraint(org.apache.accumulo.core.constraints.Constraint) Text(org.apache.hadoop.io.Text) FileStatus(org.apache.hadoop.fs.FileStatus) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) FindMax(org.apache.accumulo.core.client.admin.FindMax) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) Map(java.util.Map) RootTable(org.apache.accumulo.core.metadata.RootTable) Locations(org.apache.accumulo.core.client.admin.Locations) EnumSet(java.util.EnumSet) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) Property(org.apache.accumulo.core.conf.Property) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) ThriftNotActiveServiceException(org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException) Set(java.util.Set) TimeType(org.apache.accumulo.core.client.admin.TimeType) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Executors(java.util.concurrent.Executors) VolumeConfiguration(org.apache.accumulo.core.volume.VolumeConfiguration) Tracer(org.apache.accumulo.core.trace.Tracer) CountDownLatch(java.util.concurrent.CountDownLatch) TRowRange(org.apache.accumulo.core.data.thrift.TRowRange) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) UtilWaitThread.sleepUninterruptibly(org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Joiner(com.google.common.base.Joiner) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TableExistsException(org.apache.accumulo.core.client.TableExistsException) SummarizerConfigurationUtil(org.apache.accumulo.core.summary.SummarizerConfigurationUtil) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) MetadataServicer(org.apache.accumulo.core.metadata.MetadataServicer) TableState(org.apache.accumulo.core.master.state.tables.TableState) Key(org.apache.accumulo.core.data.Key) DiskUsage(org.apache.accumulo.core.client.admin.DiskUsage) IteratorUtil(org.apache.accumulo.core.iterators.IteratorUtil) FateOperation(org.apache.accumulo.core.master.thrift.FateOperation) Summary(org.apache.accumulo.core.client.summary.Summary) TSummaryRequest(org.apache.accumulo.core.data.thrift.TSummaryRequest) TException(org.apache.thrift.TException) IOException(java.io.IOException) TabletId(org.apache.accumulo.core.data.TabletId) InputStreamReader(java.io.InputStreamReader) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) OpTimer(org.apache.accumulo.core.util.OpTimer) TreeMap(java.util.TreeMap) CachedConfiguration(org.apache.accumulo.core.util.CachedConfiguration) ClientService(org.apache.accumulo.core.client.impl.thrift.ClientService) Preconditions(com.google.common.base.Preconditions) BufferedReader(java.io.BufferedReader) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) ThriftUtil(org.apache.accumulo.core.rpc.ThriftUtil) SortedSet(java.util.SortedSet) TTransportException(org.apache.thrift.transport.TTransportException) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TextUtil(org.apache.accumulo.core.util.TextUtil) ByteBuffer(java.nio.ByteBuffer) TDiskUsage(org.apache.accumulo.core.client.impl.thrift.TDiskUsage) LocalityGroupUtil(org.apache.accumulo.core.util.LocalityGroupUtil) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamingThreadFactory(org.apache.accumulo.core.util.NamingThreadFactory) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Path(org.apache.hadoop.fs.Path) Value(org.apache.accumulo.core.data.Value) ZipEntry(java.util.zip.ZipEntry) Collectors.toSet(java.util.stream.Collectors.toSet) Predicate(java.util.function.Predicate) Collection(java.util.Collection) TSummaries(org.apache.accumulo.core.data.thrift.TSummaries) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) TabletsSection(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection) Objects(java.util.Objects) MapCounter(org.apache.accumulo.core.util.MapCounter) List(java.util.List) Pair(org.apache.accumulo.core.util.Pair) Entry(java.util.Map.Entry) Pattern(java.util.regex.Pattern) ZipInputStream(java.util.zip.ZipInputStream) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) TabletLocation(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) Objects.requireNonNull(java.util.Objects.requireNonNull) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration) LinkedList(java.util.LinkedList) TApplicationException(org.apache.thrift.TApplicationException) ExecutorService(java.util.concurrent.ExecutorService) Retry(org.apache.accumulo.fate.util.Retry) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) SummaryRetriever(org.apache.accumulo.core.client.admin.SummaryRetriever) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TimeUnit(java.util.concurrent.TimeUnit) TabletIdImpl(org.apache.accumulo.core.data.impl.TabletIdImpl) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) RowIterator(org.apache.accumulo.core.client.RowIterator) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration) HashSet(java.util.HashSet)

Example 38 with Property

use of org.apache.accumulo.core.conf.Property in project accumulo by apache.

the class ClientContext method convertClientConfig.

/**
 * A utility method for converting client configuration to a standard configuration object for use internally.
 *
 * @param config
 *          the original {@link ClientConfiguration}
 * @return the client configuration presented in the form of an {@link AccumuloConfiguration}
 */
public static AccumuloConfiguration convertClientConfig(final ClientConfiguration config) {
    final AccumuloConfiguration defaults = DefaultConfiguration.getInstance();
    return new AccumuloConfiguration() {

        @Override
        public String get(Property property) {
            final String key = property.getKey();
            // Attempt to load sensitive properties from a CredentialProvider, if configured
            if (property.isSensitive()) {
                org.apache.hadoop.conf.Configuration hadoopConf = getHadoopConfiguration();
                if (null != hadoopConf) {
                    try {
                        char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf, key);
                        if (null != value) {
                            log.trace("Loaded sensitive value for {} from CredentialProvider", key);
                            return new String(value);
                        } else {
                            log.trace("Tried to load sensitive value for {} from CredentialProvider, but none was found", key);
                        }
                    } catch (IOException e) {
                        log.warn("Failed to extract sensitive property ({}) from Hadoop CredentialProvider, falling back to base AccumuloConfiguration", key, e);
                    }
                }
            }
            if (config.containsKey(key))
                return config.getString(key);
            else {
                // Reconstitute the server kerberos property from the client config
                if (Property.GENERAL_KERBEROS_PRINCIPAL == property) {
                    if (config.containsKey(ClientConfiguration.ClientProperty.KERBEROS_SERVER_PRIMARY.getKey())) {
                        // Avoid providing a realm since we don't know what it is...
                        return config.getString(ClientConfiguration.ClientProperty.KERBEROS_SERVER_PRIMARY.getKey()) + "/_HOST@" + SaslConnectionParams.getDefaultRealm();
                    }
                }
                return defaults.get(property);
            }
        }

        @Override
        public void getProperties(Map<String, String> props, Predicate<String> filter) {
            defaults.getProperties(props, filter);
            Iterator<String> keyIter = config.getKeys();
            while (keyIter.hasNext()) {
                String key = keyIter.next().toString();
                if (filter.test(key))
                    props.put(key, config.getString(key));
            }
            // Automatically reconstruct the server property when converting a client config.
            if (props.containsKey(ClientConfiguration.ClientProperty.KERBEROS_SERVER_PRIMARY.getKey())) {
                final String serverPrimary = props.remove(ClientConfiguration.ClientProperty.KERBEROS_SERVER_PRIMARY.getKey());
                if (filter.test(Property.GENERAL_KERBEROS_PRINCIPAL.getKey())) {
                    // Use the _HOST expansion. It should be unnecessary in "client land".
                    props.put(Property.GENERAL_KERBEROS_PRINCIPAL.getKey(), serverPrimary + "/_HOST@" + SaslConnectionParams.getDefaultRealm());
                }
            }
            // Attempt to load sensitive properties from a CredentialProvider, if configured
            org.apache.hadoop.conf.Configuration hadoopConf = getHadoopConfiguration();
            if (null != hadoopConf) {
                try {
                    for (String key : CredentialProviderFactoryShim.getKeys(hadoopConf)) {
                        if (!Property.isValidPropertyKey(key) || !Property.isSensitive(key)) {
                            continue;
                        }
                        if (filter.test(key)) {
                            char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf, key);
                            if (null != value) {
                                props.put(key, new String(value));
                            }
                        }
                    }
                } catch (IOException e) {
                    log.warn("Failed to extract sensitive properties from Hadoop CredentialProvider, falling back to accumulo-site.xml", e);
                }
            }
        }

        private org.apache.hadoop.conf.Configuration getHadoopConfiguration() {
            String credProviderPaths = config.getString(Property.GENERAL_SECURITY_CREDENTIAL_PROVIDER_PATHS.getKey());
            if (null != credProviderPaths && !credProviderPaths.isEmpty()) {
                org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
                hadoopConf.set(CredentialProviderFactoryShim.CREDENTIAL_PROVIDER_PATH, credProviderPaths);
                return hadoopConf;
            }
            log.trace("Did not find credential provider configuration in ClientConfiguration");
            return null;
        }
    };
}
Also used : DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) IOException(java.io.IOException) Predicate(java.util.function.Predicate) Property(org.apache.accumulo.core.conf.Property) Map(java.util.Map) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 39 with Property

use of org.apache.accumulo.core.conf.Property in project accumulo by apache.

the class RFileTest method testCryptoDoesntLeakSensitive.

@Test
public void testCryptoDoesntLeakSensitive() throws IOException {
    conf = setAndGetAccumuloConfig(CryptoTest.CRYPTO_ON_CONF);
    // test an empty file
    TestRFile trf = new TestRFile(conf);
    trf.openWriter();
    trf.closeWriter();
    byte[] rfBytes = trf.baos.toByteArray();
    // If we get here, we have encrypted bytes
    for (Property prop : Property.values()) {
        if (prop.isSensitive()) {
            byte[] toCheck = prop.getKey().getBytes();
            assertEquals(-1, Bytes.indexOf(rfBytes, toCheck));
        }
    }
}
Also used : Property(org.apache.accumulo.core.conf.Property) CryptoTest(org.apache.accumulo.core.security.crypto.CryptoTest) Test(org.junit.Test)

Example 40 with Property

use of org.apache.accumulo.core.conf.Property in project accumulo by apache.

the class CryptoTest method testCryptoModuleDoesntLeakSensitive.

@Test
public void testCryptoModuleDoesntLeakSensitive() throws IOException {
    AccumuloConfiguration conf = setAndGetAccumuloConfig(CRYPTO_ON_CONF);
    CryptoModuleParameters params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    params.setPlaintextOutputStream(baos);
    CryptoModule cryptoModule = CryptoModuleFactory.getCryptoModule(conf);
    cryptoModule.getEncryptingOutputStream(params);
    params.getEncryptedOutputStream().close();
    // If we get here, we have encrypted bytes
    byte[] streamBytes = baos.toByteArray();
    for (Property prop : Property.values()) {
        if (prop.isSensitive()) {
            byte[] toCheck = prop.getKey().getBytes();
            assertEquals(-1, Bytes.indexOf(streamBytes, toCheck));
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Property(org.apache.accumulo.core.conf.Property) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Aggregations

Property (org.apache.accumulo.core.conf.Property)40 Test (org.junit.Test)19 HashMap (java.util.HashMap)11 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)11 File (java.io.File)8 Path (org.apache.hadoop.fs.Path)7 IOException (java.io.IOException)6 Map (java.util.Map)6 Predicate (java.util.function.Predicate)5 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)5 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)5 AccumuloException (org.apache.accumulo.core.client.AccumuloException)4 DefaultConfiguration (org.apache.accumulo.core.conf.DefaultConfiguration)4 TableConfiguration (org.apache.accumulo.server.conf.TableConfiguration)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)3 AccumuloServerContext (org.apache.accumulo.server.AccumuloServerContext)3 NamespaceConfiguration (org.apache.accumulo.server.conf.NamespaceConfiguration)3 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)3 ArrayList (java.util.ArrayList)2