Search in sources :

Example 1 with CryptoService

use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.

the class BulkImport method computeFileToTabletMappings.

public SortedMap<KeyExtent, Bulk.Files> computeFileToTabletMappings(FileSystem fs, TableId tableId, Path dirPath, Executor executor, ClientContext context, int maxTablets) throws IOException {
    KeyExtentCache extentCache = new ConcurrentKeyExtentCache(tableId, context);
    List<FileStatus> files = filterInvalid(fs.listStatus(dirPath, p -> !p.getName().equals(Constants.BULK_LOAD_MAPPING)));
    // we know all of the file lens, so construct a cache and populate it in order to avoid later
    // trips to the namenode
    Cache<String, Long> fileLensCache = getPopulatedFileLenCache(dirPath, files);
    List<CompletableFuture<Map<KeyExtent, Bulk.FileInfo>>> futures = new ArrayList<>();
    CryptoService cs = CryptoServiceFactory.newDefaultInstance();
    for (FileStatus fileStatus : files) {
        Path filePath = fileStatus.getPath();
        CompletableFuture<Map<KeyExtent, Bulk.FileInfo>> future = CompletableFuture.supplyAsync(() -> {
            try {
                long t1 = System.currentTimeMillis();
                List<KeyExtent> extents = findOverlappingTablets(context, extentCache, filePath, fs, fileLensCache, cs);
                // make sure file isn't going to too many tablets
                checkTabletCount(maxTablets, extents.size(), filePath.toString());
                Map<KeyExtent, Long> estSizes = estimateSizes(context.getConfiguration(), filePath, fileStatus.getLen(), extents, fs, fileLensCache, cs);
                Map<KeyExtent, Bulk.FileInfo> pathLocations = new HashMap<>();
                for (KeyExtent ke : extents) {
                    pathLocations.put(ke, new Bulk.FileInfo(filePath, estSizes.getOrDefault(ke, 0L)));
                }
                long t2 = System.currentTimeMillis();
                log.debug("Mapped {} to {} tablets in {}ms", filePath, pathLocations.size(), t2 - t1);
                return pathLocations;
            } catch (Exception e) {
                throw new CompletionException(e);
            }
        }, executor);
        futures.add(future);
    }
    SortedMap<KeyExtent, Bulk.Files> mappings = new TreeMap<>();
    for (CompletableFuture<Map<KeyExtent, Bulk.FileInfo>> future : futures) {
        try {
            Map<KeyExtent, Bulk.FileInfo> pathMapping = future.get();
            pathMapping.forEach((ext, fi) -> mappings.computeIfAbsent(ext, k -> new Files()).add(fi));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
    return mergeOverlapping(mappings);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ByteSequence(org.apache.accumulo.core.data.ByteSequence) Arrays(java.util.Arrays) FileSystem(org.apache.hadoop.fs.FileSystem) LoggerFactory(org.slf4j.LoggerFactory) Text(org.apache.hadoop.io.Text) FileStatus(org.apache.hadoop.fs.FileStatus) ByteBuffer(java.nio.ByteBuffer) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) CachableBlockFile.pathToCacheId(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.pathToCacheId) ConfigurationTypeHelper(org.apache.accumulo.core.conf.ConfigurationTypeHelper) FileOperations(org.apache.accumulo.core.file.FileOperations) AccumuloBulkMergeException(org.apache.accumulo.core.clientImpl.AccumuloBulkMergeException) TableOperationsImpl(org.apache.accumulo.core.clientImpl.TableOperationsImpl) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) FileInfo(org.apache.accumulo.core.clientImpl.bulk.Bulk.FileInfo) Property(org.apache.accumulo.core.conf.Property) LoadPlan(org.apache.accumulo.core.data.LoadPlan) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Collection(java.util.Collection) FileSKVIterator(org.apache.accumulo.core.file.FileSKVIterator) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ThreadPools(org.apache.accumulo.core.util.threads.ThreadPools) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) RangeType(org.apache.accumulo.core.data.LoadPlan.RangeType) FileNotFoundException(java.io.FileNotFoundException) Sets(com.google.common.collect.Sets) VolumeConfiguration(org.apache.accumulo.core.volume.VolumeConfiguration) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Files(org.apache.accumulo.core.clientImpl.bulk.Bulk.Files) ImportDestinationArguments(org.apache.accumulo.core.client.admin.TableOperations.ImportDestinationArguments) ImportMappingOptions(org.apache.accumulo.core.client.admin.TableOperations.ImportMappingOptions) CacheBuilder(com.google.common.cache.CacheBuilder) SortedMap(java.util.SortedMap) FilenameUtils(org.apache.commons.io.FilenameUtils) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Destination(org.apache.accumulo.core.data.LoadPlan.Destination) MINUTES(java.util.concurrent.TimeUnit.MINUTES) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) ExecutorService(java.util.concurrent.ExecutorService) EXISTING_TABLE_NAME(org.apache.accumulo.core.util.Validators.EXISTING_TABLE_NAME) Retry(org.apache.accumulo.fate.util.Retry) Logger(org.slf4j.Logger) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) Executor(java.util.concurrent.Executor) UTF_8(java.nio.charset.StandardCharsets.UTF_8) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) Constants(org.apache.accumulo.core.Constants) CryptoServiceFactory(org.apache.accumulo.core.crypto.CryptoServiceFactory) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Range(org.apache.accumulo.core.data.Range) ExecutionException(java.util.concurrent.ExecutionException) TreeMap(java.util.TreeMap) Preconditions(com.google.common.base.Preconditions) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) ClientProperty(org.apache.accumulo.core.conf.ClientProperty) FileStatus(org.apache.hadoop.fs.FileStatus) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileInfo(org.apache.accumulo.core.clientImpl.bulk.Bulk.FileInfo) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) CompletableFuture(java.util.concurrent.CompletableFuture) FileInfo(org.apache.accumulo.core.clientImpl.bulk.Bulk.FileInfo) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) Files(org.apache.accumulo.core.clientImpl.bulk.Bulk.Files) ExecutionException(java.util.concurrent.ExecutionException) Path(org.apache.hadoop.fs.Path) TreeMap(java.util.TreeMap) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloBulkMergeException(org.apache.accumulo.core.clientImpl.AccumuloBulkMergeException) CompletionException(java.util.concurrent.CompletionException) FileNotFoundException(java.io.FileNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ExecutionException(java.util.concurrent.ExecutionException) CompletionException(java.util.concurrent.CompletionException) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 2 with CryptoService

use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.

the class CryptoTest method decrypt.

private void decrypt(byte[] resultingBytes, Scope scope, ConfigMode configMode) throws Exception {
    try (DataInputStream dataIn = new DataInputStream(new ByteArrayInputStream(resultingBytes))) {
        AccumuloConfiguration conf = getAccumuloConfig(configMode);
        CryptoService cs = CryptoServiceFactory.newInstance(conf, ClassloaderType.JAVA);
        FileDecrypter decrypter = getFileDecrypter(cs, scope, dataIn);
        try (DataInputStream decrypted = new DataInputStream(decrypter.decryptStream(dataIn))) {
            String markerString = decrypted.readUTF();
            int markerInt = decrypted.readInt();
            assertEquals(MARKER_STRING, markerString);
            assertEquals(MARKER_INT, markerInt);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) CryptoUtils.getFileDecrypter(org.apache.accumulo.core.crypto.CryptoUtils.getFileDecrypter) FileDecrypter(org.apache.accumulo.core.spi.crypto.FileDecrypter) DataInputStream(java.io.DataInputStream) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 3 with CryptoService

use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.

the class CryptoTest method testNoEncryptionRFILE.

@Test
public void testNoEncryptionRFILE() throws Exception {
    CryptoService cs = CryptoServiceFactory.newDefaultInstance();
    byte[] encryptedBytes = encrypt(cs, Scope.RFILE, ConfigMode.CRYPTO_OFF);
    String stringifiedBytes = Arrays.toString(encryptedBytes);
    String stringifiedMarkerBytes = getStringifiedBytes("U+1F47B".getBytes(), MARKER_STRING, MARKER_INT);
    assertEquals(stringifiedBytes, stringifiedMarkerBytes);
    decrypt(encryptedBytes, Scope.RFILE, ConfigMode.CRYPTO_OFF);
}
Also used : AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) Test(org.junit.jupiter.api.Test)

Example 4 with CryptoService

use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.

the class CryptoTest method testNoEncryptionWAL.

@Test
public void testNoEncryptionWAL() throws Exception {
    CryptoService cs = CryptoServiceFactory.newDefaultInstance();
    byte[] encryptedBytes = encrypt(cs, Scope.WAL, ConfigMode.CRYPTO_OFF);
    String stringifiedBytes = Arrays.toString(encryptedBytes);
    String stringifiedMarkerBytes = getStringifiedBytes("U+1F47B".getBytes(), MARKER_STRING, MARKER_INT);
    assertEquals(stringifiedBytes, stringifiedMarkerBytes);
    decrypt(encryptedBytes, Scope.WAL, ConfigMode.CRYPTO_OFF);
}
Also used : AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) Test(org.junit.jupiter.api.Test)

Example 5 with CryptoService

use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.

the class CryptoTest method simpleGCMTest.

@Test
public void simpleGCMTest() throws Exception {
    AccumuloConfiguration conf = getAccumuloConfig(ConfigMode.CRYPTO_ON);
    CryptoService cs = new AESCryptoService();
    cs.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
    CryptoEnvironment encEnv = new CryptoEnvironmentImpl(Scope.RFILE, null);
    FileEncrypter encrypter = cs.getFileEncrypter(encEnv);
    byte[] params = encrypter.getDecryptionParameters();
    assertNotNull(params);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(out);
    CryptoUtils.writeParams(params, dataOut);
    OutputStream encrypted = encrypter.encryptStream(dataOut);
    assertNotNull(encrypted);
    DataOutputStream cipherOut = new DataOutputStream(encrypted);
    cipherOut.writeUTF(MARKER_STRING);
    cipherOut.close();
    dataOut.close();
    encrypted.close();
    out.close();
    byte[] cipherText = out.toByteArray();
    // decrypt
    ByteArrayInputStream in = new ByteArrayInputStream(cipherText);
    FileDecrypter decrypter = getFileDecrypter(cs, Scope.RFILE, new DataInputStream(in));
    DataInputStream decrypted = new DataInputStream(decrypter.decryptStream(in));
    String plainText = decrypted.readUTF();
    decrypted.close();
    in.close();
    assertEquals(MARKER_STRING, new String(plainText));
}
Also used : CryptoEnvironment(org.apache.accumulo.core.spi.crypto.CryptoEnvironment) DataOutputStream(java.io.DataOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CryptoUtils.getFileDecrypter(org.apache.accumulo.core.crypto.CryptoUtils.getFileDecrypter) FileDecrypter(org.apache.accumulo.core.spi.crypto.FileDecrypter) DataOutputStream(java.io.DataOutputStream) NoFlushOutputStream(org.apache.accumulo.core.crypto.streams.NoFlushOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) FileEncrypter(org.apache.accumulo.core.spi.crypto.FileEncrypter) AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) ByteArrayInputStream(java.io.ByteArrayInputStream) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

CryptoService (org.apache.accumulo.core.spi.crypto.CryptoService)13 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)6 AESCryptoService (org.apache.accumulo.core.spi.crypto.AESCryptoService)5 Path (org.apache.hadoop.fs.Path)4 Test (org.junit.jupiter.api.Test)4 DataInputStream (java.io.DataInputStream)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)3 Key (org.apache.accumulo.core.data.Key)3 FileDecrypter (org.apache.accumulo.core.spi.crypto.FileDecrypter)3 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataOutputStream (java.io.DataOutputStream)2 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 TreeMap (java.util.TreeMap)2 CryptoUtils.getFileDecrypter (org.apache.accumulo.core.crypto.CryptoUtils.getFileDecrypter)2