Search in sources :

Example 11 with CryptoService

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

the class SplitLarge method execute.

@Override
public void execute(String[] args) throws Exception {
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);
    Opts opts = new Opts();
    opts.parseArgs("accumulo split-large", args);
    for (String file : opts.files) {
        AccumuloConfiguration aconf = opts.getSiteConfiguration();
        CryptoService cryptoService = CryptoServiceFactory.newInstance(aconf, CryptoServiceFactory.ClassloaderType.JAVA);
        Path path = new Path(file);
        CachableBuilder cb = new CachableBuilder().fsPath(fs, path).conf(conf).cryptoService(cryptoService);
        try (Reader iter = new RFile.Reader(cb)) {
            if (!file.endsWith(".rf")) {
                throw new IllegalArgumentException("File must end with .rf");
            }
            String smallName = file.substring(0, file.length() - 3) + "_small.rf";
            String largeName = file.substring(0, file.length() - 3) + "_large.rf";
            int blockSize = (int) aconf.getAsBytes(Property.TABLE_FILE_BLOCK_SIZE);
            try (Writer small = new RFile.Writer(new BCFile.Writer(fs.create(new Path(smallName)), null, "gz", conf, cryptoService), blockSize);
                Writer large = new RFile.Writer(new BCFile.Writer(fs.create(new Path(largeName)), null, "gz", conf, cryptoService), blockSize)) {
                small.startDefaultLocalityGroup();
                large.startDefaultLocalityGroup();
                iter.seek(new Range(), new ArrayList<>(), false);
                while (iter.hasTop()) {
                    Key key = iter.getTopKey();
                    Value value = iter.getTopValue();
                    if (key.getSize() + value.getSize() < opts.maxSize) {
                        small.append(key, value);
                    } else {
                        large.append(key, value);
                    }
                    iter.next();
                }
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ConfigOpts(org.apache.accumulo.core.cli.ConfigOpts) Reader(org.apache.accumulo.core.file.rfile.RFile.Reader) BCFile(org.apache.accumulo.core.file.rfile.bcfile.BCFile) Range(org.apache.accumulo.core.data.Range) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) FileSystem(org.apache.hadoop.fs.FileSystem) Value(org.apache.accumulo.core.data.Value) CachableBuilder(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBuilder) Writer(org.apache.accumulo.core.file.rfile.RFile.Writer) Key(org.apache.accumulo.core.data.Key) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 12 with CryptoService

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

the class CryptoTest method testMissingConfigProperties.

@Test
public void testMissingConfigProperties() throws ReflectiveOperationException {
    ConfigurationCopy aconf = new ConfigurationCopy(DefaultConfiguration.getInstance());
    Configuration conf = new Configuration(false);
    for (Map.Entry<String, String> e : conf) {
        aconf.set(e.getKey(), e.getValue());
    }
    aconf.set(Property.INSTANCE_CRYPTO_SERVICE, "org.apache.accumulo.core.spi.crypto.AESCryptoService");
    String configuredClass = aconf.get(Property.INSTANCE_CRYPTO_SERVICE.getKey());
    Class<? extends CryptoService> clazz = ClassLoaderUtil.loadClass(configuredClass, CryptoService.class);
    CryptoService cs = clazz.getDeclaredConstructor().newInstance();
    assertEquals(AESCryptoService.class, cs.getClass());
    assertThrows(NullPointerException.class, () -> cs.init(aconf.getAllPropertiesWithPrefix(Property.TABLE_PREFIX)));
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) Configuration(org.apache.hadoop.conf.Configuration) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 13 with CryptoService

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

the class DfsLogger method getDecryptingStream.

/**
 * Reads the WAL file header, and returns a decrypting stream which wraps the original stream. If
 * the file is not encrypted, the original stream is returned.
 *
 * @throws LogHeaderIncompleteException
 *           if the header cannot be fully read (can happen if the tserver died before finishing)
 */
public static DataInputStream getDecryptingStream(FSDataInputStream input, AccumuloConfiguration conf) throws LogHeaderIncompleteException, IOException {
    DataInputStream decryptingInput;
    byte[] magic4 = DfsLogger.LOG_FILE_HEADER_V4.getBytes(UTF_8);
    byte[] magic3 = DfsLogger.LOG_FILE_HEADER_V3.getBytes(UTF_8);
    if (magic4.length != magic3.length)
        throw new AssertionError("Always expect log file headers to be same length : " + magic4.length + " != " + magic3.length);
    byte[] magicBuffer = new byte[magic4.length];
    try {
        input.readFully(magicBuffer);
        if (Arrays.equals(magicBuffer, magic4)) {
            CryptoService cryptoService = CryptoServiceFactory.newInstance(conf, ClassloaderType.ACCUMULO);
            FileDecrypter decrypter = CryptoUtils.getFileDecrypter(cryptoService, Scope.WAL, input);
            log.debug("Using {} for decrypting WAL", cryptoService.getClass().getSimpleName());
            decryptingInput = cryptoService instanceof NoCryptoService ? input : new DataInputStream(decrypter.decryptStream(input));
        } else if (Arrays.equals(magicBuffer, magic3)) {
            // Read logs files from Accumulo 1.9
            String cryptoModuleClassname = input.readUTF();
            if (!cryptoModuleClassname.equals("NullCryptoModule")) {
                throw new IllegalArgumentException("Old encryption modules not supported at this time.  Unsupported module : " + cryptoModuleClassname);
            }
            decryptingInput = input;
        } else {
            throw new IllegalArgumentException("Unsupported write ahead log version " + new String(magicBuffer));
        }
    } catch (EOFException e) {
        // A TabletServer might have died before the (complete) header was written
        throw new LogHeaderIncompleteException(e);
    }
    return decryptingInput;
}
Also used : NoCryptoService(org.apache.accumulo.core.spi.crypto.NoCryptoService) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) NoCryptoService(org.apache.accumulo.core.spi.crypto.NoCryptoService) FileDecrypter(org.apache.accumulo.core.spi.crypto.FileDecrypter) EOFException(java.io.EOFException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) DataInputStream(java.io.DataInputStream)

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