Search in sources :

Example 46 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class HdfsBlobStoreImplTest method testGetFileLength.

@Test
public void testGetFileLength() throws Exception {
    Map<String, Object> conf = new HashMap<>();
    String validKey = "validkeyBasic";
    String testString = "testingblob";
    try (TestHdfsBlobStoreImpl hbs = new TestHdfsBlobStoreImpl(blobDir, conf, DFS_CLUSTER_RULE.getHadoopConf())) {
        BlobStoreFile pfile = hbs.write(validKey, false);
        // Adding metadata to avoid null pointer exception
        SettableBlobMeta meta = new SettableBlobMeta();
        meta.set_replication_factor(1);
        pfile.setMetadata(meta);
        try (OutputStream ios = pfile.getOutputStream()) {
            ios.write(testString.getBytes(StandardCharsets.UTF_8));
        }
        assertEquals(testString.getBytes(StandardCharsets.UTF_8).length, pfile.getFileLength());
    }
}
Also used : HashMap(java.util.HashMap) BlobStoreFile(org.apache.storm.blobstore.BlobStoreFile) OutputStream(java.io.OutputStream) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) Test(org.junit.Test)

Example 47 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class BlobStoreTest method testBasic.

public void testBasic(BlobStore store) throws Exception {
    assertStoreHasExactly(store);
    LOG.info("Creating test");
    // Tests for case when subject == null (security turned off) and
    // acls for the blob are set to WORLD_EVERYTHING
    SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
    try (AtomicOutputStream out = store.createBlob("test", metadata, null)) {
        out.write(1);
    }
    assertStoreHasExactly(store, "test");
    // Testing whether acls are set to WORLD_EVERYTHING
    assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
    readAssertEquals(store, "test", 1);
    LOG.info("Deleting test");
    store.deleteBlob("test", null);
    assertStoreHasExactly(store);
    // The following tests are run for both hdfs and local store to test the
    // update blob interface
    metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
    LOG.info("Creating test again");
    try (AtomicOutputStream out = store.createBlob("test", metadata, null)) {
        out.write(2);
    }
    assertStoreHasExactly(store, "test");
    readAssertEquals(store, "test", 2);
    LOG.info("Updating test");
    try (AtomicOutputStream out = store.updateBlob("test", null)) {
        out.write(3);
    }
    assertStoreHasExactly(store, "test");
    readAssertEquals(store, "test", 3);
    LOG.info("Updating test again");
    try (AtomicOutputStream out = store.updateBlob("test", null)) {
        out.write(4);
    }
    LOG.info("SLEEPING");
    Thread.sleep(2);
    if (store instanceof HdfsBlobStore) {
        ((HdfsBlobStore) store).fullCleanup(1);
    } else {
        fail("Error the blobstore is of unknowntype");
    }
}
Also used : AtomicOutputStream(org.apache.storm.blobstore.AtomicOutputStream) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 48 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class HdfsBlobStore method getBlobMeta.

@Override
public ReadableBlobMeta getBlobMeta(String key, Subject who) throws AuthorizationException, KeyNotFoundException {
    who = checkAndGetSubject(who);
    validateKey(key);
    SettableBlobMeta meta = extractBlobMeta(key);
    aclHandler.validateUserCanReadMeta(meta.get_acl(), who, key);
    ReadableBlobMeta rbm = new ReadableBlobMeta();
    rbm.set_settable(meta);
    try {
        BlobStoreFile pf = hbs.read(DATA_PREFIX + key);
        rbm.set_version(pf.getModTime());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return rbm;
}
Also used : BlobStoreFile(org.apache.storm.blobstore.BlobStoreFile) ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) IOException(java.io.IOException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 49 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class HdfsBlobStore method getStoredBlobMeta.

private SettableBlobMeta getStoredBlobMeta(String key) throws KeyNotFoundException {
    InputStream in = null;
    try {
        BlobStoreFile pf = hbs.read(META_PREFIX + key);
        try {
            in = pf.getInputStream();
        } catch (FileNotFoundException fnf) {
            throw new WrappedKeyNotFoundException(key);
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buffer = new byte[2048];
        int len;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }
        in.close();
        in = null;
        SettableBlobMeta blobMeta = Utils.thriftDeserialize(SettableBlobMeta.class, out.toByteArray());
        return blobMeta;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            // Ignored
            }
        }
    }
}
Also used : WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) BlobStoreFile(org.apache.storm.blobstore.BlobStoreFile) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 50 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class HdfsBlobStore method extractBlobMeta.

private SettableBlobMeta extractBlobMeta(String key) throws KeyNotFoundException {
    if (key == null) {
        throw new WrappedKeyNotFoundException("null can not be blob key");
    }
    SettableBlobMeta meta = cacheMetas.getIfPresent(key);
    if (meta == null) {
        meta = getStoredBlobMeta(key);
        cacheMetas.put(key, meta);
    }
    return meta;
}
Also used : WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Aggregations

SettableBlobMeta (org.apache.storm.generated.SettableBlobMeta)61 Test (org.junit.Test)20 ReadableBlobMeta (org.apache.storm.generated.ReadableBlobMeta)18 IOException (java.io.IOException)16 File (java.io.File)14 AccessControl (org.apache.storm.generated.AccessControl)12 AtomicOutputStream (org.apache.storm.blobstore.AtomicOutputStream)10 HashMap (java.util.HashMap)9 Subject (javax.security.auth.Subject)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 LocalAssignment (org.apache.storm.generated.LocalAssignment)7 TmpPath (org.apache.storm.testing.TmpPath)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BlobStore (org.apache.storm.blobstore.BlobStore)5 BlobStoreFile (org.apache.storm.blobstore.BlobStoreFile)5 FileInputStream (java.io.FileInputStream)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)3